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

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