tiny-slitaz view helper @ rev 11

helper: fix floppy size
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Jan 05 20:32:45 2016 +0100 (2016-01-05)
parents 69b7df0ddb67
children 4f59e782a307
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>Size</th>
152 <th> </th>
153 </tr>
154 </thead>
155 <tbody>
156 EOT
157 for i in $TMPDIR/pkgs/*/receipt pkgs/*/receipt ; do
158 [ -s $i ] || continue
159 case "$i" in
160 pkgs/module-*/receipt);;
161 *) continue;;
162 esac
163 UNPACKED_SIZE='-'
164 . $i
165 checked=''
166 case " $@ " in
167 *\ $PACKAGE\ *) checked='checked="checked"' ;;
168 esac
169 grep -qs "^$PACKAGE " $TMPDIR/uploadconf &&
170 checked='checked="checked"'
171 cat <<EOT
172 <tr>
173 <td><input type="checkbox" name="selected[]" value="$PACKAGE" $checked/></td>
174 <td>${PACKAGE#module-}</td>
175 <td>$VERSION</td>
176 <td>$SHORT_DESC</td>
177 <td>$UNPACKED_SIZE</td>
178 <td>$(grep -qs ^config_form $i && echo '&raquo;')</td>
179 </tr>
180 EOT
181 done
182 cat <<EOT
183 </tbody>
184 </table>
185 </div>
186 EOT
187 exit
188 }
193 get_receipt()
194 {
195 grep -l "PACKAGE=\"$1\"" $2/pkgs/*/receipt pkgs/*/receipt | head -1
196 }
201 get_suggested()
202 {
203 local pkg
204 pkg=pkgs/$1/receipt
205 [ -s $pkg ] || pkg=$2/pkgs/$1/receipt
206 [ -s $pkg ] || pkg=$(get_receipt $@)
207 . $pkg
208 echo -n $SUGGESTED
209 }
214 get_package()
215 {
216 local pkg
217 pkg=pkgs/$1/receipt
218 [ -s $pkg ] || pkg=$2/pkgs/$1/receipt
219 [ -s $pkg ] || pkg=$(get_receipt $@)
220 . $pkg
221 cd $(dirname $pkg)
222 pkg=$2$PACKAGE-$VERSION.tazpkg
223 find * | cpio -o -H newc > $pkg
224 echo -n $pkg
225 }
230 get_note()
231 {
232 pkg=$(get_receipt $1 $2)
233 [ -n "$pkg" ] || exit
234 grep -qs ^config_note $pkg || exit
235 . $pkg
236 config_note
237 }
242 get_form()
243 {
244 pkg=$(get_receipt $1 $2)
245 [ -n "$pkg" ] || exit
246 grep -qs ^config_form $pkg || exit
247 . $pkg
248 if [ -s $2/uploadconf ]; then
249 awk "{
250 if (found) {
251 if (/^ /) print;
252 else exit;
253 }
254 if (/^$PACKAGE /) found=1
255 }" < $2/uploadconf | sed -e 's/ //' -e 's/ \([A-Z_0-9]*=\)/export \1/' > $2/vars
256 . $2/vars
257 fi
258 config_form $2/fs
259 exit
260 }
265 do_pre_install()
266 {
267 pkg=$(get_receipt $1 $2)
268 [ -n "$pkg" ] || exit
269 CONFIG_FILES=""
270 . $pkg
271 grep -qs ^pre_install $pkg && pre_install $2/fs
272 [ -n "$CONFIG_FILES" ] && for i in $CONFIG_FILES; do echo $i >> $2/config_files; done
273 unlzma -c $(dirname $pkg)/fs.cpio.lzma | ( cd $2 ; cpio -idmu )
274 exit
275 }
280 do_post_install()
281 {
282 pkg=$(get_receipt $1 $2)
283 [ -n "$pkg" ] || exit
284 . $pkg
285 echo "$1 $VERSION $(md5sum $(dirname $pkg)/fs.cpio.lzma | awk '{ print $1 }')" >> $2/fs/etc/packages.conf
286 if grep -qs ^post_install $pkg; then
287 [ -s $2/vars ] && . $2/vars
288 echo "=== $pkg: $(date) ===" >> $2/post_install.log 2>&1
289 post_install $2/fs >> $2/post_install.log 2>&1
290 sed -e 's/^export/ /' -e 's/^/ /' < $2/vars >> $2/fs/etc/packages.conf
291 fi
292 rm -f $2/vars
293 exit
294 }
299 scan_depends()
300 {
301 local pkg
302 for pkg in $@ ; do
303 case " $OUTPUT " in
304 *\ $pkg\ *) continue ;;
305 esac
306 DEPENDS=""
307 . $(get_receipt $pkg $TMPDIR)
308 scan_depends $DEPENDS
309 case " $OUTPUT " in
310 *\ $pkg\ *) continue ;;
311 esac
312 OUTPUT="$OUTPUT $pkg"
313 done
314 }
319 get_depends()
320 {
321 TMPDIR=$2
322 shift 2
323 OUTPUT=""
324 scan_depends $@
325 echo -n $OUTPUT
326 exit
327 }
332 pkgs_extract()
333 {
334 cd $2
335 mkdir pkgs
336 if cpio -t < $1 | grep -q receipt; then
337 mv $1 pkgs
338 elif tar tf $1 | grep -q tazpkg; then
339 tar xf $1 -C pkgs
340 elif tar tzf $1 | grep -q tazpkg; then
341 tar xzf $1 -C pkgs
342 elif tar tjf $1 | grep -q tazpkg; then
343 tar xjf $1 -C pkgs
344 else
345 rm -rf $1 pkgs
346 exit
347 fi
348 cd pkgs
349 for i in *; do
350 mkdir tmp
351 cd tmp
352 cpio -i < ../$i
353 . ./receipt
354 cd ..
355 mv tmp $PACKAGE-$VERSION
356 done
357 exit
358 }
363 lzma_set_size()
364 {
365 n=$(unlzma -c $1 | wc -c)
366 for i in $(seq 1 8); do
367 printf '\\\\x%02X' $(($n & 255))
368 n=$(($n >> 8))
369 done | xargs echo -en | dd of=$1 conv=notrunc bs=1 seek=5 2> /dev/null
370 }
375 case "$1" in
376 --list-modules) list_modules $@ ;;
377 --list-kernels) list_kernels $@ ;;
378 --list-pkgs) list_pkgs $@ ;;
379 --get-form) get_form $2 $3 ;;
380 --get-note) get_note $2 $3 ;;
381 --pre-install) do_pre_install $2 $3 ;;
382 --post-install) do_post_install $2 $3 ;;
383 --depends) get_depends $@ ;;
384 --pkgs-extract) pkgs_extract $2 $3 ;;
385 --remove) rm -rf $2; exit ;;
386 --get-pkg) get_package $2 $3 ;;
387 --get-suggested) get_suggested $2 $3 ;;
388 --init) init ;;
389 esac
394 if [ "x$1" == "x--mkrootfs" ]; then
395 tmp=$2
396 cd $tmp/fs
397 if [ ! -d boot -a -s ../kernel ]; then # custom kernel
398 mkdir boot
399 cp ../kernel boot/bzImage
400 fi
401 find -user bellard -exec chown root.root {} \;
402 find | grep -v ^./boot | cpio -o -H newc | gzip -9 > ../rootfs.gz
403 which advdef 2> /dev/null && advdef -z4 ../rootfs.gz
404 find .. -exec ls -ld {} \; > /tmp/X
405 fi
406 if [ "x$1" == "x--mkiso" ]; then
407 tmp=$2
408 mkdir -p $tmp/iso/boot/isolinux $tmp/iso/data
409 cat $tmp/fs/boot/System.map | gzip -9 > $tmp/iso/data/sysmap.gz
410 cat $tmp/fs/boot/config | gzip -9 > $tmp/iso/data/linconf.gz
411 cat $tmp/fs/boot/config-busybox | gzip -9 > $tmp/iso/data/bbconf.gz
412 cp $tmp/fs/boot/bundle $tmp/iso/data/bundle.sh
413 cat $tmp/post_install.log | gzip -9 > $tmp/iso/data/log.gz
414 cp $tmp/config_files $tmp/iso/data/files.cnf
415 cp $tmp/fs/etc/packages.conf $tmp/iso/data/packages.cnf
416 [ -s wok/busybox/receipt ] && tar czf $tmp/iso/data/wok.tgz wok/*
417 [ -s www/index.php ] && tar czf $tmp/iso/data/www.tgz www/*
418 cp $tmp/fs/boot/bzImage $tmp/iso/boot/bzImage
419 cp $tmp/rootfs.gz $tmp/iso/boot/rootfs
420 cp /boot/isolinux/isolinux.bin $tmp/iso/boot/isolinux
421 cat > $tmp/iso/boot/isolinux/isolinux.cfg <<EOT
422 label slitaz
423 kernel /boot/bzImage
424 append initrd=/boot/rootfs rw root=/dev/null vga=normal
425 default slitaz
426 implicit 0
427 prompt 1
428 timeout 50
429 EOT
430 genisoimage -o $tmp/slitaz.iso -b boot/isolinux/isolinux.bin \
431 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
432 -V "Tiny SliTaz" -p "www.slitaz.org" -input-charset iso8859-1 \
433 -boot-info-table $tmp/iso > /dev/null 2>&1
434 [ -x /usr/bin/isohybrid ] &&
435 /usr/bin/isohybrid $tmp/slitaz.iso 2> /dev/null
436 [ -x /usr/bin/iso2exe ] &&
437 /usr/bin/iso2exe $tmp/slitaz.iso 2> /dev/null
438 fi
439 if [ "x$1" == "x--mkexe" ]; then
440 tmp=$2
441 cd $tmp
442 cp fs/boot/bzImage slitaz.exe
443 sh fs/boot/bundle slitaz.exe rootfs.gz
444 fi
445 if [ "x$1" == "x--mkimg" ]; then
446 tmp=$2
447 cd $tmp
448 cp fs/boot/bzImage slitaz.img
449 sh fs/boot/bundle slitaz.img rootfs.gz
450 [ $(stat -c %s slitaz.img) -lt 1474560 ] &&
451 dd of=slitaz.img bs=18k seek=80 count=0 2> /dev/null
452 fi
453 if [ "x$1" == "x--mkcfg" ]; then
454 tmp=$2
455 cd $tmp/fs
456 for i in $(sed 's#^/##' < ../config_files); do find $i; done | \
457 sort | uniq | cpio -o -H newc | gzip -9 > ../config_files.cpio.gz
458 fi
459 if [ "x$1" == "x--chkdist" ]; then
460 if [ pkgs/busybox-*/fs.cpio.lzma -nt dist/rootfs.cpio ]; then
461 cat pkgs/busybox-*/fs.cpio.lzma | unlzma | ( cd dist ; cpio -idmu )
462 mv -f dist/fs/* dist/
463 rmdir dist/fs
464 touch dist/*
465 fi
466 fi