tazlito view tazlito @ rev 109

Add mirror in flavors
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Sep 01 18:38:45 2009 +0200 (2009-09-01)
parents d2375d0fa398
children 536536d6001a
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 > /dev/null )
680 if [ "$3" = "--brief" ]; then
681 if [ "$4" != "--noheader" ]; then
682 echo "Name ISO Rootfs Description"
683 echo "================================================================================"
684 fi
685 printf "%-16.16s %6.6s %6.6s %s\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 for i in $LOCALSTATE/undigest/*/mirror ; do
787 [ -s $i ] && cat $i >> $FLAVOR.mirrors
788 done
789 [ -s $FLAVOR.mirrors ] && $FILES="$FILES\n$FLAVOR.mirrors"
790 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
791 gzip -9 > $FLAVOR.flavor
792 rm `echo -e $FILES`
793 status
794 echo "================================================================================"
795 echo "Flavor size : `du -sh $FLAVOR.flavor`"
796 echo ""
797 ;;
798 upgrade-flavor)
799 # Update package list to the lastest versions available.
800 FLAVOR=${2%.flavor}
801 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
802 mkdir $TMP_DIR
803 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
804 echo -n "Update $FLAVOR package list..."
805 [ -s /var/lib/tazpkg/packages.list ] || tazpkg recharge
806 packed_size=0; unpacked_size=0
807 while read org; do
808 i=0
809 pkg=$org
810 while ! grep -q ^$pkg$ /var/lib/tazpkg/packages.txt; do
811 pkg=${pkg%-*}
812 i=$(($i + 1))
813 [ $i -gt 5 ] && break;
814 done
815 set -- $(get_size $pkg)
816 packed_size=$(( $packed_size + $1 ))
817 unpacked_size=$(( $unpacked_size + $2 ))
818 for i in $(grep ^$pkg /var/lib/tazpkg/packages.list); do
819 echo $i
820 break
821 done
822 done < $TMP_DIR/$FLAVOR.pkglist \
823 > $TMP_DIR/$FLAVOR.pkglist.$$
824 mv -f $TMP_DIR/$FLAVOR.pkglist.$$ $TMP_DIR/$FLAVOR.pkglist
825 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
826 packed_size=$(($packed_size \
827 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
828 unpacked_size=$(($unpacked_size \
829 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
830 fi
831 # Estimate lzma
832 packed_size=$(($packed_size * 2 / 3))
833 iso_size=$(( $packed_size + 26000 ))
834 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
835 iso_size=$(($iso_size \
836 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
837 fi
838 sed -i -e '/Image is ready/d' \
839 -e "s/Rootfs size\( *:\) \(.*\)/Rootfs size\1 $(cent2human $unpacked_size) (estimated)/" \
840 -e "s/Initramfs size\( *:\) \(.*\)/Initramfs size\1 $(cent2human $packed_size) (estimated)/" \
841 -e "s/ISO image size\( *:\) \(.*\)/ISO image size\1 $(cent2human $iso_size) (estimated)/" \
842 -e "s/date\( *:\) \(.*\)/date\1 $(date +%Y%m%d\ \at\ \%H:%M:%S)/" \
843 $TMP_DIR/$FLAVOR.desc
844 ( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
845 $FLAVOR.flavor
846 status
847 rm -Rf $TMP_DIR
848 fi
849 ;;
850 extract-flavor)
851 # Extract a flavor into $FLAVORS_REPOSITORY.
852 FLAVOR=${2%.flavor}
853 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
854 mkdir $TMP_DIR
855 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
856 echo -n "Extract $FLAVOR..."
857 rm -rf $FLAVORS_REPOSITORY/$FLAVOR 2> /dev/null
858 mkdir -p $FLAVORS_REPOSITORY/$FLAVOR
859 echo "FLAVOR=\"$FLAVOR\"" > $FLAVORS_REPOSITORY/$FLAVOR/receipt
860 grep ^Description $TMP_DIR/$FLAVOR.desc | \
861 sed 's/.*: \(.*\)$/SHORT_DESC="\1"/' >> \
862 $FLAVORS_REPOSITORY/$FLAVOR/receipt
863 grep ^Rootfs $TMP_DIR/$FLAVOR.desc | \
864 sed 's/.*: \(.*\)$/ROOTFS_SIZE="\1"/' >> \
865 $FLAVORS_REPOSITORY/$FLAVOR/receipt
866 grep ^Initramfs $TMP_DIR/$FLAVOR.desc | \
867 sed 's/.*: \(.*\)$/INITRAMFS_SIZE="\1"/' >> \
868 $FLAVORS_REPOSITORY/$FLAVOR/receipt
869 grep ^ISO $TMP_DIR/$FLAVOR.desc | \
870 sed 's/.*: \(.*\)$/ISO_SIZE="\1"/' >> \
871 $FLAVORS_REPOSITORY/$FLAVOR/receipt
872 for i in rootcd rootfs; do
873 [ -f $TMP_DIR/$FLAVOR.$i ] || continue
874 mkdir $FLAVORS_REPOSITORY/$FLAVOR/$i
875 zcat $TMP_DIR/$FLAVOR.$i | \
876 (cd $FLAVORS_REPOSITORY/$FLAVOR/$i; \
877 cpio -idm > /dev/null)
878 done
879 [ -s $TMP_DIR/$FLAVOR.mirrors ] &&
880 cp $TMP_DIR/$FLAVOR.mirrors \
881 $FLAVORS_REPOSITORY/$FLAVOR/mirrors
882 [ -s /var/lib/tazpkg/packages.list ] || tazpkg recharge
883 while read org; do
884 i=0
885 pkg=$org
886 while ! grep -q ^$pkg$ /var/lib/tazpkg/packages.txt; do
887 pkg=${pkg%-*}
888 i=$(($i + 1))
889 [ $i -gt 5 ] && break;
890 done
891 echo $pkg
892 done < $TMP_DIR/$FLAVOR.pkglist \
893 > $FLAVORS_REPOSITORY/$FLAVOR/packages.list
894 status
895 rm -Rf $TMP_DIR
896 fi
897 ;;
898 pack-flavor)
899 # Create a flavor from $FLAVORS_REPOSITORY.
900 FLAVOR=${2%.flavor}
901 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/receipt ]; then
902 mkdir $TMP_DIR
903 echo -n "Create $FLAVOR..."
904 [ -s /var/lib/tazpkg/packages.list ] || tazpkg recharge
905 [ -s $FLAVORS_REPOSITORY/$FLAVOR/mirrors ] &&
906 cp $FLAVORS_REPOSITORY/$FLAVOR/mirrors \
907 $TMP_DIR/$FLAVOR.mirrors
908 packed_size=0; unpacked_size=0
909 grep -v ^# $FLAVORS_REPOSITORY/$FLAVOR/packages.list > \
910 $TMP_DIR/$FLAVOR.pkg
911 while read pkg; do
912 set -- $(get_size $pkg)
913 packed_size=$(( $packed_size + $1 ))
914 unpacked_size=$(( $unpacked_size + $2 ))
915 for i in $(grep ^$pkg /var/lib/tazpkg/packages.list); do
916 echo $i
917 break
918 done
919 done > $TMP_DIR/$FLAVOR.pkglist < $TMP_DIR/$FLAVOR.pkg
920 rm -f $TMP_DIR/$FLAVOR.pkg
921 for i in rootcd rootfs; do
922 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] || \
923 continue
924 ( cd $FLAVORS_REPOSITORY/$FLAVOR/$i ; find . | \
925 cpio -o -H newc ) | gzip -9 >$TMP_DIR/$FLAVOR.$i
926 done
927 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
928 packed_size=$(($packed_size \
929 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
930 unpacked_size=$(($unpacked_size \
931 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
932 fi
933 # Estimate lzma
934 packed_size=$(($packed_size * 2 / 3))
935 iso_size=$(( $packed_size + 26000 ))
936 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
937 iso_size=$(($iso_size \
938 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
939 fi
940 VERSION=""
941 MAINTAINER=""
942 ROOTFS_SIZE="$(cent2human $unpacked_size) (estimated)"
943 INITRAMFS_SIZE="$(cent2human $packed_size) (estimated)"
944 ISO_SIZE="$(cent2human $iso_size) (estimated)"
945 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
946 cat > $TMP_DIR/$FLAVOR.desc <<EOT
947 Flavor : $FLAVOR
948 Description : $SHORT_DESC
949 EOT
950 [ -n "$VERSION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
951 Version : $VERSION
952 EOT
953 [ -n "$MAINTAINER" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
954 Maintainer : $MAINTAINER
955 EOT
956 [ -n "$FRUGAL_RAM" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
957 LiveCD RAM size : $FRUGAL_RAM
958 EOT
959 cat >> $TMP_DIR/$FLAVOR.desc <<EOT
960 Build date : $(date +%Y%m%d\ \at\ \%H:%M:%S)
961 Packages : $(grep -v ^# $FLAVORS_REPOSITORY/$FLAVOR/packages.list | wc -l)
962 Rootfs size : $ROOTFS_SIZE
963 Initramfs size : $INITRAMFS_SIZE
964 ISO image size : $ISO_SIZE
965 ================================================================================
967 EOT
968 ( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
969 $FLAVOR.flavor
970 status
971 rm -Rf $TMP_DIR
972 else
973 echo "No $FLAVOR flavor in $FLAVORS_REPOSITORY."
974 fi
975 ;;
976 get-flavor)
977 # Get a flavor's files and prepare for gen-distro.
978 FLAVOR=${2%.flavor}
979 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
980 echo -n "Cleaning $DISTRO..."
981 rm -R $DISTRO 2> /dev/null
982 mkdir -p $DISTRO
983 status
984 mkdir $TMP_DIR
985 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i 2>/dev/null )
986 echo -n "Create distro-packages.list..."
987 mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
988 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
989 status
990 for i in rootcd rootfs; do
991 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
992 echo -n "Add $i..."
993 mkdir -p "$ADDFILES/$i"
994 zcat $TMP_DIR/$FLAVOR.$i | \
995 ( cd "$ADDFILES/$i"; cpio -id 2> /dev/null)
996 status
997 fi
998 done
999 if [ -s $TMP_DIR/$FLAVOR.mirrors ]; then
1000 n=""
1001 while read line; do
1002 mkdir -p $LOCALSTATE/undigest/$FLAVOR$n
1003 echo "$line" > $LOCALSTATE/undigest/$FLAVOR$n/mirror
1004 n=$(( $n + 1 ))
1005 done < $TMP_DIR/$FLAVOR.mirrors
1006 tazpkg recharge
1007 fi
1008 echo -n "Update tazlito.conf..."
1009 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
1010 cat tazlito.conf | grep -v "^#VOLUM_NAME" | \
1011 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
1012 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
1013 status
1014 rm -Rf $TMP_DIR
1015 fi
1016 ;;
1017 check-list)
1018 # Use current packages list in $PWD by default.
1019 DISTRO_PKGS_LIST=distro-packages.list
1020 [ -d "$2" ] && DISTRO_PKGS_LIST=$2/distro-packages.list
1021 [ -f "$2" ] && DISTRO_PKGS_LIST=$2
1022 [ ! -f $DISTRO_PKGS_LIST ] && echo "No packages list found." && exit 0
1023 echo ""
1024 echo -e "\033[1mLiveCD packages list check\033[0m"
1025 echo "================================================================================"
1026 for pkg in `cat $DISTRO_PKGS_LIST`
1027 do
1028 if ! grep -q "$pkg" /var/lib/tazpkg/packages.list; then
1029 echo "Update: $pkg"
1030 up=$(($up + 1))
1031 fi
1032 done
1033 [ -z $up ] && echo -e "List is up-to-date\n" && exit 0
1034 echo "================================================================================"
1035 echo -e "Updates: $up\n" ;;
1036 gen-distro)
1037 # Generate a live distro tree with a set of packages.
1039 check_root
1041 # Check if a package list was specified on cmdline.
1042 LIST_NAME="distro-packages.list"
1043 CDROM=""
1044 while [ -n "$2" ]; do
1045 case "$2" in
1046 --iso=*)
1047 CDROM="-o loop ${2#--iso=}"
1048 ;;
1049 --cdrom)
1050 CDROM="/dev/cdrom"
1051 ;;
1052 --force)
1053 DELETE_ROOTFS="true"
1054 ;;
1055 *) if [ ! -f "$2" ] ; then
1056 echo -e "\nUnable to find the specified packages list."
1057 echo -e "List name : $2\n"
1058 exit 1
1059 fi
1060 LIST_NAME=$2
1061 ;;
1062 esac
1063 shift
1064 done
1066 if [ -d $ROOTFS ] ; then
1067 # Delete $ROOTFS if --force is set on command line
1068 if [ ! -z $DELETE_ROOTFS ]; then
1069 rm -rf $ROOTFS
1070 unset $DELETE_ROOTFS
1071 else
1072 echo -e "\nA rootfs exists in : $DISTRO"
1073 echo -e "Please clean the distro tree or change directory path.\n"
1074 exit 0
1075 fi
1076 fi
1077 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
1078 # Build list with installed packages
1079 for i in $(ls $INSTALLED); do
1080 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
1081 EXTRAVERSION=""
1082 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
1083 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
1084 done
1085 fi
1086 # Exit if no list name.
1087 if [ ! -f "$LIST_NAME" ]; then
1088 echo -e "\nNo packages list found or specified. Please read the docs.\n"
1089 exit 0
1090 fi
1091 # Start generation.
1092 echo ""
1093 echo -e "\033[1mTazlito generating a distro\033[0m"
1094 echo "================================================================================"
1095 # Misc checks
1096 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
1097 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
1098 # Get the list of packages using cat for a file list.
1099 LIST=`cat $LIST_NAME`
1100 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
1101 REPACK=""
1102 DOWNLOAD=""
1103 for pkg in $LIST
1104 do
1105 [ "$pkg" = "" ] && continue
1106 pkg=${pkg%.tazpkg}
1107 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
1108 PACKAGE=$(installed_package_name $pkg)
1109 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
1110 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
1111 echo -e "\nUnable to find $pkg in the repository."
1112 echo -e "Path : $PACKAGES_REPOSITORY\n"
1113 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
1114 yesorno "Repack packages from rootfs (y/N) ? "
1115 REPACK="$answer"
1116 [ "$answer" = "y" ] || REPACK="n"
1117 [ "$DOWNLOAD" = "y" ] && break
1118 fi
1119 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
1120 yesorno "Download packages from mirror (Y/n) ? "
1121 DOWNLOAD="$answer"
1122 if [ "$answer" = "n" ]; then
1123 [ -z "$PACKAGE" ] && exit 1
1124 else
1125 DOWNLOAD="y"
1126 [ -n "$REPACK" ] && break
1127 fi
1128 fi
1129 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
1130 done
1132 # Mount cdrom to be able to repack boot-loader packages
1133 if [ ! -e /boot -a -n "$CDROM" ]; then
1134 mkdir $TMP_MNT
1135 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
1136 ln -s $TMP_MNT/boot /
1137 if [ ! -d "$ADDFILES/rootcd" ] ; then
1138 mkdir -p $ADDFILES/rootcd
1139 for i in $(ls $TMP_MNT); do
1140 [ "$i" = "boot" ] && continue
1141 cp -a $TMP_MNT/$i $ADDFILES/rootcd
1142 done
1143 fi
1144 else
1145 rmdir $TMP_MNT
1146 fi
1147 fi
1149 # Root fs stuff.
1150 echo "Preparing the rootfs directory..."
1151 mkdir -p $ROOTFS
1152 sleep 2
1153 for pkg in $LIST
1154 do
1155 [ "$pkg" = "" ] && continue
1156 # First copy and extract the package in tmp dir.
1157 pkg=${pkg%.tazpkg}
1158 PACKAGE=$(installed_package_name $pkg)
1159 mkdir -p $TMP_DIR
1160 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1161 # Look for package in cache
1162 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
1163 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
1164 # Look for package in running distribution
1165 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
1166 tazpkg repack $PACKAGE && \
1167 mv $pkg.tazpkg $PACKAGES_REPOSITORY
1168 fi
1169 fi
1170 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1171 # Get package from mirror
1172 [ "$DOWNLOAD" = "y" ] && \
1173 download $pkg.tazpkg && \
1174 mv $pkg.tazpkg $PACKAGES_REPOSITORY
1175 fi
1176 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1177 echo "Missing package $pkg."
1178 cleanup
1179 exit 1
1180 fi
1181 done
1182 if [ -f non-free.list ]; then
1183 echo "Preparing non-free packages..."
1184 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
1185 for pkg in $(cat non-free.list); do
1186 if [ ! -d $INSTALLED/$pkg ]; then
1187 if [ ! -d $INSTALLED/get-$pkg ]; then
1188 tazpkg get-install get-$pkg
1189 fi
1190 get-$pkg
1191 fi
1192 tazpkg repack $pkg
1193 pkg=$(ls $pkg*.tazpkg)
1194 grep -q "^$pkg$" $LIST_NAME || \
1195 echo $pkg >>$LIST_NAME
1196 mv $pkg $PACKAGES_REPOSITORY
1197 done
1198 fi
1199 echo ""
1200 cp $LIST_NAME $DISTRO/distro-packages.list
1201 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/distro-packages.list > $DISTRO/list-packages
1202 cd $PACKAGES_REPOSITORY
1203 yes y | tazpkg install-list \
1204 $DISTRO/list-packages --root=$ROOTFS
1205 cd $DISTRO
1206 cp distro-packages.list $ROOTFS/etc/tazlito
1207 # Copy all files from $ADDFILES/rootfs to the rootfs.
1208 if [ -d "$ADDFILES/rootfs" ] ; then
1209 echo -n "Copying addfiles content to the rootfs... "
1210 cp -a $ADDFILES/rootfs/* $ROOTFS
1211 status
1212 fi
1213 echo "Root file system is generated..."
1214 # Root CD part.
1215 echo -n "Preparing the rootcd directory..."
1216 mkdir -p $ROOTCD
1217 status
1218 # Move the boot dir with the Linux kernel from rootfs.
1219 # The boot dir goes directly on the CD.
1220 if [ -d "$ROOTFS/boot" ] ; then
1221 echo -n "Moving the boot directory..."
1222 mv $ROOTFS/boot $ROOTCD
1223 cd $ROOTCD/boot
1224 ln vmlinuz-* bzImage
1225 status
1226 fi
1227 cd $DISTRO
1228 # Copy all files from $ADDFILES/rootcd to the rootcd.
1229 if [ -d "$ADDFILES/rootcd" ] ; then
1230 echo -n "Copying addfiles content to the rootcd... "
1231 cp -a $ADDFILES/rootcd/* $ROOTCD
1232 status
1233 fi
1234 # Execute the distro script (used to perform tasks in the rootfs
1235 # before compression. Give rootfs path in arg
1236 [ -z $DISTRO_SCRIPT ] && DISTRO_SCRIPT=$TOP_DIR/distro.sh
1237 if [ -x $DISTRO_SCRIPT ]; then
1238 echo "Executing distro script..."
1239 sh $DISTRO_SCRIPT $DISTRO
1240 fi
1241 # Initramfs and ISO image stuff.
1242 gen_initramfs
1243 gen_livecd_isolinux
1244 distro_stats
1245 cleanup
1246 ;;
1247 clean-distro)
1248 # Remove old distro tree.
1250 check_root
1251 echo ""
1252 echo -e "\033[1mCleaning :\033[0m $DISTRO"
1253 echo "================================================================================"
1254 if [ -d "$DISTRO" ] ; then
1255 if [ -d "$ROOTFS" ] ; then
1256 echo -n "Removing the rootfs..."
1257 rm -f $DISTRO/$INITRAMFS
1258 rm -rf $ROOTFS
1259 status
1260 fi
1261 if [ -d "$ROOTCD" ] ; then
1262 echo -n "Removing the rootcd..."
1263 rm -rf $ROOTCD
1264 status
1265 fi
1266 echo -n "Removing eventual ISO image..."
1267 rm -f $DISTRO/$ISO_NAME.iso
1268 rm -f $DISTRO/$ISO_NAME.md5
1269 status
1270 fi
1271 echo "================================================================================"
1272 echo ""
1273 ;;
1274 check-distro)
1275 # Check for a few LiveCD needed files not installed by packages.
1277 check_rootfs
1278 echo ""
1279 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
1280 echo "================================================================================"
1281 # SliTaz release info.
1282 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
1283 echo "Missing release info : /etc/slitaz-release"
1284 else
1285 release=`cat $ROOTFS/etc/slitaz-release`
1286 echo -n "Release : $release"
1287 status
1288 fi
1289 # Tazpkg mirror.
1290 if [ ! -f "$ROOTFS/var/lib/tazpkg/mirror" ]; then
1291 echo -n "Mirror URL : Missing /var/lib/tazpkg/mirror"
1292 todomsg
1293 else
1294 echo -n "Mirror configuration exist..."
1295 status
1296 fi
1297 # Isolinux msg
1298 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.msg; then
1299 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
1300 todomsg
1301 else
1302 echo -n "Isolinux message seems good..."
1303 status
1304 fi
1305 echo "================================================================================"
1306 echo ""
1307 ;;
1308 burn-iso)
1309 # Guess cdrom device, ask user and burn the ISO.
1311 check_root
1312 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
1313 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
1314 # We can specify an alternative ISO from the cmdline.
1315 if [ -n "$2" ] ; then
1316 iso=$2
1317 else
1318 iso=$DISTRO/$ISO_NAME.iso
1319 fi
1320 if [ ! -f "$iso" ]; then
1321 echo -e "\nUnable to find ISO : $iso\n"
1322 exit 0
1323 fi
1324 echo ""
1325 echo -e "\033[1mTazlito burn ISO\033[0m "
1326 echo "================================================================================"
1327 echo "Cdrom device : /dev/$DRIVE_NAME"
1328 echo "Drive speed : $DRIVE_SPEED"
1329 echo "ISO image : $iso"
1330 echo "================================================================================"
1331 echo ""
1332 yesorno "Burn ISO image (y/N) ? "
1333 if [ "$answer" == "y" ]; then
1334 echo ""
1335 echo "Starting Wodim to burn the iso..." && sleep 2
1336 echo "================================================================================"
1337 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
1338 echo "================================================================================"
1339 echo "ISO image is burned to cdrom."
1340 else
1341 echo -e "\nExiting. No ISO burned."
1342 fi
1343 echo ""
1344 ;;
1345 merge)
1346 # Merge multiple rootfs into one iso.
1348 if [ -z "$2" ]; then
1349 cat << EOT
1350 Usage: tazlito merge size1 iso size2 rootfs2 [sizeN rootfsN]...
1352 Merge multiple rootfs into one iso. Rootfs are like russian dolls
1353 i.e: rootfsN is a subset of rootfsN-1
1354 rootfs1 is found in iso, sizeN is the RAM size need to launch rootfsN.
1355 The boot loader will select the rootfs according to the RAM size detected.
1357 Example:
1358 $ tazlito merge 160M slitaz-core.iso 96M rootfs-justx.gz 32M rootfs-base.gz
1360 Will start slitaz-core with 160M+ RAM, slitaz-justX with 96M-160M RAM,
1361 slitaz-base with 32M-96M RAM and display an error message if RAM < 32M.
1362 EOT
1363 exit 2
1364 fi
1366 shift # skip merge
1367 append="append $(( (${1%M} - 3) * 1024 )) slitaz1"
1368 shift # skip size1
1369 mkdir -p $TMP_DIR/mnt $TMP_DIR/rootfs1
1371 ISO=$1.merged
1372 # Extract filesystems
1373 echo -n "Mount $1"
1374 mount -o loop,ro $1 $TMP_DIR/mnt 2> /dev/null
1375 status || cleanup_merge
1376 cp -a $TMP_DIR/mnt $TMP_DIR/iso
1377 rm -f $TMP_DIR/iso/boot/bzImage
1378 ln $TMP_DIR/iso/boot/vmlinuz* $TMP_DIR/iso/boot/bzImage
1379 umount -d $TMP_DIR/mnt
1380 if [ -f $TMP_DIR/iso/boot/rootfs1.gz ]; then
1381 echo "$1 is already a merged iso. Abort."
1382 cleanup_merge
1383 fi
1384 if [ ! -f $TMP_DIR/iso/boot/isolinux/ifmem.c32 ]; then
1385 if [ ! -f /boot/isolinux/ifmem.c32 ]; then
1386 cat <<EOT
1387 No file /boot/isolinux/ifmem.c32
1388 Please install syslinux package !
1389 EOT
1390 rm -rf $TMP_DIR
1391 exit 1
1392 fi
1393 cp /boot/isolinux/ifmem.c32 $TMP_DIR/iso/boot/isolinux
1394 fi
1396 echo -n "Extract iso/rootfs.gz"
1397 extract_rootfs $TMP_DIR/iso/boot/rootfs.gz $TMP_DIR/rootfs1 &&
1398 [ -d $TMP_DIR/rootfs1/etc ]
1399 status || cleanup_merge
1400 n=1
1401 while [ -n "$2" ]; do
1402 shift # skip rootfs N-1
1403 p=$n
1404 n=$(($n + 1))
1405 append="$append $(( (${1%M} - 3) * 1024 )) slitaz$n"
1406 shift # skip size N
1407 mkdir -p $TMP_DIR/rootfs$n
1408 echo -n "Extract $1"
1409 extract_rootfs $1 $TMP_DIR/rootfs$n &&
1410 [ -d $TMP_DIR/rootfs$n/etc ]
1411 status || cleanup_merge
1412 echo -n "Merge rootfs$n into rootfs$p"
1413 mergefs $TMP_DIR/rootfs$n $TMP_DIR/rootfs$p
1414 status
1415 echo "Create rootfs$p.gz"
1416 pack_rootfs $TMP_DIR/rootfs$p $TMP_DIR/iso/boot/rootfs$p.gz
1417 status
1418 done
1419 echo "Create rootfs$n.gz"
1420 pack_rootfs $TMP_DIR/rootfs$n $TMP_DIR/iso/boot/rootfs$n.gz
1421 status
1422 rm -f $TMP_DIR/iso/boot/rootfs.gz
1424 echo -n "Update boot files"
1425 grep -l 'include common' $TMP_DIR/iso/boot/isolinux/*.cfg | \
1426 while read file ; do
1427 awk -v n=$n '{
1428 if (/label/) label=$0;
1429 else if (/kernel/) kernel=$0;
1430 else if (/append/) {
1431 i=index($0,"rootfs.gz");
1432 append=substr($0,i+9);
1434 else if (/include/) {
1435 for (i = 1; i <= n; i++) {
1436 print label i
1437 print kernel;
1438 initrd="initrd=/boot/rootfs" n ".gz"
1439 for (j = n - 1; j >= i; j--) {
1440 initrd=initrd ",/boot/rootfs" j ".gz";
1442 printf "\tappend %s%s\n",initrd,append;
1443 print "";
1445 print;
1447 else print;
1448 }' < $file > $file.$$
1449 mv -f $file.$$ $file
1450 done
1451 cat >> $TMP_DIR/iso/boot/isolinux/common.cfg <<EOT
1452 label slitaz
1453 kernel /boot/isolinux/ifmem.c32
1454 $append noram
1456 label noram
1457 config noram.cfg
1459 EOT
1460 cat >> $TMP_DIR/iso/boot/isolinux/noram.cfg <<EOT
1461 display isolinux.msg
1462 say Not enough RAM to boot slitaz.
1463 default reboot
1464 label reboot
1465 com32 reboot.c32
1467 implicit 0
1468 prompt 1
1469 timeout 80
1470 F1 help.txt
1471 F2 options.txt
1472 F3 isolinux.msg
1473 F4 display.txt
1474 F5 enhelp.txt
1475 F6 enopts.txt
1476 EOT
1477 status
1478 echo "Generate $ISO"
1479 create_iso $ISO $TMP_DIR/iso
1480 rm -rf $TMP_DIR
1481 ;;
1483 repack)
1484 # Repack an iso with maximum lzma compression ratio.
1487 ISO=$2
1489 mkdir -p $TMP_DIR/mnt
1490 # Extract filesystems
1491 echo -n "Mount $ISO"
1492 mount -o loop,ro $ISO $TMP_DIR/mnt 2> /dev/null
1493 status || cleanup_merge
1494 cp -a $TMP_DIR/mnt $TMP_DIR/iso
1495 umount -d $TMP_DIR/mnt
1497 for i in $TMP_DIR/iso/boot/rootfs* ; do
1498 echo -n "Repack $(basename $i)"
1499 (zcat $i || unlzma -c $i || cat $i) \
1500 2>/dev/null > $TMP_DIR/rootfs
1501 lzma e $TMP_DIR/rootfs $i \
1502 -d$(lzma_history_bits $TMP_DIR/rootfs)
1503 status
1504 done
1506 echo "Generate $ISO"
1507 create_iso $ISO $TMP_DIR/iso
1508 rm -rf $TMP_DIR
1509 ;;
1511 usage|*)
1512 # Clear and print usage also for all unknown commands.
1514 clear
1515 usage
1516 ;;
1518 esac
1520 exit 0