wok view mirror-tools/stuff/usr/bin/mkpkgiso @ rev 3760

mirror-tools/mkpkgiso: set lighttpd sort weight
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Jul 25 08:02:34 2009 +0200 (2009-07-25)
parents 2c5fb2c92a60
children 65dd59012383
line source
1 #!/bin/sh
2 # mkpkgiso, build packages ISO image.
3 # (C) 2007-TODAY SliTaz - GNU General Public License v3.
4 #
5 # Authors : Eric Joseph-Alexandre <erjo@slitaz.org>
6 # Pascal Bellard <pascal.bellard@slitaz.org>
8 VERSION=0.5
10 ROOT=/home/slitaz/iso
11 SORT_DIR=${ROOT}/_iso.$$
12 TEMP_DIR=${ROOT}/_iso.$$
13 SORT_FILE=${ROOT}/_sort.$$
14 PKG_VER=$1
15 shift
16 OPTIONS=$@
17 PKG_DIR=$TEMP_DIR/packages/$PKG_VER
18 REPOS=/var/www/slitaz/mirror/packages/$PKG_VER
19 PXE_DIR=/var/www/slitaz/mirror/pxe
20 ISO_DIR=/var/www/slitaz/mirror/iso/$PKG_VER
21 LOG=$PWD/$(basename $0).log
23 #
24 VOLUME_ID="packages-${PKG_VER}"
25 PUBLISHER="SliTaz http://www.slitaz.org/"
26 IMAGE="packages-${PKG_VER}.iso"
27 OUTPUT="$ROOT/$IMAGE"
29 # Check command line option.
30 if [ -z $PKG_VER ]; then
31 cat <<EOT
32 Usage: $(basename $0) <Version>
33 [--boot [--auto-install] [--loram-detect]]|--webboot] [--filter]
34 [--wok] [--wok-stable] [--website][--dry-run]
35 EOT
36 exit 1
37 fi
39 # Check if we provide a valide version
40 if [ ! -d $REPOS ]; then
41 echo "Boooh! $PKG_VER is not a valid version."
42 exit 1
43 fi
45 # Status function.
46 status()
47 {
48 local CHECK=$?
49 echo -en "\\033[70G[ "
50 if [ $CHECK = 0 ]; then
51 echo -en "\\033[1;33mOK"
52 else
53 echo -en "\\033[1;31mFailed"
54 fi
55 echo -e "\\033[0;39m ]"
56 }
58 # Create temp directory
59 mkdir -p $TEMP_DIR/packages/$PKG_VER
61 # Prepare evrything for ISO
63 echo ""
64 echo "Building ISO for packages $PKG_VER"
65 echo "==============================================================================="
66 echo -n "Creating working dir $(basename $TEMP_DIR)"
67 status
68 echo -n "Creating symlink"
69 status
71 # Link every packages to temp dir
72 cd $PKG_DIR
73 for i in $REPOS/*
74 do
75 ln -s $i >> $LOG 2>&1
76 done
78 echo -n "Creating install script"
79 # Create install script as suggested by Pascal.
80 cat >$TEMP_DIR/install.sh<<EOF
81 #!/bin/sh
82 #
84 DIR=\$(cd \$(busybox dirname \$0); pwd)
86 # Handle --auto-install case
87 if [ "\$DIR" == "/etc/init.d" ]; then
88 DIR=/mnt
90 # Handle loram on hybrid hard disk / usb key case
91 if [ ! -d /usr/bin ]; then
92 if [ -d /.usr.rw ]; then
93 echo -n "Mounting /usr read-write... "
94 usr=.usr.ro
95 else
96 echo -n "Mounting /usr read-only... "
97 usr=usr
98 fi
99 FS=\$DIR/usr.cromfs
100 if [ -f \$FS ]; then
101 /bin/cromfs-driver \$FS /\$usr -o ro,dev,suid,allow_other
102 elif [ -f \$DIR/usr.sqfs ]; then
103 FS=\$DIR/usr.sqfs
104 mount -o loop,ro -t squashfs \$FS /\$usr
105 elif [ -L /\$usr ]; then
106 FS=\$DIR/usr
107 fi
108 status
109 if [ -d /.usr.rw ]; then
110 if [ -x /bin/funionfs ]; then
111 /bin/funionfs -o dirs=/.usr.ro=RO:/.usr.rw -o allow_other -o suid,dev NONE /usr
112 else
113 /bin/mount -t aufs -o br:/.usr.rw:/.usr.ro none /usr
114 fi
115 fi
116 fi
117 fi
119 echo "Install packages..."
120 [ -d /var/cache/tazpkg ] || mkdir -p /var/cache/tazpkg
121 ls -d \$DIR/packages/* > /var/lib/tazpkg/mirror
122 ln -fs \$DIR/packages/*/*.tazpkg /var/cache/tazpkg/
123 ln -fs \$DIR/packages/*/packages.* /var/lib/tazpkg
124 echo "=> all $PKG_VER package are available for tazpkg/tazpkgbox"
125 EOF
126 [ -e files.list.lzma ] && cat >>$TEMP_DIR/install.sh<<EOF
127 ln -fs \$DIR/packages/*/files.list.lzma /var/lib/tazpkg
128 EOF
130 status
131 cat > $SORT_FILE <<EOT
132 $SORT_DIR/install.sh -4000
133 $SORT_DIR/README -4000
134 $SORT_DIR/index.html -4000
135 $SORT_DIR/md5sum -4000
136 $SORT_DIR/style.css -4000
137 $SORT_DIR/images/header.png -4000
138 $SORT_DIR/boot/bzImage 2
139 $SORT_DIR/boot/rootfs.gz 1
140 $SORT_DIR/packages -9000
141 EOT
142 ( cd $ROOT; ls $SORT_DIR/packages/*/packages* $SORT_DIR/packages/*/files.list.lzma ) | \
143 awk '{ printf "%s -7000\n",$0 }' >> $SORT_FILE
144 chmod 755 $TEMP_DIR/install.sh
146 case " $OPTIONS " in
147 *\ --filter\ *)
148 SIZE=0
149 for i in *.tazpkg; do
150 while read f; do
151 case "$i" in
152 $f*) continue 2;;
153 esac
154 done < packages.list
155 echo -n "Filter out $i ($(du -hs $(readlink $i) | awk '{ print $1 }'))..."
156 SIZE=$(( $SIZE + $(stat -c %s $(readlink $i)) ))
157 rm $i
158 status
159 done
160 UNIT=" bytes"
161 if [ $SIZE -gt 10240 ]; then
162 SIZE=$(( $SIZE / 1024 ))
163 UNIT="K"
164 fi
165 if [ $SIZE -gt 10240 ]; then
166 SIZE=$(( $SIZE / 1024 ))
167 UNIT="M"
168 fi
169 echo "$SIZE$UNIT removed.";;
170 esac
172 # Copy hg subtree
173 get_from_hg()
174 {
175 [ /slitaz/home/slitaz/hg/$1 ] || return
176 echo -n "Adding $2"
177 /usr/sbin/chroot /slitaz hg --repository /home/slitaz/hg/$1 pull >/dev/null
178 /usr/sbin/chroot /slitaz hg --repository /home/slitaz/hg/$1 update >/dev/null
179 mkdir $TEMP_DIR/$1
180 cp -a /slitaz/home/slitaz/hg/$1/* $TEMP_DIR/$1
181 status
182 echo "$(du -hs $TEMP_DIR/$1 | awk '{ print $1 }') used by $2."
183 }
185 for i in $OPTIONS ; do
186 case "$i" in
187 --wok)
188 cat >>$TEMP_DIR/install.sh<<EOF
189 echo "=> Wok (cooking) is in \$DIR/wok"
190 EOF
191 if get_from_hg wok "wok (cooking)"; then
192 echo "$SORT_DIR/wok -8000" >> $SORT_FILE
193 fi;;
194 --wok-stable)
195 cat >>$TEMP_DIR/install.sh<<EOF
196 echo "=> Wok (stable) is in \$DIR/wok"
197 EOF
198 if get_from_hg wok-stable "wok (stable)"; then
199 mv $TEMP_DIR/wok-stable $TEMP_DIR/wok
200 echo "$SORT_DIR/wok -8000" >> $SORT_FILE
201 fi;;
202 --website)
203 if get_from_hg website "web site"; then
204 echo "$SORT_DIR/website -6000" >> $SORT_FILE
205 echo "$(echo $SORT_DIR/packages/*/lighttpd-[0-9]*) -7100" >> $SORT_FILE
206 echo "$(echo $SORT_DIR/packages/*/pcre-[0-9]*) -7100" >> $SORT_FILE
207 cat >>$TEMP_DIR/install.sh<<EOF
208 [ -d /var/www ] || mkdir -p /var/www
209 ln -s \$DIR/website /var/www
210 tazpkg list | grep -q ^lighttpd || yes y | tazpkg get-install lighttpd > /dev/null 2>&1
211 echo "=> slitaz web site installed in http://localhost/website"
212 EOF
213 fi;;
214 esac
215 done
217 # Extract boot package function
218 extract_boot()
219 {
220 f=$(ls $REPOS/$1-[0-9]*.tazpkg 2> /dev/null)
221 [ -f "$f" ] || return 1
222 [ -d $TEMP_DIR/boot ] || mkdir $TEMP_DIR/boot
223 ( cd $TEMP_DIR/boot ; cpio -i fs.cpio.gz < $f 2> /dev/null )
224 ( cd $TEMP_DIR/boot ; zcat fs.cpio.gz | cpio -id 2> /dev/null )
225 mv $TEMP_DIR/boot/fs/boot/* $TEMP_DIR/boot
226 rm -rf $TEMP_DIR/boot/fs.cpio.gz $TEMP_DIR/boot/fs
227 return 0
228 }
230 # Gen boot part
231 BOOT_OPT=""
232 iso=$ISO_DIR/slitaz-$PKG_VER.iso
233 isoloram=$ISO_DIR/flavors/slitaz-loram-cdrom-sqfs.iso
234 case " $OPTIONS " in
235 *\ --boot\ *)
236 echo -n "Creating boot tree"
237 isoinfo -R -l -i $iso | awk '/^Directory/ { path=$4 } /^-/ { print path$12 }' | while read file; do
238 [ "$(basename $file)" == ".." ] && continue
239 [ "$file" = "/boot/isolinux/boot.cat" ] && continue
240 [ -d "$(dirname $TEMP_DIR/$file)" ] ||
241 mkdir -p "$(dirname $TEMP_DIR/$file)"
242 isoinfo -R -x "$file" -i $iso > "$TEMP_DIR/$file"
243 done
244 if [ -f "$(echo $TEMP_DIR/boot/vmlinuz*)" ]; then
245 rm -f $TEMP_DIR/boot/bzImage
246 ln $TEMP_DIR/boot/vmlinuz* $TEMP_DIR/boot/bzImage
247 fi
248 status
249 BOOT_OPT="-sort $SORT_FILE -b boot/isolinux/isolinux.bin \
250 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table"
251 case " $OPTIONS " in
252 *\ --auto-install\ *)
253 echo -n "Enable auto install"
254 cat >>$TEMP_DIR/install.sh<<EOF
255 echo "mount -o ro -t iso9660 LABEL=packages-$PKG_VER /mnt" >> /etc/init.d/local.sh
256 EOF
257 sed -i "s/rw root/rw config=LABEL=packages-$PKG_VER,install.sh root/" \
258 $TEMP_DIR/boot/isolinux/*.cfg
259 status
260 ;;
261 esac
262 [ -f $PXE_DIR/ifmem.c32 -a -f $isoloram ] && case " $OPTIONS " in
263 *\ --loram-detect\ *)
264 echo -n "Enable loram autodetection"
265 cp $PXE_DIR/ifmem.c32 "$TEMP_DIR/boot/isolinux"
266 isoinfo -R -x "/usr.sqfs" -i $isoloram > "$TEMP_DIR/usr.sqfs"
267 echo "$SORT_DIR/usr.sqfs -5000" >> $SORT_FILE
268 isoinfo -R -x "/boot/rootfs.gz" -i $isoloram > \
269 "$TEMP_DIR/boot/loram.gz"
270 cat >> $TEMP_DIR/boot/isolinux/common.cfg <<EOT
271 label noram
272 config noram.cfg
273 EOT
274 cat >> $TEMP_DIR/boot/isolinux/noram.cfg <<EOT
275 display isolinux.msg
276 say Not enough RAM to boot slitaz.
277 default reboot
278 label reboot
279 com32 reboot.c32
281 implicit 0
282 prompt 1
283 timeout 80
284 F1 help.txt
285 F2 options.txt
286 F3 isolinux.msg
287 F4 display.txt
288 F5 enhelp.txt
289 F6 enopts.txt
290 EOT
291 sed -i -e 's|kernel /boot/bzImage|kernel /boot/isolinux/ifmem.c32\n\tappend 160768 core 29696 loram noram\n|' \
292 -e 's|\(.*/\)rootfs\(.gz .*\)$|label core\n\tkernel /boot/bzImage\n\1rootfs\2\n\nlabel loram\n\tkernel /boot/bzImage\n\1loram\2|' \
293 $TEMP_DIR/boot/isolinux/*.cfg
294 status
295 ;;
296 esac
297 echo "$SORT_DIR/boot 0" >> $SORT_FILE
298 ;;
299 *\ --webboot\ *)
300 if extract_boot gpxe; then
301 echo -n "Creating web boot tree"
302 mkdir $TEMP_DIR/boot/isolinux/
303 isoinfo -x "/BOOT/ISOLINUX/ISOLINUX.BIN;1" -i $iso > \
304 $TEMP_DIR/boot/isolinux/isolinux.bin
305 mv $TEMP_DIR/boot/gpxe $TEMP_DIR/boot/isolinux
306 echo "$SORT_DIR/boot 0" >> $SORT_FILE
307 cat > $TEMP_DIR/boot/isolinux/isolinux.cfg <<EOT
308 default gpxe
309 append http://mirror.slitaz.org/pxe/pxelinux.0
310 EOT
311 status
312 BOOT_OPT="-sort $SORT_FILE -b boot/isolinux/isolinux.bin \
313 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table"
314 fi
315 ;;
316 esac
318 if [ -n "$BOOT_OPT" ]; then
319 echo "$(du -chs $TEMP_DIR/boot $TEMP_DIR/usr.sqfs 2> /dev/null | \
320 tail -1 | awk '{ print $1 }') used by boot."
321 fi
323 case " $OPTIONS " in
324 *\ --dry-run\ *)
325 echo "Please check and remove $TEMP_DIR and $SORT_FILE"
326 exit
327 ;;
328 esac
329 # Gen ISO
330 echo -n "Generating iso image"
331 /usr/bin/genisoimage -R -J -f -V $VOLUME_ID \
332 -P "$PUBLISHER" -md5-list $REPOS/packages.md5 \
333 -quiet -o $OUTPUT $BOOT_OPT $TEMP_DIR
334 status
336 echo "$(du -hs $OUTPUT | awk '{ print $1 }') used by iso image."
338 cd ${ROOT}
339 echo -n "Create hybrid DVD/CDROM"
340 [ -x /usr/bin/isohybrid ] && /usr/bin/isohybrid $IMAGE 2> /dev/null
341 status
343 echo -n "Calculate md5sum"
344 /usr/bin/md5sum $IMAGE > $(basename $IMAGE .iso).md5
345 status
347 echo -n "Moving file to mirror"
348 mv $IMAGE $ISO_DIR
349 mv $(basename $IMAGE .iso).md5 $ISO_DIR
350 status
352 # Cleaning temp files
353 rm -rf $TEMP_DIR $SORT_FILE