tazlito view tazlito @ rev 107

tazlito upgrade-flavor/pack-flavor: estimate sizes
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Aug 21 13:44:40 2009 +0200 (2009-08-21)
parents b322fa520f21
children d2375d0fa398
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 cd $ROOTFS
163 for i in $(ls etc/tazlito/*.$1 2> /dev/null); do
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 # Pack rootfs
297 pack_rootfs()
298 {
299 ( cd $1 ; find . -print | cpio -o -H newc ) | \
300 if [ "$COMPRESSION" = "none" ]; then
301 echo -n "Generating uncompressed initramfs... "
302 cat > $2
303 elif [ -x /usr/bin/lzma -a "$COMPRESSION" != "gzip" ]; then
304 echo -n "Generating lzma'ed initramfs... "
305 lzma e -si -so -d$(lzma_history_bits $1) > $2
306 else
307 echo -n "Generating gziped initramfs... "
308 gzip -9 > $2
309 fi
310 }
312 # Generate a new initramfs from the root filesystem.
313 gen_initramfs()
314 {
315 # Just in case CTRL+c
316 rm -f $DISTRO/gen
317 # Some packages may want to alter rootfs
318 genisohooks rootfs
319 cd $ROOTFS
320 echo ""
322 # Link duplicate files
323 find . -type f -size +0c -exec stat -c '%s-%a-%u-%g %i %h %n' {} \; | \
324 sort | ( save=0; old_attr=""; old_inode=""; old_link=""; old_file=""
325 while read attr inode link file; do
326 if [ "$attr" = "$old_attr" -a "$inode" != "$old_inode" ]; then
327 if cmp "$file" "$old_file" >/dev/null; then
328 rm -f "$file"
329 ln "$old_file" "$file"
330 inode="$old_inode"
331 [ "$link" = "1" ] && save="$(expr $save + ${attr%%-*})"
332 fi
333 fi
334 old_attr="$attr" ; old_inode="$inode" ; old_file="$file"
335 done
336 echo "$save bytes saved in duplicate files."
337 )
339 # Use lzma if installed
340 pack_rootfs . $DISTRO/$INITRAMFS
341 cd $DISTRO
342 mv $INITRAMFS $ROOTCD/boot
343 }
345 distro_sizes()
346 {
347 echo "Build date : `date +%Y%m%d\ \at\ \%H:%M:%S`"
348 echo "Packages : `ls -1 $ROOTFS$INSTALLED | wc -l`"
349 echo "Rootfs size : `du -sh $ROOTFS | awk '{ print $1 }'`"
350 echo "Initramfs size : `du -sh $ROOTCD/boot/$INITRAMFS | awk '{ print $1 }'`"
351 echo "ISO image size : `du -sh $ISO_NAME.iso | awk '{ print $1 }'`"
352 echo "================================================================================"
353 echo "Image is ready: $ISO_NAME.iso"
354 echo ""
355 }
357 # Print ISO and rootfs size.
358 distro_stats()
359 {
360 echo ""
361 echo -e "\033[1mDistro statistics\033[0m ($DISTRO)"
362 echo "================================================================================"
363 distro_sizes
364 }
366 # Create an empty configuration file.
367 empty_config_file()
368 {
369 cat >> tazlito.conf << "EOF"
370 # tazlito.conf: Tazlito (SliTaz Live Tool)
371 # configuration file.
372 #
374 # Name of the ISO image to generate.
375 ISO_NAME=""
377 # ISO image volume name.
378 VOLUM_NAME="SliTaz"
380 # Name of the preparer.
381 PREPARED="$USER"
383 # Path to the packages repository and the packages.list.
384 PACKAGES_REPOSITORY=""
386 # Path to the distro tree to gen-distro from a
387 # list of packages.
388 DISTRO=""
390 # Path to the directory containing additional files
391 # to copy into the rootfs and rootcd of the LiveCD.
392 ADDFILES="$DISTRO/addfiles"
394 # Default answer for binary question (Y or N)
395 DEFAULT_ANSWER="ASK"
397 # Compression utility (lzma, gzip or none)
398 COMPRESSION="lzma"
399 EOF
400 }
402 # extract rootfs.gz somewhere
403 extract_rootfs()
404 {
405 (zcat $1 || unlzma -c $1 || cat $1) 2>/dev/null | \
406 (cd $2; cpio -idm > /dev/null)
407 }
409 # Remove duplicate files
410 mergefs()
411 {
412 # merge symlinks files and devices
413 ( cd $1; find ) | while read file; do
414 if [ -L $1/$file ]; then
415 [ -L $2/$file ] &&
416 [ "$(readlink $1/$file)" == "$(readlink $2/$file)" ] &&
417 rm -f $2/$file
418 elif [ -f $1/$file ]; then
419 [ -f $2/$file ] &&
420 cmp $1/$file $2/$file > /dev/null 2>&1 && rm -f $2/$file
421 [ -f $2/$file ] &&
422 [ "$(basename $file)" == "volatile.cpio.gz" ] &&
423 [ "$(dirname $(dirname $file))" == \
424 "./var/lib/tazpkg/installed" ] && rm -f $2/$file
425 elif [ -b $1/$file ]; then
426 [ -b $2/$file ] && rm -f $2/$file
427 elif [ -c $1/$file ]; then
428 [ -c $2/$file ] && rm -f $2/$file
429 fi
430 done
432 # cleanup directories
433 ( cd $1; find ) | while read file; do
434 if [ -d $1/$file ]; then
435 [ -d $2/$file ] && rmdir $2/$file 2> /dev/null
436 fi
437 done
438 true
439 }
441 cleanup_merge()
442 {
443 rm -rf $TMP_DIR
444 exit 1
445 }
447 human2cent()
448 {
449 case "$1" in
450 *k) echo $1 | sed 's/\(.*\).\(.\)k/\1\2/';;
451 *M) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)M/\1\2/') * 1024));;
452 *G) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)G/\1\2/') * 1024 * 1024));;
453 esac
454 }
456 cent2human()
457 {
458 if [ $1 -lt 10000 ]; then
459 echo "$(($1 / 10)).$(($1 % 10))k"
460 elif [ $1 -lt 10000000 ]; then
461 echo "$(($1 / 10240)).$(( ($1/1024) % 10))M"
462 else
463 echo "$(($1 / 10485760)).$(( ($1/1048576) % 10))G"
464 fi
465 }
467 get_size()
468 {
469 awk "{ \
470 if (/^$(echo $1 | sed 's/[$+.\]/\\&/g')$/) get=1; \
471 if (/installed/ && get) { print ; get=0 } \
472 }" < /var/lib/tazpkg/packages.txt | \
473 sed 's/ *\(.*\) .\(.*\) installed./\1 \2/' | while read packed unpacked; do
474 echo "$(human2cent $packed) $(human2cent $unpacked)"
475 done
476 }
478 ####################
479 # Tazlito commands #
480 ####################
482 case "$COMMAND" in
483 stats)
484 # Tazlito general statistics from the config file.
485 #
486 echo ""
487 echo -e "\033[1mTazlito statistics\033[0m
488 ===============================================================================
489 Config file : $CONFIG_FILE
490 ISO name : $ISO_NAME.iso
491 Volume name : $VOLUM_NAME
492 Prepared : $PREPARED
493 Packages repository : $PACKAGES_REPOSITORY
494 Distro directory : $DISTRO"
495 if [ ! "$ADDFILES" = "" ] ; then
496 echo -e "Additional files : $ADDFILES"
497 fi
498 echo "================================================================================"
499 echo ""
500 ;;
501 gen-config)
502 # Generate a new config file in the current dir or the specified
503 # directory by $2.
504 #
505 if [ -n "$2" ] ; then
506 mkdir -p $2 && cd $2
507 fi
508 echo -n "Generating empty tazlito.conf..."
509 empty_config_file
510 status
511 echo ""
512 if [ -f "tazlito.conf" ] ; then
513 echo "Configuration file is ready to edit."
514 echo "File location : `pwd`/tazlito.conf"
515 echo ""
516 fi
517 ;;
518 configure)
519 # Configure a tazlito.conf config file. Start by getting
520 # a empty config file and sed it.
521 #
522 if [ -f "tazlito.conf" ] ; then
523 rm tazlito.conf
524 else
525 if test $(id -u) = 0 ; then
526 cd /etc
527 else
528 echo "You must be root to configure the main config file or in"
529 echo "the same directory of the file you want to configure."
530 exit 0
531 fi
532 fi
533 empty_config_file
534 echo""
535 echo -e "\033[1mConfiguring :\033[0m `pwd`/tazlito.conf"
536 echo "================================================================================"
537 # ISO name.
538 echo -n "ISO name : " ; read answer
539 sed -i s#'ISO_NAME=\"\"'#"ISO_NAME=\"$answer\""# tazlito.conf
540 # Volume name.
541 echo -n "Volume name : " ; read answer
542 sed -i s/'VOLUM_NAME=\"SliTaz\"'/"VOLUM_NAME=\"$answer\""/ tazlito.conf
543 # Packages repository.
544 echo -n "Packages repository : " ; read answer
545 sed -i s#'PACKAGES_REPOSITORY=\"\"'#"PACKAGES_REPOSITORY=\"$answer\""# tazlito.conf
546 # Distro path.
547 echo -n "Distro path : " ; read answer
548 sed -i s#'DISTRO=\"\"'#"DISTRO=\"$answer\""# tazlito.conf
549 echo "================================================================================"
550 echo "Config file is ready to use."
551 echo "You can now extract an ISO or generate a distro."
552 echo ""
553 ;;
554 gen-iso)
555 # Simply generate a new iso.
556 #
557 check_root
558 verify_rootcd
559 gen_livecd_isolinux
560 distro_stats
561 ;;
562 gen-initiso)
563 # Simply generate a new initramfs with a new iso.
564 #
565 check_root
566 verify_rootcd
567 gen_initramfs
568 gen_livecd_isolinux
569 distro_stats
570 ;;
571 extract-distro)
572 # Extract an ISO image to a directory and rebuild the LiveCD tree.
573 #
574 check_root
575 ISO_IMAGE=$2
576 if [ -z "$ISO_IMAGE" ] ; then
577 echo -e "\nPlease specify the path to the ISO image."
578 echo -e "Example : `basename $0` image.iso /path/target\n"
579 exit 0
580 fi
581 # Set the distro path by checking for $3 on cmdline.
582 if [ -n "$3" ] ; then
583 TARGET=$3
584 else
585 TARGET=$DISTRO
586 fi
587 # Exit if existing distro is found.
588 if [ -d "$TARGET/rootfs" ] ; then
589 echo -e "\nA rootfs exists in : $TARGET"
590 echo -e "Please clean the distro tree or change directory path.\n"
591 exit 0
592 fi
593 echo ""
594 echo -e "\033[1mTazlito extracting :\033[0m `basename $ISO_IMAGE`"
595 echo "================================================================================"
596 # Start to mount the ISO.
597 echo ""
598 echo "Mounting ISO image..."
599 mkdir -p $TMP_DIR
600 # Get ISO file size.
601 isosize=`du -sh $ISO_IMAGE | cut -f1`
602 mount -o loop $ISO_IMAGE $TMP_DIR
603 sleep 2
604 # Prepare target dir, copy the kernel and the rootfs.
605 mkdir -p $TARGET/rootfs
606 mkdir -p $TARGET/rootcd/boot
607 echo -n "Copying the Linux kernel..."
608 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
609 ln $TARGET/rootcd/boot/vmlinuz* $TARGET/rootcd/boot/bzImage
610 else
611 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
612 fi
613 status
614 echo -n "Copying isolinux files..."
615 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
616 for i in $(ls $TMP_DIR); do
617 [ "$i" = "boot" ] && continue
618 cp -a $TMP_DIR/$i $TARGET/rootcd
619 done
620 status
621 if [ -d $TMP_DIR/boot/syslinux ]; then
622 echo -n "Copying syslinux files..."
623 cp -a $TMP_DIR/boot/syslinux $TARGET/rootcd/boot
624 status
625 fi
626 if [ -d $TMP_DIR/boot/extlinux ]; then
627 echo -n "Copying extlinux files..."
628 cp -a $TMP_DIR/boot/extlinux $TARGET/rootcd/boot
629 status
630 fi
631 if [ -d $TMP_DIR/boot/grub ]; then
632 echo -n "Copying GRUB files..."
633 cp -a $TMP_DIR/boot/grub $TARGET/rootcd/boot
634 status
635 fi
637 echo -n "Copying the rootfs..."
638 cp $TMP_DIR/boot/rootfs.?z $TARGET/rootcd/boot
639 status
640 # Extract initramfs.
641 cd $TARGET/rootfs
642 echo -n "Extracting the rootfs... "
643 extract_rootfs ../rootcd/boot/rootfs.gz $TARGET/rootfs
644 # unpack /usr
645 for i in etc/tazlito/*.extract; do
646 [ -f "$i" ] && . $i ../rootcd
647 done
648 # Umount and remove temp directory and cd to $TARGET to get stats.
649 umount $TMP_DIR && rm -rf $TMP_DIR
650 cd ..
651 echo ""
652 echo "================================================================================"
653 echo "Extracted : `basename $ISO_IMAGE` ($isosize)"
654 echo "Distro tree : `pwd`"
655 echo "Rootfs size : `du -sh rootfs`"
656 echo "Rootcd size : `du -sh rootcd`"
657 echo "================================================================================"
658 echo ""
659 ;;
660 list-flavors)
661 # Show available flavors.
662 if [ ! -s /etc/tazlito/flavors.list -o "$2" == "--recharge" ]; then
663 download flavors.list -O - > /etc/tazlito/flavors.list
664 fi
665 echo ""
666 echo -e "\033[1mList of flavors\033[0m"
667 echo "================================================================================"
668 cat /etc/tazlito/flavors.list
669 echo ""
670 ;;
671 show-flavor)
672 # Show flavor description.
673 FLAVOR=${2%.flavor}
674 if [ ! -f "$FLAVOR.flavor" ]; then
675 echo "File $FLAVOR.flavor not found."
676 exit 1
677 fi
678 mkdir $TMP_DIR
679 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i 2> /dev/null )
680 if [ "$3" = "--brief" ]; then
681 if [ "$4" != "--noheader" ]; then
682 echo "Name Sizes Description"
683 echo "================================================================================"
684 fi
685 printf "%-15.15s %5.5s/%5.5s %-51s\n" "$FLAVOR" \
686 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
687 "$(field Rootfs $TMP_DIR/$FLAVOR.desc)" \
688 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
689 else
690 echo "================================================================================"
691 cat $TMP_DIR/$FLAVOR.desc
692 fi
693 rm -Rf $TMP_DIR
694 ;;
695 gen-liveflavor)
696 # Generate a new flavor form the live system.
697 FLAVOR=${2%.flavor}
698 DESC=""
699 case "$FLAVOR" in
700 '') echo -n "Flavor name : "
701 read FLAVOR
702 [ -z "$FLAVOR" ] && exit 1;;
703 -?|-h*|--help) echo -e "
705 SliTaz Live Tool - Version: $VERSION
706 \033[1mUsage: \033[0m `basename $0` gen-liveflavor flavor-name [flavor-patch-file]
707 \033[1mflavor-patch-file format: \033[0m
708 code data
709 + package to add
710 - package to remove
711 ! non-free package to add
712 ? display message
713 @ flavor description
715 \033[1mExample: \033[0m
716 @ Developer tools for slitaz maintainers
717 + slitaz-toolchain
718 + mercurial
719 "
720 exit 1;;
721 esac
722 mv /etc/tazlito/distro-packages.list \
723 /etc/tazlito/distro-packages.list.$$ 2> /dev/null
724 rm -f distro-packages.list non-free.list 2> /dev/null
725 tazpkg recharge
726 [ -n "$3" ] && while read action pkg; do
727 case "$action" in
728 +) yes | tazpkg get-install $pkg;;
729 -) yes | tazpkg remove $pkg;;
730 !) echo $pkg >> non-free.list;;
731 @) DESC="$pkg";;
732 \?) echo -en "$pkg"; read action;;
733 esac
734 done < $3
735 yes '' | tazlito gen-distro
736 echo "$DESC" | tazlito gen-flavor "$FLAVOR"
737 mv /etc/tazlito/distro-packages.list.$$ \
738 /etc/tazlito/distro-packages.list 2> /dev/null
739 ;;
740 gen-flavor)
741 # Generate a new flavor from the last iso image generated.
742 FLAVOR=${2%.flavor}
743 echo ""
744 echo -e "\033[1mFlavor generation\033[0m"
745 echo "================================================================================"
746 if [ -z "$FLAVOR" ]; then
747 echo -n "Flavor name : "
748 read FLAVOR
749 [ -z "$FLAVOR" ] && exit 1
750 fi
751 check_rootfs
752 FILES="$FLAVOR.pkglist"
753 echo -n "Creating file $FLAVOR.flavor..."
754 for i in rootcd rootfs; do
755 if [ -d "$ADDFILES/$i" ] ; then
756 FILES="$FILES\n$FLAVOR.$i"
757 ( cd "$ADDFILES/$i"; find . | \
758 cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
759 fi
760 done
761 status
762 answer=`grep -s ^Description $FLAVOR.desc`
763 answer=${answer#Description : }
764 if [ -z "$answer" ]; then
765 echo -n "Description : "
766 read answer
767 fi
768 echo -n "Compressing flavor $FLAVOR..."
769 echo "Flavor : $FLAVOR" > $FLAVOR.desc
770 echo "Description : $answer" >> $FLAVOR.desc
771 ( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
772 \rm -f $FLAVOR.pkglist $FLAVOR.nonfree 2> /dev/null
773 for i in $(ls $ROOTFS$INSTALLED); do
774 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
775 EXTRAVERSION=""
776 eval $(grep ^EXTRAVERSION= $ROOTFS$INSTALLED/$i/receipt)
777 eval $(grep ^CATEGORY= $ROOTFS$INSTALLED/$i/receipt)
778 if [ "$CATEGORY" = "non-free" -a "${i%%-*}" != "get" ]
779 then
780 echo "$i" >> $FLAVOR.nonfree
781 else
782 echo "$i-$VERSION$EXTRAVERSION" >> $FLAVOR.pkglist
783 fi
784 done
785 [ -s $FLAVOR.nonfree ] && $FILES="$FILES\n$FLAVOR.nonfree"
786 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
787 gzip -9 > $FLAVOR.flavor
788 rm `echo -e $FILES`
789 status
790 echo "================================================================================"
791 echo "Flavor size : `du -sh $FLAVOR.flavor`"
792 echo ""
793 ;;
794 upgrade-flavor)
795 # Update package list to the lastest versions available.
796 FLAVOR=${2%.flavor}
797 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
798 mkdir $TMP_DIR
799 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
800 echo -n "Update $FLAVOR package list..."
801 [ -s /var/lib/tazpkg/packages.list ] || tazpkg recharge
802 packed_size=0; unpacked_size=0
803 while read org; do
804 i=0
805 pkg=$org
806 while ! grep -q ^$pkg$ /var/lib/tazpkg/packages.txt; do
807 pkg=${pkg%-*}
808 i=$(($i + 1))
809 [ $i -gt 5 ] && break;
810 done
811 set -- $(get_size $pkg)
812 packed_size=$(( $packed_size + $1 ))
813 unpacked_size=$(( $unpacked_size + $2 ))
814 for i in $(grep ^$pkg /var/lib/tazpkg/packages.list); do
815 echo $i
816 break
817 done
818 done < $TMP_DIR/$FLAVOR.pkglist \
819 > $TMP_DIR/$FLAVOR.pkglist.$$
820 mv -f $TMP_DIR/$FLAVOR.pkglist.$$ $TMP_DIR/$FLAVOR.pkglist
821 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
822 packed_size=$(($packed_size \
823 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
824 unpacked_size=$(($unpacked_size \
825 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
826 fi
827 # Estimate lzma
828 packed_size=$(($packed_size * 2 / 3))
829 iso_size=$(( $packed_size + 26000 ))
830 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
831 iso_size=$(($iso_size \
832 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
833 fi
834 sed -i -e '/Image is ready/d' \
835 -e "s/Rootfs size\( *:\) \(.*\)/Rootfs size\1 $(cent2human $unpacked_size) (estimated)/" \
836 -e "s/Initramfs size\( *:\) \(.*\)/Initramfs size\1 $(cent2human $packed_size) (estimated)/" \
837 -e "s/ISO image size\( *:\) \(.*\)/ISO image size\1 $(cent2human $iso_size) (estimated)/" \
838 -e "s/date\( *:\) \(.*\)/date\1 $(date +%Y%m%d\ \at\ \%H:%M:%S)/" \
839 $TMP_DIR/$FLAVOR.desc
840 ( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
841 $FLAVOR.flavor
842 status
843 rm -Rf $TMP_DIR
844 fi
845 ;;
846 extract-flavor)
847 # Extract a flavor into $FLAVORS_REPOSITORY.
848 FLAVOR=${2%.flavor}
849 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
850 mkdir $TMP_DIR
851 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
852 echo -n "Extract $FLAVOR..."
853 rm -rf $FLAVORS_REPOSITORY/$FLAVOR 2> /dev/null
854 mkdir -p $FLAVORS_REPOSITORY/$FLAVOR
855 grep ^Description $TMP_DIR/$FLAVOR.desc | \
856 sed 's/.*: \(.*\)$/\1/' > \
857 $FLAVORS_REPOSITORY/$FLAVOR/desc.txt
858 for i in rootcd rootfs; do
859 [ -f $TMP_DIR/$FLAVOR.$i ] || continue
860 mkdir $FLAVORS_REPOSITORY/$FLAVOR/$i
861 zcat $TMP_DIR/$FLAVOR.$i | \
862 (cd $FLAVORS_REPOSITORY/$FLAVOR/$i; \
863 cpio -idm > /dev/null)
864 done
865 [ -s /var/lib/tazpkg/packages.list ] || tazpkg recharge
866 while read org; do
867 i=0
868 pkg=$org
869 while ! grep -q ^$pkg$ /var/lib/tazpkg/packages.txt; do
870 pkg=${pkg%-*}
871 i=$(($i + 1))
872 [ $i -gt 5 ] && break;
873 done
874 echo $pkg
875 done < $TMP_DIR/$FLAVOR.pkglist \
876 > $FLAVORS_REPOSITORY/$FLAVOR/pkglist.txt
877 status
878 rm -Rf $TMP_DIR
879 fi
880 ;;
881 pack-flavor)
882 # Create a flavor from $FLAVORS_REPOSITORY.
883 FLAVOR=${2%.flavor}
884 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/desc.txt ]; then
885 mkdir $TMP_DIR
886 echo -n "Create $FLAVOR..."
887 [ -s /var/lib/tazpkg/packages.list ] || tazpkg recharge
888 packed_size=0; unpacked_size=0
889 grep -v ^# $FLAVORS_REPOSITORY/$FLAVOR/pkglist.txt > \
890 $TMP_DIR/$FLAVOR.pkg
891 while read pkg; do
892 set -- $(get_size $pkg)
893 packed_size=$(( $packed_size + $1 ))
894 unpacked_size=$(( $unpacked_size + $2 ))
895 for i in $(grep ^$pkg /var/lib/tazpkg/packages.list); do
896 echo $i
897 break
898 done
899 done > $TMP_DIR/$FLAVOR.pkglist < $TMP_DIR/$FLAVOR.pkg
900 rm -f $TMP_DIR/$FLAVOR.pkg
901 for i in rootcd rootfs; do
902 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] || \
903 continue
904 ( cd $FLAVORS_REPOSITORY/$FLAVOR/$i ; find . | \
905 cpio -o -H newc ) | gzip -9 >$TMP_DIR/$FLAVOR.$i
906 done
907 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
908 packed_size=$(($packed_size \
909 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
910 unpacked_size=$(($unpacked_size \
911 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
912 fi
913 # Estimate lzma
914 packed_size=$(($packed_size * 2 / 3))
915 iso_size=$(( $packed_size + 26000 ))
916 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
917 iso_size=$(($iso_size \
918 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
919 fi
920 cat > $TMP_DIR/$FLAVOR.desc <<EOT
921 Flavor : $FLAVOR
922 Description : $(grep -v ^# $FLAVORS_REPOSITORY/$FLAVOR/desc.txt)
923 Build date : $(date +%Y%m%d\ \at\ \%H:%M:%S)
924 Packages : $(grep -v ^# $FLAVORS_REPOSITORY/$FLAVOR/pkglist.txt | wc -l)
925 Rootfs size : $(cent2human $unpacked_size) (estimated)
926 Initramfs size : $(cent2human $packed_size) (estimated)
927 ISO image size : $(cent2human $iso_size) (estimated)
928 ================================================================================
930 EOT
931 ( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
932 $FLAVOR.flavor
933 status
934 rm -Rf $TMP_DIR
935 else
936 echo "No $FLAVOR flavor in $FLAVORS_REPOSITORY."
937 fi
938 ;;
939 get-flavor)
940 # Get a flavor's files and prepare for gen-distro.
941 FLAVOR=${2%.flavor}
942 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
943 echo -n "Cleaning $DISTRO..."
944 rm -R $DISTRO 2> /dev/null
945 mkdir -p $DISTRO
946 status
947 mkdir $TMP_DIR
948 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i 2>/dev/null )
949 echo -n "Create distro-packages.list..."
950 mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
951 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
952 status
953 for i in rootcd rootfs; do
954 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
955 mkdir -p "$ADDFILES/$i"
956 zcat $TMP_DIR/$FLAVOR.$i | \
957 ( cd "$ADDFILES/$i"; cpio -id 2> /dev/null)
958 fi
959 done
960 echo -n "Update tazlito.conf..."
961 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
962 cat tazlito.conf | grep -v "^#VOLUM_NAME" | \
963 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
964 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
965 status
966 rm -Rf $TMP_DIR
967 fi
968 ;;
969 check-list)
970 # Use current packages list in $PWD by default.
971 DISTRO_PKGS_LIST=distro-packages.list
972 [ -d "$2" ] && DISTRO_PKGS_LIST=$2/distro-packages.list
973 [ -f "$2" ] && DISTRO_PKGS_LIST=$2
974 [ ! -f $DISTRO_PKGS_LIST ] && echo "No packages list found." && exit 0
975 echo ""
976 echo -e "\033[1mLiveCD packages list check\033[0m"
977 echo "================================================================================"
978 for pkg in `cat $DISTRO_PKGS_LIST`
979 do
980 if ! grep -q "$pkg" /var/lib/tazpkg/packages.list; then
981 echo "Update: $pkg"
982 up=$(($up + 1))
983 fi
984 done
985 [ -z $up ] && echo -e "List is up-to-date\n" && exit 0
986 echo "================================================================================"
987 echo -e "Updates: $up\n" ;;
988 gen-distro)
989 # Generate a live distro tree with a set of packages.
990 #
991 check_root
993 # Check if a package list was specified on cmdline.
994 LIST_NAME="distro-packages.list"
995 CDROM=""
996 while [ -n "$2" ]; do
997 case "$2" in
998 --iso=*)
999 CDROM="-o loop ${2#--iso=}"
1000 ;;
1001 --cdrom)
1002 CDROM="/dev/cdrom"
1003 ;;
1004 --force)
1005 DELETE_ROOTFS="true"
1006 ;;
1007 *) if [ ! -f "$2" ] ; then
1008 echo -e "\nUnable to find the specified packages list."
1009 echo -e "List name : $2\n"
1010 exit 1
1011 fi
1012 LIST_NAME=$2
1013 ;;
1014 esac
1015 shift
1016 done
1018 if [ -d $ROOTFS ] ; then
1019 # Delete $ROOTFS if --force is set on command line
1020 if [ ! -z $DELETE_ROOTFS ]; then
1021 rm -rf $ROOTFS
1022 unset $DELETE_ROOTFS
1023 else
1024 echo -e "\nA rootfs exists in : $DISTRO"
1025 echo -e "Please clean the distro tree or change directory path.\n"
1026 exit 0
1027 fi
1028 fi
1029 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
1030 # Build list with installed packages
1031 for i in $(ls $INSTALLED); do
1032 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
1033 EXTRAVERSION=""
1034 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
1035 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
1036 done
1037 fi
1038 # Exit if no list name.
1039 if [ ! -f "$LIST_NAME" ]; then
1040 echo -e "\nNo packages list found or specified. Please read the docs.\n"
1041 exit 0
1042 fi
1043 # Start generation.
1044 echo ""
1045 echo -e "\033[1mTazlito generating a distro\033[0m"
1046 echo "================================================================================"
1047 # Misc checks
1048 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
1049 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
1050 # Get the list of packages using cat for a file list.
1051 LIST=`cat $LIST_NAME`
1052 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
1053 REPACK=""
1054 DOWNLOAD=""
1055 for pkg in $LIST
1056 do
1057 [ "$pkg" = "" ] && continue
1058 pkg=${pkg%.tazpkg}
1059 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
1060 PACKAGE=$(installed_package_name $pkg)
1061 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
1062 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
1063 echo -e "\nUnable to find $pkg in the repository."
1064 echo -e "Path : $PACKAGES_REPOSITORY\n"
1065 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
1066 yesorno "Repack packages from rootfs (y/N) ? "
1067 REPACK="$answer"
1068 [ "$answer" = "y" ] || REPACK="n"
1069 [ "$DOWNLOAD" = "y" ] && break
1070 fi
1071 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
1072 yesorno "Download packages from mirror (Y/n) ? "
1073 DOWNLOAD="$answer"
1074 if [ "$answer" = "n" ]; then
1075 [ -z "$PACKAGE" ] && exit 1
1076 else
1077 DOWNLOAD="y"
1078 [ -n "$REPACK" ] && break
1079 fi
1080 fi
1081 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
1082 done
1084 # Mount cdrom to be able to repack boot-loader packages
1085 if [ ! -e /boot -a -n "$CDROM" ]; then
1086 mkdir $TMP_MNT
1087 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
1088 ln -s $TMP_MNT/boot /
1089 if [ ! -d "$ADDFILES/rootcd" ] ; then
1090 mkdir -p $ADDFILES/rootcd
1091 for i in $(ls $TMP_MNT); do
1092 [ "$i" = "boot" ] && continue
1093 cp -a $TMP_MNT/$i $ADDFILES/rootcd
1094 done
1095 fi
1096 else
1097 rmdir $TMP_MNT
1098 fi
1099 fi
1101 # Root fs stuff.
1102 echo "Preparing the rootfs directory..."
1103 mkdir -p $ROOTFS
1104 sleep 2
1105 for pkg in $LIST
1106 do
1107 [ "$pkg" = "" ] && continue
1108 # First copy and extract the package in tmp dir.
1109 pkg=${pkg%.tazpkg}
1110 PACKAGE=$(installed_package_name $pkg)
1111 mkdir -p $TMP_DIR
1112 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1113 # Look for package in cache
1114 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
1115 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
1116 # Look for package in running distribution
1117 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
1118 tazpkg repack $PACKAGE && \
1119 mv $pkg.tazpkg $PACKAGES_REPOSITORY
1120 fi
1121 fi
1122 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1123 # Get package from mirror
1124 [ "$DOWNLOAD" = "y" ] && \
1125 download $pkg.tazpkg && \
1126 mv $pkg.tazpkg $PACKAGES_REPOSITORY
1127 fi
1128 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1129 echo "Missing package $pkg."
1130 cleanup
1131 exit 1
1132 fi
1133 done
1134 if [ -f non-free.list ]; then
1135 echo "Preparing non-free packages..."
1136 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
1137 for pkg in $(cat non-free.list); do
1138 if [ ! -d $INSTALLED/$pkg ]; then
1139 if [ ! -d $INSTALLED/get-$pkg ]; then
1140 tazpkg get-install get-$pkg
1141 fi
1142 get-$pkg
1143 fi
1144 tazpkg repack $pkg
1145 pkg=$(ls $pkg*.tazpkg)
1146 grep -q "^$pkg$" $LIST_NAME || \
1147 echo $pkg >>$LIST_NAME
1148 mv $pkg $PACKAGES_REPOSITORY
1149 done
1150 fi
1151 echo ""
1152 cp $LIST_NAME $DISTRO/distro-packages.list
1153 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/distro-packages.list > $DISTRO/list-packages
1154 cd $PACKAGES_REPOSITORY
1155 yes y | tazpkg install-list \
1156 $DISTRO/list-packages --root=$ROOTFS
1157 cd $DISTRO
1158 cp distro-packages.list $ROOTFS/etc/tazlito
1159 # Copy all files from $ADDFILES/rootfs to the rootfs.
1160 if [ -d "$ADDFILES/rootfs" ] ; then
1161 echo -n "Copying addfiles content to the rootfs... "
1162 cp -a $ADDFILES/rootfs/* $ROOTFS
1163 status
1164 fi
1165 echo "Root file system is generated..."
1166 # Root CD part.
1167 echo -n "Preparing the rootcd directory..."
1168 mkdir -p $ROOTCD
1169 status
1170 # Move the boot dir with the Linux kernel from rootfs.
1171 # The boot dir goes directly on the CD.
1172 if [ -d "$ROOTFS/boot" ] ; then
1173 echo -n "Moving the boot directory..."
1174 mv $ROOTFS/boot $ROOTCD
1175 cd $ROOTCD/boot
1176 ln vmlinuz-* bzImage
1177 status
1178 fi
1179 cd $DISTRO
1180 # Copy all files from $ADDFILES/rootcd to the rootcd.
1181 if [ -d "$ADDFILES/rootcd" ] ; then
1182 echo -n "Copying addfiles content to the rootcd... "
1183 cp -a $ADDFILES/rootcd/* $ROOTCD
1184 status
1185 fi
1186 # Execute the distro script (used to perform tasks in the rootfs
1187 # before compression. Give rootfs path in arg
1188 [ -z $DISTRO_SCRIPT ] && DISTRO_SCRIPT=$TOP_DIR/distro.sh
1189 if [ -x $DISTRO_SCRIPT ]; then
1190 echo "Executing distro script..."
1191 sh $DISTRO_SCRIPT $DISTRO
1192 fi
1193 # Initramfs and ISO image stuff.
1194 gen_initramfs
1195 gen_livecd_isolinux
1196 distro_stats
1197 cleanup
1198 ;;
1199 clean-distro)
1200 # Remove old distro tree.
1202 check_root
1203 echo ""
1204 echo -e "\033[1mCleaning :\033[0m $DISTRO"
1205 echo "================================================================================"
1206 if [ -d "$DISTRO" ] ; then
1207 if [ -d "$ROOTFS" ] ; then
1208 echo -n "Removing the rootfs..."
1209 rm -f $DISTRO/$INITRAMFS
1210 rm -rf $ROOTFS
1211 status
1212 fi
1213 if [ -d "$ROOTCD" ] ; then
1214 echo -n "Removing the rootcd..."
1215 rm -rf $ROOTCD
1216 status
1217 fi
1218 echo -n "Removing eventual ISO image..."
1219 rm -f $DISTRO/$ISO_NAME.iso
1220 rm -f $DISTRO/$ISO_NAME.md5
1221 status
1222 fi
1223 echo "================================================================================"
1224 echo ""
1225 ;;
1226 check-distro)
1227 # Check for a few LiveCD needed files not installed by packages.
1229 check_rootfs
1230 echo ""
1231 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
1232 echo "================================================================================"
1233 # SliTaz release info.
1234 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
1235 echo "Missing release info : /etc/slitaz-release"
1236 else
1237 release=`cat $ROOTFS/etc/slitaz-release`
1238 echo -n "Release : $release"
1239 status
1240 fi
1241 # Tazpkg mirror.
1242 if [ ! -f "$ROOTFS/var/lib/tazpkg/mirror" ]; then
1243 echo -n "Mirror URL : Missing /var/lib/tazpkg/mirror"
1244 todomsg
1245 else
1246 echo -n "Mirror configuration exist..."
1247 status
1248 fi
1249 # Isolinux msg
1250 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.msg; then
1251 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
1252 todomsg
1253 else
1254 echo -n "Isolinux message seems good..."
1255 status
1256 fi
1257 echo "================================================================================"
1258 echo ""
1259 ;;
1260 burn-iso)
1261 # Guess cdrom device, ask user and burn the ISO.
1263 check_root
1264 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
1265 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
1266 # We can specify an alternative ISO from the cmdline.
1267 if [ -n "$2" ] ; then
1268 iso=$2
1269 else
1270 iso=$DISTRO/$ISO_NAME.iso
1271 fi
1272 if [ ! -f "$iso" ]; then
1273 echo -e "\nUnable to find ISO : $iso\n"
1274 exit 0
1275 fi
1276 echo ""
1277 echo -e "\033[1mTazlito burn ISO\033[0m "
1278 echo "================================================================================"
1279 echo "Cdrom device : /dev/$DRIVE_NAME"
1280 echo "Drive speed : $DRIVE_SPEED"
1281 echo "ISO image : $iso"
1282 echo "================================================================================"
1283 echo ""
1284 yesorno "Burn ISO image (y/N) ? "
1285 if [ "$answer" == "y" ]; then
1286 echo ""
1287 echo "Starting Wodim to burn the iso..." && sleep 2
1288 echo "================================================================================"
1289 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
1290 echo "================================================================================"
1291 echo "ISO image is burned to cdrom."
1292 else
1293 echo -e "\nExiting. No ISO burned."
1294 fi
1295 echo ""
1296 ;;
1297 merge)
1298 # Merge multiple rootfs into one iso.
1300 if [ -z "$2" ]; then
1301 cat << EOT
1302 Usage: tazlito merge size1 iso size2 rootfs2 [sizeN rootfsN]...
1304 Merge multiple rootfs into one iso. Rootfs are like russian dolls
1305 i.e: rootfsN is a subset of rootfsN-1
1306 rootfs1 is found in iso, sizeN is the RAM size need to launch rootfsN.
1307 The boot loader will select the rootfs according to the RAM size detected.
1309 Example:
1310 $ tazlito merge 160M slitaz-core.iso 96M rootfs-justx.gz 32M rootfs-base.gz
1312 Will start slitaz-core with 160M+ RAM, slitaz-justX with 96M-160M RAM,
1313 slitaz-base with 32M-96M RAM and display an error message if RAM < 32M.
1314 EOT
1315 exit 2
1316 fi
1318 shift # skip merge
1319 append="append $(( (${1%M} - 3) * 1024 )) slitaz1"
1320 shift # skip size1
1321 mkdir -p $TMP_DIR/mnt $TMP_DIR/rootfs1
1323 ISO=$1.merged
1324 # Extract filesystems
1325 echo -n "Mount $1"
1326 mount -o loop,ro $1 $TMP_DIR/mnt 2> /dev/null
1327 status || cleanup_merge
1328 cp -a $TMP_DIR/mnt $TMP_DIR/iso
1329 rm -f $TMP_DIR/iso/boot/bzImage
1330 ln $TMP_DIR/iso/boot/vmlinuz* $TMP_DIR/iso/boot/bzImage
1331 umount -d $TMP_DIR/mnt
1332 if [ -f $TMP_DIR/iso/boot/rootfs1.gz ]; then
1333 echo "$1 is already a merged iso. Abort."
1334 cleanup_merge
1335 fi
1336 if [ ! -f $TMP_DIR/iso/boot/isolinux/ifmem.c32 ]; then
1337 if [ ! -f /boot/isolinux/ifmem.c32 ]; then
1338 cat <<EOT
1339 No file /boot/isolinux/ifmem.c32
1340 Please install syslinux package !
1341 EOT
1342 rm -rf $TMP_DIR
1343 exit 1
1344 fi
1345 cp /boot/isolinux/ifmem.c32 $TMP_DIR/iso/boot/isolinux
1346 fi
1348 echo -n "Extract iso/rootfs.gz"
1349 extract_rootfs $TMP_DIR/iso/boot/rootfs.gz $TMP_DIR/rootfs1 &&
1350 [ -d $TMP_DIR/rootfs1/etc ]
1351 status || cleanup_merge
1352 n=1
1353 while [ -n "$2" ]; do
1354 shift # skip rootfs N-1
1355 p=$n
1356 n=$(($n + 1))
1357 append="$append $(( (${1%M} - 3) * 1024 )) slitaz$n"
1358 shift # skip size N
1359 mkdir -p $TMP_DIR/rootfs$n
1360 echo -n "Extract $1"
1361 extract_rootfs $1 $TMP_DIR/rootfs$n &&
1362 [ -d $TMP_DIR/rootfs$n/etc ]
1363 status || cleanup_merge
1364 echo -n "Merge rootfs$n into rootfs$p"
1365 mergefs $TMP_DIR/rootfs$n $TMP_DIR/rootfs$p
1366 status
1367 echo "Create rootfs$p.gz"
1368 pack_rootfs $TMP_DIR/rootfs$p $TMP_DIR/iso/boot/rootfs$p.gz
1369 status
1370 done
1371 echo "Create rootfs$n.gz"
1372 pack_rootfs $TMP_DIR/rootfs$n $TMP_DIR/iso/boot/rootfs$n.gz
1373 status
1374 rm -f $TMP_DIR/iso/boot/rootfs.gz
1376 echo -n "Update boot files"
1377 grep -l 'include common' $TMP_DIR/iso/boot/isolinux/*.cfg | \
1378 while read file ; do
1379 awk -v n=$n '{
1380 if (/label/) label=$0;
1381 else if (/kernel/) kernel=$0;
1382 else if (/append/) {
1383 i=index($0,"rootfs.gz");
1384 append=substr($0,i+9);
1386 else if (/include/) {
1387 for (i = 1; i <= n; i++) {
1388 print label i
1389 print kernel;
1390 initrd="initrd=/boot/rootfs" n ".gz"
1391 for (j = n - 1; j >= i; j--) {
1392 initrd=initrd ",/boot/rootfs" j ".gz";
1394 printf "\tappend %s%s\n",initrd,append;
1395 print "";
1397 print;
1399 else print;
1400 }' < $file > $file.$$
1401 mv -f $file.$$ $file
1402 done
1403 cat >> $TMP_DIR/iso/boot/isolinux/common.cfg <<EOT
1404 label slitaz
1405 kernel /boot/isolinux/ifmem.c32
1406 $append noram
1408 label noram
1409 config noram.cfg
1411 EOT
1412 cat >> $TMP_DIR/iso/boot/isolinux/noram.cfg <<EOT
1413 display isolinux.msg
1414 say Not enough RAM to boot slitaz.
1415 default reboot
1416 label reboot
1417 com32 reboot.c32
1419 implicit 0
1420 prompt 1
1421 timeout 80
1422 F1 help.txt
1423 F2 options.txt
1424 F3 isolinux.msg
1425 F4 display.txt
1426 F5 enhelp.txt
1427 F6 enopts.txt
1428 EOT
1429 status
1430 echo "Generate $ISO"
1431 create_iso $ISO $TMP_DIR/iso
1432 rm -rf $TMP_DIR
1433 ;;
1435 repack)
1436 # Repack an iso with maximum lzma compression ratio.
1439 ISO=$2
1441 mkdir -p $TMP_DIR/mnt
1442 # Extract filesystems
1443 echo -n "Mount $ISO"
1444 mount -o loop,ro $ISO $TMP_DIR/mnt 2> /dev/null
1445 status || cleanup_merge
1446 cp -a $TMP_DIR/mnt $TMP_DIR/iso
1447 umount -d $TMP_DIR/mnt
1449 for i in $TMP_DIR/iso/boot/rootfs* ; do
1450 echo -n "Repack $(basename $i)"
1451 (zcat $i || unlzma -c $i || cat $i) \
1452 2>/dev/null > $TMP_DIR/rootfs
1453 lzma e $TMP_DIR/rootfs $i \
1454 -d$(lzma_history_bits $TMP_DIR/rootfs)
1455 status
1456 done
1458 echo "Generate $ISO"
1459 create_iso $ISO $TMP_DIR/iso
1460 rm -rf $TMP_DIR
1461 ;;
1463 usage|*)
1464 # Clear and print usage also for all unknown commands.
1466 clear
1467 usage
1468 ;;
1470 esac
1472 exit 0