tazlito view tazlito @ rev 113

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