tazlito view tazlito @ rev 125

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