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

mirror-tools/mkpkgiso: do not install lighttpd
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Aug 19 15:31:08 2009 +0200 (2009-08-19)
parents 78b366b017fc
children 617322eb9d0d
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 echo ""
93 if [ -d /.usr.rw ]; then
94 echo -n "Mounting /usr read-write... "
95 usr=.usr.ro
96 else
97 echo -n "Mounting /usr read-only... "
98 usr=usr
99 fi
100 FS=\$DIR/usr.cromfs
101 if [ -f \$FS ]; then
102 /bin/cromfs-driver \$FS /\$usr -o ro,dev,suid,allow_other
103 elif [ -f \$DIR/usr.sqfs ]; then
104 FS=\$DIR/usr.sqfs
105 mount -o loop,ro -t squashfs \$FS /\$usr
106 elif [ -L /\$usr ]; then
107 FS=\$DIR/usr
108 fi
109 status
110 if [ -d /.usr.rw ]; then
111 if [ -x /bin/funionfs ]; then
112 /bin/funionfs -o dirs=/.usr.ro=RO:/.usr.rw -o allow_other -o suid,dev NONE /usr
113 else
114 /bin/mount -t aufs -o br:/.usr.rw:/.usr.ro none /usr
115 fi
116 fi
117 fi
118 fi
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 mkdir -p /home/slitaz
190 ln -s \$DIR/wok /home/slitaz
191 echo "=> Wok (cooking) is in /home/slitaz/wok"
192 EOF
193 if get_from_hg wok "wok (cooking)"; then
194 echo "$SORT_DIR/wok -8000" >> $SORT_FILE
195 fi;;
196 --wok-stable)
197 cat >>$TEMP_DIR/install.sh<<EOF
198 mkdir -p /home/slitaz
199 ln -s \$DIR/wok /home/slitaz
200 echo "=> Wok (stable) is in /home/slitaz/wok"
201 EOF
202 if get_from_hg wok-stable "wok (stable)"; then
203 mv $TEMP_DIR/wok-stable $TEMP_DIR/wok
204 echo "$SORT_DIR/wok -8000" >> $SORT_FILE
205 fi;;
206 --website)
207 if get_from_hg website "web site"; then
208 echo "$SORT_DIR/website -6000" >> $SORT_FILE
209 echo "$(echo $SORT_DIR/packages/*/lighttpd-[0-9]*) -7100" >> $SORT_FILE
210 echo "$(echo $SORT_DIR/packages/*/pcre-[0-9]*) -7100" >> $SORT_FILE
211 cat >>$TEMP_DIR/install.sh<<EOF
212 echo "=> slitaz web site installed in file:///mnt/website"
213 EOF
214 fi;;
215 esac
216 done
218 # Extract boot package function
219 extract_boot()
220 {
221 f=$(ls $REPOS/$1-[0-9]*.tazpkg 2> /dev/null)
222 [ -f "$f" ] || return 1
223 [ -d $TEMP_DIR/boot ] || mkdir $TEMP_DIR/boot
224 ( cd $TEMP_DIR/boot ; cpio -i fs.cpio.gz < $f 2> /dev/null )
225 ( cd $TEMP_DIR/boot ; zcat fs.cpio.gz | cpio -id 2> /dev/null )
226 mv $TEMP_DIR/boot/fs/boot/* $TEMP_DIR/boot
227 rm -rf $TEMP_DIR/boot/fs.cpio.gz $TEMP_DIR/boot/fs
228 return 0
229 }
231 # Gen boot part
232 BOOT_OPT=""
233 iso=$ISO_DIR/slitaz-$PKG_VER.iso
234 isoloram=$ISO_DIR/flavors/slitaz-loram-cdrom-sqfs.iso
235 case " $OPTIONS " in
236 *\ --boot\ *)
237 echo -n "Creating boot tree"
238 isoinfo -R -l -i $iso | awk '/^Directory/ { path=$4 } /^-/ { print path$12 }' | while read file; do
239 [ "$(basename $file)" == ".." ] && continue
240 [ "$file" = "/boot/isolinux/boot.cat" ] && continue
241 [ -d "$(dirname $TEMP_DIR/$file)" ] ||
242 mkdir -p "$(dirname $TEMP_DIR/$file)"
243 isoinfo -R -x "$file" -i $iso > "$TEMP_DIR/$file"
244 done
245 if [ -f "$(echo $TEMP_DIR/boot/vmlinuz*)" ]; then
246 rm -f $TEMP_DIR/boot/bzImage
247 ln $TEMP_DIR/boot/vmlinuz* $TEMP_DIR/boot/bzImage
248 fi
249 status
250 BOOT_OPT="-sort $SORT_FILE -b boot/isolinux/isolinux.bin \
251 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table"
252 case " $OPTIONS " in
253 *\ --auto-install\ *)
254 echo -n "Enable auto install"
255 cat >>$TEMP_DIR/install.sh<<EOF
256 echo "[ -f /mnt/install.sh ] || mount -o ro -t iso9660 LABEL=packages-$PKG_VER /mnt" >> /etc/init.d/local.sh
257 EOF
258 sed -i "s/rw root/rw config=LABEL=packages-$PKG_VER,install.sh root/" \
259 $TEMP_DIR/boot/isolinux/*.cfg
260 status
261 ;;
262 esac
263 [ -f $PXE_DIR/ifmem.c32 -a -f $isoloram ] && case " $OPTIONS " in
264 *\ --loram-detect\ *)
265 echo -n "Enable loram autodetection"
266 cp $PXE_DIR/ifmem.c32 "$TEMP_DIR/boot/isolinux"
267 isoinfo -R -x "/usr.sqfs" -i $isoloram > "$TEMP_DIR/usr.sqfs"
268 echo "$SORT_DIR/usr.sqfs -5000" >> $SORT_FILE
269 isoinfo -R -x "/boot/rootfs.gz" -i $isoloram > \
270 "$TEMP_DIR/boot/loram.gz"
271 cat >> $TEMP_DIR/boot/isolinux/common.cfg <<EOT
272 label noram
273 config noram.cfg
274 EOT
275 cat >> $TEMP_DIR/boot/isolinux/noram.cfg <<EOT
276 display isolinux.msg
277 say Not enough RAM to boot slitaz.
278 default reboot
279 label reboot
280 com32 reboot.c32
282 implicit 0
283 prompt 1
284 timeout 80
285 F1 help.txt
286 F2 options.txt
287 F3 isolinux.msg
288 F4 display.txt
289 F5 enhelp.txt
290 F6 enopts.txt
291 EOT
292 sed -i -e 's|kernel /boot/bzImage|kernel /boot/isolinux/ifmem.c32\n\tappend 160768 core 29696 loram noram\n|' \
293 -e 's|\(.*/\)rootfs\(.gz .*\)$|label core\n\tkernel /boot/bzImage\n\1rootfs\2\n\nlabel loram\n\tkernel /boot/bzImage\n\1loram\2|' \
294 $TEMP_DIR/boot/isolinux/*.cfg
295 status
296 ;;
297 esac
298 echo "$SORT_DIR/boot 0" >> $SORT_FILE
299 ;;
300 *\ --webboot\ *)
301 if extract_boot gpxe; then
302 echo -n "Creating web boot tree"
303 mkdir $TEMP_DIR/boot/isolinux/
304 isoinfo -x "/BOOT/ISOLINUX/ISOLINUX.BIN;1" -i $iso > \
305 $TEMP_DIR/boot/isolinux/isolinux.bin
306 mv $TEMP_DIR/boot/gpxe $TEMP_DIR/boot/isolinux
307 echo "$SORT_DIR/boot 0" >> $SORT_FILE
308 cat > $TEMP_DIR/boot/isolinux/isolinux.cfg <<EOT
309 default gpxe
310 append http://mirror.slitaz.org/pxe/pxelinux.0
311 EOT
312 status
313 BOOT_OPT="-sort $SORT_FILE -b boot/isolinux/isolinux.bin \
314 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table"
315 fi
316 ;;
317 esac
319 if [ -n "$BOOT_OPT" ]; then
320 echo "$(du -chs $TEMP_DIR/boot $TEMP_DIR/usr.sqfs 2> /dev/null | \
321 tail -1 | awk '{ print $1 }') used by boot."
322 fi
324 case " $OPTIONS " in
325 *\ --dry-run\ *)
326 echo "Please check and remove $TEMP_DIR and $SORT_FILE"
327 exit
328 ;;
329 esac
330 # Gen ISO
331 echo -n "Generating iso image"
332 /usr/bin/genisoimage -R -J -f -V $VOLUME_ID \
333 -P "$PUBLISHER" -md5-list $REPOS/packages.md5 \
334 -quiet -o $OUTPUT $BOOT_OPT $TEMP_DIR
335 status
337 echo "$(du -hs $OUTPUT | awk '{ print $1 }') used by iso image."
339 cd ${ROOT}
340 echo -n "Create hybrid DVD/CDROM"
341 [ -x /usr/bin/isohybrid ] && /usr/bin/isohybrid $IMAGE 2> /dev/null
342 status
344 echo -n "Calculate md5sum"
345 /usr/bin/md5sum $IMAGE > $(basename $IMAGE .iso).md5
346 status
348 echo -n "Moving file to mirror"
349 mv $IMAGE $ISO_DIR
350 mv $(basename $IMAGE .iso).md5 $ISO_DIR
351 status
353 # Cleaning temp files
354 rm -rf $TEMP_DIR $SORT_FILE