tiny-slitaz view helper @ rev 5
refresh
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Wed Oct 07 23:37:02 2015 +0200 (2015-10-07) |
parents | 1d33b2a53785 |
children | ac214416e736 |
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 }
13 list_pkgs()
14 {
15 TMPDIR=$2
16 shift 2
17 cat <<EOT
18 <table>
19 <tr>
20 <th></th>
21 <th>Package</th>
22 <th>Version</th>
23 <th>Description</th>
24 <th>Disk</th>
25 <th>Memory</th>
26 <th></th>
27 </tr>
28 EOT
29 for i in $TMPDIR/pkgs/*/receipt pkgs/*/receipt ; do
30 [ -s $i ] || continue
31 case "$i" in
32 pkgs/kernel-*/receipt) continue;;
33 pkgs/module-*/receipt) continue;;
34 esac
35 AUTO_SELECTION=""
36 UNPACKED_SIZE="-"
37 PACKED_SIZE="-"
38 checked=""
39 . $i
40 case " $@ " in
41 *\ $PACKAGE\ *) checked='checked="checked"';;
42 *) [ -n "$2" ] && checked="";;
43 esac
44 grep -qs "^$PACKAGE " $TMPDIR/uploadconf &&
45 checked='checked="checked"'
46 case "$AUTO_SELECTION" in
47 never)
48 checked='disabled' ;;
49 always)
50 checked='checked="checked" disabled'
51 cat <<EOT
52 <input type="hidden" name="selected[]" value="$PACKAGE" />
53 EOT
54 esac
55 cat <<EOT
56 <tr>
57 <td><input type="checkbox" name="selected[]" value="$PACKAGE" $checked /></td>
58 <td><a href="?dl=$PACKAGE-$VERSION&tmp=$TMPDIR">$PACKAGE</a></td>
59 <td>$VERSION</td>
60 <td>$SHORT_DESC</td>
61 <td>$PACKED_SIZE</td>
62 <td>$UNPACKED_SIZE</td>
63 <td>$(grep -qs ^config_form $i && echo '»')</td>
64 </tr>
65 EOT
66 done
67 cat <<EOT
68 </table>
69 <p>
70 </p>
71 EOT
72 exit
73 }
75 list_kernels()
76 {
77 TMPDIR=$2
78 shift 2
79 cat <<EOT
80 <table>
81 <tr>
82 <th></th>
83 <th>Kernel</th>
84 <th>Version</th>
85 <th>Description</th>
86 <!-- th>Size</th -->
87 </tr>
88 EOT
89 checked='checked="checked"'
90 for i in $TMPDIR/pkgs/*/receipt pkgs/*/receipt ; do
91 [ -s $i ] || continue
92 case "$i" in
93 pkgs/kernel-*/receipt);;
94 *) continue;;
95 esac
96 UNPACKED_SIZE="-"
97 . $i
98 case " $@ " in
99 *\ $PACKAGE\ *) checked='checked="checked"' ;;
100 *) [ -n "$2" ] && checked="";;
101 esac
102 cat <<EOT
103 <tr>
104 <td><input type="radio" name="kernel" value="$PACKAGE" $checked/></td>
105 <td>${PACKAGE#kernel-}</td>
106 <td>$VERSION</td>
107 <td>$SHORT_DESC</td>
108 <!-- td>$UNPACKED_SIZE</td -->
109 </tr>
110 EOT
111 checked=""
112 done
113 cat <<EOT
114 </table>
115 EOT
116 exit
117 }
119 list_modules()
120 {
121 TMPDIR=$2
122 shift 2
123 cat <<EOT
124 <table>
125 <tr>
126 <th></th>
127 <th>Module</th>
128 <th>Version</th>
129 <th>Description</th>
130 <th>Size</th>
131 <th></th>
132 </tr>
133 EOT
134 for i in $TMPDIR/pkgs/*/receipt pkgs/*/receipt ; do
135 [ -s $i ] || continue
136 case "$i" in
137 pkgs/module-*/receipt);;
138 *) continue;;
139 esac
140 UNPACKED_SIZE="-"
141 . $i
142 checked=""
143 case " $@ " in
144 *\ $PACKAGE\ *) checked='checked="checked"' ;;
145 esac
146 grep -qs "^$PACKAGE " $TMPDIR/uploadconf &&
147 checked='checked="checked"'
148 cat <<EOT
149 <tr>
150 <td><input type="checkbox" name="selected[]" value="$PACKAGE" $checked/></td>
151 <td>${PACKAGE#module-}</td>
152 <td>$VERSION</td>
153 <td>$SHORT_DESC</td>
154 <td>$UNPACKED_SIZE</td>
155 <td>$(grep -qs ^config_form $i && echo '?')</td>
156 </tr>
157 EOT
158 done
159 cat <<EOT
160 </table>
161 EOT
162 exit
163 }
165 get_receipt()
166 {
167 grep -l "PACKAGE=\"$1\"" $2/pkgs/*/receipt pkgs/*/receipt | head -1
168 }
170 get_package()
171 {
172 local pkg
173 pkg=pkgs/$1/receipt
174 [ -s $pkg ] || pkg=$2/pkgs/$1/receipt
175 [ -s $pkg ] || pkg=$(get_receipt $@)
176 . $pkg
177 cd $(dirname $pkg)
178 pkg=$2$PACKAGE-$VERSION.tazpkg
179 find * | cpio -o -H newc > $pkg
180 echo -n $pkg
181 }
183 get_note()
184 {
185 pkg=$(get_receipt $1 $2)
186 [ -n "$pkg" ] || exit
187 grep -qs ^config_note $pkg || exit
188 . $pkg
189 config_note
190 }
192 get_form()
193 {
194 pkg=$(get_receipt $1 $2)
195 [ -n "$pkg" ] || exit
196 grep -qs ^config_form $pkg || exit
197 . $pkg
198 if [ -s $2/uploadconf ]; then
199 awk "{
200 if (found) {
201 if (/^ /) print;
202 else exit;
203 }
204 if (/^$PACKAGE /) found=1
205 }" < $2/uploadconf | sed -e 's/ //' -e 's/ \([A-Z_0-9]*=\)/export \1/' > $2/vars
206 . $2/vars
207 fi
208 config_form $2/fs
209 exit
210 }
212 do_pre_install()
213 {
214 pkg=$(get_receipt $1 $2)
215 [ -n "$pkg" ] || exit
216 CONFIG_FILES=""
217 . $pkg
218 grep -qs ^pre_install $pkg && pre_install $2/fs
219 [ -n "$CONFIG_FILES" ] && for i in $CONFIG_FILES; do echo $i >> $2/config_files; done
220 unlzma -c $(dirname $pkg)/fs.cpio.lzma | ( cd $2 ; cpio -idmu )
221 exit
222 }
224 do_post_install()
225 {
226 pkg=$(get_receipt $1 $2)
227 [ -n "$pkg" ] || exit
228 . $pkg
229 echo "$1 $VERSION $(md5sum $(dirname $pkg)/fs.cpio.lzma | awk '{ print $1 }')" >> $2/fs/etc/packages.conf
230 if grep -qs ^post_install $pkg; then
231 [ -s $2/vars ] && . $2/vars
232 echo "=== $pkg: $(date) ===" >> $2/post_install.log 2>&1
233 post_install $2/fs >> $2/post_install.log 2>&1
234 sed -e 's/^export/ /' -e 's/^/ /' < $2/vars >> $2/fs/etc/packages.conf
235 fi
236 rm -f $2/vars
237 exit
238 }
240 scan_depends()
241 {
242 local pkg
243 for pkg in $@ ; do
244 case " $OUTPUT " in
245 *\ $pkg\ *) continue ;;
246 esac
247 DEPENDS=""
248 . $(get_receipt $pkg $TMPDIR)
249 scan_depends $DEPENDS
250 case " $OUTPUT " in
251 *\ $pkg\ *) continue ;;
252 esac
253 OUTPUT="$OUTPUT $pkg"
254 done
255 }
257 get_depends()
258 {
259 TMPDIR=$2
260 shift 2
261 OUTPUT=""
262 scan_depends $@
263 echo -n $OUTPUT
264 exit
265 }
267 pkgs_extract()
268 {
269 cd $2
270 mkdir pkgs
271 if cpio -t < $1 | grep -q receipt; then
272 mv $1 pkgs
273 elif tar tf $1 | grep -q tazpkg; then
274 tar xf $1 -C pkgs
275 elif tar tzf $1 | grep -q tazpkg; then
276 tar xzf $1 -C pkgs
277 elif tar tjf $1 | grep -q tazpkg; then
278 tar xjf $1 -C pkgs
279 else
280 rm -rf $1 pkgs
281 exit
282 fi
283 cd pkgs
284 for i in *; do
285 mkdir tmp
286 cd tmp
287 cpio -i < ../$i
288 . ./receipt
289 cd ..
290 mv tmp $PACKAGE-$VERSION
291 done
292 exit
293 }
295 lzma_set_size()
296 {
297 n=$(unlzma -c $1 | wc -c)
298 for i in $(seq 1 8); do
299 printf '\\\\x%02X' $(($n & 255))
300 n=$(($n >> 8))
301 done | xargs echo -en | dd of=$1 conv=notrunc bs=1 seek=5 2> /dev/null
302 }
304 case "$1" in
305 --list-modules) list_modules $@ ;;
306 --list-kernels) list_kernels $@ ;;
307 --list-pkgs) list_pkgs $@ ;;
308 --get-form) get_form $2 $3 ;;
309 --get-note) get_note $2 $3 ;;
310 --pre-install) do_pre_install $2 $3 ;;
311 --post-install) do_post_install $2 $3 ;;
312 --depends) get_depends $@ ;;
313 --pkgs-extract) pkgs_extract $2 $3 ;;
314 --remove) rm -rf $2; exit ;;
315 --get-pkg) get_package $2 $3 ;;
316 --init) init ;;
317 esac
319 if [ "x$1" == "x--mkrootfs" ]; then
320 tmp=$2
321 cd $tmp/fs
322 if [ ! -d boot -a -s ../kernel ]; then # custom kernel
323 mkdir boot
324 cp ../kernel boot/bzImage
325 fi
326 find -user bellard -exec chown root.root {} \;
327 find | grep -v ^./boot | cpio -o -H newc | gzip -9 > ../rootfs.gz
328 which advdef 2> /dev/null && advdef -z4 ../rootfs.gz
329 find .. -exec ls -ld {} \; > /tmp/X
330 fi
331 if [ "x$1" == "x--mkiso" ]; then
332 tmp=$2
333 mkdir -p $tmp/iso/boot/isolinux $tmp/iso/data
334 cat $tmp/fs/boot/System.map | gzip -9 > $tmp/iso/data/sysmap.gz
335 cat $tmp/fs/boot/config | gzip -9 > $tmp/iso/data/linconf.gz
336 cat $tmp/fs/boot/config-busybox | gzip -9 > $tmp/iso/data/bbconf.gz
337 cp $tmp/fs/boot/bundle $tmp/iso/data/bundle.sh
338 cat $tmp/post_install.log | gzip -9 > $tmp/iso/data/log.gz
339 cp $tmp/config_files $tmp/iso/data/files.cnf
340 cp $tmp/fs/etc/packages.conf $tmp/iso/data/packages.cnf
341 cp $tmp/fs/boot/bzImage $tmp/iso/boot/bzImage
342 cp $tmp/rootfs.gz $tmp/iso/boot/rootfs
343 cp /boot/isolinux/isolinux.bin $tmp/iso/boot/isolinux
344 cat > $tmp/iso/boot/isolinux/isolinux.cfg <<EOT
345 label slitaz
346 kernel /boot/bzImage
347 append initrd=/boot/rootfs rw root=/dev/null vga=normal
348 default slitaz
349 implicit 0
350 prompt 1
351 timeout 50
352 EOT
353 genisoimage -o $tmp/slitaz.iso -b boot/isolinux/isolinux.bin \
354 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
355 -V "Tiny SliTaz" -p "www.slitaz.org" -input-charset iso8859-1 \
356 -boot-info-table $tmp/iso > /dev/null 2>&1
357 [ -x /usr/bin/isohybrid ] &&
358 /usr/bin/isohybrid $tmp/slitaz.iso 2> /dev/null
359 fi
360 if [ "x$1" == "x--mkexe" ]; then
361 tmp=$2
362 cd $tmp
363 cp fs/boot/bzImage slitaz.exe
364 sh fs/boot/bundle slitaz.exe rootfs.gz exe
365 fi
366 if [ "x$1" == "x--mkimg" ]; then
367 tmp=$2
368 cd $tmp
369 cp fs/boot/bzImage slitaz.img
370 sh fs/boot/bundle slitaz.img rootfs.gz floppy
371 dd of=slitaz.img bs=18k seek=80 count=0 conv=notrunc 2> /dev/null
372 fi
373 if [ "x$1" == "x--mkcfg" ]; then
374 tmp=$2
375 cd $tmp/fs
376 for i in $(sed 's#^/##' < ../config_files); do find $i; done | \
377 sort | uniq | cpio -o -H newc | gzip -9 > ../config_files.cpio.gz
378 fi
379 if [ "x$1" == "x--chkdist" ]; then
380 if [ pkgs/busybox-*/fs.cpio.lzma -nt dist/rootfs.cpio ]; then
381 cat pkgs/busybox-*/fs.cpio.lzma | unlzma | ( cd dist ; cpio -idmu )
382 mv -f dist/fs/* dist/
383 rmdir dist/fs
384 touch dist/*
385 fi
386 fi