slitaz-dev-tools view mirror-tools/usr/bin/mkpkgiso @ rev 4

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