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

mirror-tools/mkpkgiso: fix sort weights (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jul 24 18:59:49 2009 +0200 (2009-07-24)
parents 827ab3d52e8d
children b0283dcad6f1
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 cat >>$TEMP_DIR/install.sh<<EOF
206 [ -d /var/www ] || mkdir -p /var/www
207 ln -s \$DIR/website /var/www
208 tazpkg list | grep -q ^lighttpd || yes y | tazpkg get-install lighttpd > /dev/null 2>&1
209 echo "=> slitaz web site installed in http://localhost/website"
210 EOF
211 fi;;
212 esac
213 done
215 # Extract boot package function
216 extract_boot()
217 {
218 f=$(ls $REPOS/$1-[0-9]*.tazpkg 2> /dev/null)
219 [ -f "$f" ] || return 1
220 [ -d $TEMP_DIR/boot ] || mkdir $TEMP_DIR/boot
221 ( cd $TEMP_DIR/boot ; cpio -i fs.cpio.gz < $f 2> /dev/null )
222 ( cd $TEMP_DIR/boot ; zcat fs.cpio.gz | cpio -id 2> /dev/null )
223 mv $TEMP_DIR/boot/fs/boot/* $TEMP_DIR/boot
224 rm -rf $TEMP_DIR/boot/fs.cpio.gz $TEMP_DIR/boot/fs
225 return 0
226 }
228 # Gen boot part
229 BOOT_OPT=""
230 iso=$ISO_DIR/slitaz-$PKG_VER.iso
231 isoloram=$ISO_DIR/flavors/slitaz-loram-cdrom-sqfs.iso
232 case " $OPTIONS " in
233 *\ --boot\ *)
234 echo -n "Creating boot tree"
235 isoinfo -R -l -i $iso | awk '/^Directory/ { path=$4 } /^-/ { print path$12 }' | while read file; do
236 [ "$(basename $file)" == ".." ] && continue
237 [ "$file" = "/boot/isolinux/boot.cat" ] && continue
238 [ -d "$(dirname $TEMP_DIR/$file)" ] ||
239 mkdir -p "$(dirname $TEMP_DIR/$file)"
240 isoinfo -R -x "$file" -i $iso > "$TEMP_DIR/$file"
241 done
242 if [ -f "$(echo $TEMP_DIR/boot/vmlinuz*)" ]; then
243 rm -f $TEMP_DIR/boot/bzImage
244 ln $TEMP_DIR/boot/vmlinuz* $TEMP_DIR/boot/bzImage
245 fi
246 status
247 BOOT_OPT="-sort $SORT_FILE -b boot/isolinux/isolinux.bin \
248 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table"
249 case " $OPTIONS " in
250 *\ --auto-install\ *)
251 echo -n "Enable auto install"
252 cat >>$TEMP_DIR/install.sh<<EOF
253 echo "mount -o ro -t iso9660 LABEL=packages-$PKG_VER /mnt" >> /etc/init.d/local.sh
254 EOF
255 sed -i "s/rw root/rw config=LABEL=packages-$PKG_VER,install.sh root/" \
256 $TEMP_DIR/boot/isolinux/*.cfg
257 status
258 ;;
259 esac
260 [ -f $PXE_DIR/ifmem.c32 -a -f $isoloram ] && case " $OPTIONS " in
261 *\ --loram-detect\ *)
262 echo -n "Enable loram autodetection"
263 cp $PXE_DIR/ifmem.c32 "$TEMP_DIR/boot/isolinux"
264 isoinfo -R -x "/usr.sqfs" -i $isoloram > "$TEMP_DIR/usr.sqfs"
265 echo "$SORT_DIR/usr.sqfs -5000" >> $SORT_FILE
266 isoinfo -R -x "/boot/rootfs.gz" -i $isoloram > \
267 "$TEMP_DIR/boot/loram.gz"
268 cat >> $TEMP_DIR/boot/isolinux/common.cfg <<EOT
269 label noram
270 config noram.cfg
271 EOT
272 cat >> $TEMP_DIR/boot/isolinux/noram.cfg <<EOT
273 display isolinux.msg
274 say Not enough RAM to boot slitaz.
275 default reboot
276 label reboot
277 com32 reboot.c32
279 implicit 0
280 prompt 1
281 timeout 80
282 F1 help.txt
283 F2 options.txt
284 F3 isolinux.msg
285 F4 display.txt
286 F5 enhelp.txt
287 F6 enopts.txt
288 EOT
289 sed -i -e 's|kernel /boot/bzImage|kernel /boot/isolinux/ifmem.c32\n\tappend 160768 core 29696 loram noram\n|' \
290 -e 's|\(.*/\)rootfs\(.gz .*\)$|label core\n\tkernel /boot/bzImage\n\1rootfs\2\n\nlabel loram\n\tkernel /boot/bzImage\n\1loram\2|' \
291 $TEMP_DIR/boot/isolinux/*.cfg
292 status
293 ;;
294 esac
295 echo "$SORT_DIR/boot 0" >> $SORT_FILE
296 ;;
297 *\ --webboot\ *)
298 if extract_boot gpxe; then
299 echo -n "Creating web boot tree"
300 mkdir $TEMP_DIR/boot/isolinux/
301 isoinfo -x "/BOOT/ISOLINUX/ISOLINUX.BIN;1" -i $iso > \
302 $TEMP_DIR/boot/isolinux/isolinux.bin
303 mv $TEMP_DIR/boot/gpxe $TEMP_DIR/boot/isolinux
304 echo "$SORT_DIR/boot 0" >> $SORT_FILE
305 cat > $TEMP_DIR/boot/isolinux/isolinux.cfg <<EOT
306 default gpxe
307 append http://mirror.slitaz.org/pxe/pxelinux.0
308 EOT
309 status
310 BOOT_OPT="-sort $SORT_FILE -b boot/isolinux/isolinux.bin \
311 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table"
312 fi
313 ;;
314 esac
316 if [ -n "$BOOT_OPT" ]; then
317 echo "$(du -chs $TEMP_DIR/boot $TEMP_DIR/usr.sqfs 2> /dev/null | \
318 tail -1 | awk '{ print $1 }') used by boot."
319 fi
321 case " $OPTIONS " in
322 *\ --dry-run\ *)
323 echo "Please check and remove $TEMP_DIR and $SORT_FILE"
324 exit
325 ;;
326 esac
327 # Gen ISO
328 echo -n "Generating iso image"
329 /usr/bin/genisoimage -R -J -f -V $VOLUME_ID \
330 -P "$PUBLISHER" -md5-list $REPOS/packages.md5 \
331 -quiet -o $OUTPUT $BOOT_OPT $TEMP_DIR
332 status
334 echo "$(du -hs $OUTPUT | awk '{ print $1 }') used by iso image."
336 cd ${ROOT}
337 echo -n "Create hybrid DVD/CDROM"
338 [ -x /usr/bin/isohybrid ] && /usr/bin/isohybrid $IMAGE 2> /dev/null
339 status
341 echo -n "Calculate md5sum"
342 /usr/bin/md5sum $IMAGE > $(basename $IMAGE .iso).md5
343 status
345 echo -n "Moving file to mirror"
346 mv $IMAGE $ISO_DIR
347 mv $(basename $IMAGE .iso).md5 $ISO_DIR
348 status
350 # Cleaning temp files
351 rm -rf $TEMP_DIR $SORT_FILE