tazlito view tazlito @ rev 95

Exec distro.sh if exist and tiny cosmetic change
author Christophe Lincoln <pankso@slitaz.org>
date Sun Mar 29 23:50:23 2009 +0200 (2009-03-29)
parents a2da441d750f
children 81408cb60cb0
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=1.9
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
741 if [ -d $ROOTFS ] ; then
742 echo -e "\nA rootfs exists in : $DISTRO"
743 echo -e "Please clean the distro tree or change directory path.\n"
744 exit 0
745 fi
746 # Check if a package list was specified on cmdline.
747 LIST_NAME="distro-packages.list"
748 CDROM=""
749 while [ -n "$2" ]; do
750 case "$2" in
751 --iso=*)
752 CDROM="-o loop ${2#--iso=}"
753 ;;
754 --cdrom)
755 CDROM="/dev/cdrom"
756 ;;
757 *) if [ ! -f "$2" ] ; then
758 echo -e "\nUnable to find the specified packages list."
759 echo -e "List name : $2\n"
760 exit 1
761 fi
762 LIST_NAME=$2
763 ;;
764 esac
765 shift
766 done
767 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
768 # Build list with installed packages
769 for i in $(ls $INSTALLED); do
770 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
771 EXTRAVERSION=""
772 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
773 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
774 done
775 fi
776 # Exit if no list name.
777 if [ ! -f "$LIST_NAME" ]; then
778 echo -e "\nNo packages list found or specified. Please read the docs.\n"
779 exit 0
780 fi
781 # Start generation.
782 echo ""
783 echo -e "\033[1mTazlito generating a distro\033[0m"
784 echo "================================================================================"
785 # Misc checks
786 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
787 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
788 # Get the list of packages using cat for a file list.
789 LIST=`cat $LIST_NAME`
790 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
791 REPACK=""
792 DOWNLOAD=""
793 for pkg in $LIST
794 do
795 [ "$pkg" = "" ] && continue
796 pkg=${pkg%.tazpkg}
797 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
798 PACKAGE=$(installed_package_name $pkg)
799 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
800 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
801 echo -e "\nUnable to find $pkg in the repository."
802 echo -e "Path : $PACKAGES_REPOSITORY\n"
803 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
804 yesorno "Repack packages from rootfs (y/N) ? "
805 REPACK="$answer"
806 [ "$answer" = "y" ] || REPACK="n"
807 [ "$DOWNLOAD" = "y" ] && break
808 fi
809 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
810 yesorno "Download packages from mirror (Y/n) ? "
811 DOWNLOAD="$answer"
812 if [ "$answer" = "n" ]; then
813 [ -z "$PACKAGE" ] && exit 1
814 else
815 DOWNLOAD="y"
816 [ -n "$REPACK" ] && break
817 fi
818 fi
819 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
820 done
822 # Mount cdrom to be able to repack boot-loader packages
823 if [ ! -e /boot -a -n "$CDROM" ]; then
824 mkdir $TMP_MNT
825 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
826 ln -s $TMP_MNT/boot /
827 if [ ! -d "$ADDFILES/rootcd" ] ; then
828 mkdir -p $ADDFILES/rootcd
829 for i in $(ls $TMP_MNT); do
830 [ "$i" = "boot" ] && continue
831 cp -a $TMP_MNT/$i $ADDFILES/rootcd
832 done
833 fi
834 else
835 rmdir $TMP_MNT
836 fi
837 fi
839 # Root fs stuff.
840 echo "Preparing the rootfs directory..."
841 mkdir -p $ROOTFS
842 sleep 2
843 for pkg in $LIST
844 do
845 [ "$pkg" = "" ] && continue
846 # First copy and extract the package in tmp dir.
847 pkg=${pkg%.tazpkg}
848 PACKAGE=$(installed_package_name $pkg)
849 mkdir -p $TMP_DIR
850 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
851 # Look for package in cache
852 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
853 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
854 # Look for package in running distribution
855 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
856 tazpkg repack $PACKAGE && \
857 mv $pkg.tazpkg $PACKAGES_REPOSITORY
858 fi
859 fi
860 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
861 # Get package from mirror
862 [ "$DOWNLOAD" = "y" ] && \
863 download $pkg.tazpkg && \
864 mv $pkg.tazpkg $PACKAGES_REPOSITORY
865 fi
866 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
867 echo "Missing package $pkg."
868 cleanup
869 exit 1
870 fi
871 done
872 if [ -f non-free.list ]; then
873 echo "Preparing non-free packages..."
874 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
875 for pkg in $(cat non-free.list); do
876 if [ ! -d $INSTALLED/$pkg ]; then
877 if [ ! -d $INSTALLED/get-$pkg ]; then
878 tazpkg get-install get-$pkg
879 fi
880 get-$pkg
881 fi
882 tazpkg repack $pkg
883 pkg=$(ls $pkg*.tazpkg)
884 grep -q "^$pkg$" $LIST_NAME || \
885 echo $pkg >>$LIST_NAME
886 mv $pkg $PACKAGES_REPOSITORY
887 done
888 fi
889 echo ""
890 cp $LIST_NAME $DISTRO/distro-packages.list
891 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/distro-packages.list > $DISTRO/list-packages
892 cd $PACKAGES_REPOSITORY
893 yes y | tazpkg install-list \
894 $DISTRO/list-packages --root=$ROOTFS
895 cd $DISTRO
896 cp distro-packages.list $ROOTFS/etc/tazlito
897 # Copy all files from $ADDFILES/rootfs to the rootfs.
898 if [ -d "$ADDFILES/rootfs" ] ; then
899 echo -n "Copying addfiles content to the rootfs... "
900 cp -a $ADDFILES/rootfs/* $ROOTFS
901 status
902 fi
903 echo "Root file system is generated..."
904 # Root CD part.
905 echo -n "Preparing the rootcd directory..."
906 mkdir -p $ROOTCD
907 status
908 # Move the boot dir with the Linux kernel from rootfs.
909 # The boot dir goes directly on the CD.
910 if [ -d "$ROOTFS/boot" ] ; then
911 echo -n "Moving the boot directory..."
912 mv $ROOTFS/boot $ROOTCD
913 cd $ROOTCD/boot
914 ln vmlinuz-* bzImage
915 status
916 fi
917 cd $DISTRO
918 # Copy all files from $ADDFILES/rootcd to the rootcd.
919 if [ -d "$ADDFILES/rootcd" ] ; then
920 echo -n "Copying addfiles content to the rootcd... "
921 cp -a $ADDFILES/rootcd/* $ROOTCD
922 status
923 fi
924 # Execute the distro script (used to perform tasks in the rootfs
925 # before compression. Give rootfs path in arg
926 [ -z $DISTRO_SCRIPT ] && DISTRO_SCRIPT=$TOP_DIR/distro.sh
927 if [ -x $DISTRO_SCRIPT ]; then
928 echo "Executing distro script..."
929 sh $DISTRO_SCRIPT $DISTRO
930 fi
931 # Initramfs and ISO image stuff.
932 gen_initramfs
933 gen_livecd_isolinux
934 distro_stats
935 cleanup
936 ;;
937 clean-distro)
938 # Remove old distro tree.
939 #
940 check_root
941 echo ""
942 echo -e "\033[1mCleaning :\033[0m $DISTRO"
943 echo "================================================================================"
944 if [ -d "$DISTRO" ] ; then
945 if [ -d "$ROOTFS" ] ; then
946 echo -n "Removing the rootfs..."
947 rm -f $DISTRO/$INITRAMFS
948 rm -rf $ROOTFS
949 status
950 fi
951 if [ -d "$ROOTCD" ] ; then
952 echo -n "Removing the rootcd..."
953 rm -rf $ROOTCD
954 status
955 fi
956 echo -n "Removing eventual ISO image..."
957 rm -f $DISTRO/$ISO_NAME.iso
958 rm -f $DISTRO/$ISO_NAME.md5
959 status
960 fi
961 echo "================================================================================"
962 echo ""
963 ;;
964 check-distro)
965 # Check for a few LiveCD needed files not installed by packages.
966 #
967 check_rootfs
968 echo ""
969 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
970 echo "================================================================================"
971 # SliTaz release info.
972 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
973 echo "Missing release info : /etc/slitaz-release"
974 else
975 release=`cat $ROOTFS/etc/slitaz-release`
976 echo -n "Release : $release"
977 status
978 fi
979 # Tazpkg mirror.
980 if [ ! -f "$ROOTFS/var/lib/tazpkg/mirror" ]; then
981 echo -n "Mirror URL : Missing /var/lib/tazpkg/mirror"
982 todomsg
983 else
984 echo -n "Mirror configuration exist..."
985 status
986 fi
987 # Isolinux msg
988 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.msg; then
989 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
990 todomsg
991 else
992 echo -n "Isolinux message seems good..."
993 status
994 fi
995 echo "================================================================================"
996 echo ""
997 ;;
998 burn-iso)
999 # Guess cdrom device, ask user and burn the ISO.
1001 check_root
1002 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
1003 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
1004 # We can specify an alternative ISO from the cmdline.
1005 if [ -n "$2" ] ; then
1006 iso=$2
1007 else
1008 iso=$DISTRO/$ISO_NAME.iso
1009 fi
1010 if [ ! -f "$iso" ]; then
1011 echo -e "\nUnable to find ISO : $iso\n"
1012 exit 0
1013 fi
1014 echo ""
1015 echo -e "\033[1mTazlito burn ISO\033[0m "
1016 echo "================================================================================"
1017 echo "Cdrom device : /dev/$DRIVE_NAME"
1018 echo "Drive speed : $DRIVE_SPEED"
1019 echo "ISO image : $iso"
1020 echo "================================================================================"
1021 echo ""
1022 yesorno "Burn ISO image (y/N) ? "
1023 if [ "$answer" == "y" ]; then
1024 echo ""
1025 echo "Starting Wodim to burn the iso..." && sleep 2
1026 echo "================================================================================"
1027 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
1028 echo "================================================================================"
1029 echo "ISO image is burned to cdrom."
1030 else
1031 echo -e "\nExiting. No ISO burned."
1032 fi
1033 echo ""
1034 ;;
1035 usage|*)
1036 # Clear and print usage also for all unknown commands.
1038 clear
1039 usage
1040 ;;
1042 esac
1044 exit 0