tiny-slitaz view helper @ rev 27

Multi floppy support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Sep 17 08:38:04 2019 +0200 (2019-09-17)
parents 406c6fe80674
children 26423b57df46
line source
1 #!/bin/sh
2 # $0 kernel size [initrd]
4 init()
5 {
6 [ "$(ls -t pkgs | sed q)" = "files.list.lzma" ] ||
7 for i in pkgs/*/receipt ; do
8 . $i
9 sed "s/^/$PACKAGE: /" $(dirname $i)/files.list
10 done | lzma e pkgs/files.list.lzma -si
11 }
16 list_pkgs()
17 {
18 TMPDIR=$2
19 shift 2
20 cat <<EOT
21 <div class="large">
22 <table>
23 <thead>
24 <tr>
25 <th> </th>
26 <th>Package</th>
27 <th>Version</th>
28 <th>Description</th>
29 <th>Disk</th>
30 <th>Memory</th>
31 <th> </th>
32 </tr>
33 </thead>
34 <tbody>
35 EOT
36 unlzma < $TMPDIR/pkgs/linux-[2-9]*/fs.cpio.lzma | \
37 ( cd $TMPDIR/fs ; cpio -idmu boot/config-busybox )
38 for i in $TMPDIR/pkgs/*/receipt pkgs/*/receipt; do
39 [ -s $i ] || continue
40 case "$i" in
41 pkgs/kernel-*/receipt) continue;;
42 pkgs/module-*/receipt) continue;;
43 esac
44 AUTO_SELECTION=''
45 UNPACKED_SIZE='-'
46 PACKED_SIZE='-'
47 checked=''; hidden_var=''
48 GROUP=
49 CATEGORY=
50 . $i
51 [ "$GROUP" ] || GROUP="$CATEGORY"
52 case " $@ " in
53 *\ $PACKAGE\ *) checked='checked="checked"';;
54 *) [ -n "$2" ] && checked="";;
55 esac
56 grep -qs "^$PACKAGE " $TMPDIR/uploadconf &&
57 checked='checked="checked"'
58 case "$AUTO_SELECTION" in
59 never)
60 continue;;
61 always)
62 checked='checked="checked" disabled'
63 hidden_var="<input type=\"hidden\" name=\"selected[]\" value=\"$PACKAGE\" />";;
64 CONF*)
65 grep -qs "^$AUTO_SELECTION=y$" $TMPDIR/fs/boot/config-busybox ||
66 checked='disabled';;
67 esac
68 cat <<EOT
69 <!-- $GROUP -->
70 <tr>
71 <td>$hidden_var
72 <input type="checkbox" name="selected[]" value="$PACKAGE" $checked /></td>
73 <td><a href="?dl=$PACKAGE-$VERSION&amp;tmp=$TMPDIR">$PACKAGE</a></td>
74 <td>$VERSION</td>
75 <td>$SHORT_DESC</td>
76 <td>$PACKED_SIZE</td>
77 <td>$UNPACKED_SIZE</td>
78 <td>$(grep -qs ^config_form $i && echo '&raquo;')</td>
79 </tr>
80 EOT
81 done
82 cat <<EOT
83 </tbody>
84 </table>
85 </div>
86 EOT
87 exit
88 }
93 list_kernels()
94 {
95 TMPDIR=$2
96 shift 2
97 cat <<EOT
98 <div class="large">
99 <table>
100 <thead>
101 <tr>
102 <th> </th>
103 <th>Kernel</th>
104 <th>Version</th>
105 <th>Description</th>
106 <!-- th>Size</th -->
107 </tr>
108 </thead>
109 <tbody>
110 EOT
111 checked='checked="checked"'
112 for i in $TMPDIR/pkgs/*/receipt pkgs/*/receipt ; do
113 [ -s $i ] || continue
114 case "$i" in
115 pkgs/kernel-*/receipt);;
116 *) continue;;
117 esac
118 UNPACKED_SIZE="-"
119 . $i
120 case " $@ " in
121 *\ $PACKAGE\ *) checked='checked="checked"' ;;
122 *) [ -n "$2" ] && checked="";;
123 esac
124 cat <<EOT
125 <tr>
126 <td><input type="radio" name="kernel" value="$PACKAGE" $checked/></td>
127 <td>${PACKAGE#kernel-}</td>
128 <td>$VERSION</td>
129 <td>$SHORT_DESC</td>
130 <!-- td>$UNPACKED_SIZE</td -->
131 </tr>
132 EOT
133 checked=""
134 done
135 cat <<EOT
136 </tbody>
137 </table>
138 </div>
139 EOT
140 exit
141 }
146 list_modules()
147 {
148 TMPDIR=$2
149 shift 2
150 cat <<EOT
151 <input type="hidden" name="selected[]" value="" />
152 <div class="large">
153 <table>
154 <thead>
155 <tr>
156 <th> </th>
157 <th>Module</th>
158 <th>Version</th>
159 <th>Description</th>
160 <th>Disk</th>
161 <th>Memory</th>
162 <th> </th>
163 </tr>
164 </thead>
165 <tbody>
166 EOT
167 for i in $TMPDIR/pkgs/*/receipt pkgs/*/receipt ; do
168 [ -s $i ] || continue
169 case "$i" in
170 pkgs/module-*/receipt);;
171 *) continue;;
172 esac
173 GROUP=
174 CATEGORY=
175 UNPACKED_SIZE='-'
176 . $i
177 [ "$GROUP" ] || GROUP="$CATEGORY"
178 checked=''
179 case " $@ " in
180 *\ $PACKAGE\ *) checked='checked="checked"' ;;
181 esac
182 grep -qs "^$PACKAGE " $TMPDIR/uploadconf &&
183 checked='checked="checked"'
184 cat <<EOT
185 <!-- $GROUP -->
186 <tr>
187 <td><input type="checkbox" name="selected[]" value="$PACKAGE" $checked/></td>
188 <td><a href="?dl=$PACKAGE-$VERSION&amp;tmp=$TMPDIR">${PACKAGE#module-}</a></td>
189 <td>$VERSION</td>
190 <td>$SHORT_DESC</td>
191 <td>$PACKED_SIZE</td>
192 <td>$UNPACKED_SIZE</td>
193 <td>$(grep -qs ^config_form $i && echo '&raquo;')</td>
194 </tr>
195 EOT
196 done
197 cat <<EOT
198 </tbody>
199 </table>
200 </div>
201 EOT
202 exit
203 }
208 get_receipt()
209 {
210 grep -l "PACKAGE=\"$1\"" $2/pkgs/*/receipt pkgs/*/receipt | head -1
211 }
216 get_suggested()
217 {
218 local pkg
219 pkg=pkgs/$1/receipt
220 [ -s $pkg ] || pkg=$2/pkgs/$1/receipt
221 [ -s $pkg ] || pkg=$(get_receipt $@)
222 . $pkg
223 echo -n $SUGGESTED
224 }
229 get_package()
230 {
231 local pkg
232 pkg=pkgs/$1/receipt
233 [ -s $pkg ] || pkg=$2/pkgs/$1/receipt
234 [ -s $pkg ] || pkg=$(get_receipt $@)
235 . $pkg
236 cd $(dirname $pkg)
237 pkg=$2$PACKAGE-$VERSION.tazpkg
238 find * | cpio -o -H newc > $pkg
239 echo -n $pkg
240 }
245 get_note()
246 {
247 pkg=$(get_receipt $1 $2)
248 [ -n "$pkg" ] || exit
249 grep -qs ^config_note $pkg || exit
250 . $pkg
251 config_note
252 }
257 get_form()
258 {
259 pkg=$(get_receipt $1 $2)
260 [ -n "$pkg" ] || exit
261 grep -qs ^config_form $pkg || exit
262 . $pkg
263 if [ -s $2/uploadconf ]; then
264 awk "{
265 if (found) {
266 if (/^ /) print;
267 else exit;
268 }
269 if (/^$PACKAGE /) found=1
270 }" < $2/uploadconf | sed -e 's/ //' -e 's/ \([A-Z_0-9]*=\)/export \1/' > $2/vars
271 . $2/vars
272 fi
273 config_form $2/fs
274 exit
275 }
280 do_pre_install()
281 {
282 pkg=$(get_receipt $1 $2)
283 [ -n "$pkg" ] || exit
284 CONFIG_FILES=""
285 . $pkg
286 grep -qs ^pre_install $pkg && pre_install $2/fs
287 [ -n "$CONFIG_FILES" ] && for i in $CONFIG_FILES; do echo $i >> $2/config_files; done
288 unlzma < $(dirname $pkg)/fs.cpio.lzma | ( cd $2 ; cpio -idmu )
289 exit
290 }
295 do_post_install()
296 {
297 pkg=$(get_receipt $1 $2)
298 [ -n "$pkg" ] || exit
299 . $pkg
300 echo "$1 $VERSION $(md5sum $(dirname $pkg)/fs.cpio.lzma | awk '{ print $1 }')" >> $2/fs/etc/packages.conf
301 if grep -qs ^post_install $pkg; then
302 [ -s $2/vars ] && . $2/vars
303 echo "=== $pkg: $(date) ===" >> $2/post_install.log 2>&1
304 post_install $2/fs >> $2/post_install.log 2>&1
305 sed -e 's/^export/ /' -e 's/^/ /' -e '/^ suggested=/d' \
306 < $2/vars >> $2/fs/etc/packages.conf
307 fi
308 rm -f $2/vars
309 exit
310 }
315 scan_depends()
316 {
317 local pkg
318 for pkg in $@ ; do
319 case " $OUTPUT " in
320 *\ $pkg\ *) continue ;;
321 esac
322 DEPENDS=""
323 . $(get_receipt $pkg $TMPDIR)
324 scan_depends $DEPENDS
325 case " $OUTPUT " in
326 *\ $pkg\ *) continue ;;
327 esac
328 OUTPUT="$OUTPUT $pkg"
329 done
330 }
335 get_depends()
336 {
337 TMPDIR=$2
338 shift 2
339 OUTPUT=""
340 scan_depends $@
341 echo -n $OUTPUT
342 exit
343 }
348 pkgs_extract()
349 {
350 cd $2
351 mkdir pkgs
352 if cpio -t < $1 | grep -q receipt; then
353 mv $1 pkgs
354 elif tar tf $1 | grep -q tazpkg; then
355 tar xf $1 -C pkgs
356 elif tar tzf $1 | grep -q tazpkg; then
357 tar xzf $1 -C pkgs
358 elif tar tjf $1 | grep -q tazpkg; then
359 tar xjf $1 -C pkgs
360 else
361 rm -rf $1 pkgs
362 exit
363 fi
364 cd pkgs
365 for i in *; do
366 mkdir tmp
367 cd tmp
368 cpio -i < ../$i
369 . ./receipt
370 cd ..
371 mv tmp $PACKAGE-$VERSION
372 done
373 exit
374 }
379 lzma_set_size()
380 {
381 n=$(unlzma < $1 | wc -c)
382 for i in $(seq 1 8); do
383 printf '\\\\x%02X' $(($n & 255))
384 n=$(($n >> 8))
385 done | xargs echo -en | dd of=$1 conv=notrunc bs=1 seek=5 2> /dev/null
386 }
389 compressto()
390 {
391 [ "$(which zopfli 2> /dev/null)" ] &&
392 zopfli --i100 -c /dev/stdin > $1 || gzip -9 > $1
393 [ "$(which advdef 2> /dev/null)" ] && advdef -z4 $1 > /dev/null
394 }
397 case "$1" in
398 --list-modules) list_modules $@ ;;
399 --list-kernels) list_kernels $@ ;;
400 --list-pkgs) list_pkgs $@ ;;
401 --get-form) get_form $2 $3 ;;
402 --get-note) get_note $2 $3 ;;
403 --pre-install) do_pre_install $2 $3 ;;
404 --post-install) do_post_install $2 $3 ;;
405 --depends) get_depends $@ ;;
406 --pkgs-extract) pkgs_extract $2 $3 ;;
407 --remove) rm -rf $2; exit ;;
408 --get-pkg) get_package $2 $3 ;;
409 --get-suggested) get_suggested $2 $3 ;;
410 --init) init ;;
411 esac
416 if [ "x$1" = "x--mkrootfs" ]; then
417 tmp=$2
418 cd $tmp/fs
419 [ -s boot/mkrootfs.pre_exec ] && sh boot/mkrootfs.pre_exec
420 if [ ! -d boot -a -s ../kernel ]; then # custom kernel
421 mkdir boot
422 cp ../kernel boot/bzImage
423 fi
424 find -user bellard -exec chown root.root {} \;
425 find | grep -v ^./boot | cpio -o -H newc | compressto ../rootfs.gz
426 fi
427 if [ "x$1" = "x--mkiso" ]; then
428 tmp=$2
429 mkdir -p $tmp/iso/boot/isolinux $tmp/iso/data
430 cat $tmp/fs/boot/System.map | compressto $tmp/iso/data/sysmap.gz
431 cat $tmp/fs/boot/config | compressto $tmp/iso/data/linconf.gz
432 cat $tmp/fs/boot/config-busybox | compressto $tmp/iso/data/bbconf.gz
433 cp $tmp/fs/boot/bundle $tmp/iso/data/bundle.sh
434 cat $tmp/post_install.log | compressto $tmp/iso/data/log.gz
435 cp $tmp/config_files $tmp/iso/data/files.cnf
436 cp $tmp/fs/etc/packages.conf $tmp/iso/data/packages.cnf
437 [ -s wok/busybox/receipt ] && tar czf $tmp/iso/data/wok.tgz wok/*
438 [ -s www/index.php ] && tar czf $tmp/iso/data/www.tgz www/*
439 cp $tmp/fs/boot/bzImage $tmp/iso/boot/bzImage
440 cp $tmp/rootfs.gz $tmp/iso/boot/rootfs
441 cp /boot/isolinux/isolinux.bin $tmp/iso/boot/isolinux
442 cat > $tmp/iso/boot/isolinux/isolinux.cfg <<EOT
443 label slitaz slitqw
444 kernel /boot/bzImage
445 append initrd=/boot/rootfs rw root=/dev/null vga=normal
447 EOT
448 while read bin keys; do
449 [ -s $tmp/fs/boot/$bin ] &&
450 cp $tmp/fs/boot/$bin $tmp/iso/boot/ &&
451 KEY="$KEY ${keys%% *}" &&
452 cat >> $tmp/iso/boot/isolinux/isolinux.cfg <<EOT
453 label $keys
454 kernel /boot/$bin
456 EOT
457 done <<EOT
458 memtest test memtest mem
459 ipxe web zeb ipxe pxe
460 EOT
461 [ -s $tmp/fs/boot/ipxe ] && cp $tmp/fs/boot/ipxe $tmp/iso/boot/ &&
462 [ "$KEY" ] && echo "say You can boot: slitaz (default)$KEY" >> \
463 $tmp/iso/boot/isolinux/isolinux.cfg
464 cat >> $tmp/iso/boot/isolinux/isolinux.cfg <<EOT
465 default slitaz
466 implicit 0
467 prompt 1
468 timeout 50
469 EOT
470 genisoimage -o $tmp/slitaz.iso -b boot/isolinux/isolinux.bin \
471 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
472 -V "Tiny SliTaz" -p "www.slitaz.org" -input-charset iso8859-1 \
473 -boot-info-table $tmp/iso > /dev/null 2>&1
474 [ -x /usr/bin/isohybrid ] &&
475 /usr/bin/isohybrid $tmp/slitaz.iso 2> /dev/null
476 [ -x /usr/bin/iso2exe ] &&
477 /usr/bin/iso2exe $tmp/slitaz.iso 2> /dev/null
478 fi
479 if [ "x$1" = "x--mkexe" ]; then
480 tmp=$2
481 cd $tmp
482 cp fs/boot/bzImage slitaz.exe
483 sh fs/boot/bundle slitaz.exe rootfs.gz
484 fi
485 if [ "x$1" = "x--mkimg" ]; then
486 tmp=$2
487 cd $tmp
488 if [ ! -s out ]; then
489 cp fs/boot/bzImage slitaz.img
490 sh fs/boot/bundle slitaz.img rootfs.gz
491 if [ -s fs/boot/ipxe ] && [ -s fs/boot/memtest ]; then
492 sh fs/boot/bundle out " SliTaz boot menu" slitaz.img \
493 "Tiny SliTaz" fs/boot/ipxe "SliTaz web boot" \
494 fs/boot/memtest "Check memory"
495 elif [ -s fs/boot/ipxe ]; then
496 sh fs/boot/bundle out " SliTaz boot menu" slitaz.img \
497 "Tiny SliTaz" fs/boot/ipxe "SliTaz web boot"
498 elif [ -s fs/boot/memtest ]; then
499 sh fs/boot/bundle out " SliTaz boot menu" slitaz.img \
500 "Tiny SliTaz" fs/boot/memtest "Check memory"
501 else
502 mv slitaz.img out
503 fi
504 fi
505 rm -f xa* 2> /dev/null
506 split -b ${3:-1474560} out
507 A="-abcdefghijklmnopqrstuvwxyz"
508 mv xa${A:${4:-1}:1} floppy$4.img || mv xaa floppy1.img
509 [ $(stat -c %s floppy${4:-1}.img) -lt ${3:-1474560} ] &&
510 dd of=floppy${4:-1}.img bs=1 seek=${3:-1474560} count=0 2> /dev/null
511 fi
512 if [ "x$1" = "x--mkcfg" ]; then
513 tmp=$2
514 cd $tmp/fs
515 for i in $(sed 's#^/##' < ../config_files); do find $i; done | \
516 sort | uniq | cpio -o -H newc | compressto ../config_files.cpio.gz
517 fi
518 if [ "x$1" = "x--chkdist" ]; then
519 if [ pkgs/busybox-*/fs.cpio.lzma -nt dist/rootfs.cpio ]; then
520 cat pkgs/busybox-*/fs.cpio.lzma | unlzma | ( cd dist ; cpio -idmu )
521 mv -f dist/fs/* dist/
522 rmdir dist/fs
523 touch dist/*
524 fi
525 fi