-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSlackBuild.gen
492 lines (399 loc) · 10.8 KB
/
SlackBuild.gen
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
#!/bin/sh
##
## SlackBuild.gen - Script for generating SlackBuild files
## Copyright (c) 2004-2006 by Michal Nazarewicz (mina86/AT/mina86.com)
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, see <http://www.gnu.org/licenses/>.
##
## This is part of Tiny Applications Collection
## -> http://tinyapps.sourceforge.net/
##
set -e
umask 077
APP_VERSION=1.4
echo "SlackBuild Template Generator $APP_VERSION"
echo "Copyright (c) 2006 by Michal Nazarewicz (mina86/AT/mina86.com)"
echo
echo
##
## Reads variable
##
prompt () {
case "$1" in (*[!a-zA-Z_]*)
echo "prompt: $1: invalid variable name" >&2
exit 1
esac
while :; do
if [ -n "$3" ]
then printf '%s [%s]: ' "$2" "$3"
else printf '%s: ' "$2"
fi
read $1 || return 1
if eval [ -z \"\$$1\" ] && [ -n "$3" ]; then
eval "$1=\"\$3\""
break
fi
if [ -z "$4" ] || eval \"\$4\" \"\$$1\"; then break; fi
done
}
ask () {
case $2 in
(y|Y) set -- "$1" y '%s? [Y/n]: ' ;;
(n|N) set -- "$1" n '%s? [y/N]: ' ;;
(*) set -- "$1" '' '%s? [y/n]: ' ;;
esac
while :; do
printf "$3" "$1"
read __ASK || exit 1
[ -n "$__ASK" ] || __ASK="$2"
case $__ASK in
(y|Y) return 0 ;;
(n|N) return 1 ;;
esac
done
}
##
## Functions for checking variables
##
is_valid_non_empty () {
if [ -z "$1" ]; then
echo "Value must not be empty"
return 1
fi
return 0
}
is_valid_package_name () {
case "$1" in (*[!a-zA-Z0-9_-]*)
echo "Only letters, digits, underscores and hypens are allowed"
return 1
esac
return 0
}
is_valid_version () {
case "$1" in (*[!a-zA-Z0-9_.]*)
echo "Only letters, digits, underscores and dots are allowed"
return 1
esac
return 0
}
is_valid_build () {
if ! expr X"$1" : X'[0-9][0-9]*[a-zA-Z]*$' >/dev/null; then
echo "Build must be a number followed by optional, short seqence of letters"
return 1
fi
return 0
}
is_valid_arch () {
case "$1" in (*[!a-zA-Z0-9_.]*)
echo "Only letters, digits and underscores are allowed"
return 1
esac
return 0
}
##
## Escapes value
##
escape () {
if [ $# -eq 0 ]
then sed -e "s/'/'\\\\''/g"
else printf "%s" "$*" | sed -e "s/'/'\\\\''/g"
fi
}
##
## Temporary files
##
if which mktemp >/dev/null 2>&1; then
TMPFILE=$(mktemp -t SlackBuild.gen.XXXXXX)
elif which tempfile >/dev/null 2>&1; then
TMPFILE=$(tempfile -pSBgen)
else
echo unable to create temporary file, mktemp or tempfile required >&2
exit 1
fi
SLACKBUILD="$TMPFILE.sb"
exec 3>"$SLACKBUILD"
trap 'EC=$?; rm -f -- "$TMPFILE"* 2>/dev/null; return $EC' 0
##
## Read basic variables
##
prompt MAINTAINER "Your name and email address" '' is_valid_non_empty
prompt PKGNAME "Package name" '' is_valid_package_name
prompt VERSION "Package version" '' is_valid_version
prompt BUILD "Package build" 1X is_valid_build
prompt ARCH "Package architecture" i686 is_valid_arch
##
## Start of SlacBuild
##
cat <<EOF >&3
#!/bin/sh
##
## Generated by SlackBuild Template Generator ver $APP_VERSION
## by Michal Nazarwicz (mina86/AT/mina86.com)
## Generated at $(date -u +'%Y/%m/%d %H:%M:%S')
## Maintained by $MAINTAINER
##
set -e
## Basic info
PKGNAME='$(escape "$PKGNAME")'
VERSION='$(escape "$VERSION")'
BUILD='$(escape "$BUILD")'
ARCH='$(escape "$ARCH")'
## If you give a --download-dir=<dir> argument to this SlackBuild it
## will download all needed file to this given directory instead of
## some place in /tmp. This will greatly help if you have already
## downloaded all the required files since they won't be downloaded
## once again. Well, sort of -- this script uses wget -c option so it
## will connect to server an check if there is any more data to
## download. That should work most of the time but if server does not
## support ranges the file will most likely be downloaded once again.
## It's rather rare though.
DOWNLOAD_DIR=.
case \$1 in
(--download-dir=?*)
DOWNLOAD_DIR=\$(cd "\${1#*=}" && pwd || true)
if [ -z "$DOWNLOAD_DIR" ] || ! [ -d "$DOWNLOAD_DIR" ]; then
DOWNLOAD_DIR=.
fi
;;
(--download-dir)
DOWNLOAD_DIR=$(pwd)
;;
esac
## Temporary directory
CWD=$(pwd)
TMP="/tmp/\$PKGNAME-\$VERSION-\$ARCH-\$BUILD"
mkdir -p "\$TMP"
cd -- "\$TMP"
## Download and extract
if ! [ -d "\$PKGNAME-\$VERSION" ]; then
cd -- "\$DOWNLOAD_DIR"
EOF
##
## Download
##
echo; echo
echo 'Enter URLs of files which need to be downloaded (end with ^D):'
sed -ne 's/^[[:space:]]*|[[:space:]]*$//g' -e '/./ p' >>"$TMPFILE.urls"
while read URL; do
echo " wget -cO '$(escape "${URL##*/}")' '$(escape "$URL")'"
done <"$TMPFILE.urls" >&3
##
## Generate MD5 sums
##
echo; echo
if ! which md5sum >/dev/null 2>&1; then
echo 'You are missing md5sum! What are you running? Windows?'
else
echo "This script can generate MD5 sums for all the files which you've"
echo "specified for download. We strongly encourage you to make it do so as"
echo "it may help avoid potential problems."
if ask 'Do you want to generate MD5 sums' y; then
prompt DOWNLOAD_DIR "Download directory" "(auto)"
if [ X"$DOWNLOAD_DIR" = X"(auto)" ]; then
DOWNLOAD_DIR="$TMPFILE.ddir"
echo "Downloading to: $DOWNLOAD_DIR"
fi
echo "Files won't be removed after downloading"
: >"$TMPFILE.md5"
while read URL; do
wget -cO "${URL##*/}" "$URL"
md5sum -b -- "${URL##*/}" >>"$TMPFILE.md5"
done <"$TMPFILE.urls"
echo >&3
echo >&3
echo '# MD5 Checksums' >&3
echo 'cat <<EOF | md5sum -c - || exit $?' >&3
sed -e 's/\\\$`/\\&/g' <"$TMPFILE.md5" >&3
echo EOF >&3
rm -f -- "$TMPFILE.md5"
fi
fi
##
## Uncompress
##
echo ' cd -- "$TMP"' >&3
echo >&3
echo ' # Not to leave garbage' >&3
echo ' trap '\''rm -rf "$TMP/$PKGNAME-$VERSION"'\'' 0' >&3
echo >&3
if [ -z "$VISUAL" ] && [ -n "$EDITOR" ]; then VISUAL="$EDITOR"; fi
if [ -z "$VISUAL" ]; then VISUAL=vi; fi
cat <<EOF
Now, a small shell script handling all the downloaded files will be
generated. Then, you will be asked to verify this script and alter it
if that'll be required. Inside of this script you can use PKGNAME,
VERSION, BUILD and ARCH variables which have obvius meaning. Note
that it's your responsibility to make sure command won't change CWD at
the end (you can of course enter a directory and leave it afterwards).
Finally, note also that all the files should be extracted to
\$PKGNAME-\$VERSION directory.
( You'll edit the commands in $VISUAL. You can change this by
altering VISUAL variable priori to execution of the script. )
EOF
while read URL; do
echo "FILE='\$DOWNLOAD_DIR/$(escape "${URL##*/}")'"
case "$URL" in
(*.tar.bz2|*.tbz2|*.tbz) echo 'bzip2 -d <"$FILE" | tar vx' ;;
(*.tar.gz|*.tgz) echo 'gzip -d <"$FILE" | tar vx' ;;
(*.tar) echo 'tar vxf "$FILE"' ;;
(*.patch.bz2|*.diff.bz2)
echo 'cd -- "$PKGNAME-$VERSION"'
echo 'bzip2 -d <"../$FILE" | patch -p1'
echo 'cd ..'
;;
(*.patch.gz|*.diff.gz)
echo 'cd -- "$PKGNAME-$VERSION"'
echo 'gzip -d <"../$FILE" | patch -p1'
echo 'cd ..'
;;
(*.patch|*.diff)
echo 'cd -- "$PKGNAME-$VERSION"'
echo 'patch -p1 <"../$FILE"'
echo 'cd ..'
;;
(*) echo "# Don't know what to do with this one" ;;
esac
echo
done >"$TMPFILE.f" <"$TMPFILE.urls"
echo 'Press Enter to continue.'
read _
"$VISUAL" "$TMPFILE.f"
sed -e 's/[[:space:]]*$//' -e '/./ s/^/ /' <"$TMPFILE.f" >&3
rm -f -- "$TMPFILE.urls"
echo >&3
echo ' trap - 0' >&3
echo fi >&3
##
## Flags
##
echo
prompt CFLAGS CFLAGS "-O2 -march=$ARCH -pipe"
prompt CPPFLAGS CPPFLAGS
prompt CXXFLAGS CXXFLAGS "-O2 -march=$ARCH -pipe"
prompt LDFLAGS LDFLAGS
cat <<EOF >&3
# Compilation flags
CFLAGS='$(escape "$CFLAGS")'
CPPFLAGS'$(escape "$CPPFLAGS")'
CXXFLAGS'$(escape "$CXXFLAGS")'
LDFLAGS'$(escape "$LDFLAGS")'
export ARCH CFLAGS CPPFLAGS CXXFLAGS LDFLAGS
EOF
##
## Configure
##
if ask 'Does the application contain ./configure script' y; then
prompt CONFIGURE_OPT 'Options for ./configure' \
'--prefix=/usr --disable-debug --mandir=/usr/man --sysconfdir=/etc'
cat <<EOF >&3
# Compilation
cd -- "\$PKGNAME-\$VERSION"
if [ -f Makefile ]; then make clean; fi
./configure $CONFIGURE_OPT
make
make DESTDIR="\$PWD-\$ARCH-\$BUILD" install
EOF
else
prompt MAKE_OPT 'Options for make'
cat <<EOF >&3
# Compilation
cd -- "\$PKGNAME-\$VERSION"
make $MAKE_OPT
make DESTDIR="\$PWD-\$ARCH-\$BUILD" install
EOF
fi
##
## Description
##
R="|-----handy-ruler------------------------------------------------------|"
C="$PKGNAME"
while [ -n "$C" ]; do
R=" $R"
C="${C#?}"
done
(
echo "$R"
echo "$PKGNAME: $PKGNAME ( )"
for i in 1 2 3 4 5 6 7 8; do echo "$PKGNAME: "; done
echo "$PKGNAME: Package maintainer: $MAINTAINER"
) >"$TMPFILE.f"
"$VISUAL" "$TMPFILE.f"
echo 'cd -- "$PWD-$ARCH-$BUILD"' >&3
echo 'mkdir -p install' >&3
echo 'cat <<EOF >install/slack-desc' >&3
sed -ne '/:/ {' -e 's/[[:space:]]*$//' -e 's/\\\$`/\\&/g' -ep -e '}' \
<"$TMPFILE.f" >&3
echo EOF >&3
##
## Configuration files
##
echo
echo
echo "If this package provide any configuration files which need to be"
echo "renamed to *.new it's the time to type their names. All in single"
echo "line separated by white space."
prompt CONFIG "Configuration files"
if [ -n "$CONFIG" ]; then
echo
echo '# Configuration files'
cat <<END
cat <<EOF >>install/doinst.sh
NEW_CONFIG=
cfg () {
if ! [ -f "\$1" ]; then
mv -f -- "\$1.new" "\$1"
elif [ -r "\$1" ] && ! cmp "\$1" "\$1.new" >/dev/null 2>&1; then
rm -f -- "\$1.new"
else
NEW_CONFIG=yes
fi
}
END
set -- $CONFIG
while [ $# -ne 0 ]; do
FILE="${1#/}"
shift
echo "mv -f -- '$(escape "$1")' '$(escape "$1").new'"
echo "echo cfg '$(escape '$(escape "$1")')' >>install/doinst.sh"
done
fi >&3
##
## Finalization
##
cat <<EOF >&3
# Strip binaries and compress man and info pages
( find . -type f | xargs file | \
sed -ne 's/^\([^:]*\):.* ELF .*\(executable\|shared object\).*$/\1/p' | \
xargs strip --strip-unneeded 2>/dev/null )
( find . -path '*/man?/' -name '*.?' ! -name '*.Z' | xargs gzip -9 )
( find . -path '*/info/' -name '*.info' | xargs gzip -9 )
# Create Package
makepkg -l y -c n "\$CWD/\$PKGNAME-\$VERSION-\$ARCH-\$BUILD.tgz"
echo
echo
echo "######## Package \$PKGNAME-\$VERSION-\$ARCH-\$BUILD has been created ########"
echo "######## All files in \$TMP remain there. ########"
echo
echo
EOF
##
## Done
##
mv -f -- "$SLACKBUILD" "$PKGNAME-$VERSION-$ARCH-$BUILD.SlackBuild"
echo
echo
echo "SlackBuild template saved in $PKGNAME-$VERSION-$ARCH-$BUILD.SlackBuild"
echo "Press Enter to review it in $VISUAL."
read _
exec "$VISUAL" "$PKGNAME-$VERSION-$ARCH-$BUILD.SlackBuild"