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