tiny-slitaz view helper @ rev 29

No hard coded boot menu
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Sep 20 21:20:45 2019 +0200 (2019-09-20)
parents cb1743f12df8
children f03cb925353c
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 list_suggested()
217 {
218 local pkg
219 pkg=pkgs/$1/receipt
220 TMPDIR=$2
221 [ -s $pkg ] || pkg=$TMPDIR/pkgs/$1/receipt
222 [ -s $pkg ] || pkg=$(get_receipt $@)
223 SUGGESTED=
224 . $pkg
225 SUGG=
226 for i in $SUGGESTED; do
227 case " $@ " in
228 *\ $i\ *);;
229 *) SUGG="$SUGG $i";;
230 esac
231 done
232 if [ "$SUGG" ]; then
233 cat <<EOT
234 <hr />
235 <p>
236 You may want to install the following package(s) too:
237 </p>
238 <div class="large">
239 <table>
240 <thead>
241 <tr>
242 <th> </th>
243 <th>Package</th>
244 <th>Version</th>
245 <th>Description</th>
246 <th>Disk</th>
247 <th>Memory</th>
248 <th> </th>
249 </tr>
250 </thead>
251 <tbody>
252 EOT
253 checked='checked="checked" '
254 [ $TMPDIR/uploadconf ] && checked=
255 for i in $SUGG; do
256 i=$(grep -l "PACKAGE=\"$i\"" pkgs/*/receipt)
257 . $i
258 cat <<EOT
259 <!-- $GROUP -->
260 <tr>
261 <td><input type="checkbox" name="suggested[]" value="$PACKAGE" $checked /></td>
262 <td><a href="?dl=$PACKAGE-$VERSION&amp;tmp=$TMPDIR">$PACKAGE</a></td>
263 <td>$VERSION</td>
264 <td>$SHORT_DESC</td>
265 <td>$PACKED_SIZE</td>
266 <td>$UNPACKED_SIZE</td>
267 <td>$(grep -qs ^config_form $i && echo '&raquo;')</td>
268 </tr>
269 EOT
270 done
271 cat <<EOT
272 </tbody>
273 </table>
274 </div>
275 EOT
276 fi
277 }
282 get_package()
283 {
284 local pkg
285 pkg=pkgs/$1/receipt
286 [ -s $pkg ] || pkg=$2/pkgs/$1/receipt
287 [ -s $pkg ] || pkg=$(get_receipt $@)
288 . $pkg
289 cd $(dirname $pkg)
290 pkg=$2$PACKAGE-$VERSION.tazpkg
291 find * | cpio -o -H newc > $pkg
292 echo -n $pkg
293 }
298 get_note()
299 {
300 pkg=$(get_receipt $1 $2)
301 [ -n "$pkg" ] || exit
302 grep -qs ^config_note $pkg || exit
303 . $pkg
304 config_note
305 }
310 get_form()
311 {
312 pkg=$(get_receipt $1 $2)
313 [ -n "$pkg" ] || exit
314 grep -qs ^config_form $pkg || exit
315 . $pkg
316 if [ -s $2/uploadconf ]; then
317 awk "{
318 if (found) {
319 if (/^ /) print;
320 else exit;
321 }
322 if (/^$PACKAGE /) found=1
323 }" < $2/uploadconf | sed -e 's/ //' -e 's/ \([A-Z_0-9]*=\)/export \1/' > $2/vars
324 . $2/vars
325 fi
326 config_form $2/fs
327 exit
328 }
333 do_pre_install()
334 {
335 pkg=$(get_receipt $1 $2)
336 [ -n "$pkg" ] || exit
337 CONFIG_FILES=""
338 . $pkg
339 grep -qs ^pre_install $pkg && pre_install $2/fs
340 [ -n "$CONFIG_FILES" ] && for i in $CONFIG_FILES; do echo $i >> $2/config_files; done
341 unlzma < $(dirname $pkg)/fs.cpio.lzma | ( cd $2 ; cpio -idmu )
342 exit
343 }
348 do_post_install()
349 {
350 pkg=$(get_receipt $1 $2)
351 [ -n "$pkg" ] || exit
352 . $pkg
353 echo "$1 $VERSION $(md5sum $(dirname $pkg)/fs.cpio.lzma | awk '{ print $1 }')" >> $2/fs/etc/packages.conf
354 if grep -qs ^post_install $pkg; then
355 [ -s $2/vars ] && . $2/vars
356 echo "=== $pkg: $(date) ===" >> $2/post_install.log 2>&1
357 post_install $2/fs >> $2/post_install.log 2>&1
358 sed -e 's/^export/ /' -e 's/^/ /' -e '/^ suggested=/d' \
359 < $2/vars >> $2/fs/etc/packages.conf
360 fi
361 rm -f $2/vars
362 exit
363 }
368 scan_depends()
369 {
370 local pkg
371 for pkg in $@ ; do
372 case " $OUTPUT " in
373 *\ $pkg\ *) continue ;;
374 esac
375 DEPENDS=""
376 . $(get_receipt $pkg $TMPDIR)
377 scan_depends $DEPENDS
378 case " $OUTPUT " in
379 *\ $pkg\ *) continue ;;
380 esac
381 OUTPUT="$OUTPUT $pkg"
382 done
383 }
388 get_depends()
389 {
390 TMPDIR=$2
391 shift 2
392 OUTPUT=""
393 scan_depends $@
394 echo -n $OUTPUT
395 exit
396 }
401 pkgs_extract()
402 {
403 cd $2
404 mkdir pkgs
405 if cpio -t < $1 | grep -q receipt; then
406 mv $1 pkgs
407 elif tar tf $1 | grep -q tazpkg; then
408 tar xf $1 -C pkgs
409 elif tar tzf $1 | grep -q tazpkg; then
410 tar xzf $1 -C pkgs
411 elif tar tjf $1 | grep -q tazpkg; then
412 tar xjf $1 -C pkgs
413 else
414 rm -rf $1 pkgs
415 exit
416 fi
417 cd pkgs
418 for i in *; do
419 mkdir tmp
420 cd tmp
421 cpio -i < ../$i
422 . ./receipt
423 cd ..
424 mv tmp $PACKAGE-$VERSION
425 done
426 exit
427 }
430 boot_files()
431 {
432 [ -s $1/fs/boot/bootmenu ] && while read bin button text; do
433 cat <<EOT
434 <input name="download" value="${button%%,*} ($(du -h \
435 $1/fs/boot/$bin | awk '{ printf "%s",$1 }'))" type="submit" />
436 EOT
437 done < $1/fs/boot/bootmenu
438 }
441 lzma_set_size()
442 {
443 n=$(unlzma < $1 | wc -c)
444 for i in $(seq 1 8); do
445 printf '\\\\x%02X' $(($n & 255))
446 n=$(($n >> 8))
447 done | xargs echo -en | dd of=$1 conv=notrunc bs=1 seek=5 2> /dev/null
448 }
451 compressto()
452 {
453 [ "$(which zopfli 2> /dev/null)" ] &&
454 zopfli --i100 -c /dev/stdin > $1 || gzip -9 > $1
455 [ "$(which advdef 2> /dev/null)" ] && advdef -z4 $1 > /dev/null
456 }
459 case "$1" in
460 --list-modules) list_modules $@ ;;
461 --list-kernels) list_kernels $@ ;;
462 --list-pkgs) list_pkgs $@ ;;
463 --get-form) get_form $2 $3 ;;
464 --get-note) get_note $2 $3 ;;
465 --pre-install) do_pre_install $2 $3 ;;
466 --post-install) do_post_install $2 $3 ;;
467 --depends) get_depends $@ ;;
468 --pkgs-extract) pkgs_extract $2 $3 ;;
469 --remove) rm -rf $2; exit ;;
470 --get-pkg) get_package $2 $3 ;;
471 --list-suggested) list_suggested $2 $3 $@ ;;
472 --init) init ;;
473 --boot-files) boot_files $2 ;;
474 esac
479 if [ "x$1" = "x--mkrootfs" ]; then
480 tmp=$2
481 cd $tmp/fs
482 [ -s boot/mkrootfs.pre_exec ] && sh boot/mkrootfs.pre_exec
483 if [ ! -d boot -a -s ../kernel ]; then # custom kernel
484 mkdir boot
485 cp ../kernel boot/bzImage
486 fi
487 find -user bellard -exec chown root.root {} \;
488 find | grep -v ^./boot | cpio -o -H newc | compressto ../rootfs.gz
489 fi
490 if [ "x$1" = "x--mkiso" ]; then
491 tmp=$2
492 mkdir -p $tmp/iso/boot/isolinux $tmp/iso/data
493 cat $tmp/fs/boot/System.map | compressto $tmp/iso/data/sysmap.gz
494 cat $tmp/fs/boot/config | compressto $tmp/iso/data/linconf.gz
495 cat $tmp/fs/boot/config-busybox | compressto $tmp/iso/data/bbconf.gz
496 cp $tmp/fs/boot/bundle $tmp/iso/data/bundle.sh
497 cat $tmp/post_install.log | compressto $tmp/iso/data/log.gz
498 cp $tmp/config_files $tmp/iso/data/files.cnf
499 cp $tmp/fs/etc/packages.conf $tmp/iso/data/packages.cnf
500 [ -s wok/busybox/receipt ] && tar czf $tmp/iso/data/wok.tgz wok/*
501 [ -s www/index.php ] && tar czf $tmp/iso/data/www.tgz www/*
502 cp $tmp/fs/boot/bzImage $tmp/iso/boot/bzImage
503 cp $tmp/rootfs.gz $tmp/iso/boot/rootfs
504 cp /boot/isolinux/isolinux.bin $tmp/iso/boot/isolinux
505 cat > $tmp/iso/boot/isolinux/isolinux.cfg <<EOT
506 label slitaz slitqw
507 kernel /boot/bzImage
508 append initrd=/boot/rootfs rw root=/dev/null vga=normal
510 EOT
511 [ -s $tmp/fs/boot/bootmenu ] && while read bin keys text; do
512 keys=${keys#*,}
513 KEY="$KEY ${keys%%,*}"
514 cp $tmp/fs/boot/$bin $tmp/iso/boot/$bin
515 cat >> $tmp/iso/boot/isolinux/isolinux.cfg <<EOT
516 label ${keys//,/ } $bin
517 kernel /boot/$bin
519 EOT
520 done < $tmp/fs/boot/bootmenu
521 [ "$KEY" ] && echo "say You can boot: slitaz (default)$KEY" >> \
522 $tmp/iso/boot/isolinux/isolinux.cfg
523 cat >> $tmp/iso/boot/isolinux/isolinux.cfg <<EOT
524 default slitaz
525 implicit 0
526 prompt 1
527 timeout 50
528 EOT
529 genisoimage -o $tmp/slitaz.iso -b boot/isolinux/isolinux.bin \
530 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
531 -V "Tiny SliTaz" -p "www.slitaz.org" -input-charset iso8859-1 \
532 -boot-info-table $tmp/iso > /dev/null 2>&1
533 [ -x /usr/bin/isohybrid ] &&
534 /usr/bin/isohybrid $tmp/slitaz.iso 2> /dev/null
535 [ -x /usr/bin/iso2exe ] &&
536 /usr/bin/iso2exe $tmp/slitaz.iso 2> /dev/null
537 fi
538 if [ "x$1" = "x--mkexe" ]; then
539 tmp=$2
540 cd $tmp
541 cp fs/boot/bzImage slitaz.exe
542 sh fs/boot/bundle slitaz.exe rootfs.gz
543 fi
544 if [ "x$1" = "x--mkimg" ]; then
545 tmp=$2
546 cd $tmp
547 if [ ! -s out ]; then
548 cp fs/boot/bzImage slitaz.img
549 sh fs/boot/bundle slitaz.img rootfs.gz
550 if [ -s fs/boot/bootmenu ]; then
551 echo -n "sh fs/boot/bundle out ' SliTaz boot menu'"
552 echo -n " slitaz.img 'Tiny SliTaz'"
553 while read bin button text; do
554 echo -n " fs/boot/$bin '$text'"
555 done < fs/boot/bootmenu
556 fi | sh
557 [ -s out ] || mv slitaz.img out
558 fi
559 rm -f xa* 2> /dev/null
560 split -b ${3:-1474560} out
561 A="-abcdefghijklmnopqrstuvwxyz"
562 mv xa${A:${4:-1}:1} floppy$4.img || mv xaa floppy1.img
563 [ $(stat -c %s floppy${4:-1}.img) -lt ${3:-1474560} ] &&
564 dd of=floppy${4:-1}.img bs=1 seek=${3:-1474560} count=0 2> /dev/null
565 fi
566 if [ "x$1" = "x--mkcfg" ]; then
567 tmp=$2
568 cd $tmp/fs
569 for i in $(sed 's#^/##' < ../config_files); do find $i; done | \
570 sort | uniq | cpio -o -H newc | compressto ../config_files.cpio.gz
571 fi
572 if [ "x$1" = "x--chkdist" ]; then
573 if [ pkgs/busybox-*/fs.cpio.lzma -nt dist/rootfs.cpio ]; then
574 cat pkgs/busybox-*/fs.cpio.lzma | unlzma | ( cd dist ; cpio -idmu )
575 mv -f dist/fs/* dist/
576 rmdir dist/fs
577 touch dist/*
578 fi
579 fi