wok-6.x view mirror-tools/stuff/usr/bin/mkpkgiso @ rev 4466

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