tazlito view tazlito @ rev 99

Add --force option to gen-distro command. Force removal of existing rootfs
author Eric Joseph-Alexandre <erjo@slitaz.org>
date Mon May 25 23:13:36 2009 +0200 (2009-05-25)
parents 81408cb60cb0
children ba395fa660a8
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
65 #####################
66 # Tazlito functions #
67 #####################
69 # Print the usage.
70 usage ()
71 {
72 echo -e "\nSliTaz Live Tool - Version: $VERSION\n
73 \033[1mUsage: \033[0m `basename $0` [command] [list|iso|flavor] [dir]
74 \033[1mCommands: \033[0m\n
75 usage Print this short usage.
76 stats View Tazlito and distro configuration statistics.
77 gen-config Generate a new configuration file for a distro.
78 configure Configure the main config file or a specific tazlito.conf.
79 gen-iso Generate a new ISO from a distro tree.
80 gen-initiso Generate a new initramfs and ISO from the distro tree.
81 list-flavors List all available package lists on the mirror.
82 gen-flavor Generate a new live-CD description.
83 gen-liveflavor Generate a live-CD description from current system.
84 show-flavor Show live-CD description.
85 get-flavor Get a flavor's list of packages.
86 check-list Check a distro-packages.list for updates.
87 extract-distro Extract an ISO to a directory and rebuild LiveCD tree.
88 gen-distro Generate a Live distro and ISO from a list of packages.
89 clean-distro Remove all files generated by gen-distro.
90 check-distro Help to check if distro is ready to release.
91 burn-iso Burn ISO image to a cdrom using Wodim.\n"
92 }
94 # Status function.
95 status()
96 {
97 local CHECK=$?
98 echo -en "\\033[70G[ "
99 if [ $CHECK = 0 ]; then
100 echo -en "\\033[1;33mOK"
101 else
102 echo -en "\\033[1;31mFailed"
103 fi
104 echo -e "\\033[0;39m ]"
105 }
107 yesorno()
108 {
109 echo -n "$1"
110 case "$DEFAULT_ANSWER" in
111 Y|y) answer="y";;
112 N|n) answer="n";;
113 *) read answer;;
114 esac
115 }
117 field()
118 {
119 grep "^$1" "$2" | sed 's/.*: \([0-9KMG\.]*\).*/\1/'
120 }
122 todomsg()
123 {
124 echo -e "\\033[70G[ \\033[1;31mTODO\\033[0;39m ]"
125 }
127 # Download a file from this mirror
128 download_from()
129 {
130 local i
131 local mirrors
132 mirrors="$1"
133 shift
134 for i in $mirrors; do
135 case "$i" in
136 http://*|ftp://*) wget -c $i$@ && break;;
137 *) cp $i/$1 . && break;;
138 esac
139 done
140 }
142 # Download a file trying all mirrors
143 download()
144 {
145 local i
146 for i in $(cat $MIRROR $LOCALSTATE/undigest/*/mirror 2> /dev/null); do
147 download_from "$i" "$@" && break
148 done
149 }
151 # Execute hooks provided by some packages
152 genisohooks()
153 {
154 local here=`pwd`
155 cd $ROOTFS
156 for i in $(ls etc/tazlito/*.$1 2> /dev/null); do
157 . $i $ROOTCD
158 done
159 cd $here
160 }
162 cleanup()
163 {
164 if [ -d $TMP_MNT ]; then
165 umount $TMP_MNT
166 rmdir $TMP_MNT
167 rm -f /boot
168 fi
169 }
171 # Echo the package name if the tazpkg is already installed
172 installed_package_name()
173 {
174 local tazpkg
175 local package
176 local VERSION
177 local EXTRAVERSION
178 tazpkg=$1
179 # Try to find package name and version to be able
180 # to repack it from installation
181 # A dash (-) can exist in name *and* in version
182 package=${tazpkg%-*}
183 i=$package
184 while true; do
185 VERSION=""
186 eval $(grep -s ^VERSION= $INSTALLED/$i/receipt)
187 EXTRAVERSION=""
188 eval $(grep -s ^EXTRAVERSION= $INSTALLED/$i/receipt)
189 if [ "$i-$VERSION$EXTRAVERSION" = "$tazpkg" ]; then
190 echo $i
191 break
192 fi
193 case "$i" in
194 *-*);;
195 *) break;;
196 esac
197 i=${i%-*}
198 done
199 }
201 # Check if user is root.
202 check_root()
203 {
204 if test $(id -u) != 0 ; then
205 echo -e "\nYou must be root to run `basename $0` with this option."
206 echo -e "Please type 'su' and root password to become super-user.\n"
207 exit 0
208 fi
209 }
211 # Check for the rootfs tree.
212 check_rootfs()
213 {
214 if [ ! -d "$ROOTFS/etc" ] ; then
215 echo -e "\nUnable to find a distro rootfs...\n"
216 exit 0
217 fi
218 }
220 # Check for the boot dir into the root CD tree.
221 verify_rootcd()
222 {
223 if [ ! -d "$ROOTCD/boot" ] ; then
224 echo -e "\nUnable to find the rootcd boot directory...\n"
225 exit 0
226 fi
227 }
229 # Generate a new ISO image using isolinux.
230 gen_livecd_isolinux()
231 {
232 # Some packages may want to alter iso
233 genisohooks iso
234 if [ ! -f "$ROOTCD/boot/isolinux/isolinux.bin" ]; then
235 echo -e "\nUnable to find isolinux binary.\n"
236 cleanup
237 exit 0
238 fi
239 # Set date for boot msg.
240 if grep -q 'XXXXXXXX' $ROOTCD/boot/isolinux/isolinux.msg; then
241 DATE=`date +%Y%m%d`
242 echo -n "Setting build date to: $DATE..."
243 sed -i s/'XXXXXXXX'/"$DATE"/ $ROOTCD/boot/isolinux/isolinux.msg
244 status
245 fi
246 cd $ROOTCD
247 echo -n "Computing md5..."
248 find * -type f ! -name md5sum -exec md5sum {} \; > md5sum
249 status
250 cd $DISTRO
251 echo ""
252 echo -e "\033[1mGenerating ISO image\033[0m"
253 echo "================================================================================"
254 genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
255 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
256 -V "$VOLUM_NAME" -p "$PREPARED" -input-charset iso8859-1 \
257 -boot-info-table $ROOTCD
258 if [ -x /usr/bin/isohybrid ]; then
259 echo -n "Create hybrid ISO..."
260 /usr/bin/isohybrid $ISO_NAME.iso 2> /dev/null
261 status
262 fi
263 echo -n "Creating the ISO md5sum..."
264 md5sum $ISO_NAME.iso > $ISO_NAME.md5
265 status
266 echo "================================================================================"
267 # Some packages may want to alter final iso
268 genisohooks final
269 }
271 # Generate a new initramfs from the root filesystem.
272 gen_initramfs()
273 {
274 # Just in case CTRL+c
275 rm -f $DISTRO/gen
276 # Some packages may want to alter rootfs
277 genisohooks rootfs
278 cd $ROOTFS
279 echo ""
281 # Link duplicate files
282 find . -type f -size +0c -exec stat -c '%s-%a-%u-%g %i %h %n' {} \; | \
283 sort | ( save=0; old_attr=""; old_inode=""; old_link=""; old_file=""
284 while read attr inode link file; do
285 if [ "$attr" = "$old_attr" -a "$inode" != "$old_inode" ]; then
286 if cmp "$file" "$old_file" >/dev/null; then
287 rm -f "$file"
288 ln "$old_file" "$file"
289 inode="$old_inode"
290 [ "$link" = "1" ] && save="$(expr $save + ${attr%%-*})"
291 fi
292 fi
293 old_attr="$attr" ; old_inode="$inode" ; old_file="$file"
294 done
295 echo "$save bytes saved in duplicate files."
296 )
298 # Use lzma if installed
299 if [ "$COMPRESSION" = "none" ]; then
300 echo -n "Generating uncompressed initramfs... "
301 find . -print | cpio -o -H newc > $DISTRO/$INITRAMFS
302 elif [ -x /usr/bin/lzma -a "$COMPRESSION" != "gzip" ]; then
303 echo -n "Generating lzma'ed initramfs... "
304 find . -print | cpio -o -H newc | lzma e -si -so -d24 > $DISTRO/$INITRAMFS
305 else
306 echo -n "Generating gziped initramfs... "
307 find . -print | cpio -o -H newc | gzip -9 > $DISTRO/$INITRAMFS
308 fi
309 cd $DISTRO
310 mv $INITRAMFS $ROOTCD/boot
311 }
313 distro_sizes()
314 {
315 echo "Build date : `date +%Y%m%d\ \at\ \%H:%M:%S`"
316 echo "Packages : `ls -1 $ROOTFS$INSTALLED | wc -l`"
317 echo "Rootfs size : `du -sh $ROOTFS | awk '{ print $1 }'`"
318 echo "Initramfs size : `du -sh $ROOTCD/boot/$INITRAMFS | awk '{ print $1 }'`"
319 echo "ISO image size : `du -sh $ISO_NAME.iso | awk '{ print $1 }'`"
320 echo "================================================================================"
321 echo "Image is ready: $ISO_NAME.iso"
322 echo ""
323 }
325 # Print ISO and rootfs size.
326 distro_stats()
327 {
328 echo ""
329 echo -e "\033[1mDistro statistics\033[0m ($DISTRO)"
330 echo "================================================================================"
331 distro_sizes
332 }
334 # Create an empty configuration file.
335 empty_config_file()
336 {
337 cat >> tazlito.conf << "EOF"
338 # tazlito.conf: Tazlito (SliTaz Live Tool)
339 # configuration file.
340 #
342 # Name of the ISO image to generate.
343 ISO_NAME=""
345 # ISO image volume name.
346 VOLUM_NAME="SliTaz"
348 # Name of the preparer.
349 PREPARED="$USER"
351 # Path to the packages repository and the packages.list.
352 PACKAGES_REPOSITORY=""
354 # Path to the distro tree to gen-distro from a
355 # list of packages.
356 DISTRO=""
358 # Path to the directory containing additional files
359 # to copy into the rootfs and rootcd of the LiveCD.
360 ADDFILES="$DISTRO/addfiles"
362 # Default answer for binary question (Y or N)
363 DEFAULT_ANSWER="ASK"
365 # Compression utility (lzma, gzip or none)
366 COMPRESSION="lzma"
367 EOF
368 }
370 ####################
371 # Tazlito commands #
372 ####################
374 case "$COMMAND" in
375 stats)
376 # Tazlito general statistics from the config file.
377 #
378 echo ""
379 echo -e "\033[1mTazlito statistics\033[0m
380 ===============================================================================
381 Config file : $CONFIG_FILE
382 ISO name : $ISO_NAME.iso
383 Volume name : $VOLUM_NAME
384 Prepared : $PREPARED
385 Packages repository : $PACKAGES_REPOSITORY
386 Distro directory : $DISTRO"
387 if [ ! "$ADDFILES" = "" ] ; then
388 echo -e "Additional files : $ADDFILES"
389 fi
390 echo "================================================================================"
391 echo ""
392 ;;
393 gen-config)
394 # Generate a new config file in the current dir or the specified
395 # directory by $2.
396 #
397 if [ -n "$2" ] ; then
398 mkdir -p $2 && cd $2
399 fi
400 echo -n "Generating empty tazlito.conf..."
401 empty_config_file
402 status
403 echo ""
404 if [ -f "tazlito.conf" ] ; then
405 echo "Configuration file is ready to edit."
406 echo "File location : `pwd`/tazlito.conf"
407 echo ""
408 fi
409 ;;
410 configure)
411 # Configure a tazlito.conf config file. Start by getting
412 # a empty config file and sed it.
413 #
414 if [ -f "tazlito.conf" ] ; then
415 rm tazlito.conf
416 else
417 if test $(id -u) = 0 ; then
418 cd /etc
419 else
420 echo "You must be root to configure the main config file or in"
421 echo "the same directory of the file you want to configure."
422 exit 0
423 fi
424 fi
425 empty_config_file
426 echo""
427 echo -e "\033[1mConfiguring :\033[0m `pwd`/tazlito.conf"
428 echo "================================================================================"
429 # ISO name.
430 echo -n "ISO name : " ; read answer
431 sed -i s#'ISO_NAME=\"\"'#"ISO_NAME=\"$answer\""# tazlito.conf
432 # Volume name.
433 echo -n "Volume name : " ; read answer
434 sed -i s/'VOLUM_NAME=\"SliTaz\"'/"VOLUM_NAME=\"$answer\""/ tazlito.conf
435 # Packages repository.
436 echo -n "Packages repository : " ; read answer
437 sed -i s#'PACKAGES_REPOSITORY=\"\"'#"PACKAGES_REPOSITORY=\"$answer\""# tazlito.conf
438 # Distro path.
439 echo -n "Distro path : " ; read answer
440 sed -i s#'DISTRO=\"\"'#"DISTRO=\"$answer\""# tazlito.conf
441 echo "================================================================================"
442 echo "Config file is ready to use."
443 echo "You can now extract an ISO or generate a distro."
444 echo ""
445 ;;
446 gen-iso)
447 # Simply generate a new iso.
448 #
449 check_root
450 verify_rootcd
451 gen_livecd_isolinux
452 distro_stats
453 ;;
454 gen-initiso)
455 # Simply generate a new initramfs with a new iso.
456 #
457 check_root
458 verify_rootcd
459 gen_initramfs
460 gen_livecd_isolinux
461 distro_stats
462 ;;
463 extract-distro)
464 # Extract an ISO image to a directory and rebuild the LiveCD tree.
465 #
466 check_root
467 ISO_IMAGE=$2
468 if [ -z "$ISO_IMAGE" ] ; then
469 echo -e "\nPlease specify the path to the ISO image."
470 echo -e "Example : `basename $0` image.iso /path/target\n"
471 exit 0
472 fi
473 # Set the distro path by checking for $3 on cmdline.
474 if [ -n "$3" ] ; then
475 TARGET=$3
476 else
477 TARGET=$DISTRO
478 fi
479 # Exit if existing distro is found.
480 if [ -d "$TARGET/rootfs" ] ; then
481 echo -e "\nA rootfs exists in : $TARGET"
482 echo -e "Please clean the distro tree or change directory path.\n"
483 exit 0
484 fi
485 echo ""
486 echo -e "\033[1mTazlito extracting :\033[0m `basename $ISO_IMAGE`"
487 echo "================================================================================"
488 # Start to mount the ISO.
489 echo ""
490 echo "Mounting ISO image..."
491 mkdir -p $TMP_DIR
492 # Get ISO file size.
493 isosize=`du -sh $ISO_IMAGE | cut -f1`
494 mount -o loop $ISO_IMAGE $TMP_DIR
495 sleep 2
496 # Prepare target dir, copy the kernel and the rootfs.
497 mkdir -p $TARGET/rootfs
498 mkdir -p $TARGET/rootcd/boot
499 echo -n "Copying the Linux kernel..."
500 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
501 ln $TARGET/rootcd/boot/vmlinuz* $TARGET/rootcd/boot/bzImage
502 else
503 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
504 fi
505 status
506 echo -n "Copying isolinux files..."
507 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
508 for i in $(ls $TMP_DIR); do
509 [ "$i" = "boot" ] && continue
510 cp -a $TMP_DIR/$i $TARGET/rootcd
511 done
512 status
513 if [ -d $TMP_DIR/boot/syslinux ]; then
514 echo -n "Copying syslinux files..."
515 cp -a $TMP_DIR/boot/syslinux $TARGET/rootcd/boot
516 status
517 fi
518 if [ -d $TMP_DIR/boot/extlinux ]; then
519 echo -n "Copying extlinux files..."
520 cp -a $TMP_DIR/boot/extlinux $TARGET/rootcd/boot
521 status
522 fi
523 if [ -d $TMP_DIR/boot/grub ]; then
524 echo -n "Copying GRUB files..."
525 cp -a $TMP_DIR/boot/grub $TARGET/rootcd/boot
526 status
527 fi
529 echo -n "Copying the rootfs..."
530 cp $TMP_DIR/boot/rootfs.?z $TARGET/rootcd/boot
531 status
532 # Extract initramfs.
533 cd $TARGET/rootfs
534 echo -n "Extracting the rootfs... "
535 ( zcat ../rootcd/boot/rootfs.gz 2>/dev/null || \
536 lzma d ../rootcd/boot/rootfs.?z -so 2>/dev/null || \
537 cat ../rootcd/boot/rootfs.gz ) | cpio -id
538 # unpack /usr
539 for i in etc/tazlito/*.extract; do
540 [ -f "$i" ] && . $i ../rootcd
541 done
542 # Umount and remove temp directory and cd to $TARGET to get stats.
543 umount $TMP_DIR && rm -rf $TMP_DIR
544 cd ..
545 echo ""
546 echo "================================================================================"
547 echo "Extracted : `basename $ISO_IMAGE` ($isosize)"
548 echo "Distro tree : `pwd`"
549 echo "Rootfs size : `du -sh rootfs`"
550 echo "Rootcd size : `du -sh rootcd`"
551 echo "================================================================================"
552 echo ""
553 ;;
554 list-flavors)
555 # Show available flavors.
556 if [ ! -s /etc/tazlito/flavors.list -o "$2" == "--recharge" ]; then
557 download flavors.list -O - > /etc/tazlito/flavors.list
558 fi
559 echo ""
560 echo -e "\033[1mList of flavors\033[0m"
561 echo "================================================================================"
562 cat /etc/tazlito/flavors.list
563 echo ""
564 ;;
565 show-flavor)
566 # Show flavor description.
567 FLAVOR=$2
568 if [ ! -f "$FLAVOR.flavor" ]; then
569 echo "File $FLAVOR.flavor not found."
570 exit 1
571 fi
572 mkdir $TMP_DIR
573 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i 2> /dev/null )
574 if [ "$3" = "--brief" ]; then
575 if [ "$4" != "--noheader" ]; then
576 echo "Name Sizes Description"
577 echo "================================================================================"
578 fi
579 printf "%-15.15s %5.5s/%5.5s %-51s\n" "$FLAVOR" \
580 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
581 "$(field Rootfs $TMP_DIR/$FLAVOR.desc)" \
582 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
583 else
584 echo "================================================================================"
585 cat $TMP_DIR/$FLAVOR.desc
586 fi
587 rm -Rf $TMP_DIR
588 ;;
589 gen-liveflavor)
590 # Generate a new flavor form the live system.
591 FLAVOR=$2
592 DESC=""
593 case "$FLAVOR" in
594 '') echo -n "Flavor name : "
595 read FLAVOR
596 [ -z "$FLAVOR" ] && exit 1;;
597 -?|-h*|--help) echo -e "
599 SliTaz Live Tool - Version: $VERSION
600 \033[1mUsage: \033[0m `basename $0` gen-liveflavor flavor-name [flavor-patch-file]
601 \033[1mflavor-patch-file format: \033[0m
602 code data
603 + package to add
604 - package to remove
605 ! non-free package to add
606 ? display message
607 @ flavor description
609 \033[1mExample: \033[0m
610 @ Developer tools for slitaz maintainers
611 + slitaz-toolchain
612 + mercurial
613 "
614 exit 1;;
615 esac
616 mv /etc/tazlito/distro-packages.list \
617 /etc/tazlito/distro-packages.list.$$ 2> /dev/null
618 rm -f distro-packages.list non-free.list 2> /dev/null
619 tazpkg recharge
620 [ -n "$3" ] && while read action pkg; do
621 case "$action" in
622 +) yes | tazpkg get-install $pkg;;
623 -) yes | tazpkg remove $pkg;;
624 !) echo $pkg >> non-free.list;;
625 @) DESC="$pkg";;
626 \?) echo -en "$pkg"; read action;;
627 esac
628 done < $3
629 yes '' | tazlito gen-distro
630 echo "$DESC" | tazlito gen-flavor "$FLAVOR"
631 mv /etc/tazlito/distro-packages.list.$$ \
632 /etc/tazlito/distro-packages.list 2> /dev/null
633 ;;
634 gen-flavor)
635 # Generate a new flavor from the last iso image generated.
636 FLAVOR=$2
637 echo ""
638 echo -e "\033[1mFlavor generation\033[0m"
639 echo "================================================================================"
640 if [ -z "$FLAVOR" ]; then
641 echo -n "Flavor name : "
642 read FLAVOR
643 [ -z "$FLAVOR" ] && exit 1
644 fi
645 check_rootfs
646 FILES="$FLAVOR.pkglist"
647 echo -n "Creating file $FLAVOR.flavor..."
648 for i in rootcd rootfs; do
649 if [ -d "$ADDFILES/$i" ] ; then
650 FILES="$FILES\n$FLAVOR.$i"
651 ( cd "$ADDFILES/$i"; find . | \
652 cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
653 fi
654 done
655 status
656 answer=`grep -s ^Description $FLAVOR.desc`
657 answer=${answer#Description : }
658 if [ -z "$answer" ]; then
659 echo -n "Description : "
660 read answer
661 fi
662 echo -n "Compressing flavor $FLAVOR..."
663 echo "Flavor : $FLAVOR" > $FLAVOR.desc
664 echo "Description : $answer" >> $FLAVOR.desc
665 ( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
666 \rm -f $FLAVOR.pkglist $FLAVOR.nonfree 2> /dev/null
667 for i in $(ls $ROOTFS$INSTALLED); do
668 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
669 EXTRAVERSION=""
670 eval $(grep ^EXTRAVERSION= $ROOTFS$INSTALLED/$i/receipt)
671 eval $(grep ^CATEGORY= $ROOTFS$INSTALLED/$i/receipt)
672 if [ "$CATEGORY" = "non-free" -a "${i%%-*}" != "get" ]
673 then
674 echo "$i" >> $FLAVOR.nonfree
675 else
676 echo "$i-$VERSION$EXTRAVERSION" >> $FLAVOR.pkglist
677 fi
678 done
679 [ -s $FLAVOR.nonfree ] && $FILES="$FILES\n$FLAVOR.nonfree"
680 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
681 gzip -9 > $FLAVOR.flavor
682 rm `echo -e $FILES`
683 status
684 echo "================================================================================"
685 echo "Flavor size : `du -sh $FLAVOR.flavor`"
686 echo ""
687 ;;
688 get-flavor)
689 # Get a flavor's files and prepare for gen-distro.
690 FLAVOR=$2
691 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
692 echo -n "Cleaning $DISTRO..."
693 rm -R $DISTRO 2> /dev/null
694 mkdir -p $DISTRO
695 status
696 mkdir $TMP_DIR
697 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i 2>/dev/null )
698 echo -n "Create distro-packages.list..."
699 mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
700 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
701 status
702 for i in rootcd rootfs; do
703 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
704 mkdir -p "$ADDFILES/$i"
705 zcat $TMP_DIR/$FLAVOR.$i | \
706 ( cd "$ADDFILES/$i"; cpio -id 2> /dev/null)
707 fi
708 done
709 echo -n "Update tazlito.conf..."
710 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
711 cat tazlito.conf | grep -v "^#VOLUM_NAME" | \
712 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
713 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
714 status
715 rm -Rf $TMP_DIR
716 fi
717 ;;
718 check-list)
719 # Use current packages list in $PWD by default.
720 DISTRO_PKGS_LIST=distro-packages.list
721 [ -d "$2" ] && DISTRO_PKGS_LIST=$2/distro-packages.list
722 [ -f "$2" ] && DISTRO_PKGS_LIST=$2
723 [ ! -f $DISTRO_PKGS_LIST ] && echo "No packages list found." && exit 0
724 echo ""
725 echo -e "\033[1mLiveCD packages list check\033[0m"
726 echo "================================================================================"
727 for pkg in `cat $DISTRO_PKGS_LIST`
728 do
729 if ! grep -q "$pkg" /var/lib/tazpkg/packages.list; then
730 echo "Update: $pkg"
731 up=$(($up + 1))
732 fi
733 done
734 [ -z $up ] && echo -e "List is up-to-date\n" && exit 0
735 echo "================================================================================"
736 echo -e "Updates: $up\n" ;;
737 gen-distro)
738 # Generate a live distro tree with a set of packages.
739 #
740 check_root
742 # Check if a package list was specified on cmdline.
743 LIST_NAME="distro-packages.list"
744 CDROM=""
745 while [ -n "$2" ]; do
746 case "$2" in
747 --iso=*)
748 CDROM="-o loop ${2#--iso=}"
749 ;;
750 --cdrom)
751 CDROM="/dev/cdrom"
752 ;;
753 --force)
754 DELETE_ROOTFS="true"
755 ;;
756 *) if [ ! -f "$2" ] ; then
757 echo -e "\nUnable to find the specified packages list."
758 echo -e "List name : $2\n"
759 exit 1
760 fi
761 LIST_NAME=$2
762 ;;
763 esac
764 shift
765 done
767 if [ -d $ROOTFS ] ; then
768 # Delete $ROOTFS if --force is set on command line
769 if [ ! -z $DELETE_ROOTFS ]; then
770 rm -rf $ROOTFS
771 unset $DELETE_ROOTFS
772 else
773 echo -e "\nA rootfs exists in : $DISTRO"
774 echo -e "Please clean the distro tree or change directory path.\n"
775 exit 0
776 fi
777 fi
778 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
779 # Build list with installed packages
780 for i in $(ls $INSTALLED); do
781 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
782 EXTRAVERSION=""
783 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
784 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
785 done
786 fi
787 # Exit if no list name.
788 if [ ! -f "$LIST_NAME" ]; then
789 echo -e "\nNo packages list found or specified. Please read the docs.\n"
790 exit 0
791 fi
792 # Start generation.
793 echo ""
794 echo -e "\033[1mTazlito generating a distro\033[0m"
795 echo "================================================================================"
796 # Misc checks
797 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
798 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
799 # Get the list of packages using cat for a file list.
800 LIST=`cat $LIST_NAME`
801 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
802 REPACK=""
803 DOWNLOAD=""
804 for pkg in $LIST
805 do
806 [ "$pkg" = "" ] && continue
807 pkg=${pkg%.tazpkg}
808 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
809 PACKAGE=$(installed_package_name $pkg)
810 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
811 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
812 echo -e "\nUnable to find $pkg in the repository."
813 echo -e "Path : $PACKAGES_REPOSITORY\n"
814 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
815 yesorno "Repack packages from rootfs (y/N) ? "
816 REPACK="$answer"
817 [ "$answer" = "y" ] || REPACK="n"
818 [ "$DOWNLOAD" = "y" ] && break
819 fi
820 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
821 yesorno "Download packages from mirror (Y/n) ? "
822 DOWNLOAD="$answer"
823 if [ "$answer" = "n" ]; then
824 [ -z "$PACKAGE" ] && exit 1
825 else
826 DOWNLOAD="y"
827 [ -n "$REPACK" ] && break
828 fi
829 fi
830 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
831 done
833 # Mount cdrom to be able to repack boot-loader packages
834 if [ ! -e /boot -a -n "$CDROM" ]; then
835 mkdir $TMP_MNT
836 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
837 ln -s $TMP_MNT/boot /
838 if [ ! -d "$ADDFILES/rootcd" ] ; then
839 mkdir -p $ADDFILES/rootcd
840 for i in $(ls $TMP_MNT); do
841 [ "$i" = "boot" ] && continue
842 cp -a $TMP_MNT/$i $ADDFILES/rootcd
843 done
844 fi
845 else
846 rmdir $TMP_MNT
847 fi
848 fi
850 # Root fs stuff.
851 echo "Preparing the rootfs directory..."
852 mkdir -p $ROOTFS
853 sleep 2
854 for pkg in $LIST
855 do
856 [ "$pkg" = "" ] && continue
857 # First copy and extract the package in tmp dir.
858 pkg=${pkg%.tazpkg}
859 PACKAGE=$(installed_package_name $pkg)
860 mkdir -p $TMP_DIR
861 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
862 # Look for package in cache
863 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
864 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
865 # Look for package in running distribution
866 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
867 tazpkg repack $PACKAGE && \
868 mv $pkg.tazpkg $PACKAGES_REPOSITORY
869 fi
870 fi
871 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
872 # Get package from mirror
873 [ "$DOWNLOAD" = "y" ] && \
874 download $pkg.tazpkg && \
875 mv $pkg.tazpkg $PACKAGES_REPOSITORY
876 fi
877 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
878 echo "Missing package $pkg."
879 cleanup
880 exit 1
881 fi
882 done
883 if [ -f non-free.list ]; then
884 echo "Preparing non-free packages..."
885 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
886 for pkg in $(cat non-free.list); do
887 if [ ! -d $INSTALLED/$pkg ]; then
888 if [ ! -d $INSTALLED/get-$pkg ]; then
889 tazpkg get-install get-$pkg
890 fi
891 get-$pkg
892 fi
893 tazpkg repack $pkg
894 pkg=$(ls $pkg*.tazpkg)
895 grep -q "^$pkg$" $LIST_NAME || \
896 echo $pkg >>$LIST_NAME
897 mv $pkg $PACKAGES_REPOSITORY
898 done
899 fi
900 echo ""
901 cp $LIST_NAME $DISTRO/distro-packages.list
902 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/distro-packages.list > $DISTRO/list-packages
903 cd $PACKAGES_REPOSITORY
904 yes y | tazpkg install-list \
905 $DISTRO/list-packages --root=$ROOTFS
906 cd $DISTRO
907 cp distro-packages.list $ROOTFS/etc/tazlito
908 # Copy all files from $ADDFILES/rootfs to the rootfs.
909 if [ -d "$ADDFILES/rootfs" ] ; then
910 echo -n "Copying addfiles content to the rootfs... "
911 cp -a $ADDFILES/rootfs/* $ROOTFS
912 status
913 fi
914 echo "Root file system is generated..."
915 # Root CD part.
916 echo -n "Preparing the rootcd directory..."
917 mkdir -p $ROOTCD
918 status
919 # Move the boot dir with the Linux kernel from rootfs.
920 # The boot dir goes directly on the CD.
921 if [ -d "$ROOTFS/boot" ] ; then
922 echo -n "Moving the boot directory..."
923 mv $ROOTFS/boot $ROOTCD
924 cd $ROOTCD/boot
925 ln vmlinuz-* bzImage
926 status
927 fi
928 cd $DISTRO
929 # Copy all files from $ADDFILES/rootcd to the rootcd.
930 if [ -d "$ADDFILES/rootcd" ] ; then
931 echo -n "Copying addfiles content to the rootcd... "
932 cp -a $ADDFILES/rootcd/* $ROOTCD
933 status
934 fi
935 # Execute the distro script (used to perform tasks in the rootfs
936 # before compression. Give rootfs path in arg
937 [ -z $DISTRO_SCRIPT ] && DISTRO_SCRIPT=$TOP_DIR/distro.sh
938 if [ -x $DISTRO_SCRIPT ]; then
939 echo "Executing distro script..."
940 sh $DISTRO_SCRIPT $DISTRO
941 fi
942 # Initramfs and ISO image stuff.
943 gen_initramfs
944 gen_livecd_isolinux
945 distro_stats
946 cleanup
947 ;;
948 clean-distro)
949 # Remove old distro tree.
950 #
951 check_root
952 echo ""
953 echo -e "\033[1mCleaning :\033[0m $DISTRO"
954 echo "================================================================================"
955 if [ -d "$DISTRO" ] ; then
956 if [ -d "$ROOTFS" ] ; then
957 echo -n "Removing the rootfs..."
958 rm -f $DISTRO/$INITRAMFS
959 rm -rf $ROOTFS
960 status
961 fi
962 if [ -d "$ROOTCD" ] ; then
963 echo -n "Removing the rootcd..."
964 rm -rf $ROOTCD
965 status
966 fi
967 echo -n "Removing eventual ISO image..."
968 rm -f $DISTRO/$ISO_NAME.iso
969 rm -f $DISTRO/$ISO_NAME.md5
970 status
971 fi
972 echo "================================================================================"
973 echo ""
974 ;;
975 check-distro)
976 # Check for a few LiveCD needed files not installed by packages.
977 #
978 check_rootfs
979 echo ""
980 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
981 echo "================================================================================"
982 # SliTaz release info.
983 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
984 echo "Missing release info : /etc/slitaz-release"
985 else
986 release=`cat $ROOTFS/etc/slitaz-release`
987 echo -n "Release : $release"
988 status
989 fi
990 # Tazpkg mirror.
991 if [ ! -f "$ROOTFS/var/lib/tazpkg/mirror" ]; then
992 echo -n "Mirror URL : Missing /var/lib/tazpkg/mirror"
993 todomsg
994 else
995 echo -n "Mirror configuration exist..."
996 status
997 fi
998 # Isolinux msg
999 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.msg; then
1000 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
1001 todomsg
1002 else
1003 echo -n "Isolinux message seems good..."
1004 status
1005 fi
1006 echo "================================================================================"
1007 echo ""
1008 ;;
1009 burn-iso)
1010 # Guess cdrom device, ask user and burn the ISO.
1012 check_root
1013 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
1014 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
1015 # We can specify an alternative ISO from the cmdline.
1016 if [ -n "$2" ] ; then
1017 iso=$2
1018 else
1019 iso=$DISTRO/$ISO_NAME.iso
1020 fi
1021 if [ ! -f "$iso" ]; then
1022 echo -e "\nUnable to find ISO : $iso\n"
1023 exit 0
1024 fi
1025 echo ""
1026 echo -e "\033[1mTazlito burn ISO\033[0m "
1027 echo "================================================================================"
1028 echo "Cdrom device : /dev/$DRIVE_NAME"
1029 echo "Drive speed : $DRIVE_SPEED"
1030 echo "ISO image : $iso"
1031 echo "================================================================================"
1032 echo ""
1033 yesorno "Burn ISO image (y/N) ? "
1034 if [ "$answer" == "y" ]; then
1035 echo ""
1036 echo "Starting Wodim to burn the iso..." && sleep 2
1037 echo "================================================================================"
1038 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
1039 echo "================================================================================"
1040 echo "ISO image is burned to cdrom."
1041 else
1042 echo -e "\nExiting. No ISO burned."
1043 fi
1044 echo ""
1045 ;;
1046 usage|*)
1047 # Clear and print usage also for all unknown commands.
1049 clear
1050 usage
1051 ;;
1053 esac
1055 exit 0