tiny-slitaz view helper @ rev 38

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