-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelper
executable file
·581 lines (514 loc) · 11.7 KB
/
helper
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
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
#!/bin/sh
# $0 kernel size [initrd]
init()
{
[ "$(ls -t pkgs | sed q)" = "files.list.lzma" ] ||
for i in pkgs/*/receipt ; do
. $i
sed "s/^/$PACKAGE: /" $(dirname $i)/files.list
done | lzma e pkgs/files.list.lzma -si
}
list_pkgs()
{
TMPDIR=$2
shift 2
cat <<EOT
<div class="large">
<table>
<thead>
<tr>
<th> </th>
<th>Package</th>
<th>Version</th>
<th>Description</th>
<th>Disk</th>
<th>Memory</th>
<th> </th>
</tr>
</thead>
<tbody>
EOT
unlzma < $TMPDIR/pkgs/linux-[2-9]*/fs.cpio.lzma | \
( cd $TMPDIR/fs ; cpio -idmu boot/config-busybox )
for i in $TMPDIR/pkgs/*/receipt pkgs/*/receipt; do
[ -s $i ] || continue
case "$i" in
pkgs/kernel-*/receipt) continue;;
pkgs/module-*/receipt) continue;;
esac
AUTO_SELECTION=''
UNPACKED_SIZE='-'
PACKED_SIZE='-'
checked=''; hidden_var=''
GROUP=
CATEGORY=
. $i
[ "$GROUP" ] || GROUP="$CATEGORY"
case " $@ " in
*\ $PACKAGE\ *) checked='checked="checked"';;
*) [ -n "$2" ] && checked="";;
esac
grep -qs "^$PACKAGE " $TMPDIR/uploadconf &&
checked='checked="checked"'
case "$AUTO_SELECTION" in
never)
continue;;
always)
checked='checked="checked" disabled'
hidden_var="<input type=\"hidden\" name=\"selected[]\" value=\"$PACKAGE\" />";;
CONF*)
grep -qs "^$AUTO_SELECTION=y$" $TMPDIR/fs/boot/config-busybox ||
checked='disabled';;
esac
cat <<EOT
<!-- $GROUP -->
<tr>
<td>$hidden_var
<input type="checkbox" name="selected[]" value="$PACKAGE" $checked /></td>
<td><a href="?dl=$PACKAGE-$VERSION&tmp=$TMPDIR">$PACKAGE</a></td>
<td>$VERSION</td>
<td>$SHORT_DESC</td>
<td>$PACKED_SIZE</td>
<td>$UNPACKED_SIZE</td>
<td>$(grep -qs ^config_form $i && echo '»')</td>
</tr>
EOT
done
cat <<EOT
</tbody>
</table>
</div>
EOT
exit
}
list_kernels()
{
TMPDIR=$2
shift 2
cat <<EOT
<div class="large">
<table>
<thead>
<tr>
<th> </th>
<th>Kernel</th>
<th>Version</th>
<th>Description</th>
<!-- th>Size</th -->
</tr>
</thead>
<tbody>
EOT
checked='checked="checked"'
for i in $TMPDIR/pkgs/*/receipt pkgs/*/receipt ; do
[ -s $i ] || continue
case "$i" in
pkgs/kernel-*/receipt);;
*) continue;;
esac
UNPACKED_SIZE="-"
. $i
case " $@ " in
*\ $PACKAGE\ *) checked='checked="checked"' ;;
*) [ -n "$2" ] && checked="";;
esac
cat <<EOT
<tr>
<td><input type="radio" name="kernel" value="$PACKAGE" $checked/></td>
<td>${PACKAGE#kernel-}</td>
<td>$VERSION</td>
<td>$SHORT_DESC</td>
<!-- td>$UNPACKED_SIZE</td -->
</tr>
EOT
checked=""
done
cat <<EOT
</tbody>
</table>
</div>
EOT
exit
}
list_modules()
{
TMPDIR=$2
shift 2
cat <<EOT
<input type="hidden" name="selected[]" value="" />
<div class="large">
<table>
<thead>
<tr>
<th> </th>
<th>Module</th>
<th>Version</th>
<th>Description</th>
<th>Disk</th>
<th>Memory</th>
<th> </th>
</tr>
</thead>
<tbody>
EOT
for i in $TMPDIR/pkgs/*/receipt pkgs/*/receipt ; do
[ -s $i ] || continue
case "$i" in
pkgs/module-*/receipt);;
*) continue;;
esac
GROUP=
CATEGORY=
UNPACKED_SIZE='-'
. $i
[ "$GROUP" ] || GROUP="$CATEGORY"
checked=''
case " $@ " in
*\ $PACKAGE\ *) checked='checked="checked"' ;;
esac
grep -qs "^$PACKAGE " $TMPDIR/uploadconf &&
checked='checked="checked"'
cat <<EOT
<!-- $GROUP -->
<tr>
<td><input type="checkbox" name="selected[]" value="$PACKAGE" $checked/></td>
<td><a href="?dl=$PACKAGE-$VERSION&tmp=$TMPDIR">${PACKAGE#module-}</a></td>
<td>$VERSION</td>
<td>$SHORT_DESC</td>
<td>$PACKED_SIZE</td>
<td>$UNPACKED_SIZE</td>
<td>$(grep -qs ^config_form $i && echo '»')</td>
</tr>
EOT
done
cat <<EOT
</tbody>
</table>
</div>
EOT
exit
}
get_receipt()
{
grep -l "PACKAGE=\"$1\"" $2/pkgs/*/receipt pkgs/*/receipt | head -1
}
list_suggested()
{
local pkg
pkg=pkgs/$1/receipt
TMPDIR=$2
[ -s $pkg ] || pkg=$TMPDIR/pkgs/$1/receipt
[ -s $pkg ] || pkg=$(get_receipt $@)
SUGGESTED=
. $pkg
SUGG=
for i in $SUGGESTED; do
case " $@ " in
*\ $i\ *);;
*) SUGG="$SUGG $i";;
esac
done
if [ "$SUGG" ]; then
cat <<EOT
<hr />
<p>
You may want to install the following package(s) too:
</p>
<input type="hidden" name="EXTRA_SUGGESTED" value="$SUGG" />
<div class="large">
<table>
<thead>
<tr>
<th> </th>
<th>Package</th>
<th>Version</th>
<th>Description</th>
<th>Disk</th>
<th>Memory</th>
<th> </th>
</tr>
</thead>
<tbody>
EOT
checked='checked="checked" '
[ $TMPDIR/uploadconf ] && checked=
for i in $SUGG; do
i=$(grep -l "PACKAGE=\"$i\"" pkgs/*/receipt)
. $i
cat <<EOT
<!-- $GROUP -->
<tr>
<td><input type="checkbox" name="suggested[]" value="$PACKAGE" $checked /></td>
<td><a href="?dl=$PACKAGE-$VERSION&tmp=$TMPDIR">$PACKAGE</a></td>
<td>$VERSION</td>
<td>$SHORT_DESC</td>
<td>$PACKED_SIZE</td>
<td>$UNPACKED_SIZE</td>
<td>$(grep -qs ^config_form $i && echo '»')</td>
</tr>
EOT
done
cat <<EOT
</tbody>
</table>
</div>
EOT
fi
}
get_package()
{
local pkg
pkg=pkgs/$1/receipt
[ -s $pkg ] || pkg=$2/pkgs/$1/receipt
[ -s $pkg ] || pkg=$(get_receipt $@)
. $pkg
cd $(dirname $pkg)
pkg=$2$PACKAGE-$VERSION.tazpkg
find * | cpio -o -H newc > $pkg
echo -n $pkg
}
get_note()
{
pkg=$(get_receipt $1 $2)
[ -n "$pkg" ] || exit
grep -qs ^config_note $pkg || exit
. $pkg
config_note
}
get_form()
{
pkg=$(get_receipt $1 $2)
[ -n "$pkg" ] || exit
grep -qs ^config_form $pkg || exit
. $pkg
if [ -s $2/uploadconf ]; then
awk "{
if (found) {
if (/^ /) print;
else exit;
}
if (/^$PACKAGE /) found=1
}" < $2/uploadconf | sed -e 's/ //' -e 's/ \([A-Z_0-9]*=\)/export \1/' > $2/vars
. $2/vars
fi
config_form $2/fs
exit
}
do_pre_install()
{
pkg=$(get_receipt $1 $2)
[ -n "$pkg" ] || exit
CONFIG_FILES=""
. $pkg
grep -qs ^pre_install $pkg && pre_install $2/fs
[ -n "$CONFIG_FILES" ] && for i in $CONFIG_FILES; do echo $i >> $2/config_files; done
unlzma < $(dirname $pkg)/fs.cpio.lzma | ( cd $2 ; cpio -idmu )
exit
}
do_post_install()
{
pkg=$(get_receipt $1 $2)
[ -n "$pkg" ] || exit
. $pkg
[ -d $2/fs/etc ] || mkdir -p $2/fs/etc
echo "$1 $VERSION $(md5sum $(dirname $pkg)/fs.cpio.lzma | awk '{ print $1 }')" >> $2/fs/etc/packages.conf
if grep -qs ^post_install $pkg; then
[ -s $2/vars ] && . $2/vars
echo "=== $pkg: $(date) ===" >> $2/post_install.log 2>&1
post_install $2/fs >> $2/post_install.log 2>&1
sed -e 's/^export/ /' -e 's/^/ /' -e '/^ suggested=/d' -e '/EXTRA_SUGGESTED=/d' \
< $2/vars >> $2/fs/etc/packages.conf
fi
rm -f $2/vars
exit
}
scan_depends()
{
local pkg
for pkg in $@ ; do
case " $OUTPUT " in
*\ $pkg\ *) continue ;;
esac
DEPENDS=""
. $(get_receipt $pkg $TMPDIR)
scan_depends $DEPENDS
case " $OUTPUT " in
*\ $pkg\ *) continue ;;
esac
OUTPUT="$OUTPUT $pkg"
done
}
get_depends()
{
TMPDIR=$2
shift 2
OUTPUT=""
scan_depends $@
echo -n $OUTPUT
exit
}
pkgs_extract()
{
cd $2
mkdir pkgs
if cpio -t < $1 | grep -q receipt; then
mv $1 pkgs
elif tar tf $1 | grep -q tazpkg; then
tar xf $1 -C pkgs
elif tar tzf $1 | grep -q tazpkg; then
tar xzf $1 -C pkgs
elif tar tjf $1 | grep -q tazpkg; then
tar xjf $1 -C pkgs
else
rm -rf $1 pkgs
exit
fi
cd pkgs
for i in *; do
mkdir tmp
cd tmp
cpio -i < ../$i
. ./receipt
cd ..
mv tmp $PACKAGE-$VERSION
done
exit
}
boot_files()
{
[ -s $1/fs/boot/bootmenu ] && while read bin button text; do
cat <<EOT
<input name="download" value="${button%%,*} ($(du -h \
$1/fs/boot/$bin | awk '{ printf "%s",$1 }'))" type="submit" title="$text" />
EOT
done < $1/fs/boot/bootmenu
}
lzma_set_size()
{
n=$(unlzma < $1 | wc -c)
for i in $(seq 1 8); do
printf '\\\\x%02X' $(($n & 255))
n=$(($n >> 8))
done | xargs echo -en | dd of=$1 conv=notrunc bs=1 seek=5 2> /dev/null
}
compressto()
{
[ "$(which zopfli 2> /dev/null)" ] &&
zopfli --i100 -c /dev/stdin > $1 || gzip -9 > $1
[ "$(which advdef 2> /dev/null)" ] && advdef -z4 $1 > /dev/null
}
case "$1" in
--list-modules) list_modules $@ ;;
--list-kernels) list_kernels $@ ;;
--list-pkgs) list_pkgs $@ ;;
--get-form) get_form $2 $3 ;;
--get-note) get_note $2 $3 ;;
--pre-install) do_pre_install $2 $3 ;;
--post-install) do_post_install $2 $3 ;;
--depends) get_depends $@ ;;
--pkgs-extract) pkgs_extract $2 $3 ;;
--remove) rm -rf $2; exit ;;
--get-pkg) get_package $2 $3 ;;
--list-suggested) list_suggested $2 $3 $@ ;;
--init) init ;;
--boot-files) boot_files $2 ;;
esac
if [ "x$1" = "x--mkrootfs" ]; then
tmp=$2
cd $tmp/fs
[ -s boot/mkrootfs.pre_exec ] && sh boot/mkrootfs.pre_exec
if [ ! -d boot -a -s ../kernel ]; then # custom kernel
mkdir boot
cp ../kernel boot/bzImage
fi
find -user bellard -exec chown root.root {} \;
find | grep -v ^./boot | cpio -o -H newc | compressto ../rootfs.gz
fi
if [ "x$1" = "x--mkiso" ]; then
tmp=$2
mkdir -p $tmp/iso/boot/isolinux $tmp/iso/data
cat $tmp/fs/boot/System.map | compressto $tmp/iso/data/sysmap.gz
cat $tmp/fs/boot/config | compressto $tmp/iso/data/linconf.gz
cat $tmp/fs/boot/config-busybox | compressto $tmp/iso/data/bbconf.gz
cp $tmp/fs/boot/bundle $tmp/iso/data/bundle.sh
cat $tmp/post_install.log | compressto $tmp/iso/data/log.gz
cp $tmp/config_files $tmp/iso/data/files.cnf
cp $tmp/fs/etc/packages.conf $tmp/iso/data/packages.cnf
[ -s wok/busybox/receipt ] && tar czf $tmp/iso/data/wok.tgz wok/*
[ -s www/index.php ] && tar czf $tmp/iso/data/www.tgz www/*
cp $tmp/fs/boot/bzImage $tmp/iso/boot/bzImage
cp $tmp/rootfs.gz $tmp/iso/boot/rootfs
cp /boot/isolinux/isolinux.bin $tmp/iso/boot/isolinux
cat > $tmp/iso/boot/isolinux/isolinux.cfg <<EOT
label slitaz slitqw
kernel /boot/bzImage
append initrd=/boot/rootfs rw root=/dev/null vga=normal
EOT
[ -s $tmp/fs/boot/bootmenu ] && while read bin keys text; do
keys=${keys#*,}
KEY="$KEY ${keys%%,*}"
cp $tmp/fs/boot/$bin $tmp/iso/boot/$bin
cat >> $tmp/iso/boot/isolinux/isolinux.cfg <<EOT
label ${keys//,/ } $bin
kernel /boot/$bin
EOT
done < $tmp/fs/boot/bootmenu
[ "$KEY" ] && echo "say You can boot: slitaz (default)$KEY" >> \
$tmp/iso/boot/isolinux/isolinux.cfg
cat >> $tmp/iso/boot/isolinux/isolinux.cfg <<EOT
default slitaz
implicit 0
prompt 1
timeout 50
EOT
genisoimage -o $tmp/slitaz.iso -b boot/isolinux/isolinux.bin \
-c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
-V "Tiny SliTaz" -p "www.slitaz.org" -input-charset iso8859-1 \
-boot-info-table $tmp/iso > /dev/null 2>&1
[ -x /usr/bin/isohybrid ] &&
/usr/bin/isohybrid $tmp/slitaz.iso 2> /dev/null
[ -x /usr/bin/iso2exe ] &&
/usr/bin/iso2exe $tmp/slitaz.iso 2> /dev/null
fi
if [ "x$1" = "x--mkexe" ]; then
tmp=$2
cd $tmp
cp fs/boot/bzImage slitaz.exe
sh fs/boot/bundle slitaz.exe rootfs.gz
fi
if [ "x$1" = "x--mkimg" ]; then
tmp=$2
cd $tmp
if [ ! -s out ]; then
cp fs/boot/bzImage slitaz.img
sh fs/boot/bundle slitaz.img rootfs.gz
if [ -s fs/boot/bootmenu ]; then
echo -n "sh fs/boot/bundle out ' SliTaz boot menu'"
echo -n " slitaz.img 'Tiny SliTaz'"
while read bin button text; do
echo -n " fs/boot/$bin '${text% (*}'"
done < fs/boot/bootmenu
fi | sh
[ -s out ] || mv slitaz.img out
fi
rm -f xa* 2> /dev/null
split -b ${3:-1474560} out
A="-abcdefghijklmnopqrstuvwxyz"
mv xa${A:${4:-1}:1} floppy$4.img || mv xaa floppy1.img
[ $(stat -c %s floppy${4:-1}.img) -lt ${3:-1474560} ] &&
dd of=floppy${4:-1}.img bs=1 seek=${3:-1474560} count=0 2> /dev/null
fi
if [ "x$1" = "x--mkcfg" ]; then
tmp=$2
cd $tmp/fs
for i in $(sed 's#^/##' < ../config_files); do find $i; done | \
sort | uniq | cpio -o -H newc | compressto ../config_files.cpio.gz
fi
if [ "x$1" = "x--chkdist" ]; then
if [ pkgs/busybox-*/fs.cpio.lzma -nt dist/rootfs.cpio ]; then
cat pkgs/busybox-*/fs.cpio.lzma | unlzma | ( cd dist ; cpio -idmu )
mv -f dist/fs/* dist/
rmdir dist/fs
touch dist/*
fi
fi