tiny-slitaz view helper @ rev 0

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