tiny-slitaz view helper @ rev 2

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