tiny-slitaz view helper @ rev 35

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