tiny-slitaz view helper @ rev 32

Do not suggest packages twice
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Sep 26 13:55:40 2019 +0200 (2019-09-26)
parents 26423b57df46
children 798a84e27cc9
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 echo "$1 $VERSION $(md5sum $(dirname $pkg)/fs.cpio.lzma | awk '{ print $1 }')" >> $2/fs/etc/packages.conf
355 if grep -qs ^post_install $pkg; then
356 [ -s $2/vars ] && . $2/vars
357 echo "=== $pkg: $(date) ===" >> $2/post_install.log 2>&1
358 post_install $2/fs >> $2/post_install.log 2>&1
359 sed -e 's/^export/ /' -e 's/^/ /' -e '/^ suggested=/d' \
360 < $2/vars >> $2/fs/etc/packages.conf
361 fi
362 rm -f $2/vars
363 exit
364 }
369 scan_depends()
370 {
371 local pkg
372 for pkg in $@ ; do
373 case " $OUTPUT " in
374 *\ $pkg\ *) continue ;;
375 esac
376 DEPENDS=""
377 . $(get_receipt $pkg $TMPDIR)
378 scan_depends $DEPENDS
379 case " $OUTPUT " in
380 *\ $pkg\ *) continue ;;
381 esac
382 OUTPUT="$OUTPUT $pkg"
383 done
384 }
389 get_depends()
390 {
391 TMPDIR=$2
392 shift 2
393 OUTPUT=""
394 scan_depends $@
395 echo -n $OUTPUT
396 exit
397 }
402 pkgs_extract()
403 {
404 cd $2
405 mkdir pkgs
406 if cpio -t < $1 | grep -q receipt; then
407 mv $1 pkgs
408 elif tar tf $1 | grep -q tazpkg; then
409 tar xf $1 -C pkgs
410 elif tar tzf $1 | grep -q tazpkg; then
411 tar xzf $1 -C pkgs
412 elif tar tjf $1 | grep -q tazpkg; then
413 tar xjf $1 -C pkgs
414 else
415 rm -rf $1 pkgs
416 exit
417 fi
418 cd pkgs
419 for i in *; do
420 mkdir tmp
421 cd tmp
422 cpio -i < ../$i
423 . ./receipt
424 cd ..
425 mv tmp $PACKAGE-$VERSION
426 done
427 exit
428 }
431 boot_files()
432 {
433 [ -s $1/fs/boot/bootmenu ] && while read bin button text; do
434 cat <<EOT
435 <input name="download" value="${button%%,*} ($(du -h \
436 $1/fs/boot/$bin | awk '{ printf "%s",$1 }'))" type="submit" title="$text" />
437 EOT
438 done < $1/fs/boot/bootmenu
439 }
442 lzma_set_size()
443 {
444 n=$(unlzma < $1 | wc -c)
445 for i in $(seq 1 8); do
446 printf '\\\\x%02X' $(($n & 255))
447 n=$(($n >> 8))
448 done | xargs echo -en | dd of=$1 conv=notrunc bs=1 seek=5 2> /dev/null
449 }
452 compressto()
453 {
454 [ "$(which zopfli 2> /dev/null)" ] &&
455 zopfli --i100 -c /dev/stdin > $1 || gzip -9 > $1
456 [ "$(which advdef 2> /dev/null)" ] && advdef -z4 $1 > /dev/null
457 }
460 case "$1" in
461 --list-modules) list_modules $@ ;;
462 --list-kernels) list_kernels $@ ;;
463 --list-pkgs) list_pkgs $@ ;;
464 --get-form) get_form $2 $3 ;;
465 --get-note) get_note $2 $3 ;;
466 --pre-install) do_pre_install $2 $3 ;;
467 --post-install) do_post_install $2 $3 ;;
468 --depends) get_depends $@ ;;
469 --pkgs-extract) pkgs_extract $2 $3 ;;
470 --remove) rm -rf $2; exit ;;
471 --get-pkg) get_package $2 $3 ;;
472 --list-suggested) list_suggested $2 $3 $@ ;;
473 --init) init ;;
474 --boot-files) boot_files $2 ;;
475 esac
480 if [ "x$1" = "x--mkrootfs" ]; then
481 tmp=$2
482 cd $tmp/fs
483 [ -s boot/mkrootfs.pre_exec ] && sh boot/mkrootfs.pre_exec
484 if [ ! -d boot -a -s ../kernel ]; then # custom kernel
485 mkdir boot
486 cp ../kernel boot/bzImage
487 fi
488 find -user bellard -exec chown root.root {} \;
489 find | grep -v ^./boot | cpio -o -H newc | compressto ../rootfs.gz
490 fi
491 if [ "x$1" = "x--mkiso" ]; then
492 tmp=$2
493 mkdir -p $tmp/iso/boot/isolinux $tmp/iso/data
494 cat $tmp/fs/boot/System.map | compressto $tmp/iso/data/sysmap.gz
495 cat $tmp/fs/boot/config | compressto $tmp/iso/data/linconf.gz
496 cat $tmp/fs/boot/config-busybox | compressto $tmp/iso/data/bbconf.gz
497 cp $tmp/fs/boot/bundle $tmp/iso/data/bundle.sh
498 cat $tmp/post_install.log | compressto $tmp/iso/data/log.gz
499 cp $tmp/config_files $tmp/iso/data/files.cnf
500 cp $tmp/fs/etc/packages.conf $tmp/iso/data/packages.cnf
501 [ -s wok/busybox/receipt ] && tar czf $tmp/iso/data/wok.tgz wok/*
502 [ -s www/index.php ] && tar czf $tmp/iso/data/www.tgz www/*
503 cp $tmp/fs/boot/bzImage $tmp/iso/boot/bzImage
504 cp $tmp/rootfs.gz $tmp/iso/boot/rootfs
505 cp /boot/isolinux/isolinux.bin $tmp/iso/boot/isolinux
506 cat > $tmp/iso/boot/isolinux/isolinux.cfg <<EOT
507 label slitaz slitqw
508 kernel /boot/bzImage
509 append initrd=/boot/rootfs rw root=/dev/null vga=normal
511 EOT
512 [ -s $tmp/fs/boot/bootmenu ] && while read bin keys text; do
513 keys=${keys#*,}
514 KEY="$KEY ${keys%%,*}"
515 cp $tmp/fs/boot/$bin $tmp/iso/boot/$bin
516 cat >> $tmp/iso/boot/isolinux/isolinux.cfg <<EOT
517 label ${keys//,/ } $bin
518 kernel /boot/$bin
520 EOT
521 done < $tmp/fs/boot/bootmenu
522 [ "$KEY" ] && echo "say You can boot: slitaz (default)$KEY" >> \
523 $tmp/iso/boot/isolinux/isolinux.cfg
524 cat >> $tmp/iso/boot/isolinux/isolinux.cfg <<EOT
525 default slitaz
526 implicit 0
527 prompt 1
528 timeout 50
529 EOT
530 genisoimage -o $tmp/slitaz.iso -b boot/isolinux/isolinux.bin \
531 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
532 -V "Tiny SliTaz" -p "www.slitaz.org" -input-charset iso8859-1 \
533 -boot-info-table $tmp/iso > /dev/null 2>&1
534 [ -x /usr/bin/isohybrid ] &&
535 /usr/bin/isohybrid $tmp/slitaz.iso 2> /dev/null
536 [ -x /usr/bin/iso2exe ] &&
537 /usr/bin/iso2exe $tmp/slitaz.iso 2> /dev/null
538 fi
539 if [ "x$1" = "x--mkexe" ]; then
540 tmp=$2
541 cd $tmp
542 cp fs/boot/bzImage slitaz.exe
543 sh fs/boot/bundle slitaz.exe rootfs.gz
544 fi
545 if [ "x$1" = "x--mkimg" ]; then
546 tmp=$2
547 cd $tmp
548 if [ ! -s out ]; then
549 cp fs/boot/bzImage slitaz.img
550 sh fs/boot/bundle slitaz.img rootfs.gz
551 if [ -s fs/boot/bootmenu ]; then
552 echo -n "sh fs/boot/bundle out ' SliTaz boot menu'"
553 echo -n " slitaz.img 'Tiny SliTaz'"
554 while read bin button text; do
555 echo -n " fs/boot/$bin '${text% (*}'"
556 done < fs/boot/bootmenu
557 fi | sh
558 [ -s out ] || mv slitaz.img out
559 fi
560 rm -f xa* 2> /dev/null
561 split -b ${3:-1474560} out
562 A="-abcdefghijklmnopqrstuvwxyz"
563 mv xa${A:${4:-1}:1} floppy$4.img || mv xaa floppy1.img
564 [ $(stat -c %s floppy${4:-1}.img) -lt ${3:-1474560} ] &&
565 dd of=floppy${4:-1}.img bs=1 seek=${3:-1474560} count=0 2> /dev/null
566 fi
567 if [ "x$1" = "x--mkcfg" ]; then
568 tmp=$2
569 cd $tmp/fs
570 for i in $(sed 's#^/##' < ../config_files); do find $i; done | \
571 sort | uniq | cpio -o -H newc | compressto ../config_files.cpio.gz
572 fi
573 if [ "x$1" = "x--chkdist" ]; then
574 if [ pkgs/busybox-*/fs.cpio.lzma -nt dist/rootfs.cpio ]; then
575 cat pkgs/busybox-*/fs.cpio.lzma | unlzma | ( cd dist ; cpio -idmu )
576 mv -f dist/fs/* dist/
577 rmdir dist/fs
578 touch dist/*
579 fi
580 fi