tazlito view tazlito @ rev 144

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