tiny-slitaz view helper @ rev 6

Refresh style (thanks Aleksej)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Nov 01 16:56:16 2015 +0100 (2015-11-01)
parents 577e6e91216d
children 69b7df0ddb67
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_package()
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 cd $(dirname $pkg)
209 pkg=$2$PACKAGE-$VERSION.tazpkg
210 find * | cpio -o -H newc > $pkg
211 echo -n $pkg
212 }
217 get_note()
218 {
219 pkg=$(get_receipt $1 $2)
220 [ -n "$pkg" ] || exit
221 grep -qs ^config_note $pkg || exit
222 . $pkg
223 config_note
224 }
229 get_form()
230 {
231 pkg=$(get_receipt $1 $2)
232 [ -n "$pkg" ] || exit
233 grep -qs ^config_form $pkg || exit
234 . $pkg
235 if [ -s $2/uploadconf ]; then
236 awk "{
237 if (found) {
238 if (/^ /) print;
239 else exit;
240 }
241 if (/^$PACKAGE /) found=1
242 }" < $2/uploadconf | sed -e 's/ //' -e 's/ \([A-Z_0-9]*=\)/export \1/' > $2/vars
243 . $2/vars
244 fi
245 config_form $2/fs
246 exit
247 }
252 do_pre_install()
253 {
254 pkg=$(get_receipt $1 $2)
255 [ -n "$pkg" ] || exit
256 CONFIG_FILES=""
257 . $pkg
258 grep -qs ^pre_install $pkg && pre_install $2/fs
259 [ -n "$CONFIG_FILES" ] && for i in $CONFIG_FILES; do echo $i >> $2/config_files; done
260 unlzma -c $(dirname $pkg)/fs.cpio.lzma | ( cd $2 ; cpio -idmu )
261 exit
262 }
267 do_post_install()
268 {
269 pkg=$(get_receipt $1 $2)
270 [ -n "$pkg" ] || exit
271 . $pkg
272 echo "$1 $VERSION $(md5sum $(dirname $pkg)/fs.cpio.lzma | awk '{ print $1 }')" >> $2/fs/etc/packages.conf
273 if grep -qs ^post_install $pkg; then
274 [ -s $2/vars ] && . $2/vars
275 echo "=== $pkg: $(date) ===" >> $2/post_install.log 2>&1
276 post_install $2/fs >> $2/post_install.log 2>&1
277 sed -e 's/^export/ /' -e 's/^/ /' < $2/vars >> $2/fs/etc/packages.conf
278 fi
279 rm -f $2/vars
280 exit
281 }
286 scan_depends()
287 {
288 local pkg
289 for pkg in $@ ; do
290 case " $OUTPUT " in
291 *\ $pkg\ *) continue ;;
292 esac
293 DEPENDS=""
294 . $(get_receipt $pkg $TMPDIR)
295 scan_depends $DEPENDS
296 case " $OUTPUT " in
297 *\ $pkg\ *) continue ;;
298 esac
299 OUTPUT="$OUTPUT $pkg"
300 done
301 }
306 get_depends()
307 {
308 TMPDIR=$2
309 shift 2
310 OUTPUT=""
311 scan_depends $@
312 echo -n $OUTPUT
313 exit
314 }
319 pkgs_extract()
320 {
321 cd $2
322 mkdir pkgs
323 if cpio -t < $1 | grep -q receipt; then
324 mv $1 pkgs
325 elif tar tf $1 | grep -q tazpkg; then
326 tar xf $1 -C pkgs
327 elif tar tzf $1 | grep -q tazpkg; then
328 tar xzf $1 -C pkgs
329 elif tar tjf $1 | grep -q tazpkg; then
330 tar xjf $1 -C pkgs
331 else
332 rm -rf $1 pkgs
333 exit
334 fi
335 cd pkgs
336 for i in *; do
337 mkdir tmp
338 cd tmp
339 cpio -i < ../$i
340 . ./receipt
341 cd ..
342 mv tmp $PACKAGE-$VERSION
343 done
344 exit
345 }
350 lzma_set_size()
351 {
352 n=$(unlzma -c $1 | wc -c)
353 for i in $(seq 1 8); do
354 printf '\\\\x%02X' $(($n & 255))
355 n=$(($n >> 8))
356 done | xargs echo -en | dd of=$1 conv=notrunc bs=1 seek=5 2> /dev/null
357 }
362 case "$1" in
363 --list-modules) list_modules $@ ;;
364 --list-kernels) list_kernels $@ ;;
365 --list-pkgs) list_pkgs $@ ;;
366 --get-form) get_form $2 $3 ;;
367 --get-note) get_note $2 $3 ;;
368 --pre-install) do_pre_install $2 $3 ;;
369 --post-install) do_post_install $2 $3 ;;
370 --depends) get_depends $@ ;;
371 --pkgs-extract) pkgs_extract $2 $3 ;;
372 --remove) rm -rf $2; exit ;;
373 --get-pkg) get_package $2 $3 ;;
374 --init) init ;;
375 esac
380 if [ "x$1" == "x--mkrootfs" ]; then
381 tmp=$2
382 cd $tmp/fs
383 if [ ! -d boot -a -s ../kernel ]; then # custom kernel
384 mkdir boot
385 cp ../kernel boot/bzImage
386 fi
387 find -user bellard -exec chown root.root {} \;
388 find | grep -v ^./boot | cpio -o -H newc | gzip -9 > ../rootfs.gz
389 which advdef 2> /dev/null && advdef -z4 ../rootfs.gz
390 find .. -exec ls -ld {} \; > /tmp/X
391 fi
392 if [ "x$1" == "x--mkiso" ]; then
393 tmp=$2
394 mkdir -p $tmp/iso/boot/isolinux $tmp/iso/data
395 cat $tmp/fs/boot/System.map | gzip -9 > $tmp/iso/data/sysmap.gz
396 cat $tmp/fs/boot/config | gzip -9 > $tmp/iso/data/linconf.gz
397 cat $tmp/fs/boot/config-busybox | gzip -9 > $tmp/iso/data/bbconf.gz
398 cp $tmp/fs/boot/bundle $tmp/iso/data/bundle.sh
399 cat $tmp/post_install.log | gzip -9 > $tmp/iso/data/log.gz
400 cp $tmp/config_files $tmp/iso/data/files.cnf
401 cp $tmp/fs/etc/packages.conf $tmp/iso/data/packages.cnf
402 cp $tmp/fs/boot/bzImage $tmp/iso/boot/bzImage
403 cp $tmp/rootfs.gz $tmp/iso/boot/rootfs
404 cp /boot/isolinux/isolinux.bin $tmp/iso/boot/isolinux
405 cat > $tmp/iso/boot/isolinux/isolinux.cfg <<EOT
406 label slitaz
407 kernel /boot/bzImage
408 append initrd=/boot/rootfs rw root=/dev/null vga=normal
409 default slitaz
410 implicit 0
411 prompt 1
412 timeout 50
413 EOT
414 genisoimage -o $tmp/slitaz.iso -b boot/isolinux/isolinux.bin \
415 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
416 -V "Tiny SliTaz" -p "www.slitaz.org" -input-charset iso8859-1 \
417 -boot-info-table $tmp/iso > /dev/null 2>&1
418 [ -x /usr/bin/isohybrid ] &&
419 /usr/bin/isohybrid $tmp/slitaz.iso 2> /dev/null
420 [ -x /usr/bin/iso2exe ] &&
421 /usr/bin/iso2exe $tmp/slitaz.iso 2> /dev/null
422 fi
423 if [ "x$1" == "x--mkexe" ]; then
424 tmp=$2
425 cd $tmp
426 cp fs/boot/bzImage slitaz.exe
427 sh fs/boot/bundle slitaz.exe rootfs.gz exe
428 fi
429 if [ "x$1" == "x--mkimg" ]; then
430 tmp=$2
431 cd $tmp
432 cp fs/boot/bzImage slitaz.img
433 sh fs/boot/bundle slitaz.img rootfs.gz floppy
434 dd of=slitaz.img bs=18k seek=80 count=0 conv=notrunc 2> /dev/null
435 fi
436 if [ "x$1" == "x--mkcfg" ]; then
437 tmp=$2
438 cd $tmp/fs
439 for i in $(sed 's#^/##' < ../config_files); do find $i; done | \
440 sort | uniq | cpio -o -H newc | gzip -9 > ../config_files.cpio.gz
441 fi
442 if [ "x$1" == "x--chkdist" ]; then
443 if [ pkgs/busybox-*/fs.cpio.lzma -nt dist/rootfs.cpio ]; then
444 cat pkgs/busybox-*/fs.cpio.lzma | unlzma | ( cd dist ; cpio -idmu )
445 mv -f dist/fs/* dist/
446 rmdir dist/fs
447 touch dist/*
448 fi
449 fi