forked from willtrnr/capman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mutiny.sh
executable file
·153 lines (133 loc) · 4.3 KB
/
mutiny.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#! /usr/bin/env bash
set -e
source common.sh
# Check proper usage
crewname="$1"
if [ -z "$crewname" ]; then
printf "Usage: %s <crew package>" "$0"
exit 1
fi
# Verify the package exists in crew
crewpkg="$CREW_PKG_PATH/$crewname.rb"
if [ ! -f "$crewpkg" ]; then
error "Unknown package: %s" "$crewname"
exit 1
fi
msg "Parsing the crew package file..."
pkgname="$(sanitize_name "$crewname")"
depends=()
makedepends=()
# Line by line we try to extract the fields that are useful to us
_in_sources=0
_in_sums=0
while read -r line; do
case $line in
description*)
pkgdesc="$(echo "$line" | sed -E "s/^.*description.*['\"](.+)['\"].*$/\1/")"
;;
homepage*)
url="$(echo "$line" | sed -E "s/^.*homepage.*['\"](.+)['\"].*$/\1/")"
;;
version*)
crewver="$(echo "$line" | sed -E "s/^.*version.*['\"](.+)['\"].*$/\1/")"
;;
binary_url*)
_in_sources=1
_in_sums=0
;;
binary_sha256*)
_in_sums=1
_in_sources=0
;;
x86_64*)
if [ $_in_sources -eq 1 ]; then
binary_url="\"$(echo "$line" | sed -E "s/^.*:.*['\"](.+)['\"].*$/\1/")\""
elif [ $_in_sums -eq 1 ]; then
binary_sha256="'$(echo "$line" | sed -E "s/^.*:.*['\"](.+)['\"].*$/\1/")'"
fi
;;
'})')
_in_sources=0
_in_sums=0
;;
depends_on*)
name="$(sanitize_name "$(echo "$line" | sed -E "s/^[^'\"]*['\"]([^'\"]+)['\"].*$/\1/")")"
if [[ "$line" == *:build* ]]; then
makedepends+=("'$name'")
else
depends+=("'$name'")
fi
;;
esac
done < "$crewpkg"
# Crew sometimes have pkgrels embedded in the version number
pkgver="$(sanitize_ver "$crewver")"
pkgrel="$(sanitize_rel "$crewver")"
if [ -e "$MUTINY_OVERRIDE_PATH/$crewname" ]; then
source "$MUTINY_OVERRIDE_PATH/$crewname"
fi
msg "Fetching Arch package details for %s..." "$pkgname"
# Find the package using exact name match on the Arch repository API
if (curl -s "https://www.archlinux.org/packages/search/json/?name=$pkgname" | jq -e -r '.results[0]' > "/tmp/$pkgname.json" 2> /dev/null); then
# Extract and possibly override the info we have so far
pkgdesc="$(jq -r '.pkgdesc' "/tmp/$pkgname.json")"
url="$(jq -r '.url' "/tmp/$pkgname.json")"
licenses="$(jq -r '.licenses | map("'"'"'" + . + "'"'"'") | join(" ")' "/tmp/$pkgname.json")"
groups="$(jq -r '.groups | map("'"'"'" + . + "'"'"'") | join(" ")' "/tmp/$pkgname.json")"
# unset depends
# depends="$(jq -r '.depends | map("'"'"'" + . + "'"'"'") | join(" ")' "/tmp/$pkgname.json")"
# unset makedepends
# makedepends="$(jq -r '.makedepends | map("'"'"'" + . + "'"'"'") | join(" ")' "/tmp/$pkgname.json")"
# optdepends="$(jq -r '.optdepends | map("'"'"'" + . + "'"'"'") | join("\n ")' "/tmp/$pkgname.json")"
# provides="$(jq -r '.provides | map("'"'"'" + . + "'"'"'") | join(" ")' "/tmp/$pkgname.json")"
# conflicts="$(jq -r '.conflicts | map("'"'"'" + . + "'"'"'") | join(" ")' "/tmp/$pkgname.json")"
# replaces="$(jq -r '.replaces | map("'"'"'" + . + "'"'"'") | join(" ")' "/tmp/$pkgname.json")"
else
# We'll produce the package as-is
warning "No equivalent package found, will use crew information."
fi
rm -f "/tmp/$pkgname.json"
destdir="$MUTINY_PKG_PATH/$pkgname"
msg "Writing the new PKGBUILD to %s..." "$destdir"
if [ -z "$binary_url" ]; then
warning "No binary package is available, will build from sources."
options=('staticlibs')
build="
build() {
yes | crew build "$crewname"
tar xf \"$crewname-$crewver-chromeos-\$arch.tar.xz\"
}
"
else
# If we're using binaries we don't need makedepends
unset makedepends
# However we need to make sure the package is kept mostly as-is
options=('!strip' 'staticlibs' '!zipman' '!purge')
fi
mkdir -p "$destdir"
cat > "$destdir/PKGBUILD" <<EOF
# Maintainer: $(git config --get user.name) <$(git config --get user.email)>
pkgname=$pkgname
pkgver=$pkgver
pkgrel=$pkgrel
pkgdesc="$pkgdesc"
arch=('x86_64')
url="$url"
license=(${licenses:-'custom'})
groups=($groups)
depends=(${depends[@]})
makedepends=(${makedepends[@]})
optdepends=($optdepends)
provides=($provides)
conflicts=($conflicts)
replaces=($replaces)
options=(${options[@]})
source=($binary_url)
sha256sums=($binary_sha256)
$build
package() {
install -d -m 0755 "\$pkgdir/usr"
cp -a usr/local "\$pkgdir/usr"
rm -f "\$pkgdir/usr/local/share/info/dir"{,.gz}
}
EOF