tiny-slitaz view helper @ rev 13

helper: show disk size for modules
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Feb 08 23:57:16 2016 +0100 (2016-02-08)
parents 4f59e782a307
children d076e7a5f3ae
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 for i in $TMPDIR/pkgs/*/receipt pkgs/*/receipt; do
37 [ -s $i ] || continue
38 case "$i" in
39 pkgs/kernel-*/receipt) continue;;
40 pkgs/module-*/receipt) continue;;
41 esac
42 AUTO_SELECTION=''
43 UNPACKED_SIZE='-'
44 PACKED_SIZE='-'
45 checked=''; hidden_var=''
46 . $i
47 case " $@ " in
48 *\ $PACKAGE\ *) checked='checked="checked"';;
49 *) [ -n "$2" ] && checked="";;
50 esac
51 grep -qs "^$PACKAGE " $TMPDIR/uploadconf &&
52 checked='checked="checked"'
53 case "$AUTO_SELECTION" in
54 never)
55 continue;;
56 always)
57 checked='checked="checked" disabled'
58 hidden_var="<input type=\"hidden\" name=\"selected[]\" value=\"$PACKAGE\" />";;
59 esac
60 cat <<EOT
61 <tr>
62 <td>$hidden_var
63 <input type="checkbox" name="selected[]" value="$PACKAGE" $checked /></td>
64 <td><a href="?dl=$PACKAGE-$VERSION&amp;tmp=$TMPDIR">$PACKAGE</a></td>
65 <td>$VERSION</td>
66 <td>$SHORT_DESC</td>
67 <td>$PACKED_SIZE</td>
68 <td>$UNPACKED_SIZE</td>
69 <td>$(grep -qs ^config_form $i && echo '&raquo;')</td>
70 </tr>
71 EOT
72 done
73 cat <<EOT
74 </tbody>
75 </table>
76 </div>
77 EOT
78 exit
79 }
84 list_kernels()
85 {
86 TMPDIR=$2
87 shift 2
88 cat <<EOT
89 <div class="large">
90 <table>
91 <thead>
92 <tr>
93 <th> </th>
94 <th>Kernel</th>
95 <th>Version</th>
96 <th>Description</th>
97 <!-- th>Size</th -->
98 </tr>
99 </thead>
100 <tbody>
101 EOT
102 checked='checked="checked"'
103 for i in $TMPDIR/pkgs/*/receipt pkgs/*/receipt ; do
104 [ -s $i ] || continue
105 case "$i" in
106 pkgs/kernel-*/receipt);;
107 *) continue;;
108 esac
109 UNPACKED_SIZE="-"
110 . $i
111 case " $@ " in
112 *\ $PACKAGE\ *) checked='checked="checked"' ;;
113 *) [ -n "$2" ] && checked="";;
114 esac
115 cat <<EOT
116 <tr>
117 <td><input type="radio" name="kernel" value="$PACKAGE" $checked/></td>
118 <td>${PACKAGE#kernel-}</td>
119 <td>$VERSION</td>
120 <td>$SHORT_DESC</td>
121 <!-- td>$UNPACKED_SIZE</td -->
122 </tr>
123 EOT
124 checked=""
125 done
126 cat <<EOT
127 </tbody>
128 </table>
129 </div>
130 EOT
131 exit
132 }
137 list_modules()
138 {
139 TMPDIR=$2
140 shift 2
141 cat <<EOT
142 <input type="hidden" name="selected[]" value="" />
143 <div class="large">
144 <table>
145 <thead>
146 <tr>
147 <th> </th>
148 <th>Module</th>
149 <th>Version</th>
150 <th>Description</th>
151 <th>Disk</th>
152 <th>Memory</th>
153 <th> </th>
154 </tr>
155 </thead>
156 <tbody>
157 EOT
158 for i in $TMPDIR/pkgs/*/receipt pkgs/*/receipt ; do
159 [ -s $i ] || continue
160 case "$i" in
161 pkgs/module-*/receipt);;
162 *) continue;;
163 esac
164 UNPACKED_SIZE='-'
165 . $i
166 checked=''
167 case " $@ " in
168 *\ $PACKAGE\ *) checked='checked="checked"' ;;
169 esac
170 grep -qs "^$PACKAGE " $TMPDIR/uploadconf &&
171 checked='checked="checked"'
172 cat <<EOT
173 <tr>
174 <td><input type="checkbox" name="selected[]" value="$PACKAGE" $checked/></td>
175 <td>${PACKAGE#module-}</td>
176 <td>$VERSION</td>
177 <td>$SHORT_DESC</td>
178 <td>$PACKED_SIZE</td>
179 <td>$UNPACKED_SIZE</td>
180 <td>$(grep -qs ^config_form $i && echo '&raquo;')</td>
181 </tr>
182 EOT
183 done
184 cat <<EOT
185 </tbody>
186 </table>
187 </div>
188 EOT
189 exit
190 }
195 get_receipt()
196 {
197 grep -l "PACKAGE=\"$1\"" $2/pkgs/*/receipt pkgs/*/receipt | head -1
198 }
203 get_suggested()
204 {
205 local pkg
206 pkg=pkgs/$1/receipt
207 [ -s $pkg ] || pkg=$2/pkgs/$1/receipt
208 [ -s $pkg ] || pkg=$(get_receipt $@)
209 . $pkg
210 echo -n $SUGGESTED
211 }
216 get_package()
217 {
218 local pkg
219 pkg=pkgs/$1/receipt
220 [ -s $pkg ] || pkg=$2/pkgs/$1/receipt
221 [ -s $pkg ] || pkg=$(get_receipt $@)
222 . $pkg
223 cd $(dirname $pkg)
224 pkg=$2$PACKAGE-$VERSION.tazpkg
225 find * | cpio -o -H newc > $pkg
226 echo -n $pkg
227 }
232 get_note()
233 {
234 pkg=$(get_receipt $1 $2)
235 [ -n "$pkg" ] || exit
236 grep -qs ^config_note $pkg || exit
237 . $pkg
238 config_note
239 }
244 get_form()
245 {
246 pkg=$(get_receipt $1 $2)
247 [ -n "$pkg" ] || exit
248 grep -qs ^config_form $pkg || exit
249 . $pkg
250 if [ -s $2/uploadconf ]; then
251 awk "{
252 if (found) {
253 if (/^ /) print;
254 else exit;
255 }
256 if (/^$PACKAGE /) found=1
257 }" < $2/uploadconf | sed -e 's/ //' -e 's/ \([A-Z_0-9]*=\)/export \1/' > $2/vars
258 . $2/vars
259 fi
260 config_form $2/fs
261 exit
262 }
267 do_pre_install()
268 {
269 pkg=$(get_receipt $1 $2)
270 [ -n "$pkg" ] || exit
271 CONFIG_FILES=""
272 . $pkg
273 grep -qs ^pre_install $pkg && pre_install $2/fs
274 [ -n "$CONFIG_FILES" ] && for i in $CONFIG_FILES; do echo $i >> $2/config_files; done
275 unlzma -c $(dirname $pkg)/fs.cpio.lzma | ( cd $2 ; cpio -idmu )
276 exit
277 }
282 do_post_install()
283 {
284 pkg=$(get_receipt $1 $2)
285 [ -n "$pkg" ] || exit
286 . $pkg
287 echo "$1 $VERSION $(md5sum $(dirname $pkg)/fs.cpio.lzma | awk '{ print $1 }')" >> $2/fs/etc/packages.conf
288 if grep -qs ^post_install $pkg; then
289 [ -s $2/vars ] && . $2/vars
290 echo "=== $pkg: $(date) ===" >> $2/post_install.log 2>&1
291 post_install $2/fs >> $2/post_install.log 2>&1
292 sed -e 's/^export/ /' -e 's/^/ /' < $2/vars >> $2/fs/etc/packages.conf
293 fi
294 rm -f $2/vars
295 exit
296 }
301 scan_depends()
302 {
303 local pkg
304 for pkg in $@ ; do
305 case " $OUTPUT " in
306 *\ $pkg\ *) continue ;;
307 esac
308 DEPENDS=""
309 . $(get_receipt $pkg $TMPDIR)
310 scan_depends $DEPENDS
311 case " $OUTPUT " in
312 *\ $pkg\ *) continue ;;
313 esac
314 OUTPUT="$OUTPUT $pkg"
315 done
316 }
321 get_depends()
322 {
323 TMPDIR=$2
324 shift 2
325 OUTPUT=""
326 scan_depends $@
327 echo -n $OUTPUT
328 exit
329 }
334 pkgs_extract()
335 {
336 cd $2
337 mkdir pkgs
338 if cpio -t < $1 | grep -q receipt; then
339 mv $1 pkgs
340 elif tar tf $1 | grep -q tazpkg; then
341 tar xf $1 -C pkgs
342 elif tar tzf $1 | grep -q tazpkg; then
343 tar xzf $1 -C pkgs
344 elif tar tjf $1 | grep -q tazpkg; then
345 tar xjf $1 -C pkgs
346 else
347 rm -rf $1 pkgs
348 exit
349 fi
350 cd pkgs
351 for i in *; do
352 mkdir tmp
353 cd tmp
354 cpio -i < ../$i
355 . ./receipt
356 cd ..
357 mv tmp $PACKAGE-$VERSION
358 done
359 exit
360 }
365 lzma_set_size()
366 {
367 n=$(unlzma -c $1 | wc -c)
368 for i in $(seq 1 8); do
369 printf '\\\\x%02X' $(($n & 255))
370 n=$(($n >> 8))
371 done | xargs echo -en | dd of=$1 conv=notrunc bs=1 seek=5 2> /dev/null
372 }
377 case "$1" in
378 --list-modules) list_modules $@ ;;
379 --list-kernels) list_kernels $@ ;;
380 --list-pkgs) list_pkgs $@ ;;
381 --get-form) get_form $2 $3 ;;
382 --get-note) get_note $2 $3 ;;
383 --pre-install) do_pre_install $2 $3 ;;
384 --post-install) do_post_install $2 $3 ;;
385 --depends) get_depends $@ ;;
386 --pkgs-extract) pkgs_extract $2 $3 ;;
387 --remove) rm -rf $2; exit ;;
388 --get-pkg) get_package $2 $3 ;;
389 --get-suggested) get_suggested $2 $3 ;;
390 --init) init ;;
391 esac
396 if [ "x$1" == "x--mkrootfs" ]; then
397 tmp=$2
398 cd $tmp/fs
399 if [ ! -d boot -a -s ../kernel ]; then # custom kernel
400 mkdir boot
401 cp ../kernel boot/bzImage
402 fi
403 find -user bellard -exec chown root.root {} \;
404 find | grep -v ^./boot | cpio -o -H newc | gzip -9 > ../rootfs.gz
405 which advdef 2> /dev/null && advdef -z4 ../rootfs.gz
406 find .. -exec ls -ld {} \; > /tmp/X
407 fi
408 if [ "x$1" == "x--mkiso" ]; then
409 tmp=$2
410 mkdir -p $tmp/iso/boot/isolinux $tmp/iso/data
411 cat $tmp/fs/boot/System.map | gzip -9 > $tmp/iso/data/sysmap.gz
412 cat $tmp/fs/boot/config | gzip -9 > $tmp/iso/data/linconf.gz
413 cat $tmp/fs/boot/config-busybox | gzip -9 > $tmp/iso/data/bbconf.gz
414 cp $tmp/fs/boot/bundle $tmp/iso/data/bundle.sh
415 cat $tmp/post_install.log | gzip -9 > $tmp/iso/data/log.gz
416 cp $tmp/config_files $tmp/iso/data/files.cnf
417 cp $tmp/fs/etc/packages.conf $tmp/iso/data/packages.cnf
418 [ -s wok/busybox/receipt ] && tar czf $tmp/iso/data/wok.tgz wok/*
419 [ -s www/index.php ] && tar czf $tmp/iso/data/www.tgz www/*
420 cp $tmp/fs/boot/bzImage $tmp/iso/boot/bzImage
421 cp $tmp/rootfs.gz $tmp/iso/boot/rootfs
422 cp /boot/isolinux/isolinux.bin $tmp/iso/boot/isolinux
423 cat > $tmp/iso/boot/isolinux/isolinux.cfg <<EOT
424 label slitaz
425 kernel /boot/bzImage
426 append initrd=/boot/rootfs rw root=/dev/null vga=normal
427 default slitaz
428 implicit 0
429 prompt 1
430 timeout 50
431 EOT
432 genisoimage -o $tmp/slitaz.iso -b boot/isolinux/isolinux.bin \
433 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
434 -V "Tiny SliTaz" -p "www.slitaz.org" -input-charset iso8859-1 \
435 -boot-info-table $tmp/iso > /dev/null 2>&1
436 [ -x /usr/bin/isohybrid ] &&
437 /usr/bin/isohybrid $tmp/slitaz.iso 2> /dev/null
438 [ -x /usr/bin/iso2exe ] &&
439 /usr/bin/iso2exe $tmp/slitaz.iso 2> /dev/null
440 fi
441 if [ "x$1" == "x--mkexe" ]; then
442 tmp=$2
443 cd $tmp
444 cp fs/boot/bzImage slitaz.exe
445 sh fs/boot/bundle slitaz.exe rootfs.gz
446 fi
447 if [ "x$1" == "x--mkimg" ]; then
448 tmp=$2
449 cd $tmp
450 cp fs/boot/bzImage slitaz.img
451 sh fs/boot/bundle slitaz.img rootfs.gz
452 if [ -s fs/boot/ipxe ] && [ -s fs/boot/memtest ] &&
453 [ $(du -c fs/boot/ipxe fs/boot/memtest slitaz.img | \
454 awk 'END { print $1 }') -lt 1440 ]; then
455 sh fs/boot/bundle out " SliTaz boot menu" slitaz.img \
456 "Tiny SliTaz" fs/boot/ipxe "SliTaz web boot" \
457 fs/boot/memtest "Check memory"
458 mv -f out slitaz.img
459 elif [ -s fs/boot/ipxe ] && [ $(du -c fs/boot/ipxe slitaz.img | \
460 awk 'END { print $1 }') -lt 1440 ]; then
461 sh fs/boot/bundle out " SliTaz boot menu" slitaz.img \
462 "Tiny SliTaz" fs/boot/ipxe "SliTaz web boot"
463 mv -f out slitaz.img
464 elif [ -s fs/boot/memtest ] && [ $(du -c fs/boot/memtest slitaz.img | \
465 awk 'END { print $1 }') -lt 1440 ]; 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 fi
470 [ $(stat -c %s slitaz.img) -lt 1474560 ] &&
471 dd of=slitaz.img bs=18k seek=80 count=0 2> /dev/null
472 fi
473 if [ "x$1" == "x--mkcfg" ]; then
474 tmp=$2
475 cd $tmp/fs
476 for i in $(sed 's#^/##' < ../config_files); do find $i; done | \
477 sort | uniq | cpio -o -H newc | gzip -9 > ../config_files.cpio.gz
478 fi
479 if [ "x$1" == "x--chkdist" ]; then
480 if [ pkgs/busybox-*/fs.cpio.lzma -nt dist/rootfs.cpio ]; then
481 cat pkgs/busybox-*/fs.cpio.lzma | unlzma | ( cd dist ; cpio -idmu )
482 mv -f dist/fs/* dist/
483 rmdir dist/fs
484 touch dist/*
485 fi
486 fi