tazlito view tazlito @ rev 161

tazlito pack-flavor: merge extra file from first flavor
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Feb 22 17:37:10 2010 +0100 (2010-02-22)
parents 4e3d0f1fdb7e
children 72c4b9fd1997
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=3.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 generates an ISO which boots with Qemu but gives
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 "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 $DISTRO/$(basename $1).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 additional 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 from 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 latest 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 for i in rootcd rootfs; do
1058 mkdir $TMP_DIR/$i
1059 # Copy extra files from the first flavor
1060 [ -d $FLAVORS_REPOSITORY/$2/$i ] &&
1061 cp -a $FLAVORS_REPOSITORY/$2/$i $TMP_DIR
1062 # Overload extra files by meta flavor
1063 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] &&
1064 cp -a $FLAVORS_REPOSITORY/$FLAVOR/$i $TMP_DIR
1065 [ -n "$(ls $TMP_DIR/$i)" ] &&
1066 ( cd $TMP_DIR/$i ; find . | cpio -o -H newc 2> /dev/null ) | \
1067 gzip -9 >$TMP_DIR/$FLAVOR.$i
1068 rm -rf $TMP_DIR/$i
1069 done
1070 else
1071 for i in rootcd rootfs; do
1072 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] || \
1073 continue
1074 ( cd $FLAVORS_REPOSITORY/$FLAVOR/$i ; \
1075 find . | cpio -o -H newc 2> /dev/null ) | \
1076 gzip -9 >$TMP_DIR/$FLAVOR.$i
1077 done
1078 fi
1079 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1080 packed_size=$(($packed_size \
1081 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1082 unpacked_size=$(($unpacked_size \
1083 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1084 fi
1085 # Estimate lzma
1086 packed_size=$(($packed_size * 2 / 3))
1087 iso_size=$(( $packed_size + 26000 ))
1088 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1089 iso_size=$(($iso_size \
1090 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1091 fi
1092 VERSION=""
1093 MAINTAINER=""
1094 ROOTFS_SELECTION=""
1095 ROOTFS_SIZE="$(cent2human $unpacked_size) (estimated)"
1096 INITRAMFS_SIZE="$(cent2human $packed_size) (estimated)"
1097 ISO_SIZE="$(cent2human $iso_size) (estimated)"
1098 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1099 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1100 Flavor : $FLAVOR
1101 Description : $SHORT_DESC
1102 EOT
1103 [ -n "$VERSION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1104 Version : $VERSION
1105 EOT
1106 [ -n "$MAINTAINER" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1107 Maintainer : $MAINTAINER
1108 EOT
1109 [ -n "$FRUGAL_RAM" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1110 LiveCD RAM size : $FRUGAL_RAM
1111 EOT
1112 [ -n "$ROOTFS_SELECTION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1113 Rootfs list : $ROOTFS_SELECTION
1114 EOT
1115 cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1116 Build date : $(date +%Y%m%d\ \at\ \%H:%M:%S)
1117 Packages : $(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l)
1118 Rootfs size : $ROOTFS_SIZE
1119 Initramfs size : $INITRAMFS_SIZE
1120 ISO image size : $ISO_SIZE
1121 ================================================================================
1123 EOT
1124 rm -f $TMP_DIR/packages.list
1125 ( cd $TMP_DIR ; ls | cpio -o -H newc 2> /dev/null) | \
1126 gzip -9 > $FLAVOR.flavor
1127 status
1128 rm -Rf $TMP_DIR
1129 else
1130 echo "No $FLAVOR flavor in $FLAVORS_REPOSITORY."
1131 fi
1132 ;;
1133 get-flavor)
1134 # Get a flavor's files and prepare for gen-distro.
1135 FLAVOR=${2%.flavor}
1136 echo ""
1137 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1138 echo -n "Cleaning $DISTRO..."
1139 rm -R $DISTRO 2> /dev/null
1140 mkdir -p $DISTRO
1141 status
1142 mkdir $TMP_DIR
1143 echo -n "Extracting flavor $FLAVOR.flavor... "
1144 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i 2>/dev/null )
1145 echo -n "Creating distro-packages.list..."
1146 mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
1147 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
1148 status
1149 for i in rootcd rootfs; do
1150 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
1151 echo -n "Adding $i... "
1152 mkdir -p "$ADDFILES/$i"
1153 zcat $TMP_DIR/$FLAVOR.$i | \
1154 ( cd "$ADDFILES/$i"; cpio -id 2> /dev/null)
1155 fi
1156 done
1157 if [ -s $TMP_DIR/$FLAVOR.mirrors ]; then
1158 n=""
1159 while read line; do
1160 mkdir -p $LOCALSTATE/undigest/$FLAVOR$n
1161 echo "$line" > $LOCALSTATE/undigest/$FLAVOR$n/mirror
1162 n=$(( $n + 1 ))
1163 done < $TMP_DIR/$FLAVOR.mirrors
1164 tazpkg recharge
1165 fi
1166 rm -f /etc/tazlito/rootfs.list
1167 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc &&
1168 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1169 sed 's/.*: \(.*\)$/\1/' > /etc/tazlito/rootfs.list
1170 echo -n "Updating tazlito.conf..."
1171 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
1172 cat tazlito.conf | grep -v "^#VOLUM_NAME" | \
1173 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
1174 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
1175 sed -i "s/ISO_NAME=.*/ISO_NAME=\"slitaz-$FLAVOR\"/" tazlito.conf
1176 status
1177 rm -Rf $TMP_DIR
1178 fi
1179 echo ""
1180 ;;
1181 check-list)
1182 # Use current packages list in $PWD by default.
1183 DISTRO_PKGS_LIST=distro-packages.list
1184 [ -d "$2" ] && DISTRO_PKGS_LIST=$2/distro-packages.list
1185 [ -f "$2" ] && DISTRO_PKGS_LIST=$2
1186 [ ! -f $DISTRO_PKGS_LIST ] && echo "No packages list found." && exit 0
1187 echo ""
1188 echo -e "\033[1mLiveCD packages list check\033[0m"
1189 echo "================================================================================"
1190 for pkg in `cat $DISTRO_PKGS_LIST`
1191 do
1192 if ! grep -q "$pkg" /var/lib/tazpkg/packages.list; then
1193 echo "Update: $pkg"
1194 up=$(($up + 1))
1195 fi
1196 done
1197 [ -z $up ] && echo -e "List is up-to-date\n" && exit 0
1198 echo "================================================================================"
1199 echo -e "Updates: $up\n" ;;
1200 gen-distro)
1201 # Generate a live distro tree with a set of packages.
1203 check_root
1205 # Check if a package list was specified on cmdline.
1206 LIST_NAME="distro-packages.list"
1207 CDROM=""
1208 while [ -n "$2" ]; do
1209 case "$2" in
1210 --iso=*)
1211 CDROM="-o loop ${2#--iso=}"
1212 ;;
1213 --cdrom)
1214 CDROM="/dev/cdrom"
1215 ;;
1216 --force)
1217 DELETE_ROOTFS="true"
1218 ;;
1219 *) if [ ! -f "$2" ] ; then
1220 echo -e "\nUnable to find the specified packages list."
1221 echo -e "List name : $2\n"
1222 exit 1
1223 fi
1224 LIST_NAME=$2
1225 ;;
1226 esac
1227 shift
1228 done
1230 if [ -d $ROOTFS ] ; then
1231 # Delete $ROOTFS if --force is set on command line
1232 if [ ! -z $DELETE_ROOTFS ]; then
1233 rm -rf $ROOTFS
1234 unset $DELETE_ROOTFS
1235 else
1236 echo -e "\nA rootfs exists in : $DISTRO"
1237 echo -e "Please clean the distro tree or change directory path.\n"
1238 exit 0
1239 fi
1240 fi
1241 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
1242 # Build list with installed packages
1243 for i in $(ls $INSTALLED); do
1244 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
1245 EXTRAVERSION=""
1246 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
1247 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
1248 done
1249 fi
1250 # Exit if no list name.
1251 if [ ! -f "$LIST_NAME" ]; then
1252 echo -e "\nNo packages list found or specified. Please read the docs.\n"
1253 exit 0
1254 fi
1255 # Start generation.
1256 echo ""
1257 echo -e "\033[1mTazlito generating a distro\033[0m"
1258 echo "================================================================================"
1259 # Misc checks
1260 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
1261 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
1262 # Get the list of packages using cat for a file list.
1263 LIST=`cat $LIST_NAME`
1264 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
1265 REPACK=""
1266 DOWNLOAD=""
1267 for pkg in $LIST
1268 do
1269 [ "$pkg" = "" ] && continue
1270 pkg=${pkg%.tazpkg}
1271 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
1272 PACKAGE=$(installed_package_name $pkg)
1273 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
1274 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
1275 echo -e "\nUnable to find $pkg in the repository."
1276 echo -e "Path : $PACKAGES_REPOSITORY\n"
1277 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
1278 yesorno "Repack packages from rootfs (y/N) ? "
1279 REPACK="$answer"
1280 [ "$answer" = "y" ] || REPACK="n"
1281 [ "$DOWNLOAD" = "y" ] && break
1282 fi
1283 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
1284 yesorno "Download packages from mirror (Y/n) ? "
1285 DOWNLOAD="$answer"
1286 if [ "$answer" = "n" ]; then
1287 [ -z "$PACKAGE" ] && exit 1
1288 else
1289 DOWNLOAD="y"
1290 [ -n "$REPACK" ] && break
1291 fi
1292 fi
1293 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
1294 done
1296 # Mount cdrom to be able to repack boot-loader packages
1297 if [ ! -e /boot -a -n "$CDROM" ]; then
1298 mkdir $TMP_MNT
1299 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
1300 ln -s $TMP_MNT/boot /
1301 if [ ! -d "$ADDFILES/rootcd" ] ; then
1302 mkdir -p $ADDFILES/rootcd
1303 for i in $(ls $TMP_MNT); do
1304 [ "$i" = "boot" ] && continue
1305 cp -a $TMP_MNT/$i $ADDFILES/rootcd
1306 done
1307 fi
1308 else
1309 rmdir $TMP_MNT
1310 fi
1311 fi
1313 # Root fs stuff.
1314 echo "Preparing the rootfs directory..."
1315 mkdir -p $ROOTFS
1316 sleep 2
1317 for pkg in $LIST
1318 do
1319 [ "$pkg" = "" ] && continue
1320 # First copy and extract the package in tmp dir.
1321 pkg=${pkg%.tazpkg}
1322 PACKAGE=$(installed_package_name $pkg)
1323 mkdir -p $TMP_DIR
1324 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1325 # Look for package in cache
1326 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
1327 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
1328 # Look for package in running distribution
1329 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
1330 tazpkg repack $PACKAGE && \
1331 mv $pkg.tazpkg $PACKAGES_REPOSITORY
1332 fi
1333 fi
1334 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1335 # Get package from mirror
1336 [ "$DOWNLOAD" = "y" ] && \
1337 download $pkg.tazpkg && \
1338 mv $pkg.tazpkg $PACKAGES_REPOSITORY
1339 fi
1340 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1341 echo "Missing package $pkg."
1342 cleanup
1343 exit 1
1344 fi
1345 done
1346 if [ -f non-free.list ]; then
1347 echo "Preparing non-free packages..."
1348 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
1349 for pkg in $(cat non-free.list); do
1350 if [ ! -d $INSTALLED/$pkg ]; then
1351 if [ ! -d $INSTALLED/get-$pkg ]; then
1352 tazpkg get-install get-$pkg
1353 fi
1354 get-$pkg
1355 fi
1356 tazpkg repack $pkg
1357 pkg=$(ls $pkg*.tazpkg)
1358 grep -q "^$pkg$" $LIST_NAME || \
1359 echo $pkg >>$LIST_NAME
1360 mv $pkg $PACKAGES_REPOSITORY
1361 done
1362 fi
1363 echo ""
1364 cp $LIST_NAME $DISTRO/distro-packages.list
1365 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/distro-packages.list > $DISTRO/list-packages
1366 cd $PACKAGES_REPOSITORY
1367 yes y | tazpkg install-list \
1368 $DISTRO/list-packages --root=$ROOTFS
1369 cd $DISTRO
1370 cp distro-packages.list $ROOTFS/etc/tazlito
1371 # Copy all files from $ADDFILES/rootfs to the rootfs.
1372 if [ -d "$ADDFILES/rootfs" ] ; then
1373 echo -n "Copying addfiles content to the rootfs... "
1374 cp -a $ADDFILES/rootfs/* $ROOTFS
1375 status
1376 fi
1377 echo "Root file system is generated..."
1378 # Root CD part.
1379 echo -n "Preparing the rootcd directory..."
1380 mkdir -p $ROOTCD
1381 status
1382 # Move the boot dir with the Linux kernel from rootfs.
1383 # The boot dir goes directly on the CD.
1384 if [ -d "$ROOTFS/boot" ] ; then
1385 echo -n "Moving the boot directory..."
1386 mv $ROOTFS/boot $ROOTCD
1387 cd $ROOTCD/boot
1388 ln vmlinuz-* bzImage
1389 status
1390 fi
1391 cd $DISTRO
1392 # Copy all files from $ADDFILES/rootcd to the rootcd.
1393 if [ -d "$ADDFILES/rootcd" ] ; then
1394 echo -n "Copying addfiles content to the rootcd... "
1395 cp -a $ADDFILES/rootcd/* $ROOTCD
1396 status
1397 fi
1398 # Execute the distro script used to perform tasks in the rootfs
1399 # before compression. Give rootfs path in arg
1400 [ -z $DISTRO_SCRIPT ] && DISTRO_SCRIPT=$TOP_DIR/distro.sh
1401 if [ -x $DISTRO_SCRIPT ]; then
1402 echo "Executing distro script..."
1403 sh $DISTRO_SCRIPT $DISTRO
1404 fi
1405 if [ -s /etc/tazlito/rootfs.list ]; then
1406 [ -f $ROOTCD/boot/isolinux/ifmem.c32 ] ||
1407 cp /boot/isolinux/ifmem.c32 $ROOTCD/boot/isolinux
1408 n=0
1409 last=$ROOTFS
1410 while read flavor; do
1411 n=$(($n+1))
1412 echo "Building $flavor rootfs..."
1413 download $flavor.flavor
1414 zcat $flavor.flavor | cpio -i $flavor.pkglist
1415 sed 's/.*/&.tazpkg/' < $flavor.pkglist \
1416 > $DISTRO/list-packages0$n
1417 mkdir ${ROOTFS}0$n
1418 cd $PACKAGES_REPOSITORY
1419 yes y | tazpkg install-list \
1420 $DISTRO/list-packages0$n --root=${ROOTFS}0$n
1421 rm -rf ${ROOTFS}0$n/boot
1422 status
1423 cd $DISTRO
1424 mv $flavor.pkglist ${ROOTFS}0$n/etc/tazlito/distro-packages.list
1425 rm -f $flavor.flavor install-list
1426 mergefs ${ROOTFS}0$n $last
1427 last=${ROOTFS}0$n
1428 done <<EOT
1429 $(awk '{ for (i = 4; i <= NF; i+=2) print $i; }' < /etc/tazlito/rootfs.list)
1430 EOT
1431 i=$(($n+1))
1432 while [ $n -gt 0 ]; do
1433 mv ${ROOTFS}0$n ${ROOTFS}$i
1434 echo "Compression ${ROOTFS}0$n ($(du -hs ${ROOTFS}$i | awk '{ print $1 }')) ..."
1435 gen_initramfs ${ROOTFS}$i
1436 n=$(($n-1))
1437 i=$(($i-1))
1438 done
1439 mv $ROOTFS ${ROOTFS}$i
1440 gen_initramfs ${ROOTFS}$i
1441 update_bootconfig $ROOTCD/boot/isolinux \
1442 "$(cat /etc/tazlito/rootfs.list)"
1443 else
1444 # Initramfs and ISO image stuff.
1445 gen_initramfs $ROOTFS
1446 fi
1447 gen_livecd_isolinux
1448 distro_stats
1449 cleanup
1450 ;;
1451 clean-distro)
1452 # Remove old distro tree.
1454 check_root
1455 echo ""
1456 echo -e "\033[1mCleaning :\033[0m $DISTRO"
1457 echo "================================================================================"
1458 if [ -d "$DISTRO" ] ; then
1459 if [ -d "$ROOTFS" ] ; then
1460 echo -n "Removing the rootfs..."
1461 rm -f $DISTRO/$INITRAMFS
1462 rm -rf $ROOTFS
1463 status
1464 fi
1465 if [ -d "$ROOTCD" ] ; then
1466 echo -n "Removing the rootcd..."
1467 rm -rf $ROOTCD
1468 status
1469 fi
1470 echo -n "Removing eventual ISO image..."
1471 rm -f $DISTRO/$ISO_NAME.iso
1472 rm -f $DISTRO/$ISO_NAME.md5
1473 status
1474 fi
1475 echo "================================================================================"
1476 echo ""
1477 ;;
1478 check-distro)
1479 # Check for a few LiveCD needed files not installed by packages.
1481 check_rootfs
1482 echo ""
1483 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
1484 echo "================================================================================"
1485 # SliTaz release info.
1486 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
1487 echo "Missing release info : /etc/slitaz-release"
1488 else
1489 release=`cat $ROOTFS/etc/slitaz-release`
1490 echo -n "Release : $release"
1491 status
1492 fi
1493 # Tazpkg mirror.
1494 if [ ! -f "$ROOTFS/var/lib/tazpkg/mirror" ]; then
1495 echo -n "Mirror URL : Missing /var/lib/tazpkg/mirror"
1496 todomsg
1497 else
1498 echo -n "Mirror configuration exists..."
1499 status
1500 fi
1501 # Isolinux msg
1502 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.msg; then
1503 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
1504 todomsg
1505 else
1506 echo -n "Isolinux message seems good..."
1507 status
1508 fi
1509 echo "================================================================================"
1510 echo ""
1511 ;;
1512 writeiso)
1513 # Writefs to ISO image including /home unlike gen-distro we dont use
1514 # packages to generate a rootfs, we build a compressed rootfs with all
1515 # the current filesystem similar to 'tazusb writefs'.
1517 DISTRO="/home/slitaz/distro"
1518 ROOTCD="$DISTRO/rootcd"
1519 if [ -z $2 ]; then
1520 COMPRESSION=none
1521 else
1522 COMPRESSION=$2
1523 fi
1524 if [ -z $3 ]; then
1525 ISO_NAME="slitaz"
1526 else
1527 ISO_NAME="$3"
1528 fi
1529 check_root
1530 # Start info
1531 echo ""
1532 echo -e "\033[1mWrite filesystem to ISO\033[0m
1533 ===============================================================================
1534 The command writeiso will write the current filesystem into a suitable cpio
1535 archive (rootfs.gz) and generate a bootable ISO image (slitaz.iso).
1537 Archive compression: $COMPRESSION"
1538 echo ""
1540 # Save some space
1541 rm /var/cache/tazpkg/* -r -f
1542 rm -rf /home/slitaz/distro
1544 # Optionally remove sound card selection and screen resolution.
1545 echo "Do you wish to remove the sound card and screen configs ? "
1546 echo -n "Press ENTER to keep or answer (No|yes|exit): "
1547 read anser
1548 case $anser in
1549 e|E|"exit"|Exit)
1550 exit 0 ;;
1551 y|Y|yes|Yes)
1552 echo -n "Removing current sound card and screen configurations..."
1553 rm -f /var/lib/sound-card-driver
1554 rm -f /etc/asound.state
1555 rm -f /etc/X11/screen.conf
1556 rm -f /etc/X11/xorg.conf ;;
1557 *)
1558 echo -n "Keeping current sound card and screen configurations..." ;;
1559 esac
1560 status
1562 # Create list of files including default user files since it is defined in /etc/passwd
1563 # and some new users might have been added.
1564 find /bin /etc /init /sbin /var /dev /lib /root /usr /home >/tmp/list
1566 for dir in /proc /sys /tmp /mnt /media /media/cdrom /media/flash /media/usbdisk
1567 do
1568 echo $dir >>/tmp/list
1569 done
1571 # Generate initramfs with specified compression and display rootfs
1572 # size in realtime.
1573 rm -f /tmp/rootfs
1574 write_initramfs &
1575 sleep 2
1576 echo -en "\nFilesystem size:"
1577 while [ ! -f /tmp/rootfs ]
1578 do
1579 sleep 1
1580 echo -en "\\033[18G`du -sh /rootfs.gz | awk '{print $1}'` "
1581 done
1582 echo -e "\n"
1584 # Move freshly generated rootfs to the cdrom.
1585 mkdir -p $ROOTCD/boot
1586 mv -f /rootfs.gz $ROOTCD/boot
1588 # Now we need the kernel and isolinux files.
1589 if mount /dev/cdrom /media/cdrom 2>/dev/null; then
1590 cp /media/cdrom/boot/bzImage $ROOTCD/boot
1591 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
1592 umount /media/cdrom
1593 else
1594 echo -e "
1595 Unable to mount the cdrom to copy the Kernel and needed files. When SliTaz
1596 is running in RAM the kernel and bootloader files are kept on the cdrom.
1597 Please insert a LiveCD or unmount the current cdrom to let Tazlito handle
1598 the media.\n"
1599 echo -en "----\nENTER to continue..."; read i
1600 exit 1
1601 fi
1603 # Generate the iso image.
1604 cd $DISTRO
1605 echo "Generating ISO image..."
1606 genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
1607 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
1608 -V "SliTaz" -input-charset iso8859-1 -boot-info-table $ROOTCD
1609 if [ -x /usr/bin/isohybrid ]; then
1610 echo -n "Creating hybrid ISO..."
1611 /usr/bin/isohybrid $ISO_NAME.iso 2> /dev/null
1612 status
1613 fi
1614 echo -n "Creating the ISO md5sum..."
1615 md5sum $ISO_NAME.iso > $ISO_NAME.md5
1616 status
1618 echo "==============================================================================="
1619 echo "ISO image: `du -sh /home/slitaz/distro/$ISO_NAME.iso`"
1620 echo ""
1621 echo -n "Exit or burn ISO to cdrom (Exit|burn)? "; read anser
1622 case $anser in
1623 burn)
1624 eject
1625 echo -n "Please insert a blank cdrom and press ENTER..."
1626 read i && sleep 2
1627 tazlito burn-iso /home/slitaz/distro/$ISO_NAME.iso
1628 echo -en "----\nENTER to continue..."; read i ;;
1629 *)
1630 exit 0 ;;
1631 esac ;;
1632 burn-iso)
1633 # Guess cdrom device, ask user and burn the ISO.
1635 check_root
1636 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
1637 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
1638 # We can specify an alternative ISO from the cmdline.
1639 if [ -n "$2" ] ; then
1640 iso=$2
1641 else
1642 iso=$DISTRO/$ISO_NAME.iso
1643 fi
1644 if [ ! -f "$iso" ]; then
1645 echo -e "\nUnable to find ISO : $iso\n"
1646 exit 0
1647 fi
1648 echo ""
1649 echo -e "\033[1mTazlito burn ISO\033[0m "
1650 echo "================================================================================"
1651 echo "Cdrom device : /dev/$DRIVE_NAME"
1652 echo "Drive speed : $DRIVE_SPEED"
1653 echo "ISO image : $iso"
1654 echo "================================================================================"
1655 echo ""
1656 yesorno "Burn ISO image (y/N) ? "
1657 if [ "$answer" == "y" ]; then
1658 echo ""
1659 echo "Starting Wodim to burn the iso..." && sleep 2
1660 echo "================================================================================"
1661 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
1662 echo "================================================================================"
1663 echo "ISO image is burned to cdrom."
1664 else
1665 echo -e "\nExiting. No ISO burned."
1666 fi
1667 echo ""
1668 ;;
1669 merge)
1670 # Merge multiple rootfs into one iso.
1672 if [ -z "$2" ]; then
1673 cat << EOT
1674 Usage: tazlito merge size1 iso size2 rootfs2 [sizeN rootfsN]...
1676 Merge multiple rootfs into one iso. Rootfs are like russian dolls
1677 i.e: rootfsN is a subset of rootfsN-1
1678 rootfs1 is found in iso, sizeN is the RAM size need to launch rootfsN.
1679 The boot loader will select the rootfs according to the RAM size detected.
1681 Example:
1682 $ tazlito merge 160M slitaz-core.iso 96M rootfs-justx.gz 32M rootfs-base.gz
1684 Will start slitaz-core with 160M+ RAM, slitaz-justX with 96M-160M RAM,
1685 slitaz-base with 32M-96M RAM and display an error message if RAM < 32M.
1686 EOT
1687 exit 2
1688 fi
1690 shift # skip merge
1691 append="$1 slitaz1"
1692 shift # skip size1
1693 mkdir -p $TMP_DIR/mnt $TMP_DIR/rootfs1
1695 ISO=$1.merged
1696 # Extract filesystems
1697 echo -n "Mounting $1"
1698 mount -o loop,ro $1 $TMP_DIR/mnt 2> /dev/null
1699 status || cleanup_merge
1700 cp -a $TMP_DIR/mnt $TMP_DIR/iso
1701 rm -f $TMP_DIR/iso/boot/bzImage
1702 ln $TMP_DIR/iso/boot/vmlinuz* $TMP_DIR/iso/boot/bzImage
1703 umount -d $TMP_DIR/mnt
1704 if [ -f $TMP_DIR/iso/boot/rootfs1.gz ]; then
1705 echo "$1 is already a merged iso. Aborting."
1706 cleanup_merge
1707 fi
1708 if [ ! -f $TMP_DIR/iso/boot/isolinux/ifmem.c32 ]; then
1709 if [ ! -f /boot/isolinux/ifmem.c32 ]; then
1710 cat <<EOT
1711 No file /boot/isolinux/ifmem.c32
1712 Please install syslinux package !
1713 EOT
1714 rm -rf $TMP_DIR
1715 exit 1
1716 fi
1717 cp /boot/isolinux/ifmem.c32 $TMP_DIR/iso/boot/isolinux
1718 fi
1720 echo -n "Extracting iso/rootfs.gz"
1721 extract_rootfs $TMP_DIR/iso/boot/rootfs.gz $TMP_DIR/rootfs1 &&
1722 [ -d $TMP_DIR/rootfs1/etc ]
1723 status || cleanup_merge
1724 n=1
1725 while [ -n "$2" ]; do
1726 shift # skip rootfs N-1
1727 p=$n
1728 n=$(($n + 1))
1729 append="$append $1 slitaz$n"
1730 shift # skip size N
1731 mkdir -p $TMP_DIR/rootfs$n
1732 echo -n "Extracting $1"
1733 extract_rootfs $1 $TMP_DIR/rootfs$n &&
1734 [ -d $TMP_DIR/rootfs$n/etc ]
1735 status || cleanup_merge
1736 mergefs $TMP_DIR/rootfs$n $TMP_DIR/rootfs$p
1737 echo "Creating rootfs$p.gz"
1738 pack_rootfs $TMP_DIR/rootfs$p $TMP_DIR/iso/boot/rootfs$p.gz
1739 status
1740 done
1741 echo "Creating rootfs$n.gz"
1742 pack_rootfs $TMP_DIR/rootfs$n $TMP_DIR/iso/boot/rootfs$n.gz
1743 status
1744 rm -f $TMP_DIR/iso/boot/rootfs.gz
1745 update_bootconfig $TMP_DIR/iso/boot/isolinux "$append"
1746 echo "Generating $ISO"
1747 create_iso $ISO $TMP_DIR/iso
1748 rm -rf $TMP_DIR
1749 ;;
1751 repack)
1752 # Repack an iso with maximum lzma compression ratio.
1755 ISO=$2
1757 mkdir -p $TMP_DIR/mnt
1758 # Extract filesystems
1759 echo -n "Mounting $ISO"
1760 mount -o loop,ro $ISO $TMP_DIR/mnt 2> /dev/null
1761 status || cleanup_merge
1762 cp -a $TMP_DIR/mnt $TMP_DIR/iso
1763 umount -d $TMP_DIR/mnt
1765 for i in $TMP_DIR/iso/boot/rootfs* ; do
1766 echo -n "Repacking $(basename $i)"
1767 (zcat $i || unlzma -c $i || cat $i) \
1768 2>/dev/null > $TMP_DIR/rootfs
1769 lzma e $TMP_DIR/rootfs $i \
1770 $(lzma_switches $TMP_DIR/rootfs)
1771 status
1772 done
1774 echo "Generating $ISO"
1775 create_iso $ISO $TMP_DIR/iso
1776 rm -rf $TMP_DIR ;;
1778 frugal-install|-fi)
1779 ISO_IMAGE="$2"
1780 echo ""
1781 mkdir -p /boot/frugal
1782 if [ -f "$ISO_IMAGE" ]; then
1783 echo -n "Using ISO image: $ISO_IMAGE"
1784 mkdir -p /tmp/iso && mount -o loop $ISO_IMAGE /tmp/iso
1785 status
1786 echo -n "Installing the Kernel and rootfs..."
1787 cp -a /tmp/iso/boot/bzImage /boot/frugal
1788 cp -a /tmp/iso/boot/rootfs.gz /boot/frugal
1789 umount /tmp/iso
1790 status
1791 else
1792 echo -n "Using distro: $DISTRO"
1793 cd $DISTRO && status
1794 echo -n "Installing the Kernel and rootfs..."
1795 cp -a $DISTRO/rootcd/boot/bzImage /boot/frugal
1796 cp -a $DISTRO/rootcd/boot/rootfs.gz /boot/frugal
1797 status
1798 fi
1799 # Grub entry
1800 if ! grep -q "^kernel /boot/frugal/bzImage" /boot/grub/menu.lst; then
1801 echo -n "Configuring GRUB menu list..."
1802 cat >> /boot/grub/menu.lst << EOT
1803 title SliTaz GNU/Linux (frugal)
1804 root (hd0,0)
1805 kernel /boot/frugal/bzImage root=/dev/null
1806 initrd /boot/frugal/rootfs.gz
1807 EOT
1808 else
1809 echo -n "GRUB menu list is up-to-date..."
1810 fi
1811 status
1812 echo "" ;;
1814 emu-iso)
1815 # Emulate an ISO image with Qemu.
1816 if [ -n "$2" ] ; then
1817 iso=$2
1818 else
1819 iso=$DISTRO/$ISO_NAME.iso
1820 fi
1821 if [ ! -f "$iso" ]; then
1822 echo -e "\nUnable to find ISO : $iso\n"
1823 exit 0
1824 fi
1825 if [ ! -x "/usr/bin/qemu" ]; then
1826 echo -e "\nUnable to find Qemu binary. Please install: qemu\n"
1827 exit 0
1828 fi
1829 echo -e "\nStarting Qemu emulator:\n"
1830 echo -e "qemu $QEMU_OPTS $iso\n"
1831 qemu $QEMU_OPTS $iso ;;
1833 usage|*)
1834 # Clear and print usage also for all unknown commands.
1836 clear
1837 usage ;;
1838 esac
1840 exit 0