tazlito view tazlito @ rev 149

Small cosmetic change to get-flavor
author Christophe Lincoln <pankso@slitaz.org>
date Sun Jan 24 21:04:23 2010 +0100 (2010-01-24)
parents 52c1822fdc23
children 98387557032d
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-2010 SliTaz - GNU General Public License.
11 #
12 # Authors : Christophe Lincoln <pankso@slitaz.org>
13 # Pascal Bellard <pascal.bellard@slitaz.org>
14 #
15 VERSION=2.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
64 FLAVORS_REPOSITORY=/home/slitaz/flavors
66 #####################
67 # Tazlito functions #
68 #####################
70 # Print the usage.
71 usage ()
72 {
73 echo -e "\nSliTaz Live Tool - Version: $VERSION\n
74 \033[1mUsage: \033[0m `basename $0` [command] [list|iso|flavor|compression] [dir|iso]
75 \033[1mCommands: \033[0m\n
76 usage Print this short usage.
77 stats View Tazlito and distro configuration statistics.
78 gen-config Generate a new configuration file for a distro.
79 configure Configure the main config file or a specific tazlito.conf.
80 gen-iso Generate a new ISO from a distro tree.
81 gen-initiso Generate a new initramfs and ISO from the distro tree.
82 list-flavors List all available package lists on the mirror.
83 gen-flavor Generate a new live-CD description.
84 gen-liveflavor Generate a live-CD description from current system.
85 show-flavor Show live-CD description.
86 get-flavor Get a flavor's list of packages.
87 upgrade-flavor Update package list to the latest available versions.
88 extract-flavor Extract a (*.flavor) flavor into $FLAVORS_REPOSITORY.
89 pack-flavor Pack (and update) a flavor from $FLAVORS_REPOSITORY.
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 frugal-install Frugal install in /boot/frugal from a distro or ISO
99 emu-iso Emulate an ISO image with Qemu.
100 burn-iso Burn ISO image to a cdrom using Wodim.\n"
101 }
103 # Status function.
104 status()
105 {
106 local CHECK=$?
107 echo -en "\\033[70G[ "
108 if [ $CHECK = 0 ]; then
109 echo -en "\\033[1;33mOK"
110 else
111 echo -en "\\033[1;31mFailed"
112 fi
113 echo -e "\\033[0;39m ]"
114 return $CHECK
115 }
117 yesorno()
118 {
119 echo -n "$1"
120 case "$DEFAULT_ANSWER" in
121 Y|y) answer="y";;
122 N|n) answer="n";;
123 *) read answer;;
124 esac
125 }
127 field()
128 {
129 grep "^$1" "$2" | sed 's/.*: \([0-9KMG\.]*\).*/\1/'
130 }
132 todomsg()
133 {
134 echo -e "\\033[70G[ \\033[1;31mTODO\\033[0;39m ]"
135 }
137 # Download a file from this mirror
138 download_from()
139 {
140 local i
141 local mirrors
142 mirrors="$1"
143 shift
144 for i in $mirrors; do
145 case "$i" in
146 http://*|ftp://*) wget -c $i$@ && break;;
147 *) cp $i/$1 . && break;;
148 esac
149 done
150 }
152 # Download a file trying all mirrors
153 download()
154 {
155 local i
156 for i in $(cat $MIRROR $LOCALSTATE/undigest/*/mirror 2> /dev/null); do
157 download_from "$i" "$@" && break
158 done
159 }
161 # Execute hooks provided by some packages
162 genisohooks()
163 {
164 local here=`pwd`
165 for i in $(ls $ROOTFS/etc/tazlito/*.$1 2> /dev/null); do
166 cd $ROOTFS
167 . $i $ROOTCD
168 done
169 cd $here
170 }
172 cleanup()
173 {
174 if [ -d $TMP_MNT ]; then
175 umount $TMP_MNT
176 rmdir $TMP_MNT
177 rm -f /boot
178 fi
179 }
181 # Echo the package name if the tazpkg is already installed
182 installed_package_name()
183 {
184 local tazpkg
185 local package
186 local VERSION
187 local EXTRAVERSION
188 tazpkg=$1
189 # Try to find package name and version to be able
190 # to repack it from installation
191 # A dash (-) can exist in name *and* in version
192 package=${tazpkg%-*}
193 i=$package
194 while true; do
195 VERSION=""
196 eval $(grep -s ^VERSION= $INSTALLED/$i/receipt)
197 EXTRAVERSION=""
198 eval $(grep -s ^EXTRAVERSION= $INSTALLED/$i/receipt)
199 if [ "$i-$VERSION$EXTRAVERSION" = "$tazpkg" ]; then
200 echo $i
201 break
202 fi
203 case "$i" in
204 *-*);;
205 *) break;;
206 esac
207 i=${i%-*}
208 done
209 }
211 # Check if user is root.
212 check_root()
213 {
214 if test $(id -u) != 0 ; then
215 echo -e "\nYou must be root to run `basename $0` with this option."
216 echo -e "Please type 'su' and root password to become super-user.\n"
217 exit 0
218 fi
219 }
221 # Check for the rootfs tree.
222 check_rootfs()
223 {
224 if [ ! -d "$ROOTFS/etc" ] ; then
225 echo -e "\nUnable to find a distro rootfs...\n"
226 exit 0
227 fi
228 }
230 # Check for the boot dir into the root CD tree.
231 verify_rootcd()
232 {
233 if [ ! -d "$ROOTCD/boot" ] ; then
234 echo -e "\nUnable to find the rootcd boot directory...\n"
235 exit 0
236 fi
237 }
239 create_iso()
240 {
241 genisoimage -R -o $1 -b boot/isolinux/isolinux.bin \
242 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
243 -V "$VOLUM_NAME" -p "$PREPARED" -input-charset iso8859-1 \
244 -boot-info-table $2
245 if [ -x /usr/bin/isohybrid ]; then
246 echo -n "Creating hybrid ISO..."
247 /usr/bin/isohybrid $1 2> /dev/null
248 status
249 fi
250 }
252 # Generate a new ISO image using isolinux.
253 gen_livecd_isolinux()
254 {
255 # Some packages may want to alter iso
256 genisohooks iso
257 if [ ! -f "$ROOTCD/boot/isolinux/isolinux.bin" ]; then
258 echo -e "\nUnable to find isolinux binary.\n"
259 cleanup
260 exit 0
261 fi
262 # Set date for boot msg.
263 if grep -q 'XXXXXXXX' $ROOTCD/boot/isolinux/isolinux.msg; then
264 DATE=`date +%Y%m%d`
265 echo -n "Setting build date to: $DATE..."
266 sed -i s/'XXXXXXXX'/"$DATE"/ $ROOTCD/boot/isolinux/isolinux.msg
267 status
268 fi
269 cd $ROOTCD
270 echo -n "Computing md5..."
271 find * -type f ! -name md5sum -exec md5sum {} \; > md5sum
272 status
273 cd $DISTRO
274 echo ""
275 echo -e "\033[1mGenerating ISO image\033[0m"
276 echo "================================================================================"
277 create_iso $ISO_NAME.iso $ROOTCD
278 echo -n "Creating the ISO md5sum..."
279 md5sum $ISO_NAME.iso > $ISO_NAME.md5
280 status
281 echo "================================================================================"
282 # Some packages may want to alter final iso
283 genisohooks final
284 }
286 lzma_history_bits()
287 {
288 #
289 # This genertae ISO who boot with Qemu but give
290 # rootfs errors in frugal or liveUSB mode.
291 #
292 #local n
293 #local sz
294 #n=20 # 1Mb
295 #sz=$(du -sk $1 | cut -f1)
296 #while [ $sz -gt 1024 -a $n -lt 28 ]; do
297 #n=$(( $n + 1 ))
298 #sz=$(( $sz / 2 ))
299 #done
300 #echo $n
301 echo 24
302 }
304 lzma_switches()
305 {
306 echo "-d$(lzma_history_bits $1) -mt$(grep ^processor < /proc/cpuinfo | wc -l)"
307 }
309 # Pack rootfs
310 pack_rootfs()
311 {
312 ( cd $1 ; find . -print | cpio -o -H newc ) | \
313 if [ "$COMPRESSION" = "none" ]; then
314 echo -n "Generating uncompressed initramfs... "
315 cat > $2
316 elif [ -x /usr/bin/lzma -a "$COMPRESSION" != "gzip" ]; then
317 echo -n "Generating lzma'ed initramfs... "
318 lzma e -si -so $(lzma_switches $1) > $2
319 else
320 echo -n "Generating gziped initramfs... "
321 gzip -9 > $2
322 fi
323 }
325 # Generate a new initramfs from the root filesystem.
326 gen_initramfs()
327 {
328 # Just in case CTRL+c
329 rm -f $DISTRO/gen
330 # Some packages may want to alter rootfs
331 genisohooks rootfs
332 cd $1
333 echo ""
335 # Link duplicate files
336 find . -type f -size +0c -exec stat -c '%s-%a-%u-%g %i %h %n' {} \; | \
337 sort | ( save=0; old_attr=""; old_inode=""; old_link=""; old_file=""
338 while read attr inode link file; do
339 if [ "$attr" = "$old_attr" -a "$inode" != "$old_inode" ]; then
340 if cmp "$file" "$old_file" >/dev/null; then
341 rm -f "$file"
342 ln "$old_file" "$file"
343 inode="$old_inode"
344 [ "$link" = "1" ] && save="$(expr $save + ${attr%%-*})"
345 fi
346 fi
347 old_attr="$attr" ; old_inode="$inode" ; old_file="$file"
348 done
349 echo "$save bytes saved in duplicate files."
350 )
352 # Use lzma if installed
353 pack_rootfs . $DISTRO/$(basename $1).gz
354 cd $DISTRO
355 mv $(basename $1).gz $ROOTCD/boot
356 }
358 # Compression functions for writeiso.
359 write_lzma_initramfs()
360 {
361 echo -n "Creating rootfs.gz with lzma compression... "
362 cat /tmp/list | cpio -o -H newc | lzma e -si -so > /rootfs.gz
363 echo 1 > /tmp/rootfs
364 }
365 write_gzip_initramfs()
366 {
367 echo "Creating rootfs.gz with gzip compression... "
368 cat /tmp/list | cpio -o -H newc | gzip -9 > /rootfs.gz
369 echo 1 > /tmp/rootfs
370 }
371 write_initramfs()
372 {
373 echo "Creating rootfs.gz without compression... "
374 cat /tmp/list | cpio -o -H newc > /rootfs.gz
375 echo 1 > /tmp/rootfs
376 }
378 distro_sizes()
379 {
380 echo "Build date : `date +%Y%m%d\ \at\ \%H:%M:%S`"
381 echo "Packages : `ls -1 $ROOTFS*$INSTALLED/*/receipt | wc -l`"
382 echo "Rootfs size : `du -csh $ROOTFS*/ | awk '{ s=$1 } END { print s }'`"
383 echo "Initramfs size : `du -csh $ROOTCD/boot/rootfs*.gz | awk '{ s=$1 } END { print s }'`"
384 echo "ISO image size : `du -sh $ISO_NAME.iso | awk '{ print $1 }'`"
385 echo "================================================================================"
386 echo "Image is ready: $ISO_NAME.iso"
387 echo ""
388 }
390 # Print ISO and rootfs size.
391 distro_stats()
392 {
393 echo ""
394 echo -e "\033[1mDistro statistics\033[0m ($DISTRO)"
395 echo "================================================================================"
396 distro_sizes
397 }
399 # Create an empty configuration file.
400 empty_config_file()
401 {
402 cat >> tazlito.conf << "EOF"
403 # tazlito.conf: Tazlito (SliTaz Live Tool)
404 # configuration file.
405 #
407 # Name of the ISO image to generate.
408 ISO_NAME=""
410 # ISO image volume name.
411 VOLUM_NAME="SliTaz"
413 # Name of the preparer.
414 PREPARED="$USER"
416 # Path to the packages repository and the packages.list.
417 PACKAGES_REPOSITORY=""
419 # Path to the distro tree to gen-distro from a
420 # list of packages.
421 DISTRO=""
423 # Path to the directory containing additional files
424 # to copy into the rootfs and rootcd of the LiveCD.
425 ADDFILES="$DISTRO/addfiles"
427 # Default answer for binary question (Y or N)
428 DEFAULT_ANSWER="ASK"
430 # Compression utility (lzma, gzip or none)
431 COMPRESSION="lzma"
432 EOF
433 }
435 # extract rootfs.gz somewhere
436 extract_rootfs()
437 {
438 (zcat $1 || unlzma -c $1 || cat $1) 2>/dev/null | \
439 (cd $2; cpio -idm > /dev/null)
440 }
442 # Remove duplicate files
443 mergefs()
444 {
445 echo -n "Merge $(basename $1) ($(du -hs $1 | awk '{ print $1}')) into "
446 echo -n "$(basename $2) ($(du -hs $2 | awk '{ print $1}'))"
447 # merge symlinks files and devices
448 ( cd $1; find ) | while read file; do
449 if [ -L $1/$file ]; then
450 [ -L $2/$file ] &&
451 [ "$(readlink $1/$file)" == "$(readlink $2/$file)" ] &&
452 rm -f $2/$file
453 elif [ -f $1/$file ]; then
454 [ -f $2/$file ] &&
455 cmp $1/$file $2/$file > /dev/null 2>&1 && rm -f $2/$file
456 [ -f $2/$file ] &&
457 [ "$(basename $file)" == "volatile.cpio.gz" ] &&
458 [ "$(dirname $(dirname $file))" == \
459 "./var/lib/tazpkg/installed" ] && rm -f $2/$file
460 elif [ -b $1/$file ]; then
461 [ -b $2/$file ] && rm -f $2/$file
462 elif [ -c $1/$file ]; then
463 [ -c $2/$file ] && rm -f $2/$file
464 fi
465 done
467 # cleanup directories
468 ( cd $1; find ) | while read file; do
469 if [ -d $1/$file ]; then
470 [ -d $2/$file ] && rmdir $2/$file 2> /dev/null
471 fi
472 done
473 true
474 status
475 }
477 cleanup_merge()
478 {
479 rm -rf $TMP_DIR
480 exit 1
481 }
483 human2cent()
484 {
485 case "$1" in
486 *k) echo $1 | sed 's/\(.*\).\(.\)k/\1\2/';;
487 *M) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)M/\1\2/') * 1024));;
488 *G) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)G/\1\2/') * 1024 * 1024));;
489 esac
490 }
492 cent2human()
493 {
494 if [ $1 -lt 10000 ]; then
495 echo "$(($1 / 10)).$(($1 % 10))k"
496 elif [ $1 -lt 10000000 ]; then
497 echo "$(($1 / 10240)).$(( ($1/1024) % 10))M"
498 else
499 echo "$(($1 / 10485760)).$(( ($1/1048576) % 10))G"
500 fi
501 }
503 get_size()
504 {
505 cat /var/lib/tazpkg/packages.list $TMP_DIR/packages.list 2>/dev/null | awk "{ \
506 if (/^$(echo $1 | sed 's/[$+.\]/\\&/g')$/) get=1; \
507 if (/installed/ && get == 1) { print ; get++ } \
508 }
509 END { if (get < 2) print \" 0.0k (0.0k installed)\" }" | \
510 sed 's/ *\(.*\) .\(.*\) installed./\1 \2/' | while read packed unpacked; do
511 echo "$(human2cent $packed) $(human2cent $unpacked)"
512 done
513 }
515 # Display package list with version, set packed_size and unpacked_size
516 get_pkglist()
517 {
518 packed_size=0; unpacked_size=0
519 grep -v ^# $FLAVORS_REPOSITORY/$1/packages.list > $TMP_DIR/flavor.pkg
520 while read pkg; do
521 set -- $(get_size $pkg)
522 packed_size=$(( $packed_size + $1 ))
523 unpacked_size=$(( $unpacked_size + $2 ))
524 for i in $(grep -hs ^$pkg /var/lib/tazpkg/packages.list \
525 $TMP_DIR/packages.list); do
526 echo $i
527 break
528 done
529 done < $TMP_DIR/flavor.pkg
530 rm -f $TMP_DIR/flavor.pkg
531 }
533 # Update isolinux config files for multiple rootfs
534 update_bootconfig()
535 {
536 echo -n "Updating boot config files..."
537 grep -l 'include common' $1/*.cfg | \
538 while read file ; do
539 awk -v n=$(echo $2 | awk '{ print NF/2 }') '{
540 if (/label/) label=$0;
541 else if (/kernel/) kernel=$0;
542 else if (/append/) {
543 i=index($0,"rootfs.gz");
544 append=substr($0,i+9);
545 }
546 else if (/include/) {
547 for (i = 1; i <= n; i++) {
548 print label i
549 print kernel;
550 initrd="initrd=/boot/rootfs" n ".gz"
551 for (j = n - 1; j >= i; j--) {
552 initrd=initrd ",/boot/rootfs" j ".gz";
553 }
554 printf "\tappend %s%s\n",initrd,append;
555 print "";
556 }
557 print;
558 }
559 else print;
560 }' < $file > $file.$$
561 mv -f $file.$$ $file
562 done
563 cat >> $1/common.cfg <<EOT
565 label slitaz
566 kernel /boot/isolinux/ifmem.c32
567 append$(echo $2 | awk '{
568 for (i=1; i<=NF; i++)
569 if (i % 2 == 0) printf " slitaz%d",i/2
570 else printf " %s",$i
571 }') noram
573 label noram
574 config noram.cfg
576 EOT
577 cat > $1/noram.cfg <<EOT
578 display isolinux.msg
579 say Not enough RAM to boot slitaz.
580 default reboot
581 label reboot
582 com32 reboot.c32
584 implicit 0
585 prompt 1
586 timeout 80
587 F1 help.txt
588 F2 options.txt
589 F3 isolinux.msg
590 F4 display.txt
591 F5 enhelp.txt
592 F6 enopts.txt
593 EOT
594 status
595 }
597 ####################
598 # Tazlito commands #
599 ####################
601 case "$COMMAND" in
602 stats)
603 # Tazlito general statistics from the config file.
604 #
605 echo ""
606 echo -e "\033[1mTazlito statistics\033[0m
607 ===============================================================================
608 Config file : $CONFIG_FILE
609 ISO name : $ISO_NAME.iso
610 Volume name : $VOLUM_NAME
611 Prepared : $PREPARED
612 Packages repository : $PACKAGES_REPOSITORY
613 Distro directory : $DISTRO"
614 if [ ! "$ADDFILES" = "" ] ; then
615 echo -e "Additional files : $ADDFILES"
616 fi
617 echo "================================================================================"
618 echo ""
619 ;;
620 list-addfiles)
621 # Simple list of additonal files in the rootfs
622 echo ""
623 cd $ADDFILES
624 find rootfs -type f
625 echo "" ;;
626 gen-config)
627 # Generate a new config file in the current dir or the specified
628 # directory by $2.
629 #
630 if [ -n "$2" ] ; then
631 mkdir -p $2 && cd $2
632 fi
633 echo -n "Generating empty tazlito.conf..."
634 empty_config_file
635 status
636 echo ""
637 if [ -f "tazlito.conf" ] ; then
638 echo "Configuration file is ready to edit."
639 echo "File location : `pwd`/tazlito.conf"
640 echo ""
641 fi
642 ;;
643 configure)
644 # Configure a tazlito.conf config file. Start by getting
645 # a empty config file and sed it.
646 #
647 if [ -f "tazlito.conf" ] ; then
648 rm tazlito.conf
649 else
650 if test $(id -u) = 0 ; then
651 cd /etc
652 else
653 echo "You must be root to configure the main config file or in"
654 echo "the same directory of the file you want to configure."
655 exit 0
656 fi
657 fi
658 empty_config_file
659 echo""
660 echo -e "\033[1mConfiguring :\033[0m `pwd`/tazlito.conf"
661 echo "================================================================================"
662 # ISO name.
663 echo -n "ISO name : " ; read answer
664 sed -i s#'ISO_NAME=\"\"'#"ISO_NAME=\"$answer\""# tazlito.conf
665 # Volume name.
666 echo -n "Volume name : " ; read answer
667 sed -i s/'VOLUM_NAME=\"SliTaz\"'/"VOLUM_NAME=\"$answer\""/ tazlito.conf
668 # Packages repository.
669 echo -n "Packages repository : " ; read answer
670 sed -i s#'PACKAGES_REPOSITORY=\"\"'#"PACKAGES_REPOSITORY=\"$answer\""# tazlito.conf
671 # Distro path.
672 echo -n "Distro path : " ; read answer
673 sed -i s#'DISTRO=\"\"'#"DISTRO=\"$answer\""# tazlito.conf
674 echo "================================================================================"
675 echo "Config file is ready to use."
676 echo "You can now extract an ISO or generate a distro."
677 echo ""
678 ;;
679 gen-iso)
680 # Simply generate a new iso.
681 #
682 check_root
683 verify_rootcd
684 gen_livecd_isolinux
685 distro_stats
686 ;;
687 gen-initiso)
688 # Simply generate a new initramfs with a new iso.
689 #
690 check_root
691 verify_rootcd
692 gen_initramfs $ROOTFS
693 gen_livecd_isolinux
694 distro_stats
695 ;;
696 extract-distro)
697 # Extract an ISO image to a directory and rebuild the LiveCD tree.
698 #
699 check_root
700 ISO_IMAGE=$2
701 if [ -z "$ISO_IMAGE" ] ; then
702 echo -e "\nPlease specify the path to the ISO image."
703 echo -e "Example : `basename $0` image.iso /path/target\n"
704 exit 0
705 fi
706 # Set the distro path by checking for $3 on cmdline.
707 if [ -n "$3" ] ; then
708 TARGET=$3
709 else
710 TARGET=$DISTRO
711 fi
712 # Exit if existing distro is found.
713 if [ -d "$TARGET/rootfs" ] ; then
714 echo -e "\nA rootfs exists in : $TARGET"
715 echo -e "Please clean the distro tree or change directory path.\n"
716 exit 0
717 fi
718 echo ""
719 echo -e "\033[1mTazlito extracting :\033[0m `basename $ISO_IMAGE`"
720 echo "================================================================================"
721 # Start to mount the ISO.
722 echo ""
723 echo "Mounting ISO image..."
724 mkdir -p $TMP_DIR
725 # Get ISO file size.
726 isosize=`du -sh $ISO_IMAGE | cut -f1`
727 mount -o loop $ISO_IMAGE $TMP_DIR
728 sleep 2
729 # Prepare target dir, copy the kernel and the rootfs.
730 mkdir -p $TARGET/rootfs
731 mkdir -p $TARGET/rootcd/boot
732 echo -n "Copying the Linux kernel..."
733 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
734 ln $TARGET/rootcd/boot/vmlinuz* $TARGET/rootcd/boot/bzImage
735 else
736 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
737 fi
738 status
739 echo -n "Copying isolinux files..."
740 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
741 for i in $(ls $TMP_DIR); do
742 [ "$i" = "boot" ] && continue
743 cp -a $TMP_DIR/$i $TARGET/rootcd
744 done
745 status
746 if [ -d $TMP_DIR/boot/syslinux ]; then
747 echo -n "Copying syslinux files..."
748 cp -a $TMP_DIR/boot/syslinux $TARGET/rootcd/boot
749 status
750 fi
751 if [ -d $TMP_DIR/boot/extlinux ]; then
752 echo -n "Copying extlinux files..."
753 cp -a $TMP_DIR/boot/extlinux $TARGET/rootcd/boot
754 status
755 fi
756 if [ -d $TMP_DIR/boot/grub ]; then
757 echo -n "Copying GRUB files..."
758 cp -a $TMP_DIR/boot/grub $TARGET/rootcd/boot
759 status
760 fi
762 echo -n "Copying the rootfs..."
763 cp $TMP_DIR/boot/rootfs.?z $TARGET/rootcd/boot
764 status
765 # Extract initramfs.
766 cd $TARGET/rootfs
767 echo -n "Extracting the rootfs... "
768 extract_rootfs ../rootcd/boot/rootfs.gz $TARGET/rootfs
769 # unpack /usr
770 for i in etc/tazlito/*.extract; do
771 [ -f "$i" ] && . $i ../rootcd
772 done
773 # Umount and remove temp directory and cd to $TARGET to get stats.
774 umount $TMP_DIR && rm -rf $TMP_DIR
775 cd ..
776 echo ""
777 echo "================================================================================"
778 echo "Extracted : `basename $ISO_IMAGE` ($isosize)"
779 echo "Distro tree : `pwd`"
780 echo "Rootfs size : `du -sh rootfs`"
781 echo "Rootcd size : `du -sh rootcd`"
782 echo "================================================================================"
783 echo ""
784 ;;
785 list-flavors)
786 # Show available flavors.
787 if [ ! -s /etc/tazlito/flavors.list -o "$2" == "--recharge" ]; then
788 download flavors.list -O - > /etc/tazlito/flavors.list
789 fi
790 echo ""
791 echo -e "\033[1mList of flavors\033[0m"
792 echo "================================================================================"
793 cat /etc/tazlito/flavors.list
794 echo ""
795 ;;
796 show-flavor)
797 # Show flavor description.
798 FLAVOR=${2%.flavor}
799 if [ ! -f "$FLAVOR.flavor" ]; then
800 echo "File $FLAVOR.flavor not found."
801 exit 1
802 fi
803 mkdir $TMP_DIR
804 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i 2> /dev/null)
805 if [ "$3" = "--brief" ]; then
806 if [ "$4" != "--noheader" ]; then
807 echo "Name ISO Rootfs Description"
808 echo "================================================================================"
809 fi
810 printf "%-16.16s %6.6s %6.6s %s\n" "$FLAVOR" \
811 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
812 "$(field 'Rootfs size' $TMP_DIR/$FLAVOR.desc)" \
813 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
814 else
815 echo "================================================================================"
816 cat $TMP_DIR/$FLAVOR.desc
817 fi
818 rm -Rf $TMP_DIR
819 ;;
820 gen-liveflavor)
821 # Generate a new flavor form the live system.
822 FLAVOR=${2%.flavor}
823 DESC=""
824 case "$FLAVOR" in
825 '') echo -n "Flavor name : "
826 read FLAVOR
827 [ -z "$FLAVOR" ] && exit 1;;
828 -?|-h*|--help) echo -e "
830 SliTaz Live Tool - Version: $VERSION
831 \033[1mUsage: \033[0m `basename $0` gen-liveflavor flavor-name [flavor-patch-file]
832 \033[1mflavor-patch-file format: \033[0m
833 code data
834 + package to add
835 - package to remove
836 ! non-free package to add
837 ? display message
838 @ flavor description
840 \033[1mExample: \033[0m
841 @ Developer tools for slitaz maintainers
842 + slitaz-toolchain
843 + mercurial
844 "
845 exit 1;;
846 esac
847 mv /etc/tazlito/distro-packages.list \
848 /etc/tazlito/distro-packages.list.$$ 2> /dev/null
849 rm -f distro-packages.list non-free.list 2> /dev/null
850 tazpkg recharge
851 [ -n "$3" ] && while read action pkg; do
852 case "$action" in
853 +) yes | tazpkg get-install $pkg;;
854 -) yes | tazpkg remove $pkg;;
855 !) echo $pkg >> non-free.list;;
856 @) DESC="$pkg";;
857 \?) echo -en "$pkg"; read action;;
858 esac
859 done < $3
860 yes '' | tazlito gen-distro
861 echo "$DESC" | tazlito gen-flavor "$FLAVOR"
862 mv /etc/tazlito/distro-packages.list.$$ \
863 /etc/tazlito/distro-packages.list 2> /dev/null
864 ;;
865 gen-flavor)
866 # Generate a new flavor from the last iso image generated.
867 FLAVOR=${2%.flavor}
868 echo ""
869 echo -e "\033[1mFlavor generation\033[0m"
870 echo "================================================================================"
871 if [ -z "$FLAVOR" ]; then
872 echo -n "Flavor name : "
873 read FLAVOR
874 [ -z "$FLAVOR" ] && exit 1
875 fi
876 check_rootfs
877 FILES="$FLAVOR.pkglist"
878 echo -n "Creating file $FLAVOR.flavor..."
879 for i in rootcd rootfs; do
880 if [ -d "$ADDFILES/$i" ] ; then
881 FILES="$FILES\n$FLAVOR.$i"
882 ( cd "$ADDFILES/$i"; find . | \
883 cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
884 fi
885 done
886 status
887 answer=`grep -s ^Description $FLAVOR.desc`
888 answer=${answer#Description : }
889 if [ -z "$answer" ]; then
890 echo -n "Description : "
891 read answer
892 fi
893 echo -n "Compressing flavor $FLAVOR..."
894 echo "Flavor : $FLAVOR" > $FLAVOR.desc
895 echo "Description : $answer" >> $FLAVOR.desc
896 ( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
897 \rm -f $FLAVOR.pkglist $FLAVOR.nonfree 2> /dev/null
898 for i in $(ls $ROOTFS$INSTALLED); do
899 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
900 EXTRAVERSION=""
901 eval $(grep ^EXTRAVERSION= $ROOTFS$INSTALLED/$i/receipt)
902 eval $(grep ^CATEGORY= $ROOTFS$INSTALLED/$i/receipt)
903 if [ "$CATEGORY" = "non-free" -a "${i%%-*}" != "get" ]
904 then
905 echo "$i" >> $FLAVOR.nonfree
906 else
907 echo "$i-$VERSION$EXTRAVERSION" >> $FLAVOR.pkglist
908 fi
909 done
910 [ -s $FLAVOR.nonfree ] && $FILES="$FILES\n$FLAVOR.nonfree"
911 for i in $LOCALSTATE/undigest/*/mirror ; do
912 [ -s $i ] && cat $i >> $FLAVOR.mirrors
913 done
914 [ -s $FLAVOR.mirrors ] && $FILES="$FILES\n$FLAVOR.mirrors"
915 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
916 gzip -9 > $FLAVOR.flavor
917 rm `echo -e $FILES`
918 status
919 echo "================================================================================"
920 echo "Flavor size : `du -sh $FLAVOR.flavor`"
921 echo ""
922 ;;
923 upgrade-flavor)
924 # Update package list to the lastest versions available.
925 FLAVOR=${2%.flavor}
926 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
927 mkdir $TMP_DIR
928 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
929 echo -n "Updating $FLAVOR package list..."
930 [ -s /var/lib/tazpkg/packages.list ] || tazpkg recharge
931 packed_size=0; unpacked_size=0
932 while read org; do
933 i=0
934 pkg=$org
935 while ! grep -q ^$pkg$ /var/lib/tazpkg/packages.txt; do
936 pkg=${pkg%-*}
937 i=$(($i + 1))
938 [ $i -gt 5 ] && break;
939 done
940 set -- $(get_size $pkg)
941 packed_size=$(( $packed_size + $1 ))
942 unpacked_size=$(( $unpacked_size + $2 ))
943 for i in $(grep ^$pkg /var/lib/tazpkg/packages.list); do
944 echo $i
945 break
946 done
947 done < $TMP_DIR/$FLAVOR.pkglist \
948 > $TMP_DIR/$FLAVOR.pkglist.$$
949 mv -f $TMP_DIR/$FLAVOR.pkglist.$$ $TMP_DIR/$FLAVOR.pkglist
950 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
951 packed_size=$(($packed_size \
952 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
953 unpacked_size=$(($unpacked_size \
954 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
955 fi
956 # Estimate lzma
957 packed_size=$(($packed_size * 2 / 3))
958 iso_size=$(( $packed_size + 26000 ))
959 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
960 iso_size=$(($iso_size \
961 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
962 fi
963 sed -i -e '/Image is ready/d' \
964 -e "s/Rootfs size\( *:\) \(.*\)/Rootfs size\1 $(cent2human $unpacked_size) (estimated)/" \
965 -e "s/Initramfs size\( *:\) \(.*\)/Initramfs size\1 $(cent2human $packed_size) (estimated)/" \
966 -e "s/ISO image size\( *:\) \(.*\)/ISO image size\1 $(cent2human $iso_size) (estimated)/" \
967 -e "s/date\( *:\) \(.*\)/date\1 $(date +%Y%m%d\ \at\ \%H:%M:%S)/" \
968 $TMP_DIR/$FLAVOR.desc
969 ( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
970 $FLAVOR.flavor
971 status
972 rm -Rf $TMP_DIR
973 fi
974 ;;
975 extract-flavor)
976 # Extract a flavor into $FLAVORS_REPOSITORY.
977 FLAVOR=${2%.flavor}
978 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
979 mkdir $TMP_DIR
980 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
981 echo -n "Extracting $FLAVOR..."
982 rm -rf $FLAVORS_REPOSITORY/$FLAVOR 2> /dev/null
983 mkdir -p $FLAVORS_REPOSITORY/$FLAVOR
984 echo "FLAVOR=\"$FLAVOR\"" > $FLAVORS_REPOSITORY/$FLAVOR/receipt
985 grep ^Description $TMP_DIR/$FLAVOR.desc | \
986 sed 's/.*: \(.*\)$/SHORT_DESC="\1"/' >> \
987 $FLAVORS_REPOSITORY/$FLAVOR/receipt
988 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc && \
989 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
990 sed 's/.*: \(.*\)$/ROOTFS_SELECTION="\1"/' >> \
991 $FLAVORS_REPOSITORY/$FLAVOR/receipt
992 grep '^Rootfs size' $TMP_DIR/$FLAVOR.desc | \
993 sed 's/.*: \(.*\)$/ROOTFS_SIZE="\1"/' >> \
994 $FLAVORS_REPOSITORY/$FLAVOR/receipt
995 grep ^Initramfs $TMP_DIR/$FLAVOR.desc | \
996 sed 's/.*: \(.*\)$/INITRAMFS_SIZE="\1"/' >> \
997 $FLAVORS_REPOSITORY/$FLAVOR/receipt
998 grep ^ISO $TMP_DIR/$FLAVOR.desc | \
999 sed 's/.*: \(.*\)$/ISO_SIZE="\1"/' >> \
1000 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1001 for i in rootcd rootfs; do
1002 [ -f $TMP_DIR/$FLAVOR.$i ] || continue
1003 mkdir $FLAVORS_REPOSITORY/$FLAVOR/$i
1004 zcat $TMP_DIR/$FLAVOR.$i | \
1005 (cd $FLAVORS_REPOSITORY/$FLAVOR/$i; \
1006 cpio -idm > /dev/null)
1007 done
1008 [ -s $TMP_DIR/$FLAVOR.mirrors ] &&
1009 cp $TMP_DIR/$FLAVOR.mirrors \
1010 $FLAVORS_REPOSITORY/$FLAVOR/mirrors
1011 [ -s /var/lib/tazpkg/packages.list ] || tazpkg recharge
1012 while read org; do
1013 i=0
1014 pkg=$org
1015 while ! grep -q ^$pkg$ /var/lib/tazpkg/packages.txt; do
1016 pkg=${pkg%-*}
1017 i=$(($i + 1))
1018 [ $i -gt 5 ] && break;
1019 done
1020 echo $pkg
1021 done < $TMP_DIR/$FLAVOR.pkglist \
1022 > $FLAVORS_REPOSITORY/$FLAVOR/packages.list
1023 status
1024 rm -Rf $TMP_DIR
1025 fi
1026 ;;
1027 pack-flavor)
1028 # Create a flavor from $FLAVORS_REPOSITORY.
1029 FLAVOR=${2%.flavor}
1030 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/receipt ]; then
1031 mkdir $TMP_DIR
1032 echo -n "Creating flavor $FLAVOR..."
1033 [ -s /var/lib/tazpkg/packages.list ] || tazpkg recharge
1034 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/mirrors ]; then
1035 cp $FLAVORS_REPOSITORY/$FLAVOR/mirrors \
1036 $TMP_DIR/$FLAVOR.mirrors
1037 for i in $(cat $TMP_DIR/$FLAVOR.mirrors); do
1038 wget -O - $i/packages.list >> $TMP_DIR/packages.list
1039 done
1040 fi
1041 [ -s $FLAVORS_REPOSITORY/$FLAVOR/packages.list ] &&
1042 get_pkglist $FLAVOR > $TMP_DIR/$FLAVOR.pkglist
1043 if grep -q ^ROOTFS_SELECTION \
1044 $FLAVORS_REPOSITORY/$FLAVOR/receipt; then
1045 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1046 set -- $ROOTFS_SELECTION
1047 [ -n "$FRUGAL_RAM" ] || FRUGAL_RAM=$1
1048 [ -f $FLAVORS_REPOSITORY/$2/packages.list ] ||
1049 tazlito extract-flavor $2
1050 get_pkglist $2 > $TMP_DIR/$FLAVOR.pkglist
1051 fi
1052 for i in rootcd rootfs; do
1053 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] || \
1054 continue
1055 ( cd $FLAVORS_REPOSITORY/$FLAVOR/$i ; find . | \
1056 cpio -o -H newc 2> /dev/null ) | \
1057 gzip -9 >$TMP_DIR/$FLAVOR.$i
1058 done
1059 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1060 packed_size=$(($packed_size \
1061 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1062 unpacked_size=$(($unpacked_size \
1063 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1064 fi
1065 # Estimate lzma
1066 packed_size=$(($packed_size * 2 / 3))
1067 iso_size=$(( $packed_size + 26000 ))
1068 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1069 iso_size=$(($iso_size \
1070 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1071 fi
1072 VERSION=""
1073 MAINTAINER=""
1074 ROOTFS_SELECTION=""
1075 ROOTFS_SIZE="$(cent2human $unpacked_size) (estimated)"
1076 INITRAMFS_SIZE="$(cent2human $packed_size) (estimated)"
1077 ISO_SIZE="$(cent2human $iso_size) (estimated)"
1078 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1079 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1080 Flavor : $FLAVOR
1081 Description : $SHORT_DESC
1082 EOT
1083 [ -n "$VERSION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1084 Version : $VERSION
1085 EOT
1086 [ -n "$MAINTAINER" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1087 Maintainer : $MAINTAINER
1088 EOT
1089 [ -n "$FRUGAL_RAM" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1090 LiveCD RAM size : $FRUGAL_RAM
1091 EOT
1092 [ -n "$ROOTFS_SELECTION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1093 Rootfs list : $ROOTFS_SELECTION
1094 EOT
1095 cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1096 Build date : $(date +%Y%m%d\ \at\ \%H:%M:%S)
1097 Packages : $(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l)
1098 Rootfs size : $ROOTFS_SIZE
1099 Initramfs size : $INITRAMFS_SIZE
1100 ISO image size : $ISO_SIZE
1101 ================================================================================
1103 EOT
1104 rm -f $TMP_DIR/packages.list
1105 ( cd $TMP_DIR ; ls | cpio -o -H newc 2> /dev/null) | \
1106 gzip -9 > $FLAVOR.flavor
1107 status
1108 rm -Rf $TMP_DIR
1109 else
1110 echo "No $FLAVOR flavor in $FLAVORS_REPOSITORY."
1111 fi
1112 ;;
1113 get-flavor)
1114 # Get a flavor's files and prepare for gen-distro.
1115 FLAVOR=${2%.flavor}
1116 echo ""
1117 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1118 echo -n "Cleaning $DISTRO..."
1119 rm -R $DISTRO 2> /dev/null
1120 mkdir -p $DISTRO
1121 status
1122 mkdir $TMP_DIR
1123 echo -n "Extracting flavor $FLAVOR.flavor... "
1124 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i 2>/dev/null )
1125 echo -n "Creating distro-packages.list..."
1126 mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
1127 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
1128 status
1129 for i in rootcd rootfs; do
1130 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
1131 echo -n "Adding $i... "
1132 mkdir -p "$ADDFILES/$i"
1133 zcat $TMP_DIR/$FLAVOR.$i | \
1134 ( cd "$ADDFILES/$i"; cpio -id 2> /dev/null)
1135 status
1136 fi
1137 done
1138 if [ -s $TMP_DIR/$FLAVOR.mirrors ]; then
1139 n=""
1140 while read line; do
1141 mkdir -p $LOCALSTATE/undigest/$FLAVOR$n
1142 echo "$line" > $LOCALSTATE/undigest/$FLAVOR$n/mirror
1143 n=$(( $n + 1 ))
1144 done < $TMP_DIR/$FLAVOR.mirrors
1145 tazpkg recharge
1146 fi
1147 rm -f /etc/tazlito/rootfs.list
1148 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc &&
1149 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1150 sed 's/.*: \(.*\)$/\1/' > /etc/tazlito/rootfs.list
1151 echo -n "Updating tazlito.conf..."
1152 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
1153 cat tazlito.conf | grep -v "^#VOLUM_NAME" | \
1154 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
1155 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
1156 sed -i "s/ISO_NAME=.*/ISO_NAME=\"slitaz-$FLAVOR\"/" tazlito.conf
1157 status
1158 rm -Rf $TMP_DIR
1159 fi
1160 echo ""
1161 ;;
1162 check-list)
1163 # Use current packages list in $PWD by default.
1164 DISTRO_PKGS_LIST=distro-packages.list
1165 [ -d "$2" ] && DISTRO_PKGS_LIST=$2/distro-packages.list
1166 [ -f "$2" ] && DISTRO_PKGS_LIST=$2
1167 [ ! -f $DISTRO_PKGS_LIST ] && echo "No packages list found." && exit 0
1168 echo ""
1169 echo -e "\033[1mLiveCD packages list check\033[0m"
1170 echo "================================================================================"
1171 for pkg in `cat $DISTRO_PKGS_LIST`
1172 do
1173 if ! grep -q "$pkg" /var/lib/tazpkg/packages.list; then
1174 echo "Update: $pkg"
1175 up=$(($up + 1))
1176 fi
1177 done
1178 [ -z $up ] && echo -e "List is up-to-date\n" && exit 0
1179 echo "================================================================================"
1180 echo -e "Updates: $up\n" ;;
1181 gen-distro)
1182 # Generate a live distro tree with a set of packages.
1184 check_root
1186 # Check if a package list was specified on cmdline.
1187 LIST_NAME="distro-packages.list"
1188 CDROM=""
1189 while [ -n "$2" ]; do
1190 case "$2" in
1191 --iso=*)
1192 CDROM="-o loop ${2#--iso=}"
1193 ;;
1194 --cdrom)
1195 CDROM="/dev/cdrom"
1196 ;;
1197 --force)
1198 DELETE_ROOTFS="true"
1199 ;;
1200 *) if [ ! -f "$2" ] ; then
1201 echo -e "\nUnable to find the specified packages list."
1202 echo -e "List name : $2\n"
1203 exit 1
1204 fi
1205 LIST_NAME=$2
1206 ;;
1207 esac
1208 shift
1209 done
1211 if [ -d $ROOTFS ] ; then
1212 # Delete $ROOTFS if --force is set on command line
1213 if [ ! -z $DELETE_ROOTFS ]; then
1214 rm -rf $ROOTFS
1215 unset $DELETE_ROOTFS
1216 else
1217 echo -e "\nA rootfs exists in : $DISTRO"
1218 echo -e "Please clean the distro tree or change directory path.\n"
1219 exit 0
1220 fi
1221 fi
1222 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
1223 # Build list with installed packages
1224 for i in $(ls $INSTALLED); do
1225 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
1226 EXTRAVERSION=""
1227 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
1228 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
1229 done
1230 fi
1231 # Exit if no list name.
1232 if [ ! -f "$LIST_NAME" ]; then
1233 echo -e "\nNo packages list found or specified. Please read the docs.\n"
1234 exit 0
1235 fi
1236 # Start generation.
1237 echo ""
1238 echo -e "\033[1mTazlito generating a distro\033[0m"
1239 echo "================================================================================"
1240 # Misc checks
1241 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
1242 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
1243 # Get the list of packages using cat for a file list.
1244 LIST=`cat $LIST_NAME`
1245 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
1246 REPACK=""
1247 DOWNLOAD=""
1248 for pkg in $LIST
1249 do
1250 [ "$pkg" = "" ] && continue
1251 pkg=${pkg%.tazpkg}
1252 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
1253 PACKAGE=$(installed_package_name $pkg)
1254 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
1255 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
1256 echo -e "\nUnable to find $pkg in the repository."
1257 echo -e "Path : $PACKAGES_REPOSITORY\n"
1258 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
1259 yesorno "Repack packages from rootfs (y/N) ? "
1260 REPACK="$answer"
1261 [ "$answer" = "y" ] || REPACK="n"
1262 [ "$DOWNLOAD" = "y" ] && break
1263 fi
1264 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
1265 yesorno "Download packages from mirror (Y/n) ? "
1266 DOWNLOAD="$answer"
1267 if [ "$answer" = "n" ]; then
1268 [ -z "$PACKAGE" ] && exit 1
1269 else
1270 DOWNLOAD="y"
1271 [ -n "$REPACK" ] && break
1272 fi
1273 fi
1274 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
1275 done
1277 # Mount cdrom to be able to repack boot-loader packages
1278 if [ ! -e /boot -a -n "$CDROM" ]; then
1279 mkdir $TMP_MNT
1280 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
1281 ln -s $TMP_MNT/boot /
1282 if [ ! -d "$ADDFILES/rootcd" ] ; then
1283 mkdir -p $ADDFILES/rootcd
1284 for i in $(ls $TMP_MNT); do
1285 [ "$i" = "boot" ] && continue
1286 cp -a $TMP_MNT/$i $ADDFILES/rootcd
1287 done
1288 fi
1289 else
1290 rmdir $TMP_MNT
1291 fi
1292 fi
1294 # Root fs stuff.
1295 echo "Preparing the rootfs directory..."
1296 mkdir -p $ROOTFS
1297 sleep 2
1298 for pkg in $LIST
1299 do
1300 [ "$pkg" = "" ] && continue
1301 # First copy and extract the package in tmp dir.
1302 pkg=${pkg%.tazpkg}
1303 PACKAGE=$(installed_package_name $pkg)
1304 mkdir -p $TMP_DIR
1305 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1306 # Look for package in cache
1307 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
1308 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
1309 # Look for package in running distribution
1310 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
1311 tazpkg repack $PACKAGE && \
1312 mv $pkg.tazpkg $PACKAGES_REPOSITORY
1313 fi
1314 fi
1315 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1316 # Get package from mirror
1317 [ "$DOWNLOAD" = "y" ] && \
1318 download $pkg.tazpkg && \
1319 mv $pkg.tazpkg $PACKAGES_REPOSITORY
1320 fi
1321 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1322 echo "Missing package $pkg."
1323 cleanup
1324 exit 1
1325 fi
1326 done
1327 if [ -f non-free.list ]; then
1328 echo "Preparing non-free packages..."
1329 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
1330 for pkg in $(cat non-free.list); do
1331 if [ ! -d $INSTALLED/$pkg ]; then
1332 if [ ! -d $INSTALLED/get-$pkg ]; then
1333 tazpkg get-install get-$pkg
1334 fi
1335 get-$pkg
1336 fi
1337 tazpkg repack $pkg
1338 pkg=$(ls $pkg*.tazpkg)
1339 grep -q "^$pkg$" $LIST_NAME || \
1340 echo $pkg >>$LIST_NAME
1341 mv $pkg $PACKAGES_REPOSITORY
1342 done
1343 fi
1344 echo ""
1345 cp $LIST_NAME $DISTRO/distro-packages.list
1346 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/distro-packages.list > $DISTRO/list-packages
1347 cd $PACKAGES_REPOSITORY
1348 yes y | tazpkg install-list \
1349 $DISTRO/list-packages --root=$ROOTFS
1350 cd $DISTRO
1351 cp distro-packages.list $ROOTFS/etc/tazlito
1352 # Copy all files from $ADDFILES/rootfs to the rootfs.
1353 if [ -d "$ADDFILES/rootfs" ] ; then
1354 echo -n "Copying addfiles content to the rootfs... "
1355 cp -a $ADDFILES/rootfs/* $ROOTFS
1356 status
1357 fi
1358 echo "Root file system is generated..."
1359 # Root CD part.
1360 echo -n "Preparing the rootcd directory..."
1361 mkdir -p $ROOTCD
1362 status
1363 # Move the boot dir with the Linux kernel from rootfs.
1364 # The boot dir goes directly on the CD.
1365 if [ -d "$ROOTFS/boot" ] ; then
1366 echo -n "Moving the boot directory..."
1367 mv $ROOTFS/boot $ROOTCD
1368 cd $ROOTCD/boot
1369 ln vmlinuz-* bzImage
1370 status
1371 fi
1372 cd $DISTRO
1373 # Copy all files from $ADDFILES/rootcd to the rootcd.
1374 if [ -d "$ADDFILES/rootcd" ] ; then
1375 echo -n "Copying addfiles content to the rootcd... "
1376 cp -a $ADDFILES/rootcd/* $ROOTCD
1377 status
1378 fi
1379 # Execute the distro script (used to perform tasks in the rootfs
1380 # before compression. Give rootfs path in arg
1381 [ -z $DISTRO_SCRIPT ] && DISTRO_SCRIPT=$TOP_DIR/distro.sh
1382 if [ -x $DISTRO_SCRIPT ]; then
1383 echo "Executing distro script..."
1384 sh $DISTRO_SCRIPT $DISTRO
1385 fi
1386 if [ -s /etc/tazlito/rootfs.list ]; then
1387 [ -f $ROOTCD/boot/isolinux/ifmem.c32 ] ||
1388 cp /boot/isolinux/ifmem.c32 $ROOTCD/boot/isolinux
1389 n=0
1390 last=$ROOTFS
1391 while read flavor; do
1392 n=$(($n+1))
1393 echo "Building $flavor rootfs..."
1394 download $flavor.flavor
1395 zcat $flavor.flavor | cpio -i $flavor.pkglist
1396 sed 's/.*/&.tazpkg/' < $flavor.pkglist \
1397 > $DISTRO/list-packages0$n
1398 mkdir ${ROOTFS}0$n
1399 cd $PACKAGES_REPOSITORY
1400 yes y | tazpkg install-list \
1401 $DISTRO/list-packages0$n --root=${ROOTFS}0$n
1402 rm -rf ${ROOTFS}0$n/boot
1403 status
1404 cd $DISTRO
1405 mv $flavor.pkglist ${ROOTFS}0$n/etc/tazlito/distro-packages.list
1406 rm -f $flavor.flavor install-list
1407 mergefs ${ROOTFS}0$n $last
1408 last=${ROOTFS}0$n
1409 done <<EOT
1410 $(awk '{ for (i = 4; i <= NF; i+=2) print $i; }' < /etc/tazlito/rootfs.list)
1411 EOT
1412 i=$(($n+1))
1413 while [ $n -gt 0 ]; do
1414 mv ${ROOTFS}0$n ${ROOTFS}$i
1415 echo "Compression ${ROOTFS}0$n ($(du -hs ${ROOTFS}$i | awk '{ print $1 }')) ..."
1416 gen_initramfs ${ROOTFS}$i
1417 n=$(($n-1))
1418 i=$(($i-1))
1419 done
1420 mv $ROOTFS ${ROOTFS}$i
1421 gen_initramfs ${ROOTFS}$i
1422 update_bootconfig $ROOTCD/boot/isolinux \
1423 "$(cat /etc/tazlito/rootfs.list)"
1424 else
1425 # Initramfs and ISO image stuff.
1426 gen_initramfs $ROOTFS
1427 fi
1428 gen_livecd_isolinux
1429 distro_stats
1430 cleanup
1431 ;;
1432 clean-distro)
1433 # Remove old distro tree.
1435 check_root
1436 echo ""
1437 echo -e "\033[1mCleaning :\033[0m $DISTRO"
1438 echo "================================================================================"
1439 if [ -d "$DISTRO" ] ; then
1440 if [ -d "$ROOTFS" ] ; then
1441 echo -n "Removing the rootfs..."
1442 rm -f $DISTRO/$INITRAMFS
1443 rm -rf $ROOTFS
1444 status
1445 fi
1446 if [ -d "$ROOTCD" ] ; then
1447 echo -n "Removing the rootcd..."
1448 rm -rf $ROOTCD
1449 status
1450 fi
1451 echo -n "Removing eventual ISO image..."
1452 rm -f $DISTRO/$ISO_NAME.iso
1453 rm -f $DISTRO/$ISO_NAME.md5
1454 status
1455 fi
1456 echo "================================================================================"
1457 echo ""
1458 ;;
1459 check-distro)
1460 # Check for a few LiveCD needed files not installed by packages.
1462 check_rootfs
1463 echo ""
1464 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
1465 echo "================================================================================"
1466 # SliTaz release info.
1467 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
1468 echo "Missing release info : /etc/slitaz-release"
1469 else
1470 release=`cat $ROOTFS/etc/slitaz-release`
1471 echo -n "Release : $release"
1472 status
1473 fi
1474 # Tazpkg mirror.
1475 if [ ! -f "$ROOTFS/var/lib/tazpkg/mirror" ]; then
1476 echo -n "Mirror URL : Missing /var/lib/tazpkg/mirror"
1477 todomsg
1478 else
1479 echo -n "Mirror configuration exists..."
1480 status
1481 fi
1482 # Isolinux msg
1483 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.msg; then
1484 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
1485 todomsg
1486 else
1487 echo -n "Isolinux message seems good..."
1488 status
1489 fi
1490 echo "================================================================================"
1491 echo ""
1492 ;;
1493 writeiso)
1494 # Writefs to ISO image including /home unlike gen-distro we dont use
1495 # packages to generate a rootfs, we build a compressed rootfs with all
1496 # the current filesystem similar to 'tazusb writefs'.
1498 DISTRO="/home/slitaz/distro"
1499 ROOTCD="$DISTRO/rootcd"
1500 if [ -z $2 ]; then
1501 COMPRESSION=none
1502 else
1503 COMPRESSION=$2
1504 fi
1505 if [ -z $3 ]; then
1506 ISO_NAME="slitaz"
1507 else
1508 ISO_NAME="$3"
1509 fi
1510 check_root
1511 # Start info
1512 echo ""
1513 echo -e "\033[1mWrite filesystem to ISO\033[0m
1514 ===============================================================================
1515 The command writeiso will write the current filesystem into a suitable cpio
1516 archive (rootfs.gz) and generate a bootable ISO image (slitaz.iso).
1518 Archive compression: $COMPRESSION"
1519 echo ""
1521 # Save some space
1522 rm /var/cache/tazpkg/* -r -f
1523 rm -rf /home/slitaz/distro
1525 # Optionally remove sound card selection and screen resolution.
1526 echo "Do you wish to remove the sound card and screen configs ? "
1527 echo -n "Press ENTER to keep or answer (No|yes|exit): "
1528 read anser
1529 case $anser in
1530 e|E|"exit"|Exit)
1531 exit 0 ;;
1532 y|Y|yes|Yes)
1533 echo -n "Removing current sound card and screen configurations..."
1534 rm -f /var/lib/sound-card-driver
1535 rm -f /etc/asound.state
1536 rm -f /etc/X11/screen.conf
1537 rm -f /etc/X11/xorg.conf ;;
1538 *)
1539 echo -n "Keeping current sound card and screen configurations..." ;;
1540 esac
1541 status
1543 # Create list of files including default user files since it is defined in /etc/passwd
1544 # and some new users might have been added.
1545 find /bin /etc /init /sbin /var /dev /lib /root /usr /home >/tmp/list
1547 for dir in /proc /sys /tmp /mnt /media /media/cdrom /media/flash /media/usbdisk
1548 do
1549 echo $dir >>/tmp/list
1550 done
1551 rm -f /tmp/rootfs
1553 # Generate initramfs with specified compression and display rootfs
1554 # size in realtime.
1555 if [ "$COMPRESSION" = "lzma" ]; then
1556 write_lzma_initramfs &
1557 elif [ "$COMPRESSION" = "gzip" ]; then
1558 write_gzip_initramfs &
1559 else
1560 write_initramfs &
1561 fi
1562 sleep 2
1563 echo -en "\nFilesystem size:"
1564 while [ ! -f /tmp/rootfs ]
1565 do
1566 sleep 1
1567 echo -en "\\033[18G`du -sh /rootfs.gz | awk '{print $1}'` "
1568 done
1569 echo -e "\n"
1571 # Move freshly generated rootfs to the cdrom.
1572 mkdir -p $ROOTCD/boot
1573 mv -f /rootfs.gz $ROOTCD/boot
1575 # Now we need the kernel and isolinux files.
1576 if mount /dev/cdrom /media/cdrom 2>/dev/null; then
1577 cp /media/cdrom/boot/bzImage $ROOTCD/boot
1578 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
1579 umount /media/cdrom
1580 else
1581 echo -e "
1582 Unable to mount the cdrom to copy the Kernel and needed files. When SliTaz
1583 is running in RAM the kernel and bootloader files are kept on the cdrom.
1584 Please insert a LiveCD or unmount the current cdrom to let Tazlito handle
1585 the media.\n"
1586 echo -en "----\nENTER to continue..."; read i
1587 exit 1
1588 fi
1590 # Generate the iso image.
1591 cd $DISTRO
1592 echo "Generating ISO image..."
1593 genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
1594 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
1595 -V "SliTaz" -input-charset iso8859-1 -boot-info-table $ROOTCD
1596 if [ -x /usr/bin/isohybrid ]; then
1597 echo -n "Creating hybrid ISO..."
1598 /usr/bin/isohybrid $ISO_NAME.iso 2> /dev/null
1599 status
1600 fi
1601 echo -n "Creating the ISO md5sum..."
1602 md5sum $ISO_NAME.iso > $ISO_NAME.md5
1603 status
1605 echo "==============================================================================="
1606 echo "ISO image: `du -sh /home/slitaz/distro/$ISO_NAME.iso`"
1607 echo ""
1608 echo -n "Exit or burn ISO to cdrom (Exit|burn)? "; read anser
1609 case $anser in
1610 burn)
1611 eject
1612 echo -n "Please insert a blank cdrom and press ENTER..."
1613 read i && sleep 2
1614 tazlito burn-iso /home/slitaz/distro/$ISO_NAME.iso
1615 echo -en "----\nENTER to continue..."; read i ;;
1616 *)
1617 exit 0 ;;
1618 esac ;;
1619 burn-iso)
1620 # Guess cdrom device, ask user and burn the ISO.
1622 check_root
1623 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
1624 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
1625 # We can specify an alternative ISO from the cmdline.
1626 if [ -n "$2" ] ; then
1627 iso=$2
1628 else
1629 iso=$DISTRO/$ISO_NAME.iso
1630 fi
1631 if [ ! -f "$iso" ]; then
1632 echo -e "\nUnable to find ISO : $iso\n"
1633 exit 0
1634 fi
1635 echo ""
1636 echo -e "\033[1mTazlito burn ISO\033[0m "
1637 echo "================================================================================"
1638 echo "Cdrom device : /dev/$DRIVE_NAME"
1639 echo "Drive speed : $DRIVE_SPEED"
1640 echo "ISO image : $iso"
1641 echo "================================================================================"
1642 echo ""
1643 yesorno "Burn ISO image (y/N) ? "
1644 if [ "$answer" == "y" ]; then
1645 echo ""
1646 echo "Starting Wodim to burn the iso..." && sleep 2
1647 echo "================================================================================"
1648 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
1649 echo "================================================================================"
1650 echo "ISO image is burned to cdrom."
1651 else
1652 echo -e "\nExiting. No ISO burned."
1653 fi
1654 echo ""
1655 ;;
1656 merge)
1657 # Merge multiple rootfs into one iso.
1659 if [ -z "$2" ]; then
1660 cat << EOT
1661 Usage: tazlito merge size1 iso size2 rootfs2 [sizeN rootfsN]...
1663 Merge multiple rootfs into one iso. Rootfs are like russian dolls
1664 i.e: rootfsN is a subset of rootfsN-1
1665 rootfs1 is found in iso, sizeN is the RAM size need to launch rootfsN.
1666 The boot loader will select the rootfs according to the RAM size detected.
1668 Example:
1669 $ tazlito merge 160M slitaz-core.iso 96M rootfs-justx.gz 32M rootfs-base.gz
1671 Will start slitaz-core with 160M+ RAM, slitaz-justX with 96M-160M RAM,
1672 slitaz-base with 32M-96M RAM and display an error message if RAM < 32M.
1673 EOT
1674 exit 2
1675 fi
1677 shift # skip merge
1678 append="$1 slitaz1"
1679 shift # skip size1
1680 mkdir -p $TMP_DIR/mnt $TMP_DIR/rootfs1
1682 ISO=$1.merged
1683 # Extract filesystems
1684 echo -n "Mounting $1"
1685 mount -o loop,ro $1 $TMP_DIR/mnt 2> /dev/null
1686 status || cleanup_merge
1687 cp -a $TMP_DIR/mnt $TMP_DIR/iso
1688 rm -f $TMP_DIR/iso/boot/bzImage
1689 ln $TMP_DIR/iso/boot/vmlinuz* $TMP_DIR/iso/boot/bzImage
1690 umount -d $TMP_DIR/mnt
1691 if [ -f $TMP_DIR/iso/boot/rootfs1.gz ]; then
1692 echo "$1 is already a merged iso. Aborting."
1693 cleanup_merge
1694 fi
1695 if [ ! -f $TMP_DIR/iso/boot/isolinux/ifmem.c32 ]; then
1696 if [ ! -f /boot/isolinux/ifmem.c32 ]; then
1697 cat <<EOT
1698 No file /boot/isolinux/ifmem.c32
1699 Please install syslinux package !
1700 EOT
1701 rm -rf $TMP_DIR
1702 exit 1
1703 fi
1704 cp /boot/isolinux/ifmem.c32 $TMP_DIR/iso/boot/isolinux
1705 fi
1707 echo -n "Extracting iso/rootfs.gz"
1708 extract_rootfs $TMP_DIR/iso/boot/rootfs.gz $TMP_DIR/rootfs1 &&
1709 [ -d $TMP_DIR/rootfs1/etc ]
1710 status || cleanup_merge
1711 n=1
1712 while [ -n "$2" ]; do
1713 shift # skip rootfs N-1
1714 p=$n
1715 n=$(($n + 1))
1716 append="$append $1 slitaz$n"
1717 shift # skip size N
1718 mkdir -p $TMP_DIR/rootfs$n
1719 echo -n "Extracting $1"
1720 extract_rootfs $1 $TMP_DIR/rootfs$n &&
1721 [ -d $TMP_DIR/rootfs$n/etc ]
1722 status || cleanup_merge
1723 mergefs $TMP_DIR/rootfs$n $TMP_DIR/rootfs$p
1724 echo "Creating rootfs$p.gz"
1725 pack_rootfs $TMP_DIR/rootfs$p $TMP_DIR/iso/boot/rootfs$p.gz
1726 status
1727 done
1728 echo "Creating rootfs$n.gz"
1729 pack_rootfs $TMP_DIR/rootfs$n $TMP_DIR/iso/boot/rootfs$n.gz
1730 status
1731 rm -f $TMP_DIR/iso/boot/rootfs.gz
1732 update_bootconfig $TMP_DIR/iso/boot/isolinux "$append"
1733 echo "Generating $ISO"
1734 create_iso $ISO $TMP_DIR/iso
1735 rm -rf $TMP_DIR
1736 ;;
1738 repack)
1739 # Repack an iso with maximum lzma compression ratio.
1742 ISO=$2
1744 mkdir -p $TMP_DIR/mnt
1745 # Extract filesystems
1746 echo -n "Mounting $ISO"
1747 mount -o loop,ro $ISO $TMP_DIR/mnt 2> /dev/null
1748 status || cleanup_merge
1749 cp -a $TMP_DIR/mnt $TMP_DIR/iso
1750 umount -d $TMP_DIR/mnt
1752 for i in $TMP_DIR/iso/boot/rootfs* ; do
1753 echo -n "Repacking $(basename $i)"
1754 (zcat $i || unlzma -c $i || cat $i) \
1755 2>/dev/null > $TMP_DIR/rootfs
1756 lzma e $TMP_DIR/rootfs $i \
1757 $(lzma_switches $TMP_DIR/rootfs)
1758 status
1759 done
1761 echo "Generating $ISO"
1762 create_iso $ISO $TMP_DIR/iso
1763 rm -rf $TMP_DIR ;;
1765 frugal-install|-fi)
1766 ISO_IMAGE="$2"
1767 echo ""
1768 mkdir -p /boot/frugal
1769 if [ -f "$ISO_IMAGE" ]; then
1770 echo -n "Using ISO image: $ISO_IMAGE"
1771 mkdir -p /tmp/iso && mount -o loop $ISO_IMAGE /tmp/iso
1772 status
1773 echo -n "Installing the Kernel and rootfs..."
1774 cp -a /tmp/iso/boot/bzImage /boot/frugal
1775 cp -a /tmp/iso/boot/rootfs.gz /boot/frugal
1776 umount /tmp/iso
1777 status
1778 else
1779 echo -n "Using distro: $DISTRO"
1780 cd $DISTRO && status
1781 echo -n "Installing the Kernel and rootfs..."
1782 cp -a $DISTRO/rootcd/boot/bzImage /boot/frugal
1783 cp -a $DISTRO/rootcd/boot/rootfs.gz /boot/frugal
1784 status
1785 fi
1786 # Grub entry
1787 if ! grep -q "^kernel /boot/frugal/bzImage" /boot/grub/menu.lst; then
1788 echo -n "Configuring GRUB menu list..."
1789 cat >> /boot/grub/menu.lst << EOT
1790 title SliTaz GNU/Linux (frugal)
1791 root (hd0,0)
1792 kernel /boot/frugal/bzImage root=/dev/null
1793 initrd /boot/frugal/rootfs.gz
1794 EOT
1795 else
1796 echo -n "GRUB menu list is up-to-date..."
1797 fi
1798 status
1799 echo "" ;;
1801 emu-iso)
1802 # Emulate an ISO image with Qemu.
1803 if [ -n "$2" ] ; then
1804 iso=$2
1805 else
1806 iso=$DISTRO/$ISO_NAME.iso
1807 fi
1808 if [ ! -f "$iso" ]; then
1809 echo -e "\nUnable to find ISO : $iso\n"
1810 exit 0
1811 fi
1812 if [ ! -x "/usr/bin/qemu" ]; then
1813 echo -e "\nUnable to find Qemu binary. Please install: qemu\n"
1814 exit 0
1815 fi
1816 echo -e "\nStarting Qemu emulator:\n"
1817 echo -e "qemu $QEMU_OPTS $iso\n"
1818 qemu $QEMU_OPTS $iso ;;
1820 usage|*)
1821 # Clear and print usage also for all unknown commands.
1823 clear
1824 usage ;;
1825 esac
1827 exit 0