-
Notifications
You must be signed in to change notification settings - Fork 3
/
newpkg
executable file
·216 lines (193 loc) · 3.96 KB
/
newpkg
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/sh
usage()
{
echo "usage: $(basename $0) [-f] pack [version]" >&2
}
geturl()
{
if ! wget --quiet -O "$1" "$2"
then
echo "error: download failed: $2"
fi
}
sedesc()
{
echo "$1" | sed -e 's/\(\&\|\.\|\/\|\*\|\[\|\]\|\\\)/\\&/g'
}
octave_to_arch_license()
{
case "$1" in
"GPL version 2")
echo GPL2
;;
"GPL version 2 or later" | "GPLv2+")
echo GPL
;;
"GPL version 3" | "GPL version 3 or later" | "GPLv3+")
echo GPL3
;;
GFDL)
echo FDL
;;
BSD | GPL | GPL2 | GPL3 | LGPL)
echo "$1"
;;
*)
return 1
;;
esac
return 0
}
try_convert()
{
echo "$1" |
sed -e 's/(see\( individual\)\? files)//' -e 's/ and /\n/g' |
{
first=true
while read octlic
do
archlic=$(octave_to_arch_license "$octlic") || return 1
$first || echo -n " "
echo -n "'$archlic'"
first=false
done
}
}
force=
while test $# -gt 0
do
case $1 in
-f)
force=t
;;
*)
break
;;
esac
shift
done
if test $# -lt 1 -o $# -gt 2
then
usage
exit 1
fi
_pack=$1
pkgname=octave-$_pack
version=$2
if test -z "$version"
then
version=$(
geturl - "http://octave.sourceforge.net/$_pack/index.html" |
sed -n 's/.*Package Version:.*<td>\([^<]\+\)<\/td>.*/\1/p' |
head -1
)
fi
if test -z "$version"
then
echo "error: could not determine package version" >&2
exit 1
fi
if test -z "$force" -a -e "$pkgname"
then
echo "error: directory already exists: $pkgname" >&2
exit 1
fi
mkdir -p "$pkgname"
cp PKGBUILD.source "$pkgname/PKGBUILD"
cp octave-pkgname.install "$pkgname/$pkgname.install"
cd "$pkgname"
_archive=$_pack-$version.tar.gz
if ! geturl "$_archive" "http://downloads.sourceforge.net/octave/$_archive"
then
exit 1
fi
get_dep() {
assume_octave=
optional=
while test $# -gt 0
do
case $1 in
--octave)
assume_octave=YesPlease
;;
--optional)
optional=YesPlease
;;
*)
break
;;
esac
shift
done
label="$1"
sed -n "s/^$label: //p" |
sed 's/, /\n/g' |
{
first=true
while read package version
do
if printf "%s" "$package" | grep -qi "^octave$"
then
package=octave
elif test -n "$assume_octave"
then
package=octave-$package
else
# Arch puts header files with the regular
# package.
package=$(echo "$package" | sed 's/-dev\(el\)\?$//')
fi
if echo "$version" | grep -q '\<optional\>'
then
test -n "$optional" || continue
else
test -z "$optional" || continue
fi
$first || echo -n " "
echo -n "'$package $version'" | sed 's/ (\?optional)\?//g; s/[ ()]//g'
first=false
done
}
}
dfile=$(
tar tzf "$_archive" |
grep "^[^/]*\(/\)\?\<DESCRIPTION$" |
head -n 1
)
dcontent=$(tar xzfO "$_archive" "$dfile" | sed 's/\r*$//')
description=$(
echo "$dcontent" |
sed -n 's/^Description: //; ta; d; :a; H; n; /^ / ba; g; s/\n//gp'
)
depends=$(echo "$dcontent" | get_dep --octave Depends)
requires_pattern='\(BuildRequires\|SystemRequirements\)';
makedepends=$(echo "$dcontent" | get_dep "$requires_pattern")
optdepends=$(echo "$dcontent" | get_dep --optional "$requires_pattern")
license=$(echo "$dcontent" | sed -n 's/^License: //p')
md5sum=$(md5sum "$_archive" | cut -f1 -d' ')
if ! archlicense="$(try_convert "$license")"
then
archlicense="'custom'"
fi
echo "version: $version"
echo "depends: $depends"
test -n "$makedepends" && echo "makedepends: $makedepends"
test -n "$optdepends" && echo "optdepends: $optdepends"
echo "license: $archlicense ($license)"
# Truncate to maximum description length allowed by AUR
limit=255
if test $(echo -n "$description" | wc -c) -gt "$limit"
then
description=$(echo "$description" | cut -b 1-"$(($limit-6))")
description="$description [...]"
fi
sed \
-e "s#@@NAME@@#$(sedesc "$_pack")#g" \
-e "s#@@VERSION@@#$(sedesc "$version")#g" \
-e "s#@@DESCRIPTION@@#$(sedesc "$description")#g" \
-e "s#@@LICENSE@@#$(sedesc "$archlicense")#g" \
-e "s#@@DEPENDS@@#$(sedesc "$depends")#g" \
-e "s#@@MAKEDEPENDS@@#$(sedesc "$makedepends")#g" \
-e "s#@@OPTDEPENDS@@#$(sedesc "$optdepends")#g" \
-e "s#@@MD5SUMS@@#$(sedesc "$md5sum")#g" \
-i PKGBUILD "$pkgname.install"