tazlito view tazlito @ rev 112

pack-flavor: look for undigest mirrors
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Nov 07 13:28:44 2009 +0100 (2009-11-07)
parents 536536d6001a
children 1f0a9a164e71
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 awk "{ \
478 if (/^$(echo $1 | sed 's/[$+.\]/\\&/g')$/) get=1; \
479 if (/installed/ && get) { print ; get=0 } \
480 }" < /var/lib/tazpkg/packages.txt | \
481 sed 's/ *\(.*\) .\(.*\) installed./\1 \2/' | while read packed unpacked; do
482 echo "$(human2cent $packed) $(human2cent $unpacked)"
483 done
484 }
486 # Display package list with version, set packed_size and unpacked_size
487 get_pkglist()
488 {
489 packed_size=0; unpacked_size=0
490 grep -v ^# $FLAVORS_REPOSITORY/$1/packages.list > $TMP_DIR/flavor.pkg
491 while read pkg; do
492 set -- $(get_size $pkg)
493 packed_size=$(( $packed_size + $1 ))
494 unpacked_size=$(( $unpacked_size + $2 ))
495 for i in $(grep -hs ^$pkg /var/lib/tazpkg/packages.list \
496 $TMP_DIR/packages.list); do
497 echo $i
498 break
499 done
500 done < $TMP_DIR/flavor.pkg
501 rm -f $TMP_DIR/flavor.pkg
502 }
504 # Update isolinux config files for multiple rootfs
505 update_bootconfig()
506 {
507 echo -n "Update boot config files"
508 grep -l 'include common' $1/*.cfg | \
509 while read file ; do
510 awk -v n=$(echo $2 | awk '{ print NF/2 }') '{
511 if (/label/) label=$0;
512 else if (/kernel/) kernel=$0;
513 else if (/append/) {
514 i=index($0,"rootfs.gz");
515 append=substr($0,i+9);
516 }
517 else if (/include/) {
518 for (i = 1; i <= n; i++) {
519 print label i
520 print kernel;
521 initrd="initrd=/boot/rootfs" n ".gz"
522 for (j = n - 1; j >= i; j--) {
523 initrd=initrd ",/boot/rootfs" j ".gz";
524 }
525 printf "\tappend %s%s\n",initrd,append;
526 print "";
527 }
528 print;
529 }
530 else print;
531 }' < $file > $file.$$
532 mv -f $file.$$ $file
533 done
534 cat >> $1/common.cfg <<EOT
536 label slitaz
537 kernel /boot/isolinux/ifmem.c32
538 append$(echo $2 | awk '{
539 for (i=1; i<=NF; i++)
540 if (i % 2 == 0) printf " slitaz%d",i/2
541 else printf " %s",$i
542 }') noram
544 label noram
545 config noram.cfg
547 EOT
548 cat > $1/noram.cfg <<EOT
549 display isolinux.msg
550 say Not enough RAM to boot slitaz.
551 default reboot
552 label reboot
553 com32 reboot.c32
555 implicit 0
556 prompt 1
557 timeout 80
558 F1 help.txt
559 F2 options.txt
560 F3 isolinux.msg
561 F4 display.txt
562 F5 enhelp.txt
563 F6 enopts.txt
564 EOT
565 status
566 }
568 ####################
569 # Tazlito commands #
570 ####################
572 case "$COMMAND" in
573 stats)
574 # Tazlito general statistics from the config file.
575 #
576 echo ""
577 echo -e "\033[1mTazlito statistics\033[0m
578 ===============================================================================
579 Config file : $CONFIG_FILE
580 ISO name : $ISO_NAME.iso
581 Volume name : $VOLUM_NAME
582 Prepared : $PREPARED
583 Packages repository : $PACKAGES_REPOSITORY
584 Distro directory : $DISTRO"
585 if [ ! "$ADDFILES" = "" ] ; then
586 echo -e "Additional files : $ADDFILES"
587 fi
588 echo "================================================================================"
589 echo ""
590 ;;
591 gen-config)
592 # Generate a new config file in the current dir or the specified
593 # directory by $2.
594 #
595 if [ -n "$2" ] ; then
596 mkdir -p $2 && cd $2
597 fi
598 echo -n "Generating empty tazlito.conf..."
599 empty_config_file
600 status
601 echo ""
602 if [ -f "tazlito.conf" ] ; then
603 echo "Configuration file is ready to edit."
604 echo "File location : `pwd`/tazlito.conf"
605 echo ""
606 fi
607 ;;
608 configure)
609 # Configure a tazlito.conf config file. Start by getting
610 # a empty config file and sed it.
611 #
612 if [ -f "tazlito.conf" ] ; then
613 rm tazlito.conf
614 else
615 if test $(id -u) = 0 ; then
616 cd /etc
617 else
618 echo "You must be root to configure the main config file or in"
619 echo "the same directory of the file you want to configure."
620 exit 0
621 fi
622 fi
623 empty_config_file
624 echo""
625 echo -e "\033[1mConfiguring :\033[0m `pwd`/tazlito.conf"
626 echo "================================================================================"
627 # ISO name.
628 echo -n "ISO name : " ; read answer
629 sed -i s#'ISO_NAME=\"\"'#"ISO_NAME=\"$answer\""# tazlito.conf
630 # Volume name.
631 echo -n "Volume name : " ; read answer
632 sed -i s/'VOLUM_NAME=\"SliTaz\"'/"VOLUM_NAME=\"$answer\""/ tazlito.conf
633 # Packages repository.
634 echo -n "Packages repository : " ; read answer
635 sed -i s#'PACKAGES_REPOSITORY=\"\"'#"PACKAGES_REPOSITORY=\"$answer\""# tazlito.conf
636 # Distro path.
637 echo -n "Distro path : " ; read answer
638 sed -i s#'DISTRO=\"\"'#"DISTRO=\"$answer\""# tazlito.conf
639 echo "================================================================================"
640 echo "Config file is ready to use."
641 echo "You can now extract an ISO or generate a distro."
642 echo ""
643 ;;
644 gen-iso)
645 # Simply generate a new iso.
646 #
647 check_root
648 verify_rootcd
649 gen_livecd_isolinux
650 distro_stats
651 ;;
652 gen-initiso)
653 # Simply generate a new initramfs with a new iso.
654 #
655 check_root
656 verify_rootcd
657 gen_initramfs $ROOTFS
658 gen_livecd_isolinux
659 distro_stats
660 ;;
661 extract-distro)
662 # Extract an ISO image to a directory and rebuild the LiveCD tree.
663 #
664 check_root
665 ISO_IMAGE=$2
666 if [ -z "$ISO_IMAGE" ] ; then
667 echo -e "\nPlease specify the path to the ISO image."
668 echo -e "Example : `basename $0` image.iso /path/target\n"
669 exit 0
670 fi
671 # Set the distro path by checking for $3 on cmdline.
672 if [ -n "$3" ] ; then
673 TARGET=$3
674 else
675 TARGET=$DISTRO
676 fi
677 # Exit if existing distro is found.
678 if [ -d "$TARGET/rootfs" ] ; then
679 echo -e "\nA rootfs exists in : $TARGET"
680 echo -e "Please clean the distro tree or change directory path.\n"
681 exit 0
682 fi
683 echo ""
684 echo -e "\033[1mTazlito extracting :\033[0m `basename $ISO_IMAGE`"
685 echo "================================================================================"
686 # Start to mount the ISO.
687 echo ""
688 echo "Mounting ISO image..."
689 mkdir -p $TMP_DIR
690 # Get ISO file size.
691 isosize=`du -sh $ISO_IMAGE | cut -f1`
692 mount -o loop $ISO_IMAGE $TMP_DIR
693 sleep 2
694 # Prepare target dir, copy the kernel and the rootfs.
695 mkdir -p $TARGET/rootfs
696 mkdir -p $TARGET/rootcd/boot
697 echo -n "Copying the Linux kernel..."
698 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
699 ln $TARGET/rootcd/boot/vmlinuz* $TARGET/rootcd/boot/bzImage
700 else
701 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
702 fi
703 status
704 echo -n "Copying isolinux files..."
705 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
706 for i in $(ls $TMP_DIR); do
707 [ "$i" = "boot" ] && continue
708 cp -a $TMP_DIR/$i $TARGET/rootcd
709 done
710 status
711 if [ -d $TMP_DIR/boot/syslinux ]; then
712 echo -n "Copying syslinux files..."
713 cp -a $TMP_DIR/boot/syslinux $TARGET/rootcd/boot
714 status
715 fi
716 if [ -d $TMP_DIR/boot/extlinux ]; then
717 echo -n "Copying extlinux files..."
718 cp -a $TMP_DIR/boot/extlinux $TARGET/rootcd/boot
719 status
720 fi
721 if [ -d $TMP_DIR/boot/grub ]; then
722 echo -n "Copying GRUB files..."
723 cp -a $TMP_DIR/boot/grub $TARGET/rootcd/boot
724 status
725 fi
727 echo -n "Copying the rootfs..."
728 cp $TMP_DIR/boot/rootfs.?z $TARGET/rootcd/boot
729 status
730 # Extract initramfs.
731 cd $TARGET/rootfs
732 echo -n "Extracting the rootfs... "
733 extract_rootfs ../rootcd/boot/rootfs.gz $TARGET/rootfs
734 # unpack /usr
735 for i in etc/tazlito/*.extract; do
736 [ -f "$i" ] && . $i ../rootcd
737 done
738 # Umount and remove temp directory and cd to $TARGET to get stats.
739 umount $TMP_DIR && rm -rf $TMP_DIR
740 cd ..
741 echo ""
742 echo "================================================================================"
743 echo "Extracted : `basename $ISO_IMAGE` ($isosize)"
744 echo "Distro tree : `pwd`"
745 echo "Rootfs size : `du -sh rootfs`"
746 echo "Rootcd size : `du -sh rootcd`"
747 echo "================================================================================"
748 echo ""
749 ;;
750 list-flavors)
751 # Show available flavors.
752 if [ ! -s /etc/tazlito/flavors.list -o "$2" == "--recharge" ]; then
753 download flavors.list -O - > /etc/tazlito/flavors.list
754 fi
755 echo ""
756 echo -e "\033[1mList of flavors\033[0m"
757 echo "================================================================================"
758 cat /etc/tazlito/flavors.list
759 echo ""
760 ;;
761 show-flavor)
762 # Show flavor description.
763 FLAVOR=${2%.flavor}
764 if [ ! -f "$FLAVOR.flavor" ]; then
765 echo "File $FLAVOR.flavor not found."
766 exit 1
767 fi
768 mkdir $TMP_DIR
769 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i > /dev/null )
770 if [ "$3" = "--brief" ]; then
771 if [ "$4" != "--noheader" ]; then
772 echo "Name ISO Rootfs Description"
773 echo "================================================================================"
774 fi
775 printf "%-16.16s %6.6s %6.6s %s\n" "$FLAVOR" \
776 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
777 "$(field Rootfs $TMP_DIR/$FLAVOR.desc)" \
778 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
779 else
780 echo "================================================================================"
781 cat $TMP_DIR/$FLAVOR.desc
782 fi
783 rm -Rf $TMP_DIR
784 ;;
785 gen-liveflavor)
786 # Generate a new flavor form the live system.
787 FLAVOR=${2%.flavor}
788 DESC=""
789 case "$FLAVOR" in
790 '') echo -n "Flavor name : "
791 read FLAVOR
792 [ -z "$FLAVOR" ] && exit 1;;
793 -?|-h*|--help) echo -e "
795 SliTaz Live Tool - Version: $VERSION
796 \033[1mUsage: \033[0m `basename $0` gen-liveflavor flavor-name [flavor-patch-file]
797 \033[1mflavor-patch-file format: \033[0m
798 code data
799 + package to add
800 - package to remove
801 ! non-free package to add
802 ? display message
803 @ flavor description
805 \033[1mExample: \033[0m
806 @ Developer tools for slitaz maintainers
807 + slitaz-toolchain
808 + mercurial
809 "
810 exit 1;;
811 esac
812 mv /etc/tazlito/distro-packages.list \
813 /etc/tazlito/distro-packages.list.$$ 2> /dev/null
814 rm -f distro-packages.list non-free.list 2> /dev/null
815 tazpkg recharge
816 [ -n "$3" ] && while read action pkg; do
817 case "$action" in
818 +) yes | tazpkg get-install $pkg;;
819 -) yes | tazpkg remove $pkg;;
820 !) echo $pkg >> non-free.list;;
821 @) DESC="$pkg";;
822 \?) echo -en "$pkg"; read action;;
823 esac
824 done < $3
825 yes '' | tazlito gen-distro
826 echo "$DESC" | tazlito gen-flavor "$FLAVOR"
827 mv /etc/tazlito/distro-packages.list.$$ \
828 /etc/tazlito/distro-packages.list 2> /dev/null
829 ;;
830 gen-flavor)
831 # Generate a new flavor from the last iso image generated.
832 FLAVOR=${2%.flavor}
833 echo ""
834 echo -e "\033[1mFlavor generation\033[0m"
835 echo "================================================================================"
836 if [ -z "$FLAVOR" ]; then
837 echo -n "Flavor name : "
838 read FLAVOR
839 [ -z "$FLAVOR" ] && exit 1
840 fi
841 check_rootfs
842 FILES="$FLAVOR.pkglist"
843 echo -n "Creating file $FLAVOR.flavor..."
844 for i in rootcd rootfs; do
845 if [ -d "$ADDFILES/$i" ] ; then
846 FILES="$FILES\n$FLAVOR.$i"
847 ( cd "$ADDFILES/$i"; find . | \
848 cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
849 fi
850 done
851 status
852 answer=`grep -s ^Description $FLAVOR.desc`
853 answer=${answer#Description : }
854 if [ -z "$answer" ]; then
855 echo -n "Description : "
856 read answer
857 fi
858 echo -n "Compressing flavor $FLAVOR..."
859 echo "Flavor : $FLAVOR" > $FLAVOR.desc
860 echo "Description : $answer" >> $FLAVOR.desc
861 ( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
862 \rm -f $FLAVOR.pkglist $FLAVOR.nonfree 2> /dev/null
863 for i in $(ls $ROOTFS$INSTALLED); do
864 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
865 EXTRAVERSION=""
866 eval $(grep ^EXTRAVERSION= $ROOTFS$INSTALLED/$i/receipt)
867 eval $(grep ^CATEGORY= $ROOTFS$INSTALLED/$i/receipt)
868 if [ "$CATEGORY" = "non-free" -a "${i%%-*}" != "get" ]
869 then
870 echo "$i" >> $FLAVOR.nonfree
871 else
872 echo "$i-$VERSION$EXTRAVERSION" >> $FLAVOR.pkglist
873 fi
874 done
875 [ -s $FLAVOR.nonfree ] && $FILES="$FILES\n$FLAVOR.nonfree"
876 for i in $LOCALSTATE/undigest/*/mirror ; do
877 [ -s $i ] && cat $i >> $FLAVOR.mirrors
878 done
879 [ -s $FLAVOR.mirrors ] && $FILES="$FILES\n$FLAVOR.mirrors"
880 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
881 gzip -9 > $FLAVOR.flavor
882 rm `echo -e $FILES`
883 status
884 echo "================================================================================"
885 echo "Flavor size : `du -sh $FLAVOR.flavor`"
886 echo ""
887 ;;
888 upgrade-flavor)
889 # Update package list to the lastest versions available.
890 FLAVOR=${2%.flavor}
891 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
892 mkdir $TMP_DIR
893 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
894 echo -n "Update $FLAVOR package list..."
895 [ -s /var/lib/tazpkg/packages.list ] || tazpkg recharge
896 packed_size=0; unpacked_size=0
897 while read org; do
898 i=0
899 pkg=$org
900 while ! grep -q ^$pkg$ /var/lib/tazpkg/packages.txt; do
901 pkg=${pkg%-*}
902 i=$(($i + 1))
903 [ $i -gt 5 ] && break;
904 done
905 set -- $(get_size $pkg)
906 packed_size=$(( $packed_size + $1 ))
907 unpacked_size=$(( $unpacked_size + $2 ))
908 for i in $(grep ^$pkg /var/lib/tazpkg/packages.list); do
909 echo $i
910 break
911 done
912 done < $TMP_DIR/$FLAVOR.pkglist \
913 > $TMP_DIR/$FLAVOR.pkglist.$$
914 mv -f $TMP_DIR/$FLAVOR.pkglist.$$ $TMP_DIR/$FLAVOR.pkglist
915 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
916 packed_size=$(($packed_size \
917 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
918 unpacked_size=$(($unpacked_size \
919 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
920 fi
921 # Estimate lzma
922 packed_size=$(($packed_size * 2 / 3))
923 iso_size=$(( $packed_size + 26000 ))
924 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
925 iso_size=$(($iso_size \
926 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
927 fi
928 sed -i -e '/Image is ready/d' \
929 -e "s/Rootfs size\( *:\) \(.*\)/Rootfs size\1 $(cent2human $unpacked_size) (estimated)/" \
930 -e "s/Initramfs size\( *:\) \(.*\)/Initramfs size\1 $(cent2human $packed_size) (estimated)/" \
931 -e "s/ISO image size\( *:\) \(.*\)/ISO image size\1 $(cent2human $iso_size) (estimated)/" \
932 -e "s/date\( *:\) \(.*\)/date\1 $(date +%Y%m%d\ \at\ \%H:%M:%S)/" \
933 $TMP_DIR/$FLAVOR.desc
934 ( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
935 $FLAVOR.flavor
936 status
937 rm -Rf $TMP_DIR
938 fi
939 ;;
940 extract-flavor)
941 # Extract a flavor into $FLAVORS_REPOSITORY.
942 FLAVOR=${2%.flavor}
943 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
944 mkdir $TMP_DIR
945 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
946 echo -n "Extract $FLAVOR..."
947 rm -rf $FLAVORS_REPOSITORY/$FLAVOR 2> /dev/null
948 mkdir -p $FLAVORS_REPOSITORY/$FLAVOR
949 echo "FLAVOR=\"$FLAVOR\"" > $FLAVORS_REPOSITORY/$FLAVOR/receipt
950 grep ^Description $TMP_DIR/$FLAVOR.desc | \
951 sed 's/.*: \(.*\)$/SHORT_DESC="\1"/' >> \
952 $FLAVORS_REPOSITORY/$FLAVOR/receipt
953 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc && \
954 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
955 sed 's/.*: \(.*\)$/ROOTFS_SELECTION="\1"/' >> \
956 $FLAVORS_REPOSITORY/$FLAVOR/receipt
957 grep '^Rootfs size' $TMP_DIR/$FLAVOR.desc | \
958 sed 's/.*: \(.*\)$/ROOTFS_SIZE="\1"/' >> \
959 $FLAVORS_REPOSITORY/$FLAVOR/receipt
960 grep ^Initramfs $TMP_DIR/$FLAVOR.desc | \
961 sed 's/.*: \(.*\)$/INITRAMFS_SIZE="\1"/' >> \
962 $FLAVORS_REPOSITORY/$FLAVOR/receipt
963 grep ^ISO $TMP_DIR/$FLAVOR.desc | \
964 sed 's/.*: \(.*\)$/ISO_SIZE="\1"/' >> \
965 $FLAVORS_REPOSITORY/$FLAVOR/receipt
966 for i in rootcd rootfs; do
967 [ -f $TMP_DIR/$FLAVOR.$i ] || continue
968 mkdir $FLAVORS_REPOSITORY/$FLAVOR/$i
969 zcat $TMP_DIR/$FLAVOR.$i | \
970 (cd $FLAVORS_REPOSITORY/$FLAVOR/$i; \
971 cpio -idm > /dev/null)
972 done
973 [ -s $TMP_DIR/$FLAVOR.mirrors ] &&
974 cp $TMP_DIR/$FLAVOR.mirrors \
975 $FLAVORS_REPOSITORY/$FLAVOR/mirrors
976 [ -s /var/lib/tazpkg/packages.list ] || tazpkg recharge
977 while read org; do
978 i=0
979 pkg=$org
980 while ! grep -q ^$pkg$ /var/lib/tazpkg/packages.txt; do
981 pkg=${pkg%-*}
982 i=$(($i + 1))
983 [ $i -gt 5 ] && break;
984 done
985 echo $pkg
986 done < $TMP_DIR/$FLAVOR.pkglist \
987 > $FLAVORS_REPOSITORY/$FLAVOR/packages.list
988 status
989 rm -Rf $TMP_DIR
990 fi
991 ;;
992 pack-flavor)
993 # Create a flavor from $FLAVORS_REPOSITORY.
994 FLAVOR=${2%.flavor}
995 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/receipt ]; then
996 mkdir $TMP_DIR
997 echo -n "Create $FLAVOR..."
998 [ -s /var/lib/tazpkg/packages.list ] || tazpkg recharge
999 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/mirrors ]; then
1000 cp $FLAVORS_REPOSITORY/$FLAVOR/mirrors \
1001 $TMP_DIR/$FLAVOR.mirrors
1002 for i in $(cat $TMP_DIR/$FLAVOR.mirrors); do
1003 wget -O - $i/packages.list >> $TMP_DIR/packages.list
1004 done
1005 fi
1006 [ -s $FLAVORS_REPOSITORY/$FLAVOR/packages.list ] &&
1007 get_pkglist $FLAVOR > $TMP_DIR/$FLAVOR.pkglist
1008 if grep -q ^ROOTFS_SELECTION \
1009 $FLAVORS_REPOSITORY/$FLAVOR/receipt; then
1010 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1011 set -- $ROOTFS_SELECTION
1012 [ -n "$FRUGAL_RAM" ] || FRUGAL_RAM=$1
1013 [ -f $FLAVORS_REPOSITORY/$2/packages.list ] ||
1014 tazlito extract-flavor $2
1015 get_pkglist $2 > $TMP_DIR/$FLAVOR.pkglist
1016 fi
1017 for i in rootcd rootfs; do
1018 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] || \
1019 continue
1020 ( cd $FLAVORS_REPOSITORY/$FLAVOR/$i ; find . | \
1021 cpio -o -H newc ) | gzip -9 >$TMP_DIR/$FLAVOR.$i
1022 done
1023 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1024 packed_size=$(($packed_size \
1025 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1026 unpacked_size=$(($unpacked_size \
1027 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1028 fi
1029 # Estimate lzma
1030 packed_size=$(($packed_size * 2 / 3))
1031 iso_size=$(( $packed_size + 26000 ))
1032 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1033 iso_size=$(($iso_size \
1034 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1035 fi
1036 VERSION=""
1037 MAINTAINER=""
1038 ROOTFS_SELECTION=""
1039 ROOTFS_SIZE="$(cent2human $unpacked_size) (estimated)"
1040 INITRAMFS_SIZE="$(cent2human $packed_size) (estimated)"
1041 ISO_SIZE="$(cent2human $iso_size) (estimated)"
1042 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1043 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1044 Flavor : $FLAVOR
1045 Description : $SHORT_DESC
1046 EOT
1047 [ -n "$VERSION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1048 Version : $VERSION
1049 EOT
1050 [ -n "$MAINTAINER" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1051 Maintainer : $MAINTAINER
1052 EOT
1053 [ -n "$FRUGAL_RAM" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1054 LiveCD RAM size : $FRUGAL_RAM
1055 EOT
1056 [ -n "$ROOTFS_SELECTION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1057 Rootfs list : $ROOTFS_SELECTION
1058 EOT
1059 cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1060 Build date : $(date +%Y%m%d\ \at\ \%H:%M:%S)
1061 Packages : $(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l)
1062 Rootfs size : $ROOTFS_SIZE
1063 Initramfs size : $INITRAMFS_SIZE
1064 ISO image size : $ISO_SIZE
1065 ================================================================================
1067 EOT
1068 rm -f $TMP_DIR/packages.list
1069 ( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
1070 $FLAVOR.flavor
1071 status
1072 rm -Rf $TMP_DIR
1073 else
1074 echo "No $FLAVOR flavor in $FLAVORS_REPOSITORY."
1075 fi
1076 ;;
1077 get-flavor)
1078 # Get a flavor's files and prepare for gen-distro.
1079 FLAVOR=${2%.flavor}
1080 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1081 echo -n "Cleaning $DISTRO..."
1082 rm -R $DISTRO 2> /dev/null
1083 mkdir -p $DISTRO
1084 status
1085 mkdir $TMP_DIR
1086 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i 2>/dev/null )
1087 echo -n "Create distro-packages.list..."
1088 mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
1089 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
1090 status
1091 for i in rootcd rootfs; do
1092 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
1093 echo -n "Add $i..."
1094 mkdir -p "$ADDFILES/$i"
1095 zcat $TMP_DIR/$FLAVOR.$i | \
1096 ( cd "$ADDFILES/$i"; cpio -id 2> /dev/null)
1097 status
1098 fi
1099 done
1100 if [ -s $TMP_DIR/$FLAVOR.mirrors ]; then
1101 n=""
1102 while read line; do
1103 mkdir -p $LOCALSTATE/undigest/$FLAVOR$n
1104 echo "$line" > $LOCALSTATE/undigest/$FLAVOR$n/mirror
1105 n=$(( $n + 1 ))
1106 done < $TMP_DIR/$FLAVOR.mirrors
1107 tazpkg recharge
1108 fi
1109 rm -f /etc/tazlito/rootfs.list
1110 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc &&
1111 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1112 sed 's/.*: \(.*\)$/\1/' > /etc/tazlito/rootfs.list
1113 echo -n "Update tazlito.conf..."
1114 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
1115 cat tazlito.conf | grep -v "^#VOLUM_NAME" | \
1116 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
1117 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
1118 status
1119 rm -Rf $TMP_DIR
1120 fi
1121 ;;
1122 check-list)
1123 # Use current packages list in $PWD by default.
1124 DISTRO_PKGS_LIST=distro-packages.list
1125 [ -d "$2" ] && DISTRO_PKGS_LIST=$2/distro-packages.list
1126 [ -f "$2" ] && DISTRO_PKGS_LIST=$2
1127 [ ! -f $DISTRO_PKGS_LIST ] && echo "No packages list found." && exit 0
1128 echo ""
1129 echo -e "\033[1mLiveCD packages list check\033[0m"
1130 echo "================================================================================"
1131 for pkg in `cat $DISTRO_PKGS_LIST`
1132 do
1133 if ! grep -q "$pkg" /var/lib/tazpkg/packages.list; then
1134 echo "Update: $pkg"
1135 up=$(($up + 1))
1136 fi
1137 done
1138 [ -z $up ] && echo -e "List is up-to-date\n" && exit 0
1139 echo "================================================================================"
1140 echo -e "Updates: $up\n" ;;
1141 gen-distro)
1142 # Generate a live distro tree with a set of packages.
1144 check_root
1146 # Check if a package list was specified on cmdline.
1147 LIST_NAME="distro-packages.list"
1148 CDROM=""
1149 while [ -n "$2" ]; do
1150 case "$2" in
1151 --iso=*)
1152 CDROM="-o loop ${2#--iso=}"
1153 ;;
1154 --cdrom)
1155 CDROM="/dev/cdrom"
1156 ;;
1157 --force)
1158 DELETE_ROOTFS="true"
1159 ;;
1160 *) if [ ! -f "$2" ] ; then
1161 echo -e "\nUnable to find the specified packages list."
1162 echo -e "List name : $2\n"
1163 exit 1
1164 fi
1165 LIST_NAME=$2
1166 ;;
1167 esac
1168 shift
1169 done
1171 if [ -d $ROOTFS ] ; then
1172 # Delete $ROOTFS if --force is set on command line
1173 if [ ! -z $DELETE_ROOTFS ]; then
1174 rm -rf $ROOTFS
1175 unset $DELETE_ROOTFS
1176 else
1177 echo -e "\nA rootfs exists in : $DISTRO"
1178 echo -e "Please clean the distro tree or change directory path.\n"
1179 exit 0
1180 fi
1181 fi
1182 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
1183 # Build list with installed packages
1184 for i in $(ls $INSTALLED); do
1185 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
1186 EXTRAVERSION=""
1187 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
1188 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
1189 done
1190 fi
1191 # Exit if no list name.
1192 if [ ! -f "$LIST_NAME" ]; then
1193 echo -e "\nNo packages list found or specified. Please read the docs.\n"
1194 exit 0
1195 fi
1196 # Start generation.
1197 echo ""
1198 echo -e "\033[1mTazlito generating a distro\033[0m"
1199 echo "================================================================================"
1200 # Misc checks
1201 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
1202 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
1203 # Get the list of packages using cat for a file list.
1204 LIST=`cat $LIST_NAME`
1205 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
1206 REPACK=""
1207 DOWNLOAD=""
1208 for pkg in $LIST
1209 do
1210 [ "$pkg" = "" ] && continue
1211 pkg=${pkg%.tazpkg}
1212 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
1213 PACKAGE=$(installed_package_name $pkg)
1214 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
1215 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
1216 echo -e "\nUnable to find $pkg in the repository."
1217 echo -e "Path : $PACKAGES_REPOSITORY\n"
1218 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
1219 yesorno "Repack packages from rootfs (y/N) ? "
1220 REPACK="$answer"
1221 [ "$answer" = "y" ] || REPACK="n"
1222 [ "$DOWNLOAD" = "y" ] && break
1223 fi
1224 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
1225 yesorno "Download packages from mirror (Y/n) ? "
1226 DOWNLOAD="$answer"
1227 if [ "$answer" = "n" ]; then
1228 [ -z "$PACKAGE" ] && exit 1
1229 else
1230 DOWNLOAD="y"
1231 [ -n "$REPACK" ] && break
1232 fi
1233 fi
1234 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
1235 done
1237 # Mount cdrom to be able to repack boot-loader packages
1238 if [ ! -e /boot -a -n "$CDROM" ]; then
1239 mkdir $TMP_MNT
1240 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
1241 ln -s $TMP_MNT/boot /
1242 if [ ! -d "$ADDFILES/rootcd" ] ; then
1243 mkdir -p $ADDFILES/rootcd
1244 for i in $(ls $TMP_MNT); do
1245 [ "$i" = "boot" ] && continue
1246 cp -a $TMP_MNT/$i $ADDFILES/rootcd
1247 done
1248 fi
1249 else
1250 rmdir $TMP_MNT
1251 fi
1252 fi
1254 # Root fs stuff.
1255 echo "Preparing the rootfs directory..."
1256 mkdir -p $ROOTFS
1257 sleep 2
1258 for pkg in $LIST
1259 do
1260 [ "$pkg" = "" ] && continue
1261 # First copy and extract the package in tmp dir.
1262 pkg=${pkg%.tazpkg}
1263 PACKAGE=$(installed_package_name $pkg)
1264 mkdir -p $TMP_DIR
1265 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1266 # Look for package in cache
1267 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
1268 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
1269 # Look for package in running distribution
1270 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
1271 tazpkg repack $PACKAGE && \
1272 mv $pkg.tazpkg $PACKAGES_REPOSITORY
1273 fi
1274 fi
1275 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1276 # Get package from mirror
1277 [ "$DOWNLOAD" = "y" ] && \
1278 download $pkg.tazpkg && \
1279 mv $pkg.tazpkg $PACKAGES_REPOSITORY
1280 fi
1281 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1282 echo "Missing package $pkg."
1283 cleanup
1284 exit 1
1285 fi
1286 done
1287 if [ -f non-free.list ]; then
1288 echo "Preparing non-free packages..."
1289 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
1290 for pkg in $(cat non-free.list); do
1291 if [ ! -d $INSTALLED/$pkg ]; then
1292 if [ ! -d $INSTALLED/get-$pkg ]; then
1293 tazpkg get-install get-$pkg
1294 fi
1295 get-$pkg
1296 fi
1297 tazpkg repack $pkg
1298 pkg=$(ls $pkg*.tazpkg)
1299 grep -q "^$pkg$" $LIST_NAME || \
1300 echo $pkg >>$LIST_NAME
1301 mv $pkg $PACKAGES_REPOSITORY
1302 done
1303 fi
1304 echo ""
1305 cp $LIST_NAME $DISTRO/distro-packages.list
1306 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/distro-packages.list > $DISTRO/list-packages
1307 cd $PACKAGES_REPOSITORY
1308 yes y | tazpkg install-list \
1309 $DISTRO/list-packages --root=$ROOTFS
1310 cd $DISTRO
1311 cp distro-packages.list $ROOTFS/etc/tazlito
1312 # Copy all files from $ADDFILES/rootfs to the rootfs.
1313 if [ -d "$ADDFILES/rootfs" ] ; then
1314 echo -n "Copying addfiles content to the rootfs... "
1315 cp -a $ADDFILES/rootfs/* $ROOTFS
1316 status
1317 fi
1318 echo "Root file system is generated..."
1319 # Root CD part.
1320 echo -n "Preparing the rootcd directory..."
1321 mkdir -p $ROOTCD
1322 status
1323 # Move the boot dir with the Linux kernel from rootfs.
1324 # The boot dir goes directly on the CD.
1325 if [ -d "$ROOTFS/boot" ] ; then
1326 echo -n "Moving the boot directory..."
1327 mv $ROOTFS/boot $ROOTCD
1328 cd $ROOTCD/boot
1329 ln vmlinuz-* bzImage
1330 status
1331 fi
1332 cd $DISTRO
1333 # Copy all files from $ADDFILES/rootcd to the rootcd.
1334 if [ -d "$ADDFILES/rootcd" ] ; then
1335 echo -n "Copying addfiles content to the rootcd... "
1336 cp -a $ADDFILES/rootcd/* $ROOTCD
1337 status
1338 fi
1339 # Execute the distro script (used to perform tasks in the rootfs
1340 # before compression. Give rootfs path in arg
1341 [ -z $DISTRO_SCRIPT ] && DISTRO_SCRIPT=$TOP_DIR/distro.sh
1342 if [ -x $DISTRO_SCRIPT ]; then
1343 echo "Executing distro script..."
1344 sh $DISTRO_SCRIPT $DISTRO
1345 fi
1346 if [ -s /etc/tazlito/rootfs.list ]; then
1347 [ -f $ROOTCD/boot/isolinux/ifmem.c32 ] ||
1348 cp /boot/isolinux/ifmem.c32 $ROOTCD/boot/isolinux
1349 n=0
1350 last=$ROOTFS
1351 while read flavor; do
1352 n=$(($n+1))
1353 echo "Building $flavor rootfs..."
1354 download $flavor.flavor
1355 zcat $flavor.flavor | cpio -i $flavor.pkglist
1356 sed 's/.*/&.tazpkg/' < $flavor.pkglist \
1357 > $DISTRO/list-packages0$n
1358 mkdir ${ROOTFS}0$n
1359 cd $PACKAGES_REPOSITORY
1360 yes y | tazpkg install-list \
1361 $DISTRO/list-packages0$n --root=${ROOTFS}0$n
1362 rm -rf ${ROOTFS}0$n/boot
1363 status
1364 cd $DISTRO
1365 mv $flavor.pkglist ${ROOTFS}0$n/etc/tazlito/distro-packages.list
1366 rm -f $flavor.flavor install-list
1367 mergefs ${ROOTFS}0$n $last
1368 last=${ROOTFS}0$n
1369 done <<EOT
1370 $(awk '{ for (i = 4; i <= NF; i+=2) print $i; }' < /etc/tazlito/rootfs.list)
1371 EOT
1372 i=$(($n+1))
1373 while [ $n -gt 0 ]; do
1374 mv ${ROOTFS}0$n ${ROOTFS}$i
1375 echo "Compression ${ROOTFS}0$n ($(du -hs ${ROOTFS}$i | awk '{ print $1 }')) ..."
1376 gen_initramfs ${ROOTFS}$i
1377 n=$(($n-1))
1378 i=$(($i-1))
1379 done
1380 mv $ROOTFS ${ROOTFS}$i
1381 gen_initramfs ${ROOTFS}$i
1382 update_bootconfig $ROOTCD/boot/isolinux \
1383 "$(cat /etc/tazlito/rootfs.list)"
1384 else
1385 # Initramfs and ISO image stuff.
1386 gen_initramfs $ROOTFS
1387 fi
1388 gen_livecd_isolinux
1389 distro_stats
1390 cleanup
1391 ;;
1392 clean-distro)
1393 # Remove old distro tree.
1395 check_root
1396 echo ""
1397 echo -e "\033[1mCleaning :\033[0m $DISTRO"
1398 echo "================================================================================"
1399 if [ -d "$DISTRO" ] ; then
1400 if [ -d "$ROOTFS" ] ; then
1401 echo -n "Removing the rootfs..."
1402 rm -f $DISTRO/$INITRAMFS
1403 rm -rf $ROOTFS
1404 status
1405 fi
1406 if [ -d "$ROOTCD" ] ; then
1407 echo -n "Removing the rootcd..."
1408 rm -rf $ROOTCD
1409 status
1410 fi
1411 echo -n "Removing eventual ISO image..."
1412 rm -f $DISTRO/$ISO_NAME.iso
1413 rm -f $DISTRO/$ISO_NAME.md5
1414 status
1415 fi
1416 echo "================================================================================"
1417 echo ""
1418 ;;
1419 check-distro)
1420 # Check for a few LiveCD needed files not installed by packages.
1422 check_rootfs
1423 echo ""
1424 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
1425 echo "================================================================================"
1426 # SliTaz release info.
1427 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
1428 echo "Missing release info : /etc/slitaz-release"
1429 else
1430 release=`cat $ROOTFS/etc/slitaz-release`
1431 echo -n "Release : $release"
1432 status
1433 fi
1434 # Tazpkg mirror.
1435 if [ ! -f "$ROOTFS/var/lib/tazpkg/mirror" ]; then
1436 echo -n "Mirror URL : Missing /var/lib/tazpkg/mirror"
1437 todomsg
1438 else
1439 echo -n "Mirror configuration exist..."
1440 status
1441 fi
1442 # Isolinux msg
1443 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.msg; then
1444 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
1445 todomsg
1446 else
1447 echo -n "Isolinux message seems good..."
1448 status
1449 fi
1450 echo "================================================================================"
1451 echo ""
1452 ;;
1453 burn-iso)
1454 # Guess cdrom device, ask user and burn the ISO.
1456 check_root
1457 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
1458 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
1459 # We can specify an alternative ISO from the cmdline.
1460 if [ -n "$2" ] ; then
1461 iso=$2
1462 else
1463 iso=$DISTRO/$ISO_NAME.iso
1464 fi
1465 if [ ! -f "$iso" ]; then
1466 echo -e "\nUnable to find ISO : $iso\n"
1467 exit 0
1468 fi
1469 echo ""
1470 echo -e "\033[1mTazlito burn ISO\033[0m "
1471 echo "================================================================================"
1472 echo "Cdrom device : /dev/$DRIVE_NAME"
1473 echo "Drive speed : $DRIVE_SPEED"
1474 echo "ISO image : $iso"
1475 echo "================================================================================"
1476 echo ""
1477 yesorno "Burn ISO image (y/N) ? "
1478 if [ "$answer" == "y" ]; then
1479 echo ""
1480 echo "Starting Wodim to burn the iso..." && sleep 2
1481 echo "================================================================================"
1482 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
1483 echo "================================================================================"
1484 echo "ISO image is burned to cdrom."
1485 else
1486 echo -e "\nExiting. No ISO burned."
1487 fi
1488 echo ""
1489 ;;
1490 merge)
1491 # Merge multiple rootfs into one iso.
1493 if [ -z "$2" ]; then
1494 cat << EOT
1495 Usage: tazlito merge size1 iso size2 rootfs2 [sizeN rootfsN]...
1497 Merge multiple rootfs into one iso. Rootfs are like russian dolls
1498 i.e: rootfsN is a subset of rootfsN-1
1499 rootfs1 is found in iso, sizeN is the RAM size need to launch rootfsN.
1500 The boot loader will select the rootfs according to the RAM size detected.
1502 Example:
1503 $ tazlito merge 160M slitaz-core.iso 96M rootfs-justx.gz 32M rootfs-base.gz
1505 Will start slitaz-core with 160M+ RAM, slitaz-justX with 96M-160M RAM,
1506 slitaz-base with 32M-96M RAM and display an error message if RAM < 32M.
1507 EOT
1508 exit 2
1509 fi
1511 shift # skip merge
1512 append="$1 slitaz1"
1513 shift # skip size1
1514 mkdir -p $TMP_DIR/mnt $TMP_DIR/rootfs1
1516 ISO=$1.merged
1517 # Extract filesystems
1518 echo -n "Mount $1"
1519 mount -o loop,ro $1 $TMP_DIR/mnt 2> /dev/null
1520 status || cleanup_merge
1521 cp -a $TMP_DIR/mnt $TMP_DIR/iso
1522 rm -f $TMP_DIR/iso/boot/bzImage
1523 ln $TMP_DIR/iso/boot/vmlinuz* $TMP_DIR/iso/boot/bzImage
1524 umount -d $TMP_DIR/mnt
1525 if [ -f $TMP_DIR/iso/boot/rootfs1.gz ]; then
1526 echo "$1 is already a merged iso. Abort."
1527 cleanup_merge
1528 fi
1529 if [ ! -f $TMP_DIR/iso/boot/isolinux/ifmem.c32 ]; then
1530 if [ ! -f /boot/isolinux/ifmem.c32 ]; then
1531 cat <<EOT
1532 No file /boot/isolinux/ifmem.c32
1533 Please install syslinux package !
1534 EOT
1535 rm -rf $TMP_DIR
1536 exit 1
1537 fi
1538 cp /boot/isolinux/ifmem.c32 $TMP_DIR/iso/boot/isolinux
1539 fi
1541 echo -n "Extract iso/rootfs.gz"
1542 extract_rootfs $TMP_DIR/iso/boot/rootfs.gz $TMP_DIR/rootfs1 &&
1543 [ -d $TMP_DIR/rootfs1/etc ]
1544 status || cleanup_merge
1545 n=1
1546 while [ -n "$2" ]; do
1547 shift # skip rootfs N-1
1548 p=$n
1549 n=$(($n + 1))
1550 append="$append $1 slitaz$n"
1551 shift # skip size N
1552 mkdir -p $TMP_DIR/rootfs$n
1553 echo -n "Extract $1"
1554 extract_rootfs $1 $TMP_DIR/rootfs$n &&
1555 [ -d $TMP_DIR/rootfs$n/etc ]
1556 status || cleanup_merge
1557 mergefs $TMP_DIR/rootfs$n $TMP_DIR/rootfs$p
1558 echo "Create rootfs$p.gz"
1559 pack_rootfs $TMP_DIR/rootfs$p $TMP_DIR/iso/boot/rootfs$p.gz
1560 status
1561 done
1562 echo "Create rootfs$n.gz"
1563 pack_rootfs $TMP_DIR/rootfs$n $TMP_DIR/iso/boot/rootfs$n.gz
1564 status
1565 rm -f $TMP_DIR/iso/boot/rootfs.gz
1566 update_bootconfig $TMP_DIR/iso/boot/isolinux "$append"
1567 echo "Generate $ISO"
1568 create_iso $ISO $TMP_DIR/iso
1569 rm -rf $TMP_DIR
1570 ;;
1572 repack)
1573 # Repack an iso with maximum lzma compression ratio.
1576 ISO=$2
1578 mkdir -p $TMP_DIR/mnt
1579 # Extract filesystems
1580 echo -n "Mount $ISO"
1581 mount -o loop,ro $ISO $TMP_DIR/mnt 2> /dev/null
1582 status || cleanup_merge
1583 cp -a $TMP_DIR/mnt $TMP_DIR/iso
1584 umount -d $TMP_DIR/mnt
1586 for i in $TMP_DIR/iso/boot/rootfs* ; do
1587 echo -n "Repack $(basename $i)"
1588 (zcat $i || unlzma -c $i || cat $i) \
1589 2>/dev/null > $TMP_DIR/rootfs
1590 lzma e $TMP_DIR/rootfs $i \
1591 $(lzma_switches $TMP_DIR/rootfs)
1592 status
1593 done
1595 echo "Generate $ISO"
1596 create_iso $ISO $TMP_DIR/iso
1597 rm -rf $TMP_DIR
1598 ;;
1600 usage|*)
1601 # Clear and print usage also for all unknown commands.
1603 clear
1604 usage
1605 ;;
1607 esac
1609 exit 0