tiny-slitaz view helper @ rev 26

Take care of busybox config
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Sep 07 11:54:26 2019 +0200 (2019-09-07)
parents 293348721e35
children cb1743f12df8
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 . $i
49 case " $@ " in
50 *\ $PACKAGE\ *) checked='checked="checked"';;
51 *) [ -n "$2" ] && checked="";;
52 esac
53 grep -qs "^$PACKAGE " $TMPDIR/uploadconf &&
54 checked='checked="checked"'
55 case "$AUTO_SELECTION" in
56 never)
57 continue;;
58 always)
59 checked='checked="checked" disabled'
60 hidden_var="<input type=\"hidden\" name=\"selected[]\" value=\"$PACKAGE\" />";;
61 CONF*)
62 grep -qs "^$AUTO_SELECTION=y$" $TMPDIR/fs/boot/config-busybox ||
63 checked='disabled';;
64 esac
65 cat <<EOT
66 <tr>
67 <td>$hidden_var
68 <input type="checkbox" name="selected[]" value="$PACKAGE" $checked /></td>
69 <td><a href="?dl=$PACKAGE-$VERSION&amp;tmp=$TMPDIR">$PACKAGE</a></td>
70 <td>$VERSION</td>
71 <td>$SHORT_DESC</td>
72 <td>$PACKED_SIZE</td>
73 <td>$UNPACKED_SIZE</td>
74 <td>$(grep -qs ^config_form $i && echo '&raquo;')</td>
75 </tr>
76 EOT
77 done
78 cat <<EOT
79 </tbody>
80 </table>
81 </div>
82 EOT
83 exit
84 }
89 list_kernels()
90 {
91 TMPDIR=$2
92 shift 2
93 cat <<EOT
94 <div class="large">
95 <table>
96 <thead>
97 <tr>
98 <th> </th>
99 <th>Kernel</th>
100 <th>Version</th>
101 <th>Description</th>
102 <!-- th>Size</th -->
103 </tr>
104 </thead>
105 <tbody>
106 EOT
107 checked='checked="checked"'
108 for i in $TMPDIR/pkgs/*/receipt pkgs/*/receipt ; do
109 [ -s $i ] || continue
110 case "$i" in
111 pkgs/kernel-*/receipt);;
112 *) continue;;
113 esac
114 UNPACKED_SIZE="-"
115 . $i
116 case " $@ " in
117 *\ $PACKAGE\ *) checked='checked="checked"' ;;
118 *) [ -n "$2" ] && checked="";;
119 esac
120 cat <<EOT
121 <tr>
122 <td><input type="radio" name="kernel" value="$PACKAGE" $checked/></td>
123 <td>${PACKAGE#kernel-}</td>
124 <td>$VERSION</td>
125 <td>$SHORT_DESC</td>
126 <!-- td>$UNPACKED_SIZE</td -->
127 </tr>
128 EOT
129 checked=""
130 done
131 cat <<EOT
132 </tbody>
133 </table>
134 </div>
135 EOT
136 exit
137 }
142 list_modules()
143 {
144 TMPDIR=$2
145 shift 2
146 cat <<EOT
147 <input type="hidden" name="selected[]" value="" />
148 <div class="large">
149 <table>
150 <thead>
151 <tr>
152 <th> </th>
153 <th>Module</th>
154 <th>Version</th>
155 <th>Description</th>
156 <th>Disk</th>
157 <th>Memory</th>
158 <th> </th>
159 </tr>
160 </thead>
161 <tbody>
162 EOT
163 for i in $TMPDIR/pkgs/*/receipt pkgs/*/receipt ; do
164 [ -s $i ] || continue
165 case "$i" in
166 pkgs/module-*/receipt);;
167 *) continue;;
168 esac
169 UNPACKED_SIZE='-'
170 . $i
171 checked=''
172 case " $@ " in
173 *\ $PACKAGE\ *) checked='checked="checked"' ;;
174 esac
175 grep -qs "^$PACKAGE " $TMPDIR/uploadconf &&
176 checked='checked="checked"'
177 cat <<EOT
178 <tr>
179 <td><input type="checkbox" name="selected[]" value="$PACKAGE" $checked/></td>
180 <td>${PACKAGE#module-}</td>
181 <td>$VERSION</td>
182 <td>$SHORT_DESC</td>
183 <td>$PACKED_SIZE</td>
184 <td>$UNPACKED_SIZE</td>
185 <td>$(grep -qs ^config_form $i && echo '&raquo;')</td>
186 </tr>
187 EOT
188 done
189 cat <<EOT
190 </tbody>
191 </table>
192 </div>
193 EOT
194 exit
195 }
200 get_receipt()
201 {
202 grep -l "PACKAGE=\"$1\"" $2/pkgs/*/receipt pkgs/*/receipt | head -1
203 }
208 get_suggested()
209 {
210 local pkg
211 pkg=pkgs/$1/receipt
212 [ -s $pkg ] || pkg=$2/pkgs/$1/receipt
213 [ -s $pkg ] || pkg=$(get_receipt $@)
214 . $pkg
215 echo -n $SUGGESTED
216 }
221 get_package()
222 {
223 local pkg
224 pkg=pkgs/$1/receipt
225 [ -s $pkg ] || pkg=$2/pkgs/$1/receipt
226 [ -s $pkg ] || pkg=$(get_receipt $@)
227 . $pkg
228 cd $(dirname $pkg)
229 pkg=$2$PACKAGE-$VERSION.tazpkg
230 find * | cpio -o -H newc > $pkg
231 echo -n $pkg
232 }
237 get_note()
238 {
239 pkg=$(get_receipt $1 $2)
240 [ -n "$pkg" ] || exit
241 grep -qs ^config_note $pkg || exit
242 . $pkg
243 config_note
244 }
249 get_form()
250 {
251 pkg=$(get_receipt $1 $2)
252 [ -n "$pkg" ] || exit
253 grep -qs ^config_form $pkg || exit
254 . $pkg
255 if [ -s $2/uploadconf ]; then
256 awk "{
257 if (found) {
258 if (/^ /) print;
259 else exit;
260 }
261 if (/^$PACKAGE /) found=1
262 }" < $2/uploadconf | sed -e 's/ //' -e 's/ \([A-Z_0-9]*=\)/export \1/' > $2/vars
263 . $2/vars
264 fi
265 config_form $2/fs
266 exit
267 }
272 do_pre_install()
273 {
274 pkg=$(get_receipt $1 $2)
275 [ -n "$pkg" ] || exit
276 CONFIG_FILES=""
277 . $pkg
278 grep -qs ^pre_install $pkg && pre_install $2/fs
279 [ -n "$CONFIG_FILES" ] && for i in $CONFIG_FILES; do echo $i >> $2/config_files; done
280 unlzma < $(dirname $pkg)/fs.cpio.lzma | ( cd $2 ; cpio -idmu )
281 exit
282 }
287 do_post_install()
288 {
289 pkg=$(get_receipt $1 $2)
290 [ -n "$pkg" ] || exit
291 . $pkg
292 echo "$1 $VERSION $(md5sum $(dirname $pkg)/fs.cpio.lzma | awk '{ print $1 }')" >> $2/fs/etc/packages.conf
293 if grep -qs ^post_install $pkg; then
294 [ -s $2/vars ] && . $2/vars
295 echo "=== $pkg: $(date) ===" >> $2/post_install.log 2>&1
296 post_install $2/fs >> $2/post_install.log 2>&1
297 sed -e 's/^export/ /' -e 's/^/ /' -e '/^ suggested=/d' \
298 < $2/vars >> $2/fs/etc/packages.conf
299 fi
300 rm -f $2/vars
301 exit
302 }
307 scan_depends()
308 {
309 local pkg
310 for pkg in $@ ; do
311 case " $OUTPUT " in
312 *\ $pkg\ *) continue ;;
313 esac
314 DEPENDS=""
315 . $(get_receipt $pkg $TMPDIR)
316 scan_depends $DEPENDS
317 case " $OUTPUT " in
318 *\ $pkg\ *) continue ;;
319 esac
320 OUTPUT="$OUTPUT $pkg"
321 done
322 }
327 get_depends()
328 {
329 TMPDIR=$2
330 shift 2
331 OUTPUT=""
332 scan_depends $@
333 echo -n $OUTPUT
334 exit
335 }
340 pkgs_extract()
341 {
342 cd $2
343 mkdir pkgs
344 if cpio -t < $1 | grep -q receipt; then
345 mv $1 pkgs
346 elif tar tf $1 | grep -q tazpkg; then
347 tar xf $1 -C pkgs
348 elif tar tzf $1 | grep -q tazpkg; then
349 tar xzf $1 -C pkgs
350 elif tar tjf $1 | grep -q tazpkg; then
351 tar xjf $1 -C pkgs
352 else
353 rm -rf $1 pkgs
354 exit
355 fi
356 cd pkgs
357 for i in *; do
358 mkdir tmp
359 cd tmp
360 cpio -i < ../$i
361 . ./receipt
362 cd ..
363 mv tmp $PACKAGE-$VERSION
364 done
365 exit
366 }
371 lzma_set_size()
372 {
373 n=$(unlzma < $1 | wc -c)
374 for i in $(seq 1 8); do
375 printf '\\\\x%02X' $(($n & 255))
376 n=$(($n >> 8))
377 done | xargs echo -en | dd of=$1 conv=notrunc bs=1 seek=5 2> /dev/null
378 }
383 case "$1" in
384 --list-modules) list_modules $@ ;;
385 --list-kernels) list_kernels $@ ;;
386 --list-pkgs) list_pkgs $@ ;;
387 --get-form) get_form $2 $3 ;;
388 --get-note) get_note $2 $3 ;;
389 --pre-install) do_pre_install $2 $3 ;;
390 --post-install) do_post_install $2 $3 ;;
391 --depends) get_depends $@ ;;
392 --pkgs-extract) pkgs_extract $2 $3 ;;
393 --remove) rm -rf $2; exit ;;
394 --get-pkg) get_package $2 $3 ;;
395 --get-suggested) get_suggested $2 $3 ;;
396 --init) init ;;
397 esac
402 if [ "x$1" = "x--mkrootfs" ]; then
403 tmp=$2
404 cd $tmp/fs
405 [ -s boot/mkrootfs.pre_exec ] && sh boot/mkrootfs.pre_exec
406 if [ ! -d boot -a -s ../kernel ]; then # custom kernel
407 mkdir boot
408 cp ../kernel boot/bzImage
409 fi
410 find -user bellard -exec chown root.root {} \;
411 find | grep -v ^./boot | cpio -o -H newc | gzip -9 > ../rootfs.gz
412 which advdef 2> /dev/null && advdef -z4 ../rootfs.gz
413 fi
414 if [ "x$1" = "x--mkiso" ]; then
415 tmp=$2
416 mkdir -p $tmp/iso/boot/isolinux $tmp/iso/data
417 cat $tmp/fs/boot/System.map | gzip -9 > $tmp/iso/data/sysmap.gz
418 cat $tmp/fs/boot/config | gzip -9 > $tmp/iso/data/linconf.gz
419 cat $tmp/fs/boot/config-busybox | gzip -9 > $tmp/iso/data/bbconf.gz
420 cp $tmp/fs/boot/bundle $tmp/iso/data/bundle.sh
421 cat $tmp/post_install.log | gzip -9 > $tmp/iso/data/log.gz
422 cp $tmp/config_files $tmp/iso/data/files.cnf
423 cp $tmp/fs/etc/packages.conf $tmp/iso/data/packages.cnf
424 [ -s wok/busybox/receipt ] && tar czf $tmp/iso/data/wok.tgz wok/*
425 [ -s www/index.php ] && tar czf $tmp/iso/data/www.tgz www/*
426 cp $tmp/fs/boot/bzImage $tmp/iso/boot/bzImage
427 cp $tmp/rootfs.gz $tmp/iso/boot/rootfs
428 cp /boot/isolinux/isolinux.bin $tmp/iso/boot/isolinux
429 cat > $tmp/iso/boot/isolinux/isolinux.cfg <<EOT
430 label slitaz
431 kernel /boot/bzImage
432 append initrd=/boot/rootfs rw root=/dev/null vga=normal
433 default slitaz
434 implicit 0
435 prompt 1
436 timeout 50
437 EOT
438 genisoimage -o $tmp/slitaz.iso -b boot/isolinux/isolinux.bin \
439 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
440 -V "Tiny SliTaz" -p "www.slitaz.org" -input-charset iso8859-1 \
441 -boot-info-table $tmp/iso > /dev/null 2>&1
442 [ -x /usr/bin/isohybrid ] &&
443 /usr/bin/isohybrid $tmp/slitaz.iso 2> /dev/null
444 [ -x /usr/bin/iso2exe ] &&
445 /usr/bin/iso2exe $tmp/slitaz.iso 2> /dev/null
446 fi
447 if [ "x$1" = "x--mkexe" ]; then
448 tmp=$2
449 cd $tmp
450 cp fs/boot/bzImage slitaz.exe
451 sh fs/boot/bundle slitaz.exe rootfs.gz
452 fi
453 if [ "x$1" = "x--mkimg" ]; then
454 tmp=$2
455 cd $tmp
456 cp fs/boot/bzImage slitaz.img
457 sh fs/boot/bundle slitaz.img rootfs.gz
458 if [ -s fs/boot/ipxe ] && [ -s fs/boot/memtest ]; then
459 sh fs/boot/bundle out " SliTaz boot menu" slitaz.img \
460 "Tiny SliTaz" fs/boot/ipxe "SliTaz web boot" \
461 fs/boot/memtest "Check memory"
462 elif [ -s fs/boot/ipxe ]; then
463 sh fs/boot/bundle out " SliTaz boot menu" slitaz.img \
464 "Tiny SliTaz" fs/boot/ipxe "SliTaz web boot"
465 elif [ -s fs/boot/memtest ]; then
466 sh fs/boot/bundle out " SliTaz boot menu" slitaz.img \
467 "Tiny SliTaz" fs/boot/memtest "Check memory"
468 mv -f out slitaz.img
469 else
470 cp slitaz.img out
471 fi
472 [ $(stat -c %s out) -le 1474560 ] && mv -f out slitaz.img || rm -f out
473 [ $(stat -c %s slitaz.img) -lt 1474560 ] &&
474 dd of=slitaz.img bs=18k seek=80 count=0 2> /dev/null
475 fi
476 if [ "x$1" = "x--mkcfg" ]; then
477 tmp=$2
478 cd $tmp/fs
479 for i in $(sed 's#^/##' < ../config_files); do find $i; done | \
480 sort | uniq | cpio -o -H newc | gzip -9 > ../config_files.cpio.gz
481 fi
482 if [ "x$1" = "x--chkdist" ]; then
483 if [ pkgs/busybox-*/fs.cpio.lzma -nt dist/rootfs.cpio ]; then
484 cat pkgs/busybox-*/fs.cpio.lzma | unlzma | ( cd dist ; cpio -idmu )
485 mv -f dist/fs/* dist/
486 rmdir dist/fs
487 touch dist/*
488 fi
489 fi