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

mirror-tools: fix USB key case
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Aug 20 13:10:20 2009 +0200 (2009-08-20)
parents 617322eb9d0d
children 1d293d17e640
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.6
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=/cdrom
89 if [ ! -f /cdrom/install.sh ]; then
90 mkdir /cdrom 2> /dev/null
91 mount --bind /mnt /cdrom
92 fi
93 # Handle loram on hybrid hard disk / usb key case
94 if [ ! -d /usr/bin ]; then
95 echo ""
96 if [ -d /.usr.rw ]; then
97 echo -n "Mounting /usr read-write... "
98 usr=.usr.ro
99 else
100 echo -n "Mounting /usr read-only... "
101 usr=usr
102 fi
103 FS=\$DIR/usr.cromfs
104 if [ -f \$FS ]; then
105 /bin/cromfs-driver \$FS /\$usr -o ro,dev,suid,allow_other
106 elif [ -f \$DIR/usr.sqfs ]; then
107 FS=\$DIR/usr.sqfs
108 mount -o loop,ro -t squashfs \$FS /\$usr
109 elif [ -L /\$usr ]; then
110 FS=\$DIR/usr
111 fi
112 status
113 if [ -d /.usr.rw ]; then
114 if [ -x /bin/funionfs ]; then
115 /bin/funionfs -o dirs=/.usr.ro=RO:/.usr.rw -o allow_other -o suid,dev NONE /usr
116 else
117 /bin/mount -t aufs -o br:/.usr.rw:/.usr.ro none /usr
118 fi
119 fi
120 fi
121 fi
123 [ -d /var/cache/tazpkg ] || mkdir -p /var/cache/tazpkg
124 ls -d \$DIR/packages/* > /var/lib/tazpkg/mirror
125 ln -fs \$DIR/packages/*/*.tazpkg /var/cache/tazpkg/
126 ln -fs \$DIR/packages/*/packages.* /var/lib/tazpkg
127 echo ""
128 echo "=> all $PKG_VER packages are available for tazpkg/tazpkgbox"
129 EOF
130 [ -e files.list.lzma ] && cat >>$TEMP_DIR/install.sh<<EOF
131 ln -fs \$DIR/packages/*/files.list.lzma /var/lib/tazpkg
132 EOF
134 status
135 cat > $SORT_FILE <<EOT
136 $SORT_DIR/install.sh -4000
137 $SORT_DIR/README -4000
138 $SORT_DIR/index.html -4000
139 $SORT_DIR/md5sum -4000
140 $SORT_DIR/style.css -4000
141 $SORT_DIR/images/header.png -4000
142 $SORT_DIR/boot/bzImage 2
143 $SORT_DIR/boot/rootfs.gz 1
144 $SORT_DIR/packages -9000
145 EOT
146 ( cd $ROOT; ls $SORT_DIR/packages/*/packages* $SORT_DIR/packages/*/files.list.lzma ) | \
147 awk '{ printf "%s -7000\n",$0 }' >> $SORT_FILE
148 chmod 755 $TEMP_DIR/install.sh
150 case " $OPTIONS " in
151 *\ --filter\ *)
152 SIZE=0
153 for i in *.tazpkg; do
154 while read f; do
155 case "$i" in
156 $f*) continue 2;;
157 esac
158 done < packages.list
159 echo -n "Filter out $i ($(du -hs $(readlink $i) | awk '{ print $1 }'))..."
160 SIZE=$(( $SIZE + $(stat -c %s $(readlink $i)) ))
161 rm $i
162 status
163 done
164 UNIT=" bytes"
165 if [ $SIZE -gt 10240 ]; then
166 SIZE=$(( $SIZE / 1024 ))
167 UNIT="K"
168 fi
169 if [ $SIZE -gt 10240 ]; then
170 SIZE=$(( $SIZE / 1024 ))
171 UNIT="M"
172 fi
173 echo "$SIZE$UNIT removed.";;
174 esac
176 # Copy hg subtree
177 get_from_hg()
178 {
179 [ /slitaz/home/slitaz/hg/$1 ] || return
180 echo -n "Adding $2"
181 /usr/sbin/chroot /slitaz hg --repository /home/slitaz/hg/$1 pull >/dev/null
182 /usr/sbin/chroot /slitaz hg --repository /home/slitaz/hg/$1 update >/dev/null
183 mkdir $TEMP_DIR/$1
184 cp -a /slitaz/home/slitaz/hg/$1/* $TEMP_DIR/$1
185 status
186 echo "$(du -hs $TEMP_DIR/$1 | awk '{ print $1 }') used by $2."
187 }
189 for i in $OPTIONS ; do
190 case "$i" in
191 --wok)
192 cat >>$TEMP_DIR/install.sh<<EOF
193 mkdir -p /home/slitaz
194 ln -s \$DIR/wok /home/slitaz
195 echo "=> Wok (cooking) is in /home/slitaz/wok"
196 EOF
197 if get_from_hg wok "wok (cooking)"; then
198 echo "$SORT_DIR/wok -8000" >> $SORT_FILE
199 fi;;
200 --wok-stable)
201 cat >>$TEMP_DIR/install.sh<<EOF
202 mkdir -p /home/slitaz
203 ln -s \$DIR/wok /home/slitaz
204 echo "=> Wok (stable) is in /home/slitaz/wok"
205 EOF
206 if get_from_hg wok-stable "wok (stable)"; then
207 mv $TEMP_DIR/wok-stable $TEMP_DIR/wok
208 echo "$SORT_DIR/wok -8000" >> $SORT_FILE
209 fi;;
210 --website)
211 if get_from_hg website "web site"; then
212 echo "$SORT_DIR/website -6000" >> $SORT_FILE
213 echo "$(echo $SORT_DIR/packages/*/lighttpd-[0-9]*) -7100" >> $SORT_FILE
214 echo "$(echo $SORT_DIR/packages/*/pcre-[0-9]*) -7100" >> $SORT_FILE
215 cat >>$TEMP_DIR/install.sh<<EOF
216 echo "=> slitaz web site installed in file://\$DIR/website/index.html"
217 EOF
218 fi;;
219 esac
220 done
222 # Extract boot package function
223 extract_boot()
224 {
225 f=$(ls $REPOS/$1-[0-9]*.tazpkg 2> /dev/null)
226 [ -f "$f" ] || return 1
227 [ -d $TEMP_DIR/boot ] || mkdir $TEMP_DIR/boot
228 ( cd $TEMP_DIR/boot ; cpio -i fs.cpio.gz < $f 2> /dev/null )
229 ( cd $TEMP_DIR/boot ; zcat fs.cpio.gz | cpio -id 2> /dev/null )
230 mv $TEMP_DIR/boot/fs/boot/* $TEMP_DIR/boot
231 rm -rf $TEMP_DIR/boot/fs.cpio.gz $TEMP_DIR/boot/fs
232 return 0
233 }
235 # Gen boot part
236 BOOT_OPT=""
237 iso=$ISO_DIR/slitaz-$PKG_VER.iso
238 isoloram=$ISO_DIR/flavors/slitaz-loram-cdrom-sqfs.iso
239 case " $OPTIONS " in
240 *\ --boot\ *)
241 echo -n "Creating boot tree"
242 isoinfo -R -l -i $iso | awk '/^Directory/ { path=$4 } /^-/ { print path$12 }' | while read file; do
243 [ "$(basename $file)" == ".." ] && continue
244 [ "$file" = "/boot/isolinux/boot.cat" ] && continue
245 [ -d "$(dirname $TEMP_DIR/$file)" ] ||
246 mkdir -p "$(dirname $TEMP_DIR/$file)"
247 isoinfo -R -x "$file" -i $iso > "$TEMP_DIR/$file"
248 done
249 if [ -f "$(echo $TEMP_DIR/boot/vmlinuz*)" ]; then
250 rm -f $TEMP_DIR/boot/bzImage
251 ln $TEMP_DIR/boot/vmlinuz* $TEMP_DIR/boot/bzImage
252 fi
253 status
254 BOOT_OPT="-sort $SORT_FILE -b boot/isolinux/isolinux.bin \
255 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table"
256 case " $OPTIONS " in
257 *\ --auto-install\ *)
258 echo -n "Enable auto install"
259 sed -i "s/rw root/rw config=LABEL=packages-$PKG_VER,install.sh root/" \
260 $TEMP_DIR/boot/isolinux/*.cfg
261 status
262 ;;
263 esac
264 [ -f $PXE_DIR/ifmem.c32 -a -f $isoloram ] && case " $OPTIONS " in
265 *\ --loram-detect\ *)
266 echo -n "Enable loram autodetection"
267 cp $PXE_DIR/ifmem.c32 "$TEMP_DIR/boot/isolinux"
268 isoinfo -R -x "/usr.sqfs" -i $isoloram > "$TEMP_DIR/usr.sqfs"
269 echo "$SORT_DIR/usr.sqfs -5000" >> $SORT_FILE
270 isoinfo -R -x "/boot/rootfs.gz" -i $isoloram > \
271 "$TEMP_DIR/boot/loram.gz"
272 cat >> $TEMP_DIR/boot/isolinux/common.cfg <<EOT
273 label noram
274 config noram.cfg
275 EOT
276 cat >> $TEMP_DIR/boot/isolinux/noram.cfg <<EOT
277 display isolinux.msg
278 say Not enough RAM to boot slitaz.
279 default reboot
280 label reboot
281 com32 reboot.c32
283 implicit 0
284 prompt 1
285 timeout 80
286 F1 help.txt
287 F2 options.txt
288 F3 isolinux.msg
289 F4 display.txt
290 F5 enhelp.txt
291 F6 enopts.txt
292 EOT
293 sed -i -e 's|kernel /boot/bzImage|kernel /boot/isolinux/ifmem.c32\n\tappend 160768 core 29696 loram noram\n|' \
294 -e 's|\(.*/\)rootfs\(.gz .*\)$|label core\n\tkernel /boot/bzImage\n\1rootfs\2\n\nlabel loram\n\tkernel /boot/bzImage\n\1loram\2|' \
295 $TEMP_DIR/boot/isolinux/*.cfg
296 status
297 ;;
298 esac
299 echo "$SORT_DIR/boot 0" >> $SORT_FILE
300 ;;
301 *\ --webboot\ *)
302 if extract_boot gpxe; then
303 echo -n "Creating web boot tree"
304 mkdir $TEMP_DIR/boot/isolinux/
305 isoinfo -x "/BOOT/ISOLINUX/ISOLINUX.BIN;1" -i $iso > \
306 $TEMP_DIR/boot/isolinux/isolinux.bin
307 mv $TEMP_DIR/boot/gpxe $TEMP_DIR/boot/isolinux
308 echo "$SORT_DIR/boot 0" >> $SORT_FILE
309 cat > $TEMP_DIR/boot/isolinux/isolinux.cfg <<EOT
310 default gpxe
311 append http://mirror.slitaz.org/pxe/pxelinux.0
312 EOT
313 status
314 BOOT_OPT="-sort $SORT_FILE -b boot/isolinux/isolinux.bin \
315 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table"
316 fi
317 ;;
318 esac
320 if [ -n "$BOOT_OPT" ]; then
321 echo "$(du -chs $TEMP_DIR/boot $TEMP_DIR/usr.sqfs 2> /dev/null | \
322 tail -1 | awk '{ print $1 }') used by boot."
323 fi
325 case " $OPTIONS " in
326 *\ --dry-run\ *)
327 echo "Please check and remove $TEMP_DIR and $SORT_FILE"
328 exit
329 ;;
330 esac
331 # Gen ISO
332 echo -n "Generating iso image"
333 /usr/bin/genisoimage -R -J -f -V $VOLUME_ID \
334 -P "$PUBLISHER" -md5-list $REPOS/packages.md5 \
335 -quiet -o $OUTPUT $BOOT_OPT $TEMP_DIR
336 status
338 echo "$(du -hs $OUTPUT | awk '{ print $1 }') used by iso image."
340 cd ${ROOT}
341 echo -n "Create hybrid DVD/CDROM"
342 [ -x /usr/bin/isohybrid ] && /usr/bin/isohybrid $IMAGE 2> /dev/null
343 status
345 echo -n "Calculate md5sum"
346 /usr/bin/md5sum $IMAGE > $(basename $IMAGE .iso).md5
347 status
349 echo -n "Moving file to mirror"
350 mv $IMAGE $ISO_DIR
351 mv $(basename $IMAGE .iso).md5 $ISO_DIR
352 status
354 # Cleaning temp files
355 rm -rf $TEMP_DIR $SORT_FILE