tiny-slitaz view helper @ rev 1

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