tazlito view tazlito @ rev 217

Add extraction tools in loram builder for slitaz-installer : no extra package to install during install
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Apr 27 11:57:31 2011 +0200 (2011-04-27)
parents 5efb0b404472
children 88bd4377be4d
line source
1 #!/bin/sh
2 # TazLito - SliTaz Live Tool.
3 #
4 # Tazlito is a tool to help generate and configure SliTaz LiveCD
5 # ISO images. You can create a custom distro in one command from a list of
6 # packages, extract an existing ISO image to hack it, create a new initramfs
7 # and/or a new ISO. Most commands must be run by root, except the stats
8 # and the configuration file manipulation.
9 #
10 # (C) 2007-2011 SliTaz - GNU General Public License.
11 #
12 # Authors : Christophe Lincoln <pankso@slitaz.org>
13 # Pascal Bellard <pascal.bellard@slitaz.org>
14 #
15 VERSION=4.0
17 # Tazlito configuration variables to be shorter
18 # and to use words rather than numbers.
19 COMMAND=$1
20 LIST_NAME=$2
21 TMP_DIR=/tmp/tazlito-$$-$RANDOM
22 TMP_MNT=/media/tazlito-$$-$RANDOM
23 TOP_DIR=`pwd`
24 INITRAMFS=rootfs.gz
25 LOCALSTATE=/var/lib/tazpkg
26 INSTALLED=$LOCALSTATE/installed
27 CACHE_DIR=/var/cache/tazpkg
28 MIRROR=$LOCALSTATE/mirror
29 DEFAULT_MIRROR="http://mirror.slitaz.org/packages/`cat /etc/slitaz-release`/"
31 # Try to include config file, continue if command is gen-config or exit.
32 # The main config used by default is in /etc/tazlito.
33 if [ -f "/etc/tazlito/tazlito.conf" ] ; then
34 CONFIG_FILE="/etc/tazlito/tazlito.conf"
35 fi
36 # Specific distro config file can be put in a distro tree.
37 if [ -f "$TOP_DIR/tazlito.conf" ] ; then
38 CONFIG_FILE="$TOP_DIR/tazlito.conf"
39 fi
40 if [ ! "$CONFIG_FILE" = "" ] ; then
41 . $CONFIG_FILE
42 else
43 if [ "$COMMAND" = "gen-config" ] ; then
44 continue
45 else
46 echo "Unable to find any configuration file. Please read the docs"
47 echo "or run '`basename $0` gen-config' to get an empty config file."
48 exit 0
49 fi
50 fi
52 # While Tazpkg is not used the default mirror url file does not exist
53 # and user can't recharge the list of flavors.
54 if test $(id -u) = 0 ; then
55 if [ ! -f "$MIRROR" ]; then
56 echo "$DEFAULT_MIRROR" > $MIRROR
57 fi
58 fi
60 # Set the rootfs and rootcd path with $DISTRO
61 # configuration variable.
62 ROOTFS=$DISTRO/rootfs
63 ROOTCD=$DISTRO/rootcd
65 #####################
66 # Tazlito functions #
67 #####################
69 # Print the usage.
70 usage ()
71 {
72 echo -e "\nSliTaz Live Tool - Version: $VERSION\n
73 \033[1mUsage: \033[0m `basename $0` [command] [list|iso|flavor|compression] [dir|iso]
74 \033[1mCommands: \033[0m\n
75 usage Print this short usage.
76 stats View Tazlito and distro configuration statistics.
77 gen-config Generate a new configuration file for a distro.
78 configure Configure the main config file or a specific tazlito.conf.
79 gen-iso Generate a new ISO from a distro tree.
80 gen-initiso Generate a new initramfs and ISO from the distro tree.
81 list-flavors List all available package lists on the mirror.
82 gen-flavor Generate a new live-CD description.
83 gen-liveflavor Generate a live-CD description from current system.
84 show-flavor Show live-CD description.
85 get-flavor Get a flavor's list of packages.
86 upgrade-flavor Update package list to the latest available versions.
87 extract-flavor Extract a (*.flavor) flavor into $FLAVORS_REPOSITORY.
88 pack-flavor Pack (and update) a flavor from $FLAVORS_REPOSITORY.
89 iso2flavor Create a flavor file from a SliTaz iso image.
90 check-list Check a distro-packages.list for updates.
91 extract-distro Extract an ISO to a directory and rebuild LiveCD tree.
92 gen-distro Generate a Live distro and ISO from a list of packages.
93 clean-distro Remove all files generated by gen-distro.
94 check-distro Help to check if distro is ready to release.
95 writeiso Use running system to generate a bootable ISO (with /home).
96 merge Merge multiple rootfs into one iso.
97 repack Recompress rootfs into iso with maximum ratio.
98 build-loram Generate a live-CD for low ram systems.
99 frugal-install Frugal install in /boot/frugal from a distro or ISO.
100 emu-iso Emulate an ISO image with Qemu.
101 burn-iso Burn ISO image to a cdrom using Wodim.\n"
102 }
104 # Status function.
105 status()
106 {
107 local CHECK=$?
108 echo -en "\\033[70G[ "
109 if [ $CHECK = 0 ]; then
110 echo -en "\\033[1;33mOK"
111 else
112 echo -en "\\033[1;31mFailed"
113 fi
114 echo -e "\\033[0;39m ]"
115 return $CHECK
116 }
118 yesorno()
119 {
120 echo -n "$1"
121 case "$DEFAULT_ANSWER" in
122 Y|y) answer="y";;
123 N|n) answer="n";;
124 *) read answer;;
125 esac
126 }
128 field()
129 {
130 grep "^$1" "$2" | sed 's/.*: \([0-9KMG\.]*\).*/\1/'
131 }
133 todomsg()
134 {
135 echo -e "\\033[70G[ \\033[1;31mTODO\\033[0;39m ]"
136 }
138 # Download a file from this mirror
139 download_from()
140 {
141 local i
142 local mirrors
143 mirrors="$1"
144 shift
145 for i in $mirrors; do
146 case "$i" in
147 http://*|ftp://*) wget -c $i$@ && break;;
148 *) cp $i/$1 . && break;;
149 esac
150 done
151 }
153 # Download a file trying all mirrors
154 download()
155 {
156 local i
157 for i in $(cat $MIRROR $LOCALSTATE/undigest/*/mirror 2> /dev/null); do
158 download_from "$i" "$@" && break
159 done
160 }
162 # Execute hooks provided by some packages
163 genisohooks()
164 {
165 local here=`pwd`
166 for i in $(ls $ROOTFS/etc/tazlito/*.$1 2> /dev/null); do
167 cd $ROOTFS
168 . $i $ROOTCD
169 done
170 cd $here
171 }
173 cleanup()
174 {
175 if [ -d $TMP_MNT ]; then
176 umount $TMP_MNT
177 rmdir $TMP_MNT
178 rm -f /boot
179 fi
180 }
182 # Echo the package name if the tazpkg is already installed
183 installed_package_name()
184 {
185 local tazpkg
186 local package
187 local VERSION
188 local EXTRAVERSION
189 tazpkg=$1
190 # Try to find package name and version to be able
191 # to repack it from installation
192 # A dash (-) can exist in name *and* in version
193 package=${tazpkg%-*}
194 i=$package
195 while true; do
196 VERSION=""
197 eval $(grep -s ^VERSION= $INSTALLED/$i/receipt)
198 EXTRAVERSION=""
199 eval $(grep -s ^EXTRAVERSION= $INSTALLED/$i/receipt)
200 if [ "$i-$VERSION$EXTRAVERSION" = "$tazpkg" ]; then
201 echo $i
202 break
203 fi
204 case "$i" in
205 *-*);;
206 *) break;;
207 esac
208 i=${i%-*}
209 done
210 }
212 # Check if user is root.
213 check_root()
214 {
215 if test $(id -u) != 0 ; then
216 echo -e "\nYou must be root to run `basename $0` with this option."
217 echo -e "Please type 'su' and root password to become super-user.\n"
218 exit 0
219 fi
220 }
222 # Check for the rootfs tree.
223 check_rootfs()
224 {
225 if [ ! -d "$ROOTFS/etc" ] ; then
226 echo -e "\nUnable to find a distro rootfs...\n"
227 exit 0
228 fi
229 }
231 # Check for the boot dir into the root CD tree.
232 verify_rootcd()
233 {
234 if [ ! -d "$ROOTCD/boot" ] ; then
235 echo -e "\nUnable to find the rootcd boot directory...\n"
236 exit 0
237 fi
238 }
240 create_iso()
241 {
242 echo "Generating $1"
243 if [ $(ls $2/boot/vmlinuz* $2/boot/bzImage | wc -l) -eq 2 ]; then
244 if cmp $2/boot/vmlinuz* $2/boot/bzImage > /dev/null; then
245 rm -f $2/boot/bzImage
246 ln $2/boot/vmlinuz* $2/boot/bzImage
247 fi
248 fi
249 genisoimage -R -o $1 -b boot/isolinux/isolinux.bin \
250 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
251 -V "$VOLUM_NAME" -p "$PREPARED" -input-charset iso8859-1 \
252 -boot-info-table $2
253 if [ -x /usr/bin/isohybrid ]; then
254 echo -n "Creating hybrid ISO..."
255 /usr/bin/isohybrid $1 -entry 2 2> /dev/null
256 status
257 fi
258 if [ -s /etc/tazlito/info ]; then
259 if [ $(stat -c %s /etc/tazlito/info) -lt $(( 31*1024 )) ]; then
260 echo -n "Storing ISO info..."
261 dd if=/etc/tazlito/info bs=1k seek=1 of=$1 \
262 conv=notrunc 2> /dev/null
263 status
264 fi
265 fi
266 }
268 # Generate a new ISO image using isolinux.
269 gen_livecd_isolinux()
270 {
271 # Some packages may want to alter iso
272 genisohooks iso
273 if [ ! -f "$ROOTCD/boot/isolinux/isolinux.bin" ]; then
274 echo -e "\nUnable to find isolinux binary.\n"
275 cleanup
276 exit 0
277 fi
278 # Set date for boot msg.
279 if grep -q 'XXXXXXXX' $ROOTCD/boot/isolinux/isolinux.msg; then
280 DATE=`date +%Y%m%d`
281 echo -n "Setting build date to: $DATE..."
282 sed -i s/'XXXXXXXX'/"$DATE"/ $ROOTCD/boot/isolinux/isolinux.msg
283 status
284 fi
285 cd $ROOTCD
286 echo -n "Computing md5..."
287 find * -type f ! -name md5sum -exec md5sum {} \; > md5sum
288 sed -i '/ boot\/isolinux\/isolinux.bin$/d' md5sum
289 status
290 cd $DISTRO
291 echo ""
292 echo -e "\033[1mGenerating ISO image\033[0m"
293 echo "================================================================================"
294 create_iso $ISO_NAME.iso $ROOTCD
295 echo -n "Creating the ISO md5sum..."
296 md5sum $ISO_NAME.iso > $ISO_NAME.md5
297 status
298 echo "================================================================================"
299 # Some packages may want to alter final iso
300 genisohooks final
301 }
303 lzma_history_bits()
304 {
305 #
306 # This generates an ISO which boots with Qemu but gives
307 # rootfs errors in frugal or liveUSB mode.
308 #
309 #local n
310 #local sz
311 #n=20 # 1Mb
312 #sz=$(du -sk $1 | cut -f1)
313 #while [ $sz -gt 1024 -a $n -lt 28 ]; do
314 #n=$(( $n + 1 ))
315 #sz=$(( $sz / 2 ))
316 #done
317 #echo $n
318 echo 24
319 }
321 lzma_switches()
322 {
323 echo "-d$(lzma_history_bits $1) -mt$(grep '^processor' < /proc/cpuinfo | wc -l)"
324 }
326 # Pack rootfs
327 pack_rootfs()
328 {
329 ( cd $1 ; find . -print | cpio -o -H newc ) | \
330 if [ "$COMPRESSION" = "none" ]; then
331 echo "Generating uncompressed initramfs... "
332 cat > $2
333 elif [ -x /usr/bin/lzma -a "$COMPRESSION" != "gzip" ]; then
334 echo -n "Generating lzma'ed initramfs... "
335 lzma e -si -so $(lzma_switches $1) > $2
336 else
337 echo "Generating gziped initramfs... "
338 gzip -9 > $2
339 fi
340 echo 1 > /tmp/rootfs
341 }
343 # Compression functions for writeiso.
344 write_initramfs()
345 {
346 if [ "$COMPRESSION" = "lzma" ]; then
347 echo -n "Creating rootfs.gz with lzma compression... "
348 cat /tmp/list | cpio -o -H newc | lzma e -si -so > /rootfs.gz
349 elif [ "$COMPRESSION" = "gzip" ]; then
350 echo "Creating rootfs.gz with gzip compression... "
351 cat /tmp/list | cpio -o -H newc | gzip -9 > /rootfs.gz
352 else
353 echo "Creating rootfs.gz without compression... "
354 cat /tmp/list | cpio -o -H newc > /rootfs.gz
355 fi
356 echo 1 > /tmp/rootfs
357 }
359 # Generate a new initramfs from the root filesystem.
360 gen_initramfs()
361 {
362 # Just in case CTRL+c
363 rm -f $DISTRO/gen
364 # Some packages may want to alter rootfs
365 genisohooks rootfs
366 cd $1
367 echo ""
369 # Link duplicate files
370 find . -type f -size +0c -exec stat -c '%s-%a-%u-%g %i %h %n' {} \; | \
371 sort | ( save=0; old_attr=""; old_inode=""; old_link=""; old_file=""
372 while read attr inode link file; do
373 if [ "$attr" = "$old_attr" -a "$inode" != "$old_inode" ]; then
374 if cmp "$file" "$old_file" >/dev/null; then
375 rm -f "$file"
376 ln "$old_file" "$file"
377 inode="$old_inode"
378 [ "$link" = "1" ] && save="$(expr $save + ${attr%%-*})"
379 fi
380 fi
381 old_attr="$attr" ; old_inode="$inode" ; old_file="$file"
382 done
383 echo "$save bytes saved in duplicate files."
384 )
386 # Use lzma if installed. Display rootfs size in realtime.
387 rm -f /tmp/rootfs
388 pack_rootfs . $DISTRO/$(basename $1).gz &
389 sleep 2
390 echo -en "\nFilesystem size:"
391 while [ ! -f /tmp/rootfs ]
392 do
393 sleep 1
394 echo -en "\\033[18G`du -sh $DISTRO/$(basename $1).gz | awk '{print $1}'` "
395 done
396 echo -e "\n"
397 cd $DISTRO
398 mv $(basename $1).gz $ROOTCD/boot
399 }
401 distro_sizes()
402 {
403 echo "Build date : `date +%Y%m%d\ \at\ \%H:%M:%S`"
404 echo "Packages : `ls -1 $ROOTFS*$INSTALLED/*/receipt | wc -l`"
405 echo "Rootfs size : `du -csh $ROOTFS*/ | awk '{ s=$1 } END { print s }'`"
406 echo "Initramfs size : `du -csh $ROOTCD/boot/rootfs*.gz | awk '{ s=$1 } END { print s }'`"
407 echo "ISO image size : `du -sh $ISO_NAME.iso | awk '{ print $1 }'`"
408 echo "================================================================================"
409 echo "Image is ready: $ISO_NAME.iso"
410 echo ""
411 }
413 # Print ISO and rootfs size.
414 distro_stats()
415 {
416 echo ""
417 echo -e "\033[1mDistro statistics\033[0m ($DISTRO)"
418 echo "================================================================================"
419 distro_sizes
420 }
422 # Create an empty configuration file.
423 empty_config_file()
424 {
425 cat >> tazlito.conf << "EOF"
426 # tazlito.conf: Tazlito (SliTaz Live Tool)
427 # configuration file.
428 #
430 # Name of the ISO image to generate.
431 ISO_NAME=""
433 # ISO image volume name.
434 VOLUM_NAME="SliTaz"
436 # Name of the preparer.
437 PREPARED="$USER"
439 # Path to the packages repository and the packages.list.
440 PACKAGES_REPOSITORY=""
442 # Path to the distro tree to gen-distro from a
443 # list of packages.
444 DISTRO=""
446 # Path to the directory containing additional files
447 # to copy into the rootfs and rootcd of the LiveCD.
448 ADDFILES="$DISTRO/addfiles"
450 # Default answer for binary question (Y or N)
451 DEFAULT_ANSWER="ASK"
453 # Compression utility (lzma, gzip or none)
454 COMPRESSION="lzma"
455 EOF
456 }
458 # extract rootfs.gz somewhere
459 extract_rootfs()
460 {
461 (zcat $1 || unlzma -c $1 || cat $1) 2>/dev/null | \
462 (cd $2; cpio -idm > /dev/null)
463 }
465 # Remove duplicate files
466 mergefs()
467 {
468 echo -n "Merge $(basename $1) ($(du -hs $1 | awk '{ print $1}')) into "
469 echo -n "$(basename $2) ($(du -hs $2 | awk '{ print $1}'))"
470 # merge symlinks files and devices
471 ( cd $1; find ) | while read file; do
472 if [ -L $1/$file ]; then
473 [ -L $2/$file ] &&
474 [ "$(readlink $1/$file)" == "$(readlink $2/$file)" ] &&
475 rm -f $2/$file
476 elif [ -f $1/$file ]; then
477 [ -f $2/$file ] &&
478 cmp $1/$file $2/$file > /dev/null 2>&1 && rm -f $2/$file
479 [ -f $2/$file ] &&
480 [ "$(basename $file)" == "volatile.cpio.gz" ] &&
481 [ "$(dirname $(dirname $file))" == \
482 ".$INSTALLED" ] && rm -f $2/$file
483 elif [ -b $1/$file ]; then
484 [ -b $2/$file ] && rm -f $2/$file
485 elif [ -c $1/$file ]; then
486 [ -c $2/$file ] && rm -f $2/$file
487 fi
488 done
490 # cleanup directories
491 ( cd $1; find ) | while read file; do
492 if [ -d $1/$file ]; then
493 [ -d $2/$file ] && rmdir $2/$file 2> /dev/null
494 fi
495 done
496 true
497 status
498 }
500 cleanup_merge()
501 {
502 rm -rf $TMP_DIR
503 exit 1
504 }
506 human2cent()
507 {
508 case "$1" in
509 *k) echo $1 | sed 's/\(.*\).\(.\)k/\1\2/';;
510 *M) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)M/\1\2/') * 1024));;
511 *G) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)G/\1\2/') * 1024 * 1024));;
512 esac
513 }
515 cent2human()
516 {
517 if [ $1 -lt 10000 ]; then
518 echo "$(($1 / 10)).$(($1 % 10))k"
519 elif [ $1 -lt 10000000 ]; then
520 echo "$(($1 / 10240)).$(( ($1/1024) % 10))M"
521 else
522 echo "$(($1 / 10485760)).$(( ($1/1048576) % 10))G"
523 fi
524 }
526 get_size()
527 {
528 cat $LOCALSTATE/packages.list $TMP_DIR/packages.list 2>/dev/null | awk "{ \
529 if (/^$(echo $1 | sed 's/[$+.\]/\\&/g')$/) get=1; \
530 if (/installed/ && get == 1) { print ; get++ } \
531 }
532 END { if (get < 2) print \" 0.0k (0.0k installed)\" }" | \
533 sed 's/ *\(.*\) .\(.*\) installed./\1 \2/' | while read packed unpacked; do
534 echo "$(human2cent $packed) $(human2cent $unpacked)"
535 done
536 }
538 # Display package list with version, set packed_size and unpacked_size
539 get_pkglist()
540 {
541 packed_size=0; unpacked_size=0
542 grep -v ^# $FLAVORS_REPOSITORY/$1/packages.list > $TMP_DIR/flavor.pkg
543 while read pkg; do
544 set -- $(get_size $pkg)
545 packed_size=$(( $packed_size + $1 ))
546 unpacked_size=$(( $unpacked_size + $2 ))
547 for i in $(grep -hs ^$pkg $LOCALSTATE/packages.list \
548 $TMP_DIR/packages.list); do
549 echo $i
550 break
551 done
552 done < $TMP_DIR/flavor.pkg
553 rm -f $TMP_DIR/flavor.pkg
554 }
556 # Update isolinux config files for multiple rootfs
557 update_bootconfig()
558 {
559 echo -n "Updating boot config files..."
560 grep -l 'include common' $1/*.cfg | \
561 while read file ; do
562 awk -v n=$(echo $2 | awk '{ print NF/2 }') '{
563 if (/label/) label=$0;
564 else if (/kernel/) kernel=$0;
565 else if (/append/) {
566 i=index($0,"rootfs.gz");
567 append=substr($0,i+9);
568 }
569 else if (/include/) {
570 for (i = 1; i <= n; i++) {
571 print label i
572 print kernel;
573 initrd="initrd=/boot/rootfs" n ".gz"
574 for (j = n - 1; j >= i; j--) {
575 initrd=initrd ",/boot/rootfs" j ".gz";
576 }
577 printf "\tappend %s%s\n",initrd,append;
578 print "";
579 }
580 print;
581 }
582 else print;
583 }' < $file > $file.$$
584 mv -f $file.$$ $file
585 done
586 cat >> $1/common.cfg <<EOT
588 label slitaz
589 kernel /boot/isolinux/ifmem.c32
590 append$(echo $2 | awk '{
591 for (i=1; i<=NF; i++)
592 if (i % 2 == 0) printf " slitaz%d",i/2
593 else printf " %s",$i
594 }') noram
596 label noram
597 config noram.cfg
599 EOT
600 cat > $1/noram.cfg <<EOT
601 display isolinux.msg
602 say Not enough RAM to boot slitaz.
603 default reboot
604 label reboot
605 com32 reboot.c32
607 implicit 0
608 prompt 1
609 timeout 80
610 F1 help.txt
611 F2 options.txt
612 F3 isolinux.msg
613 F4 display.txt
614 F5 enhelp.txt
615 F6 enopts.txt
616 EOT
617 # Restore real label names
618 echo $2 | awk '{ for (i=NF; i>1; i-=2) printf "%d/%s\n",i/2,$i }' | \
619 while read pat; do
620 sed -i "s/slitaz$pat/" $1/common.cfg \
621 $(grep -l 'include common' $1/*.cfg)
622 done
623 status
624 }
626 # Install a missing package
627 install_package()
628 {
629 echo -n "Install package $1 "
630 [ -n "$2" ] && echo -n "for kernel $2 "
631 echo -n "?"
632 read answer
633 case "$answer" in
634 y*|Y*|o*|O*) yes y | tazpkg get-install $1;;
635 *) return 1;;
636 esac
637 }
639 # Check iso for loram transformation
640 check_iso_for_loram()
641 {
642 [ -s $TMP_DIR/iso/boot/rootfs.gz ] ||
643 [ -s $TMP_DIR/iso/boot/rootfs1.gz ]
644 }
646 # Build initial rootfs for loram ISO ram/cdrom/http
647 build_initfs()
648 {
649 urliso="mirror.slitaz.org mirror.switch.ch/ftp/mirror/slitaz \
650 download.tuxfamily.org/slitaz slitaz.c3sl.ufpr.br"
651 version=$(ls $TMP_DIR/iso/boot/vmlinuz-* | sed 's/.*vmlinuz-//')
652 need_lib=false
653 mkdir -p $TMP_DIR/initfs/bin $TMP_DIR/initfs/dev $TMP_DIR/initfs/lib \
654 $TMP_DIR/initfs/mnt $TMP_DIR/initfs/proc $TMP_DIR/initfs/tmp \
655 $TMP_DIR/initfs/sys
656 while [ ! -f /lib/modules/$version/kernel/fs/aufs/aufs.ko.gz ]; do
657 install_package aufs $version || return 1
658 done
659 # bootfloppybox will need floppy.ko.gz, /dev/fd0, /dev/tty0
660 cp /lib/modules/$version/kernel/drivers/block/floppy.ko.gz \
661 $TMP_DIR/initfs/lib 2> /dev/null
662 cp -a /dev/tty0 /dev/fd0 $TMP_DIR/initfs/dev 2> /dev/null
663 cp /lib/modules/$version/kernel/fs/aufs/aufs.ko.gz \
664 $TMP_DIR/initfs/lib
665 if [ -f /bin/cromfs-driver ]; then
666 cp /bin/cromfs-driver $TMP_DIR/initfs/bin
667 ls /bin/unmkcromfs | \
668 cpio -o -H newc > $TMP_DIR/initfs/extractfs.cpio
669 else
670 [ ! -f /usr/sbin/mksquashfs ] && ! install_package squashfs && return 1
671 while [ ! -f /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.gz ]; do
672 install_package linux-squashfs $version || return 1
673 done
674 cp /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.gz \
675 $TMP_DIR/initfs/lib
676 ls /sbin/unsquashfs /usr/lib/liblzma.so* $INSTALLED/squashfs/* | \
677 cpio -o -H newc > $TMP_DIR/initfs/extractfs.cpio
678 fi
679 if [ "$1" == "cdrom" ]; then
680 for i in $(ls /dev/[hs]d[a-f]*); do
681 cp -a $i $TMP_DIR/initfs/dev
682 done
683 fi
684 if [ "$1" == "http" ]; then
685 mkdir $TMP_DIR/initfs/etc
686 ln -s /proc/mounts $TMP_DIR/initfs/etc/mtab
687 cp /usr/share/udhcpc/default.script $TMP_DIR/initfs/lib/udhcpc
688 sed -i 's|/sbin/||' $TMP_DIR/initfs/lib/udhcpc
689 cp -a /dev/fuse $TMP_DIR/initfs/dev
690 if ! $need_lib && [ -x /usr/share/boot/fusermount-static ]; then
691 cp /usr/share/boot/fusermount-static $TMP_DIR/initfs/bin/httpfs
692 else
693 cp /usr/bin/fusermount $TMP_DIR/initfs/bin
694 need_lib=true
695 fi
696 if ! $need_lib && [ -x /usr/share/boot/httpfs-static ]; then
697 cp /usr/share/boot/httpfs-static $TMP_DIR/initfs/bin/httpfs
698 else
699 [ ! -f /usr/bin/httpfs ] && ! install_package httpfs-fuse && return 1
700 cp /usr/bin/httpfs $TMP_DIR/initfs/bin
701 cp -a /lib/librt* $TMP_DIR/initfs/lib
702 cp -a /lib/libdl* $TMP_DIR/initfs/lib
703 cp -a /lib/libpthread* $TMP_DIR/initfs/lib
704 cp -a /usr/lib/libfuse* $TMP_DIR/initfs/lib
705 cp -a /lib/libresolv* $TMP_DIR/initfs/lib
706 cp -a /lib/libnss_dns* $TMP_DIR/initfs/lib
707 need_lib=true
708 fi
709 cd $TMP_DIR/initfs
710 echo "Getting slitaz-release..."
711 for i in $TMP_DIR/iso/boot/rootfs*.gz; do
712 ( zcat $i 2> /dev/null || unlzma -c $i) | \
713 cpio -idmu etc/slitaz-release > /dev/null
714 done
715 cd - > /dev/null
716 echo "Default urls for /iso/$(cat $TMP_DIR/initfs/etc/slitaz-release)/flavors/slitaz-loram-cdrom.iso /iso/$(cat $TMP_DIR/initfs/etc/slitaz-release)/flavors/slitaz-$(cat $TMP_DIR/initfs/etc/slitaz-release)-loram-cdrom.iso: $urliso"
717 echo -n "List of urls to insert: "
718 read -t 30 urliso2
719 urliso="$urliso2 $urliso"
720 fi
721 if ! $need_lib && [ -x /usr/share/boot/busybox-static ]; then
722 cp /usr/share/boot/busybox-static $TMP_DIR/initfs/bin/busybox
723 else
724 cp /bin/busybox $TMP_DIR/initfs/bin
725 need_lib=true
726 fi
727 for i in $($TMP_DIR/initfs/bin/busybox | awk \
728 '{ if (s) printf "%s",$0 } /Currently/ { s=1 }' | sed 's/,//g'); do
729 ln $TMP_DIR/initfs/bin/busybox $TMP_DIR/initfs/bin/$i
730 done
731 for i in /dev/console /dev/loop* /dev/null /dev/tty /dev/zero \
732 /dev/kmem /dev/mem /dev/random /dev/urandom; do
733 cp -a $i $TMP_DIR/initfs/dev
734 done
735 $need_lib && for i in /lib/ld-* /lib/lib[cm].so* /lib/lib[cm]-* ; do
736 cp -a $i $TMP_DIR/initfs/lib
737 done
738 cat > $TMP_DIR/initfs/init <<EOTEOT
739 #!/bin/sh
741 getarg()
742 {
743 grep -q " \$1=" /proc/cmdline || return 1
744 eval \$2=\$(sed "s/.* \$1=\\\\([^ ]*\\\\).*/\\\\1/" < /proc/cmdline)
745 return 0
746 }
748 copy_rootfs()
749 {
750 total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g')
751 need=\$(du -c \${path}rootfs* | tail -n 1 | cut -f1)
752 [ \$(( \$total / \$need )) -gt 1 ] || return 1
753 if ! grep -q " keep-loram" /proc/cmdline && cp \${path}rootfs* /mnt; then
754 path=/mnt/
755 return 0
756 else
757 rm -f /mnt/rootfs*
758 return 1
759 fi
760 }
762 echo "Switching / to tmpfs..."
763 mount -t proc proc /proc
764 size="\$(grep rootfssize= < /proc/cmdline | \\
765 sed 's/.*rootfssize=\\([0-9]*[kmg%]\\).*/-o size=\\1/')"
766 [ -n "\$size" ] || size="-o size=90%"
768 if [ -x /bin/httpfs ]; then # loram-http
770 while read var default; do
771 eval \$var=\$default
772 getarg \$var \$var
773 done <<EOT
774 eth eth0
775 dns 208.67.222.222,208.67.220.220
776 netmask 255.255.255.0
777 gw
778 ip
779 EOT
780 if [ -n "\$ip" ]; then
781 ifconfig \$eth \$ip netmask \$netmask up
782 route add default gateway \$gw
783 for i in \$(echo \$dns | sed 's/,/ /g'); do
784 echo "nameserver \$i" >> /etc/resolv.conf
785 done
786 else
787 udhcpc -f -q -s /lib/udhcpc -i \$eth
788 fi
789 for i in $urliso ; do
790 [ -n "\$URLISO" ] && URLISO="\$URLISO,"
791 URLISO="\${URLISO}http://\$i/iso/\$(cat /etc/slitaz-release)/flavors/slitaz-loram-cdrom.iso,http://\$i/iso/\$(cat /etc/slitaz-release)/flavors/slitaz-\$(cat /etc/slitaz-release)-loram-cdrom.iso"
792 done
793 getarg urliso URLISO
794 DIR=fs
795 if getarg loram DIR; then
796 DEVICE=\${DIR%,*}
797 DIR=/\${DIR#*,}
798 fi
799 mount -t tmpfs \$size tmpfs /mnt
800 path2=/mnt/.httpfs/
801 path=/mnt/.cdrom/
802 mkdir -p /mnt/.rw \$path \$path2
803 while [ ! -d \$path/boot ]; do
804 for i in \$(echo \$URLISO | sed 's/,/ /g'); do
805 httpfs \$i \$path2 && break
806 done
807 mount -o loop,ro -t iso9660 \$path2/*.iso \$path
808 done
809 #copy_rootfs && umount -d \$path && umount -d \$path2
811 elif [ -f \$(echo /rootfs*.gz | cut -f1 -d' ') ]; then # loram-ram
813 total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g')
814 free=\$(grep MemFree /proc/meminfo | sed 's/[^0-9]//g')
815 if [ \$(( \$total/\$free )) -gt 1 ] || ! mount -t tmpfs \$size tmpfs /mnt; then
816 echo "No tmpfs for /mnt"
817 mkdir -p /mnt/.rw
818 mount -t tmpfs tmpfs /mnt/.rw
819 mkdir -p /mnt/.rw/mnt/.rw
820 path=/
821 else
822 mkdir -p /mnt/.rw
823 path=/mnt/.
824 for i in rootfs* ; do
825 mv /\$i \$path\$i
826 done
827 fi
829 else # loram-cdrom
831 getarg cdrom DRIVE_NAME ||
832 DRIVE_NAME=\$(grep "drive name" < /proc/sys/dev/cdrom/info | cut -f 3)
833 DEVICE=/dev/\$DRIVE_NAME
834 DIR=fs
835 if getarg loram DIR; then
836 DEVICE=\${DIR%,*}
837 DIR=/\${DIR#*,}
838 fi
839 mount -t tmpfs \$size tmpfs /mnt
840 mkdir -p /mnt/.rw /mnt/.cdrom /mnt/mnt/.cdrom
841 i=0
842 while [ \$i -lt 5 ] && ! mount -r \$DEVICE /mnt/.cdrom; do
843 case "\$DEVICE" in
844 /dev/sd*|UUID=*|LABEL=*)
845 mount -t sysfs sysfs /sys
846 USBDELAY=\$(cat /sys/module/usb_storage/parameters/delay_use)
847 umount /sys
848 sleep \$((1+\$USBDELAY)) ;;
849 esac
850 i=\$((i+1))
851 done
852 path=/mnt/.cdrom/
853 copy_rootfs && umount -d /mnt/.cdrom
855 fi
857 memfree=\$(grep MemFree /proc/meminfo | sed 's/[^0-9]//g')
858 umount /proc
859 branch=br=/mnt/.rw:/mnt/.cdrom/\$DIR
860 if [ ! -d /mnt/.cdrom/\$DIR/etc ]; then
861 branch=br=/mnt/.rw
862 for i in \${path}rootfs* ; do
863 fs=\${i#*root}
864 branch=\$branch:/mnt/.\$fs
865 mkdir -p /mnt/.rw/mnt/.\$fs /mnt/.\$fs /mnt/.rw/mnt/.cdrom
866 if [ -f /bin/cromfs-driver ]; then
867 cromfs-driver \${path}root\$fs /mnt/.\$fs -o ro,dev,suid,allow_other
868 else
869 insmod /lib/squashfs.ko.gz 2> /dev/null
870 mount -o loop,ro -t squashfs \${path}root\$fs /mnt/.\$fs
871 fi
872 done
873 else
874 mkdir -p /mnt/.rw/mnt/.httpfs
875 fi
876 insmod /lib/aufs.ko.gz
877 mount -t aufs -o \$branch none /mnt
878 [ -x /bin/httpfs ] && sed -i 's/DHCP="yes"/DHCP="no"/' /mnt/etc/network.conf
879 [ \$memfree -lt 30000 ] && sed -i 's/ slim//' /mnt/etc/rcS.conf
880 [ -x /mnt/sbin/init ] && exec /bin/switch_root mnt /sbin/init || sh
881 EOTEOT
882 chmod +x $TMP_DIR/initfs/init
883 ( cd $TMP_DIR/initfs ; find | busybox cpio -o -H newc 2> /dev/null) | \
884 lzma e $TMP_DIR/initfs.gz -si
885 rm -rf $TMP_DIR/initfs
886 rem=$(( $(stat -c "%s" $TMP_DIR/initfs.gz) % 4 ))
887 [ $rem -ne 0 ] &&
888 dd if=/dev/zero bs=1 count=$(( 4 - $rem )) >> $TMP_DIR/initfs.gz 2> /dev/null
889 return 0
890 }
892 # Move each initramfs to squashfs (or cromfs)
893 build_loram_rootfs()
894 {
895 rootfs_sizes=""
896 for i in $TMP_DIR/iso/boot/rootfs*.gz; do
897 mkdir -p $TMP_DIR/fs
898 cd $TMP_DIR/fs
899 ( zcat $i 2> /dev/null || unlzma -c $i) | cpio -idm
900 cd - > /dev/null
901 rootfs=$TMP_DIR/$(basename $i)
902 if [ -x /usr/bin/mkcromfs ]; then
903 /usr/bin/mkcromfs -qq -f 262144 -b 16384 $TMP_DIR/fs $rootfs
904 else
905 /usr/sbin/mksquashfs $TMP_DIR/fs $rootfs -comp xz -Xbcj x86
906 fi
907 cd $TMP_DIR
908 rootfs_sizes="$rootfs_sizes $(( $(du -s $TMP_DIR/fs | cut -f1) - $(du -s $rootfs | cut -f1) ))"
909 ( cd $(dirname $rootfs); echo $(basename $rootfs) | \
910 cpio -o -H newc ) > $rootfs.cpio
911 rm -f $rootfs
912 mv $rootfs.cpio $rootfs
913 cd - > /dev/null
914 rm -rf $TMP_DIR/fs
915 done
916 }
918 # Move each initramfs to squashfs (or cromfs)
919 build_loram_rootfs_cdrom()
920 {
921 mkdir -p $TMP_DIR/fs
922 cd $TMP_DIR/fs
923 for i in $TMP_DIR/iso/boot/rootfs*.gz; do
924 ( zcat $i 2> /dev/null || unlzma -c $i) | cpio -idm
925 done
926 rootfs=$TMP_DIR/rootfs.gz
927 if [ -x /usr/bin/mkcromfs ]; then
928 /usr/bin/mkcromfs -qq -f 262144 -b 16384 $TMP_DIR/fs $rootfs
929 else
930 /usr/sbin/mksquashfs $TMP_DIR/fs $rootfs -comp xz -Xbcj x86
931 fi
932 rm -rf $TMP_DIR/fs
933 cd $TMP_DIR
934 }
936 # Move meta boot configuration files to basic configuration files
937 # because meta loram flavor is useless when rootfs is not loaded in ram
938 unmeta_boot()
939 {
940 if [ -f $TMP_DIR/loramiso/boot/isolinux/noram.cfg ]; then
941 # We keep enough information to do unloram...
942 sed -i 's/label slitaz/label orgslitaz/' \
943 $TMP_DIR/loramiso/boot/isolinux/common.cfg
944 sed -i -e 's|=/boot/rootfs\(.*\).gz |=/boot/rootfs.gz |' \
945 -e 's|label slitaz1|label slitaz|' \
946 -e '/label slitaz[1-9]/{NNNd}' \
947 $TMP_DIR/loramiso/boot/isolinux/*.cfg
948 fi
949 }
951 # Move rootfs to squashfs filesystem(s) to the cdrom writeable with aufs.
952 # These squashfs may be loaded in ram a boot time.
953 # Rootfs are also copied to cdrom for tiny ramsize systems.
954 # Meta flavors are converted to normal flavors.
955 build_loram_cdrom()
956 {
957 build_initfs cdrom || return 1
958 build_loram_rootfs_cdrom
959 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
960 if [ "$1" == "small" ]; then
961 rm -f $TMP_DIR/loramiso/boot/root*
962 else
963 mkdir $TMP_DIR/loramiso/fs
964 cd $TMP_DIR/loramiso/fs
965 for i in $( ls ../boot/root* | sort -r ) ; do
966 ( zcat $i 2> /dev/null || unlzma -c $i ) | cpio -idmu
967 rm -f $i
968 done
969 mkdir -p $TMP_DIR/loramiso/fs/mnt/.cdrom
970 cd - > /dev/null
971 fi
972 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
973 mv $TMP_DIR/rootfs*.gz $TMP_DIR/loramiso
974 unmeta_boot
975 VOLUM_NAME="SliTaz_LoRAM_CDROM"
976 sed -i "s/root=/loram=LABEL=$VOLUM_NAME,fs &/" \
977 $TMP_DIR/loramiso/boot/isolinux/*.cfg
978 create_iso $OUTPUT $TMP_DIR/loramiso
979 }
981 # Create http bootstrap to load and remove loram_cdrom
982 # Meta flavors are converted to normal flavors.
983 build_loram_http()
984 {
985 build_initfs http || return 1
986 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
987 rm -f $TMP_DIR/loramiso/boot/rootfs*
988 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
989 unmeta_boot
990 create_iso $OUTPUT $TMP_DIR/loramiso
991 }
993 # Update meta flavor selection sizes.
994 # Reduce sizes with rootfs gains.
995 update_metaiso_sizes()
996 {
997 local append="$(grep append $TMP_DIR/loramiso/boot/isolinux/common.cfg)"
998 local new
999 [ -n "$append" ] || return
1000 set -- $append
1001 shift
1002 new=""
1003 while [ -n "$2" ]; do
1004 local s
1005 case "$1" in
1006 *G) s=$(( ${1%G} * 1024 * 1024 ));;
1007 *M) s=$(( ${1%M} * 1024 ));;
1008 *) s=${1%K};;
1009 esac
1010 rootfs_sizes=${rootfs_sizes#* }
1011 for i in $rootfs_sizes ; do
1012 s=$(( $s - $i ))
1013 done
1014 new="$new $s $2"
1015 shift 2
1016 done
1017 sed -i "s/append .*/append$new $1/" $TMP_DIR/loramiso/boot/isolinux/common.cfg
1020 # Move rootfs to a squashfs filesystem into the initramfs writeable with aufs.
1021 # Meta flavor selection sizes are updated.
1022 build_loram_ram()
1024 build_initfs ram || return 1
1025 build_loram_rootfs
1026 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1027 rm -f $TMP_DIR/loramiso/boot/bzImage
1028 ln $TMP_DIR/loramiso/boot/vmlinuz* $TMP_DIR/loramiso/boot/bzImage
1029 rootfs=$(ls $TMP_DIR/rootfs* | sort | tail -n 1)
1030 cat $rootfs >> $TMP_DIR/initfs.gz
1031 mv $TMP_DIR/initfs.gz $rootfs
1032 cp $TMP_DIR/rootfs* $TMP_DIR/loramiso/boot
1033 update_metaiso_sizes
1034 create_iso $OUTPUT $TMP_DIR/loramiso
1037 # Remove files installed by packages
1038 find_flavor_rootfs()
1040 for i in $1/etc/tazlito/*.extract; do
1041 [ -e $i ] || continue
1042 chroot $1 /bin/sh ${i#$1}
1043 done
1045 # Clean hardlinks and files patched by genisofs in /boot
1046 for i in isolinux/isolinux.bin isolinux/boot.cat bzImage ; do
1047 rm -f $1/boot/$i
1048 done
1050 # Clean files generated in post_install
1051 rm -f $1/lib/modules/*/modules.* $1/etc/mtab \
1052 $1/dev/core $1/dev/fd $1/dev/std*
1054 # Verify md5
1055 cat $1$INSTALLED/*/md5sum | \
1056 while read md5 file; do
1057 [ -e $1$file ] || continue
1058 [ "$(cat $1$file | md5sum)" == "$md5 -" ] &&
1059 rm -f $1$file
1060 done
1062 # Check configuration files
1063 for i in $1$INSTALLED/*/volatile.cpio.gz; do
1064 [ -e $i ] || continue
1065 mkdir /tmp/volatile$$
1066 zcat $i | ( cd /tmp/volatile$$ ; cpio -idmu > /dev/null )
1067 ( cd /tmp/volatile$$ ; find * -type f ) | while read file ; do
1068 [ -e $1/$file ] || continue
1069 cmp -s /tmp/volatile$$/$file $1/$file && rm -f $1/$file
1070 done
1071 rm -rf /tmp/volatile$$
1072 done
1074 # Remove other files blindly
1075 for i in $1$INSTALLED/*/files.list; do
1076 for file in $(cat $i); do
1077 [ $1$file -nt $i ] && continue
1078 [ -f $1$file -a ! -L $1$file ] && continue
1079 [ -d $1$file ] || rm -f $1$file
1080 done
1081 done
1083 # Remove tazpkg files and tmp files
1084 rm -rf $1$INSTALLED* $1/tmp $1/var/tmp
1085 rm -f $1$LOCALSTATE/*packages* $1$LOCALSTATE/files.list.lzma \
1086 $1$LOCALSTATE/mirror* $1/var/cache/*/* \
1087 $1/var/lock/* $1/var/log/* $1/var/run/* $1/var/run/*/* \
1088 $1/var/lib/* $1/var/lib/dbus/* 2> /dev/null
1090 # Cleanup directory tree
1091 cd $1
1092 find * -type d | sort -r | while read dir; do
1093 rmdir $dir 2> /dev/null
1094 done
1095 cd - > /dev/null
1098 ####################
1099 # Tazlito commands #
1100 ####################
1102 case "$COMMAND" in
1103 stats)
1104 # Tazlito general statistics from the config file.
1106 echo ""
1107 echo -e "\033[1mTazlito statistics\033[0m
1108 ===============================================================================
1109 Config file : $CONFIG_FILE
1110 ISO name : $ISO_NAME.iso
1111 Volume name : $VOLUM_NAME
1112 Prepared : $PREPARED
1113 Packages repository : $PACKAGES_REPOSITORY
1114 Distro directory : $DISTRO"
1115 if [ ! "$ADDFILES" = "" ] ; then
1116 echo -e "Additional files : $ADDFILES"
1117 fi
1118 echo "================================================================================"
1119 echo ""
1120 ;;
1121 list-addfiles)
1122 # Simple list of additional files in the rootfs
1123 echo ""
1124 cd $ADDFILES
1125 find rootfs -type f
1126 echo "" ;;
1127 gen-config)
1128 # Generate a new config file in the current dir or the specified
1129 # directory by $2.
1131 if [ -n "$2" ] ; then
1132 mkdir -p $2 && cd $2
1133 fi
1134 echo -n "Generating empty tazlito.conf..."
1135 empty_config_file
1136 status
1137 echo ""
1138 if [ -f "tazlito.conf" ] ; then
1139 echo "Configuration file is ready to edit."
1140 echo "File location : `pwd`/tazlito.conf"
1141 echo ""
1142 fi
1143 ;;
1144 configure)
1145 # Configure a tazlito.conf config file. Start by getting
1146 # a empty config file and sed it.
1148 if [ -f "tazlito.conf" ] ; then
1149 rm tazlito.conf
1150 else
1151 if test $(id -u) = 0 ; then
1152 cd /etc
1153 else
1154 echo "You must be root to configure the main config file or in"
1155 echo "the same directory of the file you want to configure."
1156 exit 0
1157 fi
1158 fi
1159 empty_config_file
1160 echo""
1161 echo -e "\033[1mConfiguring :\033[0m `pwd`/tazlito.conf"
1162 echo "================================================================================"
1163 # ISO name.
1164 echo -n "ISO name : " ; read answer
1165 sed -i s#'ISO_NAME=\"\"'#"ISO_NAME=\"$answer\""# tazlito.conf
1166 # Volume name.
1167 echo -n "Volume name : " ; read answer
1168 sed -i s/'VOLUM_NAME=\"SliTaz\"'/"VOLUM_NAME=\"$answer\""/ tazlito.conf
1169 # Packages repository.
1170 echo -n "Packages repository : " ; read answer
1171 sed -i s#'PACKAGES_REPOSITORY=\"\"'#"PACKAGES_REPOSITORY=\"$answer\""# tazlito.conf
1172 # Distro path.
1173 echo -n "Distro path : " ; read answer
1174 sed -i s#'DISTRO=\"\"'#"DISTRO=\"$answer\""# tazlito.conf
1175 echo "================================================================================"
1176 echo "Config file is ready to use."
1177 echo "You can now extract an ISO or generate a distro."
1178 echo ""
1179 ;;
1180 gen-iso)
1181 # Simply generate a new iso.
1183 check_root
1184 verify_rootcd
1185 gen_livecd_isolinux
1186 distro_stats
1187 ;;
1188 gen-initiso)
1189 # Simply generate a new initramfs with a new iso.
1191 check_root
1192 verify_rootcd
1193 gen_initramfs $ROOTFS
1194 gen_livecd_isolinux
1195 distro_stats
1196 ;;
1197 extract-distro)
1198 # Extract an ISO image to a directory and rebuild the LiveCD tree.
1200 check_root
1201 ISO_IMAGE=$2
1202 if [ -z "$ISO_IMAGE" ] ; then
1203 echo -e "\nPlease specify the path to the ISO image."
1204 echo -e "Example : `basename $0` image.iso /path/target\n"
1205 exit 0
1206 fi
1207 # Set the distro path by checking for $3 on cmdline.
1208 if [ -n "$3" ] ; then
1209 TARGET=$3
1210 else
1211 TARGET=$DISTRO
1212 fi
1213 # Exit if existing distro is found.
1214 if [ -d "$TARGET/rootfs" ] ; then
1215 echo -e "\nA rootfs exists in : $TARGET"
1216 echo -e "Please clean the distro tree or change directory path.\n"
1217 exit 0
1218 fi
1219 echo ""
1220 echo -e "\033[1mTazlito extracting :\033[0m `basename $ISO_IMAGE`"
1221 echo "================================================================================"
1222 # Start to mount the ISO.
1223 echo ""
1224 echo "Mounting ISO image..."
1225 mkdir -p $TMP_DIR
1226 # Get ISO file size.
1227 isosize=`du -sh $ISO_IMAGE | cut -f1`
1228 mount -o loop $ISO_IMAGE $TMP_DIR
1229 sleep 2
1230 # Prepare target dir, copy the kernel and the rootfs.
1231 mkdir -p $TARGET/rootfs
1232 mkdir -p $TARGET/rootcd/boot
1233 echo -n "Copying the Linux kernel..."
1234 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
1235 ln $TARGET/rootcd/boot/vmlinuz* $TARGET/rootcd/boot/bzImage
1236 else
1237 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
1238 fi
1239 status
1240 echo -n "Copying isolinux files..."
1241 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
1242 for i in $(ls $TMP_DIR); do
1243 [ "$i" = "boot" ] && continue
1244 cp -a $TMP_DIR/$i $TARGET/rootcd
1245 done
1246 status
1247 if [ -d $TMP_DIR/boot/syslinux ]; then
1248 echo -n "Copying syslinux files..."
1249 cp -a $TMP_DIR/boot/syslinux $TARGET/rootcd/boot
1250 status
1251 fi
1252 if [ -d $TMP_DIR/boot/extlinux ]; then
1253 echo -n "Copying extlinux files..."
1254 cp -a $TMP_DIR/boot/extlinux $TARGET/rootcd/boot
1255 status
1256 fi
1257 if [ -d $TMP_DIR/boot/grub ]; then
1258 echo -n "Copying GRUB files..."
1259 cp -a $TMP_DIR/boot/grub $TARGET/rootcd/boot
1260 status
1261 fi
1263 echo -n "Copying the rootfs..."
1264 cp $TMP_DIR/boot/rootfs.?z $TARGET/rootcd/boot
1265 status
1266 # Extract initramfs.
1267 cd $TARGET/rootfs
1268 echo -n "Extracting the rootfs... "
1269 extract_rootfs ../rootcd/boot/rootfs.gz $TARGET/rootfs
1270 # unpack /usr
1271 for i in etc/tazlito/*.extract; do
1272 [ -f "$i" ] && . $i ../rootcd
1273 done
1274 # Umount and remove temp directory and cd to $TARGET to get stats.
1275 umount $TMP_DIR && rm -rf $TMP_DIR
1276 cd ..
1277 echo ""
1278 echo "================================================================================"
1279 echo "Extracted : `basename $ISO_IMAGE` ($isosize)"
1280 echo "Distro tree : `pwd`"
1281 echo "Rootfs size : `du -sh rootfs`"
1282 echo "Rootcd size : `du -sh rootcd`"
1283 echo "================================================================================"
1284 echo ""
1285 ;;
1286 list-flavors)
1287 # Show available flavors.
1288 if [ ! -s /etc/tazlito/flavors.list -o "$2" == "--recharge" ]; then
1289 download flavors.list -O - > /etc/tazlito/flavors.list
1290 fi
1291 echo ""
1292 echo -e "\033[1mList of flavors\033[0m"
1293 echo "================================================================================"
1294 cat /etc/tazlito/flavors.list
1295 echo ""
1296 ;;
1297 show-flavor)
1298 # Show flavor description.
1299 FLAVOR=${2%.flavor}
1300 if [ ! -f "$FLAVOR.flavor" ]; then
1301 echo "File $FLAVOR.flavor not found."
1302 exit 1
1303 fi
1304 mkdir $TMP_DIR
1305 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i > /dev/null)
1306 if [ "$3" = "--brief" ]; then
1307 if [ "$4" != "--noheader" ]; then
1308 echo "Name ISO Rootfs Description"
1309 echo "================================================================================"
1310 fi
1311 printf "%-16.16s %6.6s %6.6s %s\n" "$FLAVOR" \
1312 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
1313 "$(field 'Rootfs size' $TMP_DIR/$FLAVOR.desc)" \
1314 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
1315 else
1316 echo "================================================================================"
1317 cat $TMP_DIR/$FLAVOR.desc
1318 fi
1319 rm -Rf $TMP_DIR
1320 ;;
1321 gen-liveflavor)
1322 # Generate a new flavor from the live system.
1323 FLAVOR=${2%.flavor}
1324 DESC=""
1325 case "$FLAVOR" in
1326 '') echo -n "Flavor name : "
1327 read FLAVOR
1328 [ -z "$FLAVOR" ] && exit 1;;
1329 -?|-h*|--help) echo -e "
1331 SliTaz Live Tool - Version: $VERSION
1332 \033[1mUsage: \033[0m `basename $0` gen-liveflavor flavor-name [flavor-patch-file]
1333 \033[1mflavor-patch-file format: \033[0m
1334 code data
1335 + package to add
1336 - package to remove
1337 ! non-free package to add
1338 ? display message
1339 @ flavor description
1341 \033[1mExample: \033[0m
1342 @ Developer tools for slitaz maintainers
1343 + slitaz-toolchain
1344 + mercurial
1346 exit 1;;
1347 esac
1348 mv /etc/tazlito/distro-packages.list \
1349 /etc/tazlito/distro-packages.list.$$ 2> /dev/null
1350 rm -f distro-packages.list non-free.list 2> /dev/null
1351 tazpkg recharge
1352 [ -n "$3" ] && while read action pkg; do
1353 case "$action" in
1354 +) yes | tazpkg get-install $pkg;;
1355 -) yes | tazpkg remove $pkg;;
1356 !) echo $pkg >> non-free.list;;
1357 @) DESC="$pkg";;
1358 \?) echo -en "$pkg"; read action;;
1359 esac
1360 done < $3
1361 yes '' | tazlito gen-distro
1362 echo "$DESC" | tazlito gen-flavor "$FLAVOR"
1363 mv /etc/tazlito/distro-packages.list.$$ \
1364 /etc/tazlito/distro-packages.list 2> /dev/null
1365 ;;
1366 gen-flavor)
1367 # Generate a new flavor from the last iso image generated.
1368 FLAVOR=${2%.flavor}
1369 echo ""
1370 echo -e "\033[1mFlavor generation\033[0m"
1371 echo "================================================================================"
1372 if [ -z "$FLAVOR" ]; then
1373 echo -n "Flavor name : "
1374 read FLAVOR
1375 [ -z "$FLAVOR" ] && exit 1
1376 fi
1377 check_rootfs
1378 FILES="$FLAVOR.pkglist"
1379 echo -n "Creating file $FLAVOR.flavor..."
1380 for i in rootcd rootfs; do
1381 if [ -d "$ADDFILES/$i" ] ; then
1382 FILES="$FILES\n$FLAVOR.$i"
1383 ( cd "$ADDFILES/$i"; find . | \
1384 cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
1385 fi
1386 done
1387 status
1388 answer=`grep -s ^Description $FLAVOR.desc`
1389 answer=${answer#Description : }
1390 if [ -z "$answer" ]; then
1391 echo -n "Description : "
1392 read answer
1393 fi
1394 echo -n "Compressing flavor $FLAVOR..."
1395 echo "Flavor : $FLAVOR" > $FLAVOR.desc
1396 echo "Description : $answer" >> $FLAVOR.desc
1397 ( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
1398 \rm -f $FLAVOR.pkglist $FLAVOR.nonfree 2> /dev/null
1399 for i in $(ls $ROOTFS$INSTALLED); do
1400 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
1401 EXTRAVERSION=""
1402 eval $(grep ^EXTRAVERSION= $ROOTFS$INSTALLED/$i/receipt)
1403 eval $(grep ^CATEGORY= $ROOTFS$INSTALLED/$i/receipt)
1404 if [ "$CATEGORY" = "non-free" -a "${i%%-*}" != "get" ]
1405 then
1406 echo "$i" >> $FLAVOR.nonfree
1407 else
1408 echo "$i-$VERSION$EXTRAVERSION" >> $FLAVOR.pkglist
1409 fi
1410 done
1411 [ -s $FLAVOR.nonfree ] && $FILES="$FILES\n$FLAVOR.nonfree"
1412 for i in $LOCALSTATE/undigest/*/mirror ; do
1413 [ -s $i ] && cat $i >> $FLAVOR.mirrors
1414 done
1415 [ -s $FLAVOR.mirrors ] && $FILES="$FILES\n$FLAVOR.mirrors"
1416 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
1417 gzip -9 > $FLAVOR.flavor
1418 rm `echo -e $FILES`
1419 status
1420 echo "================================================================================"
1421 echo "Flavor size : `du -sh $FLAVOR.flavor`"
1422 echo ""
1423 ;;
1424 upgrade-flavor)
1425 # Update package list to the latest versions available.
1426 FLAVOR=${2%.flavor}
1427 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1428 mkdir $TMP_DIR
1429 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1430 echo -n "Updating $FLAVOR package list..."
1431 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1432 packed_size=0; unpacked_size=0
1433 while read org; do
1434 i=0
1435 pkg=$org
1436 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
1437 pkg=${pkg%-*}
1438 i=$(($i + 1))
1439 [ $i -gt 5 ] && break;
1440 done
1441 set -- $(get_size $pkg)
1442 packed_size=$(( $packed_size + $1 ))
1443 unpacked_size=$(( $unpacked_size + $2 ))
1444 for i in $(grep ^$pkg $LOCALSTATE/packages.list); do
1445 echo $i
1446 break
1447 done
1448 done < $TMP_DIR/$FLAVOR.pkglist \
1449 > $TMP_DIR/$FLAVOR.pkglist.$$
1450 mv -f $TMP_DIR/$FLAVOR.pkglist.$$ $TMP_DIR/$FLAVOR.pkglist
1451 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1452 packed_size=$(($packed_size \
1453 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1454 unpacked_size=$(($unpacked_size \
1455 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1456 fi
1457 # Estimate lzma
1458 packed_size=$(($packed_size * 2 / 3))
1459 iso_size=$(( $packed_size + 26000 ))
1460 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1461 iso_size=$(($iso_size \
1462 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1463 fi
1464 sed -i -e '/Image is ready/d' \
1465 -e "s/Rootfs size\( *:\) \(.*\)/Rootfs size\1 $(cent2human $unpacked_size) (estimated)/" \
1466 -e "s/Initramfs size\( *:\) \(.*\)/Initramfs size\1 $(cent2human $packed_size) (estimated)/" \
1467 -e "s/ISO image size\( *:\) \(.*\)/ISO image size\1 $(cent2human $iso_size) (estimated)/" \
1468 -e "s/date\( *:\) \(.*\)/date\1 $(date +%Y%m%d\ \at\ \%H:%M:%S)/" \
1469 $TMP_DIR/$FLAVOR.desc
1470 ( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
1471 $FLAVOR.flavor
1472 status
1473 rm -Rf $TMP_DIR
1474 fi
1475 ;;
1476 extract-flavor)
1477 # Extract a flavor into $FLAVORS_REPOSITORY.
1478 FLAVOR=${2%.flavor}
1479 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1480 mkdir $TMP_DIR
1481 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1482 echo -n "Extracting $FLAVOR..."
1483 rm -rf $FLAVORS_REPOSITORY/$FLAVOR 2> /dev/null
1484 mkdir -p $FLAVORS_REPOSITORY/$FLAVOR
1485 echo "FLAVOR=\"$FLAVOR\"" > $FLAVORS_REPOSITORY/$FLAVOR/receipt
1486 grep ^Description $TMP_DIR/$FLAVOR.desc | \
1487 sed 's/.*: \(.*\)$/SHORT_DESC="\1"/' >> \
1488 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1489 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc && \
1490 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1491 sed 's/.*: \(.*\)$/ROOTFS_SELECTION="\1"/' >> \
1492 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1493 grep '^Rootfs size' $TMP_DIR/$FLAVOR.desc | \
1494 sed 's/.*: \(.*\)$/ROOTFS_SIZE="\1"/' >> \
1495 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1496 grep ^Initramfs $TMP_DIR/$FLAVOR.desc | \
1497 sed 's/.*: \(.*\)$/INITRAMFS_SIZE="\1"/' >> \
1498 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1499 grep ^ISO $TMP_DIR/$FLAVOR.desc | \
1500 sed 's/.*: \(.*\)$/ISO_SIZE="\1"/' >> \
1501 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1502 for i in rootcd rootfs; do
1503 [ -f $TMP_DIR/$FLAVOR.$i ] || continue
1504 mkdir $FLAVORS_REPOSITORY/$FLAVOR/$i
1505 zcat $TMP_DIR/$FLAVOR.$i | \
1506 (cd $FLAVORS_REPOSITORY/$FLAVOR/$i; \
1507 cpio -idm > /dev/null)
1508 done
1509 [ -s $TMP_DIR/$FLAVOR.mirrors ] &&
1510 cp $TMP_DIR/$FLAVOR.mirrors \
1511 $FLAVORS_REPOSITORY/$FLAVOR/mirrors
1512 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1513 while read org; do
1514 i=0
1515 pkg=$org
1516 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
1517 pkg=${pkg%-*}
1518 i=$(($i + 1))
1519 [ $i -gt 5 ] && break;
1520 done
1521 echo $pkg
1522 done < $TMP_DIR/$FLAVOR.pkglist \
1523 > $FLAVORS_REPOSITORY/$FLAVOR/packages.list
1524 status
1525 rm -Rf $TMP_DIR
1526 fi
1527 ;;
1528 pack-flavor)
1529 # Create a flavor from $FLAVORS_REPOSITORY.
1530 FLAVOR=${2%.flavor}
1531 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/receipt ]; then
1532 mkdir $TMP_DIR
1533 echo -n "Creating flavor $FLAVOR..."
1534 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1535 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/mirrors ]; then
1536 cp $FLAVORS_REPOSITORY/$FLAVOR/mirrors \
1537 $TMP_DIR/$FLAVOR.mirrors
1538 for i in $(cat $TMP_DIR/$FLAVOR.mirrors); do
1539 wget -O - $i/packages.list >> $TMP_DIR/packages.list
1540 done
1541 fi
1542 [ -s $FLAVORS_REPOSITORY/$FLAVOR/packages.list ] &&
1543 get_pkglist $FLAVOR > $TMP_DIR/$FLAVOR.pkglist
1544 if grep -q ^ROOTFS_SELECTION \
1545 $FLAVORS_REPOSITORY/$FLAVOR/receipt; then
1546 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1547 set -- $ROOTFS_SELECTION
1548 [ -n "$FRUGAL_RAM" ] || FRUGAL_RAM=$1
1549 [ -f $FLAVORS_REPOSITORY/$2/packages.list ] ||
1550 tazlito extract-flavor $2
1551 get_pkglist $2 > $TMP_DIR/$FLAVOR.pkglist
1552 for i in rootcd rootfs; do
1553 mkdir $TMP_DIR/$i
1554 # Copy extra files from the first flavor
1555 [ -d $FLAVORS_REPOSITORY/$2/$i ] &&
1556 cp -a $FLAVORS_REPOSITORY/$2/$i $TMP_DIR
1557 # Overload extra files by meta flavor
1558 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] &&
1559 cp -a $FLAVORS_REPOSITORY/$FLAVOR/$i $TMP_DIR
1560 [ -n "$(ls $TMP_DIR/$i)" ] &&
1561 ( cd $TMP_DIR/$i ; find . | cpio -o -H newc 2> /dev/null ) | \
1562 gzip -9 >$TMP_DIR/$FLAVOR.$i
1563 rm -rf $TMP_DIR/$i
1564 done
1565 else
1566 for i in rootcd rootfs; do
1567 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] || \
1568 continue
1569 ( cd $FLAVORS_REPOSITORY/$FLAVOR/$i ; \
1570 find . | cpio -o -H newc 2> /dev/null ) | \
1571 gzip -9 >$TMP_DIR/$FLAVOR.$i
1572 done
1573 fi
1574 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1575 packed_size=$(($packed_size \
1576 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1577 unpacked_size=$(($unpacked_size \
1578 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1579 fi
1580 # Estimate lzma
1581 packed_size=$(($packed_size * 2 / 3))
1582 iso_size=$(( $packed_size + 26000 ))
1583 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1584 iso_size=$(($iso_size \
1585 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1586 fi
1587 VERSION=""
1588 MAINTAINER=""
1589 ROOTFS_SELECTION=""
1590 ROOTFS_SIZE="$(cent2human $unpacked_size) (estimated)"
1591 INITRAMFS_SIZE="$(cent2human $packed_size) (estimated)"
1592 ISO_SIZE="$(cent2human $iso_size) (estimated)"
1593 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1594 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1595 Flavor : $FLAVOR
1596 Description : $SHORT_DESC
1597 EOT
1598 [ -n "$VERSION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1599 Version : $VERSION
1600 EOT
1601 [ -n "$MAINTAINER" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1602 Maintainer : $MAINTAINER
1603 EOT
1604 [ -n "$FRUGAL_RAM" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1605 LiveCD RAM size : $FRUGAL_RAM
1606 EOT
1607 [ -n "$ROOTFS_SELECTION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1608 Rootfs list : $ROOTFS_SELECTION
1609 EOT
1610 cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1611 Build date : $(date +%Y%m%d\ \at\ \%H:%M:%S)
1612 Packages : $(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l)
1613 Rootfs size : $ROOTFS_SIZE
1614 Initramfs size : $INITRAMFS_SIZE
1615 ISO image size : $ISO_SIZE
1616 ================================================================================
1618 EOT
1619 rm -f $TMP_DIR/packages.list
1620 ( cd $TMP_DIR ; ls | cpio -o -H newc 2> /dev/null) | \
1621 gzip -9 > $FLAVOR.flavor
1622 status
1623 rm -Rf $TMP_DIR
1624 else
1625 echo "No $FLAVOR flavor in $FLAVORS_REPOSITORY."
1626 fi
1627 ;;
1628 get-flavor)
1629 # Get a flavor's files and prepare for gen-distro.
1630 FLAVOR=${2%.flavor}
1631 echo -e "\n\033[1mPreparing $FLAVOR distro flavor\033[0m"
1632 echo "================================================================================"
1633 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1634 echo -n "Cleaning $DISTRO..."
1635 rm -R $DISTRO 2> /dev/null
1636 mkdir -p $DISTRO
1637 status
1638 mkdir $TMP_DIR
1639 echo -n "Extracting flavor $FLAVOR.flavor... "
1640 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1641 echo -n "Creating distro-packages.list..."
1642 mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
1643 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
1644 status
1645 infos="$FLAVOR.desc"
1646 for i in rootcd rootfs; do
1647 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
1648 echo -n "Adding $i files... "
1649 mkdir -p "$ADDFILES/$i"
1650 zcat $TMP_DIR/$FLAVOR.$i | \
1651 ( cd "$ADDFILES/$i"; cpio -id > /dev/null)
1652 zcat $TMP_DIR/$FLAVOR.$i | cpio -tv \
1653 > $TMP_DIR/$FLAVOR.list$i
1654 infos="$infos\n$FLAVOR.list$i"
1655 fi
1656 done
1657 if [ -s $TMP_DIR/$FLAVOR.mirrors ]; then
1658 n=""
1659 while read line; do
1660 mkdir -p $LOCALSTATE/undigest/$FLAVOR$n
1661 echo "$line" > $LOCALSTATE/undigest/$FLAVOR$n/mirror
1662 n=$(( $n + 1 ))
1663 done < $TMP_DIR/$FLAVOR.mirrors
1664 infos="$infos\n$FLAVOR.mirrors"
1665 tazpkg recharge
1666 fi
1667 rm -f /etc/tazlito/rootfs.list
1668 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc &&
1669 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1670 sed 's/.*: \(.*\)$/\1/' > /etc/tazlito/rootfs.list
1671 echo -n "Updating tazlito.conf..."
1672 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
1673 cat tazlito.conf | grep -v "^#VOLUM_NAME" | \
1674 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
1675 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
1676 sed -i "s/ISO_NAME=.*/ISO_NAME=\"slitaz-$FLAVOR\"/" tazlito.conf
1677 status
1678 ( cd $TMP_DIR ; echo -e $infos | cpio -o -H newc ) | \
1679 gzip -9 > /etc/tazlito/info
1680 rm -Rf $TMP_DIR
1681 fi
1682 echo "================================================================================"
1683 echo -e "Flavor is ready to be generated by: tazlito gen-distro\n"
1684 ;;
1686 iso2flavor)
1687 if [ -z "$3" -o ! -s "$2" ]; then
1688 cat <<EOT
1689 Usage : tazlito iso2flavor image.iso flavor_name
1691 Create a file flavor_name.flavor from the cdrom image file image.iso
1692 EOT
1693 exit 1
1694 fi
1695 FLAVOR=${3%.flavor}
1696 mkdir -p $TMP_DIR/iso $TMP_DIR/rootfs
1697 mount -o loop,ro $2 $TMP_DIR/iso
1698 if [ -s $TMP_DIR/iso/boot/rootfs1.gz ]; then
1699 echo "META flavors are not supported."
1700 umount -d $TMP_DIR/iso
1701 elif [ ! -s $TMP_DIR/iso/boot/rootfs.gz ]; then
1702 echo "No /boot/rootfs.gz in iso image. Needs a SliTaz iso."
1703 umount -d $TMP_DIR/iso
1704 else
1705 ( unlzma -c $TMP_DIR/iso/boot/rootfs.gz || \
1706 zcat $TMP_DIR/iso/boot/rootfs.gz ) | \
1707 ( cd $TMP_DIR/rootfs ; cpio -idmu > /dev/null )
1708 if [ ! -s $TMP_DIR/rootfs/etc/slitaz-release ]; then
1709 echo "No file /etc/slitaz-release in /boot/rootfs.gz of iso image. Needs a non loram SliTaz iso."
1710 umount -d $TMP_DIR/iso
1711 else
1712 ROOTFS_SIZE=$(du -hs $TMP_DIR/rootfs | awk '{ print $1 }')
1713 RAM_SIZE=$(du -s $TMP_DIR/rootfs | awk '{ print 32*int(($1+36000)/32768) "M" }')
1714 cp -a $TMP_DIR/iso $TMP_DIR/rootcd
1715 ISO_SIZE=$(df -h $TMP_DIR/iso | awk 'END { print $2 }')
1716 BUILD_DATE=$(date +%Y%m%d\ \at\ \%H:%M:%S -r $TMP_DIR/iso/md5sum)
1717 umount -d $TMP_DIR/iso
1718 INITRAMFS_SIZE=$(du -chs $TMP_DIR/rootcd/boot/rootfs.gz | awk '{ s=$1 } END { print $1 }')
1719 rm -f $TMP_DIR/rootcd/boot/rootfs.gz $TMP_DIR/rootcd/md5sum
1720 mv $TMP_DIR/rootcd/boot $TMP_DIR/rootfs
1721 sed 's/.* \(.*\).tazpkg*/\1/' > $TMP_DIR/$FLAVOR.pkglist \
1722 < $TMP_DIR/rootfs$INSTALLED.md5
1723 #[ -s $TMP_DIR/rootfs/etc/tazlito/distro-packages.list ] &&
1724 # mv $TMP_DIR/rootfs/etc/tazlito/distro-packages.list $TMP_DIR/$FLAVOR.pkglist
1725 PKGCNT=$(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l | awk '{ print $1 }')
1726 find_flavor_rootfs $TMP_DIR/rootfs
1727 [ -d $TMP_DIR/rootfs/boot ] && mv $TMP_DIR/rootfs/boot $TMP_DIR/rootcd
1728 [ -n "$(ls $TMP_DIR/rootfs)" ] && ( cd $TMP_DIR/rootfs ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootfs
1729 [ -n "$(ls $TMP_DIR/rootcd)" ] && ( cd $TMP_DIR/rootcd ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootcd
1730 rm -rf $TMP_DIR/rootcd $TMP_DIR/rootfs
1731 VERSION=""; MAINTAINER=""
1732 echo -en "Flavor short description \007: "; read -t 30 DESCRIPTION
1733 if [ -n "$DESCRIPTION" ]; then
1734 echo -en "Flavor version : "; read -t 30 VERSION
1735 echo -en "Flavor maintainer (your email) : "; read -t 30 MAINTAINER
1736 fi
1737 [ -n "$DESCRIPTION" ] || DESCRIPTION="Slitaz $FLAVOR flavor"
1738 [ -n "$VERSION" ] || VERSION="1.0"
1739 [ -n "$MAINTAINER" ] || MAINTAINER="nobody@slitaz.org"
1740 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1741 Flavor : $FLAVOR
1742 Description : $DESCRIPTION
1743 Version : $VERSION
1744 Maintainer : $MAINTAINER
1745 LiveCD RAM size : $RAM_SIZE
1746 Build date : $BUILD_DATE
1747 Packages : $PKGCNT
1748 Rootfs size : $ROOTFS_SIZE
1749 Initramfs size : $INITRAMFS_SIZE
1750 ISO image size : $ISO_SIZE
1751 ================================================================================
1753 EOT
1754 ( cd $TMP_DIR ; ls $FLAVOR.* | cpio -o -H newc ) | gzip -9 > $FLAVOR.flavor
1755 cat <<EOT
1756 Tazlito can't detect each file installed during a package post_install.
1757 You should extract this flavor (tazlito extract-flavor $FLAVOR),
1758 check the files in /home/slitaz/flavors/$FLAVOR/rootfs tree and remove
1759 files generated by post_installs.
1760 Check /home/slitaz/flavors/$FLAVOR/receipt too and repack the flavor
1761 (tazlito pack-flavor $FLAVOR)
1762 EOT
1763 fi
1764 fi
1765 rm -rf $TMP_DIR
1766 ;;
1768 check-list)
1769 # Use current packages list in $PWD by default.
1770 DISTRO_PKGS_LIST=distro-packages.list
1771 [ -d "$2" ] && DISTRO_PKGS_LIST=$2/distro-packages.list
1772 [ -f "$2" ] && DISTRO_PKGS_LIST=$2
1773 [ ! -f $DISTRO_PKGS_LIST ] && echo "No packages list found." && exit 0
1774 echo ""
1775 echo -e "\033[1mLiveCD packages list check\033[0m"
1776 echo "================================================================================"
1777 for pkg in `cat $DISTRO_PKGS_LIST`
1778 do
1779 if ! grep -q "$pkg" $LOCALSTATE/packages.list; then
1780 echo "Updating: $pkg"
1781 up=$(($up + 1))
1782 fi
1783 done
1784 [ -z $up ] && echo -e "List is up-to-date\n" && exit 0
1785 echo "================================================================================"
1786 echo -e "Updates: $up\n" ;;
1787 gen-distro)
1788 # Generate a live distro tree with a set of packages.
1790 check_root
1792 # Check if a package list was specified on cmdline.
1793 LIST_NAME="distro-packages.list"
1794 CDROM=""
1795 while [ -n "$2" ]; do
1796 case "$2" in
1797 --iso=*)
1798 CDROM="-o loop ${2#--iso=}"
1799 ;;
1800 --cdrom)
1801 CDROM="/dev/cdrom"
1802 ;;
1803 --force)
1804 DELETE_ROOTFS="true"
1805 ;;
1806 *) if [ ! -f "$2" ] ; then
1807 echo -e "\nUnable to find the specified packages list."
1808 echo -e "List name : $2\n"
1809 exit 1
1810 fi
1811 LIST_NAME=$2
1812 ;;
1813 esac
1814 shift
1815 done
1817 if [ -d $ROOTFS ] ; then
1818 # Delete $ROOTFS if --force is set on command line
1819 if [ ! -z $DELETE_ROOTFS ]; then
1820 rm -rf $ROOTFS
1821 unset $DELETE_ROOTFS
1822 else
1823 echo -e "\nA rootfs exists in : $DISTRO"
1824 echo -e "Please clean the distro tree or change directory path.\n"
1825 exit 0
1826 fi
1827 fi
1828 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
1829 # Build list with installed packages
1830 for i in $(ls $INSTALLED); do
1831 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
1832 EXTRAVERSION=""
1833 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
1834 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
1835 done
1836 fi
1837 # Exit if no list name.
1838 if [ ! -f "$LIST_NAME" ]; then
1839 echo -e "\nNo packages list found or specified. Please read the docs.\n"
1840 exit 0
1841 fi
1842 # Start generation.
1843 echo ""
1844 echo -e "\033[1mTazlito generating a distro\033[0m"
1845 echo "================================================================================"
1846 # Misc checks
1847 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
1848 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
1849 # Get the list of packages using cat for a file list.
1850 LIST=`cat $LIST_NAME`
1851 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
1852 REPACK=""
1853 DOWNLOAD=""
1854 for pkg in $LIST
1855 do
1856 [ "$pkg" = "" ] && continue
1857 pkg=${pkg%.tazpkg}
1858 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
1859 PACKAGE=$(installed_package_name $pkg)
1860 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
1861 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
1862 echo -e "\nUnable to find $pkg in the repository."
1863 echo -e "Path : $PACKAGES_REPOSITORY\n"
1864 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
1865 yesorno "Repack packages from rootfs (y/N) ? "
1866 REPACK="$answer"
1867 [ "$answer" = "y" ] || REPACK="n"
1868 [ "$DOWNLOAD" = "y" ] && break
1869 fi
1870 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
1871 yesorno "Download packages from mirror (Y/n) ? "
1872 DOWNLOAD="$answer"
1873 if [ "$answer" = "n" ]; then
1874 [ -z "$PACKAGE" ] && exit 1
1875 else
1876 DOWNLOAD="y"
1877 [ -n "$REPACK" ] && break
1878 fi
1879 fi
1880 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
1881 done
1883 # Mount cdrom to be able to repack boot-loader packages
1884 if [ ! -e /boot -a -n "$CDROM" ]; then
1885 mkdir $TMP_MNT
1886 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
1887 ln -s $TMP_MNT/boot /
1888 if [ ! -d "$ADDFILES/rootcd" ] ; then
1889 mkdir -p $ADDFILES/rootcd
1890 for i in $(ls $TMP_MNT); do
1891 [ "$i" = "boot" ] && continue
1892 cp -a $TMP_MNT/$i $ADDFILES/rootcd
1893 done
1894 fi
1895 else
1896 rmdir $TMP_MNT
1897 fi
1898 fi
1900 # Root fs stuff.
1901 echo "Preparing the rootfs directory..."
1902 mkdir -p $ROOTFS
1903 sleep 2
1904 for pkg in $LIST
1905 do
1906 [ "$pkg" = "" ] && continue
1907 # First copy and extract the package in tmp dir.
1908 pkg=${pkg%.tazpkg}
1909 PACKAGE=$(installed_package_name $pkg)
1910 mkdir -p $TMP_DIR
1911 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1912 # Look for package in cache
1913 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
1914 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
1915 # Look for package in running distribution
1916 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
1917 tazpkg repack $PACKAGE && \
1918 mv $pkg.tazpkg $PACKAGES_REPOSITORY
1919 fi
1920 fi
1921 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1922 # Get package from mirror
1923 [ "$DOWNLOAD" = "y" ] && \
1924 download $pkg.tazpkg && \
1925 mv $pkg.tazpkg $PACKAGES_REPOSITORY
1926 fi
1927 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1928 echo "Missing package $pkg."
1929 cleanup
1930 exit 1
1931 fi
1932 done
1933 if [ -f non-free.list ]; then
1934 echo "Preparing non-free packages..."
1935 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
1936 for pkg in $(cat non-free.list); do
1937 if [ ! -d $INSTALLED/$pkg ]; then
1938 if [ ! -d $INSTALLED/get-$pkg ]; then
1939 tazpkg get-install get-$pkg
1940 fi
1941 get-$pkg
1942 fi
1943 tazpkg repack $pkg
1944 pkg=$(ls $pkg*.tazpkg)
1945 grep -q "^$pkg$" $LIST_NAME || \
1946 echo $pkg >>$LIST_NAME
1947 mv $pkg $PACKAGES_REPOSITORY
1948 done
1949 fi
1950 echo ""
1951 cp $LIST_NAME $DISTRO/distro-packages.list
1952 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/distro-packages.list > $DISTRO/list-packages
1953 cd $PACKAGES_REPOSITORY
1954 yes y | tazpkg install-list \
1955 $DISTRO/list-packages --root=$ROOTFS
1956 cd $DISTRO
1957 cp distro-packages.list $ROOTFS/etc/tazlito
1958 # Copy all files from $ADDFILES/rootfs to the rootfs.
1959 if [ -d "$ADDFILES/rootfs" ] ; then
1960 echo -n "Copying addfiles content to the rootfs... "
1961 cp -a $ADDFILES/rootfs/* $ROOTFS
1962 status
1963 fi
1964 echo "Root file system is generated..."
1965 # Root CD part.
1966 echo -n "Preparing the rootcd directory..."
1967 mkdir -p $ROOTCD
1968 status
1969 # Move the boot dir with the Linux kernel from rootfs.
1970 # The boot dir goes directly on the CD.
1971 if [ -d "$ROOTFS/boot" ] ; then
1972 echo -n "Moving the boot directory..."
1973 mv $ROOTFS/boot $ROOTCD
1974 cd $ROOTCD/boot
1975 ln vmlinuz-* bzImage
1976 status
1977 fi
1978 cd $DISTRO
1979 # Copy all files from $ADDFILES/rootcd to the rootcd.
1980 if [ -d "$ADDFILES/rootcd" ] ; then
1981 echo -n "Copying addfiles content to the rootcd... "
1982 cp -a $ADDFILES/rootcd/* $ROOTCD
1983 status
1984 fi
1985 # Execute the distro script used to perform tasks in the rootfs
1986 # before compression. Give rootfs path in arg
1987 [ -z $DISTRO_SCRIPT ] && DISTRO_SCRIPT=$TOP_DIR/distro.sh
1988 if [ -x $DISTRO_SCRIPT ]; then
1989 echo "Executing distro script..."
1990 sh $DISTRO_SCRIPT $DISTRO
1991 fi
1992 if [ -s /etc/tazlito/rootfs.list ]; then
1993 FLAVOR_LIST="$(awk '{ for (i = 2; i <= NF; i+=2) \
1994 printf("%s ",$i) }' < /etc/tazlito/rootfs.list)"
1995 sed -i "s/ *//;s/)/), flavors $FLAVOR_LIST/" \
1996 $ROOTCD/boot/isolinux/isolinux.msg
1997 [ -f $ROOTCD/boot/isolinux/ifmem.c32 ] ||
1998 cp /boot/isolinux/ifmem.c32 $ROOTCD/boot/isolinux
1999 n=0
2000 last=$ROOTFS
2001 while read flavor; do
2002 n=$(($n+1))
2003 echo "Building $flavor rootfs..."
2004 download $flavor.flavor
2005 zcat $flavor.flavor | cpio -i \
2006 $flavor.pkglist $flavor.rootfs
2007 sed 's/.*/&.tazpkg/' < $flavor.pkglist \
2008 > $DISTRO/list-packages0$n
2009 mkdir ${ROOTFS}0$n
2010 cd $PACKAGES_REPOSITORY
2011 yes y | tazpkg install-list \
2012 $DISTRO/list-packages0$n --root=${ROOTFS}0$n
2013 rm -rf ${ROOTFS}0$n/boot
2014 status
2015 cd $DISTRO
2016 if [ -s $flavor.rootfs ]; then
2017 echo "Adding $flavor rootfs extra files..."
2018 zcat $flavor.rootfs | \
2019 ( cd ${ROOTFS}0$n ; cpio -idmu )
2020 fi
2021 mv $flavor.pkglist ${ROOTFS}0$n/etc/tazlito/distro-packages.list
2022 rm -f $flavor.flavor install-list
2023 mergefs ${ROOTFS}0$n $last
2024 last=${ROOTFS}0$n
2025 done <<EOT
2026 $(awk '{ for (i = 4; i <= NF; i+=2) print $i; }' < /etc/tazlito/rootfs.list)
2027 EOT
2028 i=$(($n+1))
2029 while [ $n -gt 0 ]; do
2030 mv ${ROOTFS}0$n ${ROOTFS}$i
2031 echo "Compression ${ROOTFS}0$n ($(du -hs ${ROOTFS}$i | awk '{ print $1 }')) ..."
2032 gen_initramfs ${ROOTFS}$i
2033 n=$(($n-1))
2034 i=$(($i-1))
2035 done
2036 mv $ROOTFS ${ROOTFS}$i
2037 gen_initramfs ${ROOTFS}$i
2038 update_bootconfig $ROOTCD/boot/isolinux \
2039 "$(cat /etc/tazlito/rootfs.list)"
2040 else
2041 # Initramfs and ISO image stuff.
2042 gen_initramfs $ROOTFS
2043 fi
2044 gen_livecd_isolinux
2045 distro_stats
2046 cleanup
2047 ;;
2048 clean-distro)
2049 # Remove old distro tree.
2051 check_root
2052 echo ""
2053 echo -e "\033[1mCleaning :\033[0m $DISTRO"
2054 echo "================================================================================"
2055 if [ -d "$DISTRO" ] ; then
2056 if [ -d "$ROOTFS" ] ; then
2057 echo -n "Removing the rootfs..."
2058 rm -f $DISTRO/$INITRAMFS
2059 rm -rf $ROOTFS
2060 status
2061 fi
2062 if [ -d "$ROOTCD" ] ; then
2063 echo -n "Removing the rootcd..."
2064 rm -rf $ROOTCD
2065 status
2066 fi
2067 echo -n "Removing eventual ISO image..."
2068 rm -f $DISTRO/$ISO_NAME.iso
2069 rm -f $DISTRO/$ISO_NAME.md5
2070 status
2071 fi
2072 echo "================================================================================"
2073 echo ""
2074 ;;
2075 check-distro)
2076 # Check for a few LiveCD needed files not installed by packages.
2078 check_rootfs
2079 echo ""
2080 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
2081 echo "================================================================================"
2082 # SliTaz release info.
2083 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
2084 echo "Missing release info : /etc/slitaz-release"
2085 else
2086 release=`cat $ROOTFS/etc/slitaz-release`
2087 echo -n "Release : $release"
2088 status
2089 fi
2090 # Tazpkg mirror.
2091 if [ ! -f "$ROOTFS$LOCALSTATE/mirror" ]; then
2092 echo -n "Mirror URL : Missing $LOCALSTATE/mirror"
2093 todomsg
2094 else
2095 echo -n "Mirror configuration exists..."
2096 status
2097 fi
2098 # Isolinux msg
2099 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.msg; then
2100 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
2101 todomsg
2102 else
2103 echo -n "Isolinux message seems good..."
2104 status
2105 fi
2106 echo "================================================================================"
2107 echo ""
2108 ;;
2109 writeiso)
2110 # Writefs to ISO image including /home unlike gen-distro we dont use
2111 # packages to generate a rootfs, we build a compressed rootfs with all
2112 # the current filesystem similar to 'tazusb writefs'.
2114 DISTRO="/home/slitaz/distro"
2115 ROOTCD="$DISTRO/rootcd"
2116 if [ -z $2 ]; then
2117 COMPRESSION=none
2118 else
2119 COMPRESSION=$2
2120 fi
2121 if [ -z $3 ]; then
2122 ISO_NAME="slitaz"
2123 else
2124 ISO_NAME="$3"
2125 fi
2126 check_root
2127 # Start info
2128 echo ""
2129 echo -e "\033[1mWrite filesystem to ISO\033[0m
2130 ===============================================================================
2131 The command writeiso will write the current filesystem into a suitable cpio
2132 archive (rootfs.gz) and generate a bootable ISO image (slitaz.iso).
2134 Archive compression: $COMPRESSION"
2135 echo ""
2137 # Save some space
2138 rm /var/cache/tazpkg/* -r -f
2139 rm -rf /home/slitaz/distro
2141 # Optionally remove sound card selection and screen resolution.
2142 echo "Do you wish to remove the sound card and screen configs ? "
2143 echo -n "Press ENTER to keep or answer (No|yes|exit): "
2144 read anser
2145 case $anser in
2146 e|E|"exit"|Exit)
2147 exit 0 ;;
2148 y|Y|yes|Yes)
2149 echo -n "Removing current sound card and screen configurations..."
2150 rm -f /var/lib/sound-card-driver
2151 rm -f /etc/asound.state
2152 rm -f /etc/X11/screen.conf
2153 rm -f /etc/X11/xorg.conf ;;
2154 *)
2155 echo -n "Keeping current sound card and screen configurations..." ;;
2156 esac
2157 status
2159 cd /
2160 # Create list of files including default user files since it is defined in /etc/passwd
2161 # and some new users might have been added.
2162 find bin etc init sbin var dev lib root usr home >/tmp/list
2164 for dir in proc sys tmp mnt media media/cdrom media/flash media/usbdisk
2165 do
2166 echo $dir >>/tmp/list
2167 done
2169 # Generate initramfs with specified compression and display rootfs
2170 # size in realtime.
2171 rm -f /tmp/rootfs
2172 write_initramfs &
2173 sleep 2
2174 cd - > /dev/null
2175 echo -en "\nFilesystem size:"
2176 while [ ! -f /tmp/rootfs ]
2177 do
2178 sleep 1
2179 echo -en "\\033[18G`du -sh /rootfs.gz | awk '{print $1}'` "
2180 done
2181 echo -e "\n"
2183 # Move freshly generated rootfs to the cdrom.
2184 mkdir -p $ROOTCD/boot
2185 mv -f /rootfs.gz $ROOTCD/boot
2187 # Now we need the kernel and isolinux files.
2188 if mount /dev/cdrom /media/cdrom 2>/dev/null; then
2189 cp /media/cdrom/boot/bzImage $ROOTCD/boot
2190 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
2191 umount /media/cdrom
2192 else
2193 echo -e "
2194 Unable to mount the cdrom to copy the Kernel and needed files. When SliTaz
2195 is running in RAM the kernel and bootloader files are kept on the cdrom.
2196 Please insert a LiveCD or unmount the current cdrom to let Tazlito handle
2197 the media.\n"
2198 echo -en "----\nENTER to continue..."; read i
2199 exit 1
2200 fi
2202 # Generate the iso image.
2203 cd $DISTRO
2204 echo "Generating ISO image..."
2205 genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
2206 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
2207 -V "SliTaz" -input-charset iso8859-1 -boot-info-table $ROOTCD
2208 if [ -x /usr/bin/isohybrid ]; then
2209 echo -n "Creating hybrid ISO..."
2210 /usr/bin/isohybrid $ISO_NAME.iso 2> /dev/null
2211 status
2212 fi
2213 echo -n "Creating the ISO md5sum..."
2214 md5sum $ISO_NAME.iso > $ISO_NAME.md5
2215 status
2217 echo "==============================================================================="
2218 echo "ISO image: `du -sh /home/slitaz/distro/$ISO_NAME.iso`"
2219 echo ""
2220 echo -n "Exit or burn ISO to cdrom (Exit|burn)? "; read anser
2221 case $anser in
2222 burn)
2223 eject
2224 echo -n "Please insert a blank cdrom and press ENTER..."
2225 read i && sleep 2
2226 tazlito burn-iso /home/slitaz/distro/$ISO_NAME.iso
2227 echo -en "----\nENTER to continue..."; read i ;;
2228 *)
2229 exit 0 ;;
2230 esac ;;
2231 burn-iso)
2232 # Guess cdrom device, ask user and burn the ISO.
2234 check_root
2235 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
2236 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
2237 # We can specify an alternative ISO from the cmdline.
2238 if [ -n "$2" ] ; then
2239 iso=$2
2240 else
2241 iso=$DISTRO/$ISO_NAME.iso
2242 fi
2243 if [ ! -f "$iso" ]; then
2244 echo -e "\nUnable to find ISO : $iso\n"
2245 exit 0
2246 fi
2247 echo ""
2248 echo -e "\033[1mTazlito burn ISO\033[0m "
2249 echo "================================================================================"
2250 echo "Cdrom device : /dev/$DRIVE_NAME"
2251 echo "Drive speed : $DRIVE_SPEED"
2252 echo "ISO image : $iso"
2253 echo "================================================================================"
2254 echo ""
2255 yesorno "Burn ISO image (y/N) ? "
2256 if [ "$answer" == "y" ]; then
2257 echo ""
2258 echo "Starting Wodim to burn the iso..." && sleep 2
2259 echo "================================================================================"
2260 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
2261 echo "================================================================================"
2262 echo "ISO image is burned to cdrom."
2263 else
2264 echo -e "\nExiting. No ISO burned."
2265 fi
2266 echo ""
2267 ;;
2268 merge)
2269 # Merge multiple rootfs into one iso.
2271 if [ -z "$2" ]; then
2272 cat << EOT
2273 Usage: tazlito merge size1 iso size2 rootfs2 [sizeN rootfsN]...
2275 Merge multiple rootfs into one iso. Rootfs are like russian dolls
2276 i.e: rootfsN is a subset of rootfsN-1
2277 rootfs1 is found in iso, sizeN is the RAM size need to launch rootfsN.
2278 The boot loader will select the rootfs according to the RAM size detected.
2280 Example:
2281 $ tazlito merge 160M slitaz-core.iso 96M rootfs-justx.gz 32M rootfs-base.gz
2283 Will start slitaz-core with 160M+ RAM, slitaz-justX with 96M-160M RAM,
2284 slitaz-base with 32M-96M RAM and display an error message if RAM < 32M.
2285 EOT
2286 exit 2
2287 fi
2289 shift # skip merge
2290 append="$1 slitaz1"
2291 shift # skip size1
2292 mkdir -p $TMP_DIR/mnt $TMP_DIR/rootfs1
2294 ISO=$1.merged
2295 # Extract filesystems
2296 echo -n "Mounting $1"
2297 mount -o loop,ro $1 $TMP_DIR/mnt 2> /dev/null
2298 status || cleanup_merge
2299 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2300 rm -f $TMP_DIR/iso/boot/bzImage
2301 ln $TMP_DIR/iso/boot/vmlinuz* $TMP_DIR/iso/boot/bzImage
2302 umount -d $TMP_DIR/mnt
2303 if [ -f $TMP_DIR/iso/boot/rootfs1.gz ]; then
2304 echo "$1 is already a merged iso. Aborting."
2305 cleanup_merge
2306 fi
2307 if [ ! -f $TMP_DIR/iso/boot/isolinux/ifmem.c32 ]; then
2308 if [ ! -f /boot/isolinux/ifmem.c32 ]; then
2309 cat <<EOT
2310 No file /boot/isolinux/ifmem.c32
2311 Please install syslinux package !
2312 EOT
2313 rm -rf $TMP_DIR
2314 exit 1
2315 fi
2316 cp /boot/isolinux/ifmem.c32 $TMP_DIR/iso/boot/isolinux
2317 fi
2319 echo -n "Extracting iso/rootfs.gz"
2320 extract_rootfs $TMP_DIR/iso/boot/rootfs.gz $TMP_DIR/rootfs1 &&
2321 [ -d $TMP_DIR/rootfs1/etc ]
2322 status || cleanup_merge
2323 n=1
2324 while [ -n "$2" ]; do
2325 shift # skip rootfs N-1
2326 p=$n
2327 n=$(($n + 1))
2328 append="$append $1 slitaz$n"
2329 shift # skip size N
2330 mkdir -p $TMP_DIR/rootfs$n
2331 echo -n "Extracting $1"
2332 extract_rootfs $1 $TMP_DIR/rootfs$n &&
2333 [ -d $TMP_DIR/rootfs$n/etc ]
2334 status || cleanup_merge
2335 mergefs $TMP_DIR/rootfs$n $TMP_DIR/rootfs$p
2336 echo "Creating rootfs$p.gz"
2337 pack_rootfs $TMP_DIR/rootfs$p $TMP_DIR/iso/boot/rootfs$p.gz
2338 status
2339 done
2340 echo "Creating rootfs$n.gz"
2341 pack_rootfs $TMP_DIR/rootfs$n $TMP_DIR/iso/boot/rootfs$n.gz
2342 status
2343 rm -f $TMP_DIR/iso/boot/rootfs.gz
2344 update_bootconfig $TMP_DIR/iso/boot/isolinux "$append"
2345 create_iso $ISO $TMP_DIR/iso
2346 rm -rf $TMP_DIR
2347 ;;
2349 repack)
2350 # Repack an iso with maximum lzma compression ratio.
2353 ISO=$2
2355 mkdir -p $TMP_DIR/mnt
2356 # Extract filesystems
2357 echo -n "Mounting $ISO"
2358 mount -o loop,ro $ISO $TMP_DIR/mnt 2> /dev/null
2359 status || cleanup_merge
2360 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2361 umount -d $TMP_DIR/mnt
2363 for i in $TMP_DIR/iso/boot/rootfs* ; do
2364 echo -n "Repacking $(basename $i)"
2365 (zcat $i 2> /dev/null || unlzma -c $i || cat $i) \
2366 2>/dev/null > $TMP_DIR/rootfs
2367 lzma e $TMP_DIR/rootfs $i \
2368 $(lzma_switches $TMP_DIR/rootfs)
2369 status
2370 done
2372 create_iso $ISO $TMP_DIR/iso
2373 rm -rf $TMP_DIR ;;
2375 build-loram)
2376 # Build a Live CD for low ram systems.
2379 ISO=$2
2380 OUTPUT=$3
2381 mkdir -p $TMP_DIR/iso
2382 mount -o loop,ro -t iso9660 $ISO $TMP_DIR/iso
2383 if ! check_iso_for_loram ; then
2384 echo "$2 is not a valid SliTaz live CD. Abort."
2385 umount -d $TMP_DIR/iso
2386 rm -rf $TMP_DIR
2387 exit 1
2388 fi
2390 case "$4" in
2391 cdrom) build_loram_cdrom ;;
2392 smallcdrom) build_loram_cdrom small ;;
2393 http) build_loram_http ;;
2394 *) build_loram_ram ;;
2395 esac
2396 umount -d $TMP_DIR/iso
2397 rm -rf $TMP_DIR ;;
2400 frugal-install|-fi)
2401 ISO_IMAGE="$2"
2402 echo ""
2403 mkdir -p /boot/frugal
2404 if [ -f "$ISO_IMAGE" ]; then
2405 echo -n "Using ISO image: $ISO_IMAGE"
2406 mkdir -p /tmp/iso && mount -o loop $ISO_IMAGE /tmp/iso
2407 status
2408 echo -n "Installing the Kernel and rootfs..."
2409 cp -a /tmp/iso/boot/bzImage /boot/frugal
2410 cp -a /tmp/iso/boot/rootfs.gz /boot/frugal
2411 umount /tmp/iso
2412 status
2413 else
2414 echo -n "Using distro: $DISTRO"
2415 cd $DISTRO && status
2416 echo -n "Installing the Kernel and rootfs..."
2417 cp -a $DISTRO/rootcd/boot/bzImage /boot/frugal
2418 cp -a $DISTRO/rootcd/boot/rootfs.gz /boot/frugal
2419 status
2420 fi
2421 # Grub entry
2422 if ! grep -q "^kernel /boot/frugal/bzImage" /boot/grub/menu.lst; then
2423 echo -n "Configuring GRUB menu list..."
2424 cat >> /boot/grub/menu.lst << EOT
2425 title SliTaz GNU/Linux (frugal)
2426 root (hd0,0)
2427 kernel /boot/frugal/bzImage root=/dev/null
2428 initrd /boot/frugal/rootfs.gz
2429 EOT
2430 else
2431 echo -n "GRUB menu list is up-to-date..."
2432 fi
2433 status
2434 echo "" ;;
2436 emu-iso)
2437 # Emulate an ISO image with Qemu.
2438 if [ -n "$2" ] ; then
2439 iso=$2
2440 else
2441 iso=$DISTRO/$ISO_NAME.iso
2442 fi
2443 if [ ! -f "$iso" ]; then
2444 echo -e "\nUnable to find ISO : $iso\n"
2445 exit 0
2446 fi
2447 if [ ! -x "/usr/bin/qemu" ]; then
2448 echo -e "\nUnable to find Qemu binary. Please install: qemu\n"
2449 exit 0
2450 fi
2451 echo -e "\nStarting Qemu emulator:\n"
2452 echo -e "qemu $QEMU_OPTS $iso\n"
2453 qemu $QEMU_OPTS $iso ;;
2455 usage|*)
2456 # Clear and print usage also for all unknown commands.
2458 clear
2459 usage ;;
2460 esac
2462 exit 0