slitaz-forge view dvd/mkpkgiso @ rev 612
tank, pangolin: add console link
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Wed Feb 03 18:29:16 2016 +0100 (2016-02-03) |
parents | d658c9cd743b |
children | 061a079077a3 |
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 "Filtering 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 # Build hybdrid shell/mbr boot
295 shhybrid()
296 {
297 blkuuid="$(blkid $1 | sed 's/.* UUID="\([^"]*\).*/\1/')"
298 echo -e "#\xE4\x73\x1C\nexec sed 1,/^#@/d/^\$/q \$0" | dd of=$1 conv=notrunc 2>/dev/null
299 dd bs=512 seek=1 conv=notrunc of=$1 2>/dev/null <<EOT
301 #@
302 #!/bin/sh
304 dev=\$({ blkid $1; blkid; } | sed '/$blkuuid/!d;s/:.*//;q')
306 if [ -n "\$dev" ]; then
307 mkdir -p /mnt/packages
308 mount -t iso9660 -o loop,ro \$dev /mnt/packages
309 /mnt/packages/install.sh
310 fi
312 EOT
313 }
315 # Gen boot part
316 BOOT_OPT=""
317 iso=$ISO_DIR/slitaz-$PKG_VER.iso
318 for i in slitaz-loram-cdrom-sqfs slitaz-$PKG_VER-loram-cdrom ; do
319 isoloram=$ISO_DIR/flavors/$i.iso
320 [ -s $isoloram ] && break
321 done
322 case " $OPTIONS " in
323 *\ --boot\ *)
324 echo -n "Creating boot tree"
325 need $iso
326 which isoinfo > /dev/null || need /usr/bin/isoinfo
327 isoinfo -R -l -i $iso | awk '/^Directory/ { path=$4 } /^-/ { print path$12 }' | while read file; do
328 [ "$(basename $file)" == ".." ] && continue
329 [ "$file" = "/boot/isolinux/boot.cat" ] && continue
330 [ -d "$(dirname $TEMP_DIR/$file)" ] ||
331 mkdir -p "$(dirname $TEMP_DIR/$file)"
332 isoinfo -R -x "$file" -i $iso > "$TEMP_DIR/$file"
333 done
334 if [ -f "$(echo $TEMP_DIR/boot/vmlinuz*)" ]; then
335 rm -f $TEMP_DIR/boot/bzImage
336 ln $TEMP_DIR/boot/vmlinuz* $TEMP_DIR/boot/bzImage
337 fi
338 status
339 BOOT_OPT="-sort $SORT_FILE -b boot/isolinux/isolinux.bin \
340 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table"
341 case " $OPTIONS " in
342 *\ --auto-install\ *)
343 echo -n "Enabling auto install"
344 sed -i "s/rw root/rw config=LABEL=packages-$PKG_VER,install.sh root/" \
345 $TEMP_DIR/boot/isolinux/*.cfg
346 status
347 ;;
348 esac
349 case " $OPTIONS " in
350 *\ --loram-detect\ *)
351 echo -n "Enabling loram autodetection"
352 need $IFMEM_C32 $isoloram
353 which isoinfo > /dev/null || need /usr/bin/isoinfo
354 cp $IFMEM_C32 "$TEMP_DIR/boot/isolinux"
355 isoinfo -R -x "/usr.sqfs" -i $isoloram \
356 > "$TEMP_DIR/usr.sqfs" 2> /dev/null
357 if [ -s "$TEMP_DIR/usr.sqfs" ]; then
358 echo "$SORT_DIR/usr.sqfs -5000" >> $SORT_FILE
359 else
360 rm -f "$TEMP_DIR/usr.sqfs"
361 isoinfo -R -x "/rootfs.gz" -i $isoloram \
362 > "$TEMP_DIR/rootfs.gz" 2> /dev/null
363 echo "$SORT_DIR/rootfs.gz -5000" >> $SORT_FILE
364 fi
365 isoinfo -R -x "/boot/rootfs.gz" -i $isoloram > \
366 "$TEMP_DIR/boot/loram.gz"
367 cat >> $TEMP_DIR/boot/isolinux/common.cfg <<EOT
368 label noram
369 config noram.cfg
370 EOT
371 cat >> $TEMP_DIR/boot/isolinux/noram.cfg <<EOT
372 display isolinux.msg
373 say Not enough RAM to boot slitaz.
374 default reboot
375 label reboot
376 com32 reboot.c32
378 implicit 0
379 prompt 1
380 timeout 80
381 F1 help.txt
382 F2 options.txt
383 F3 isolinux.msg
384 F4 display.txt
385 F5 enhelp.txt
386 F6 enopts.txt
387 EOT
388 sed -i -e 's|kernel /boot/bzImage|kernel /boot/isolinux/ifmem.c32\n\tappend 160768 core 29696 loram noram\n|' \
389 -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,|" \
390 $TEMP_DIR/boot/isolinux/*.cfg
391 status
392 ;;
393 esac
394 echo "$SORT_DIR/boot 0" >> $SORT_FILE
395 ;;
396 *\ --webboot\ *)
397 if extract_boot gpxe; then
398 echo -n "Creating web boot tree"
399 which isoinfo > /dev/null || need /usr/bin/isoinfo
400 mkdir $TEMP_DIR/boot/isolinux/
401 isoinfo -R -x "/boot/isolinux/isolinux.bin" -i $iso > \
402 $TEMP_DIR/boot/isolinux/isolinux.bin
403 mv $TEMP_DIR/boot/gpxe $TEMP_DIR/boot/isolinux
404 echo "$SORT_DIR/boot 0" >> $SORT_FILE
405 cat > $TEMP_DIR/boot/isolinux/isolinux.cfg <<EOT
406 default gpxe
407 append http://mirror.slitaz.org/pxe/pxelinux.0
408 EOT
409 status
410 BOOT_OPT="-sort $SORT_FILE -b boot/isolinux/isolinux.bin \
411 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table"
412 fi
413 ;;
414 esac
416 if [ -n "$BOOT_OPT" ]; then
417 echo "$(du -chs $TEMP_DIR/boot $TEMP_DIR/usr.sqfs 2> /dev/null | \
418 awk 'END { print $1 }') used by boot."
419 fi
421 case " $OPTIONS " in
422 *\ --dry-run\ *)
423 echo "Please check and remove $TEMP_DIR and $SORT_FILE"
424 exit
425 ;;
426 esac
427 # Gen ISO
428 echo -n "Generating iso image"
429 genisoimage -R -J -f -V $VOLUME_ID \
430 -P "$PUBLISHER" -md5-list $REPOS/packages.md5 \
431 -quiet -o $OUTPUT $BOOT_OPT $TEMP_DIR
432 status
434 echo "$(du -hs $OUTPUT | awk '{ print $1 }') used by iso image."
436 cd ${ROOT}
437 echo -n "Creating hybrid DVD/CDROM"
438 which isohybrid > /dev/null && isohybrid $IMAGE 2> /dev/null
439 status
441 echo -n "Creating hybrid shell/mbr"
442 shhybrid $IMAGE
443 status
445 echo -n "Calculating md5sum"
446 md5sum $IMAGE > $(basename $IMAGE .iso).md5
447 status
449 echo -n "Moving file to mirror"
450 mv $IMAGE $ISO_DIR
451 mv $(basename $IMAGE .iso).md5 $ISO_DIR
452 status
454 # Cleaning temp files
455 rm -rf $TEMP_DIR $SORT_FILE