tazlito view tazlito @ rev 122

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