tazlito view tazlito @ rev 93

Remove obsolet addhacker
author Christophe Lincoln <pankso@slitaz.org>
date Thu Mar 05 20:00:37 2009 +0100 (2009-03-05)
parents 99ede412a318
children a2da441d750f
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 rater 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 Generated 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 file system.
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`"
318 echo "Initramfs size : `du -sh $ROOTCD/boot/$INITRAMFS`"
319 echo "ISO image size : `du -sh $ISO_NAME.iso`"
320 echo "================================================================================"
321 echo ""
322 }
324 # Print ISO and rootfs size.
325 distro_stats()
326 {
327 echo ""
328 echo -e "\033[1mDistro statistics\033[0m"
329 echo "================================================================================"
330 distro_sizes
331 }
333 # Create an empty configuration file.
334 empty_config_file()
335 {
336 cat >> tazlito.conf << "EOF"
337 # tazlito.conf: Tazlito (SliTaz Live Tool)
338 # configuration file.
339 #
341 # Name of the ISO image to generate.
342 ISO_NAME=""
344 # ISO image volume name.
345 VOLUM_NAME="SliTaz"
347 # Name of the preparer.
348 PREPARED="$USER"
350 # Path to the packages repository and the packages.list.
351 PACKAGES_REPOSITORY=""
353 # Path to the distro tree to gen-distro from a
354 # list of packages.
355 DISTRO=""
357 # Path to the directory containing additional files
358 # to copy into the rootfs and rootcd of the LiveCD.
359 ADDFILES="$DISTRO/addfiles"
361 # Default answer for binary question (Y or N)
362 DEFAULT_ANSWER="ASK"
364 # Compression utility (lzma, gzip or none)
365 COMPRESSION="lzma"
366 EOF
367 }
369 ####################
370 # Tazlito commands #
371 ####################
373 case "$COMMAND" in
374 stats)
375 # Tazlito general statistics from the config file.
376 #
377 echo ""
378 echo -e "\033[1mTazlito statistics\033[0m
379 ===============================================================================
380 Config file : $CONFIG_FILE
381 ISO name : $ISO_NAME.iso
382 Volum name : $VOLUM_NAME
383 Prepared : $PREPARED
384 Packages repository : $PACKAGES_REPOSITORY
385 Distro directory : $DISTRO"
386 if [ ! "$ADDFILES" = "" ] ; then
387 echo -e "Additional files : $ADDFILES"
388 fi
389 echo "================================================================================"
390 echo ""
391 ;;
392 gen-config)
393 # Generate a new config file in the current dir or the specified
394 # directory by $2.
395 #
396 if [ -n "$2" ] ; then
397 mkdir -p $2 && cd $2
398 fi
399 echo -n "Generating empty tazlito.conf..."
400 empty_config_file
401 status
402 echo ""
403 if [ -f "tazlito.conf" ] ; then
404 echo "Configuration file is ready to edit."
405 echo "File location : `pwd`/tazlito.conf"
406 echo ""
407 fi
408 ;;
409 configure)
410 # Configure a tazlito.conf config file. Start by getting
411 # a empty config file and sed it.
412 #
413 if [ -f "tazlito.conf" ] ; then
414 rm tazlito.conf
415 else
416 if test $(id -u) = 0 ; then
417 cd /etc
418 else
419 echo "You must be root to configure the main config file or in"
420 echo "the same directory of the file you want to configure."
421 exit 0
422 fi
423 fi
424 empty_config_file
425 echo""
426 echo -e "\033[1mConfiguring :\033[0m `pwd`/tazlito.conf"
427 echo "================================================================================"
428 # ISO name.
429 echo -n "ISO name : " ; read answer
430 sed -i s#'ISO_NAME=\"\"'#"ISO_NAME=\"$answer\""# tazlito.conf
431 # Volume name.
432 echo -n "Volume name : " ; read answer
433 sed -i s/'VOLUM_NAME=\"SliTaz\"'/"VOLUM_NAME=\"$answer\""/ tazlito.conf
434 # Packages repository.
435 echo -n "Packages repository : " ; read answer
436 sed -i s#'PACKAGES_REPOSITORY=\"\"'#"PACKAGES_REPOSITORY=\"$answer\""# tazlito.conf
437 # Distro path.
438 echo -n "Distro path : " ; read answer
439 sed -i s#'DISTRO=\"\"'#"DISTRO=\"$answer\""# tazlito.conf
440 echo "================================================================================"
441 echo "Config file is ready to use."
442 echo "You can now extract an ISO or generate a distro."
443 echo ""
444 ;;
445 gen-iso)
446 # Simply generated a new iso.
447 #
448 check_root
449 verify_rootcd
450 gen_livecd_isolinux
451 distro_stats
452 ;;
453 gen-initiso)
454 # Simply generated a new initramfs with a new iso.
455 #
456 check_root
457 verify_rootcd
458 gen_initramfs
459 gen_livecd_isolinux
460 distro_stats
461 ;;
462 extract-distro)
463 # Extract an ISO image to a directory and rebuild the LiveCD tree.
464 #
465 check_root
466 ISO_IMAGE=$2
467 if [ -z "$ISO_IMAGE" ] ; then
468 echo -e "\nPlease specify the path to the ISO image."
469 echo -e "Example : `basename $0` image.iso /path/target\n"
470 exit 0
471 fi
472 # Set the distro path by checking for $3 on cmdline.
473 if [ -n "$3" ] ; then
474 TARGET=$3
475 else
476 TARGET=$DISTRO
477 fi
478 # Exit if existing distro is found.
479 if [ -d "$TARGET/rootfs" ] ; then
480 echo -e "\nA rootfs exist in : $TARGET"
481 echo -e "Please clean the distro tree or change directory path.\n"
482 exit 0
483 fi
484 echo ""
485 echo -e "\033[1mTazlito extracting :\033[0m `basename $ISO_IMAGE`"
486 echo "================================================================================"
487 # Start to mount the ISO.
488 echo ""
489 echo "Mounting ISO image..."
490 mkdir -p $TMP_DIR
491 # Get ISO file size.
492 isosize=`du -sh $ISO_IMAGE | cut -f1`
493 mount -o loop $ISO_IMAGE $TMP_DIR
494 sleep 2
495 # Prepare target dir, copy the kernel and the rootfs.
496 mkdir -p $TARGET/rootfs
497 mkdir -p $TARGET/rootcd/boot
498 echo -n "Copying the Linux kernel..."
499 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
500 ln $TARGET/rootcd/boot/vmlinuz* $TARGET/rootcd/boot/bzImage
501 else
502 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
503 fi
504 status
505 echo -n "Copying isolinux files..."
506 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
507 for i in $(ls $TMP_DIR); do
508 [ "$i" = "boot" ] && continue
509 cp -a $TMP_DIR/$i $TARGET/rootcd
510 done
511 status
512 if [ -d $TMP_DIR/boot/syslinux ]; then
513 echo -n "Copying syslinux files..."
514 cp -a $TMP_DIR/boot/syslinux $TARGET/rootcd/boot
515 status
516 fi
517 if [ -d $TMP_DIR/boot/extlinux ]; then
518 echo -n "Copying extlinux files..."
519 cp -a $TMP_DIR/boot/extlinux $TARGET/rootcd/boot
520 status
521 fi
522 if [ -d $TMP_DIR/boot/grub ]; then
523 echo -n "Copying GRUB files..."
524 cp -a $TMP_DIR/boot/grub $TARGET/rootcd/boot
525 status
526 fi
528 echo -n "Copying the rootfs..."
529 cp $TMP_DIR/boot/rootfs.?z $TARGET/rootcd/boot
530 status
531 # Exract initramfs.
532 cd $TARGET/rootfs
533 echo -n "Extracting the rootfs... "
534 ( zcat ../rootcd/boot/rootfs.gz 2>/dev/null || \
535 lzma d ../rootcd/boot/rootfs.?z -so 2>/dev/null || \
536 cat ../rootcd/boot/rootfs.gz ) | cpio -id
537 # unpack /usr
538 for i in etc/tazlito/*.extract; do
539 [ -f "$i" ] && . $i ../rootcd
540 done
541 # Umount and remove temp directory and cd to $TARGET to get stats.
542 umount $TMP_DIR && rm -rf $TMP_DIR
543 cd ..
544 echo ""
545 echo "================================================================================"
546 echo "Extracted : `basename $ISO_IMAGE` ($isosize)"
547 echo "Distro tree : `pwd`"
548 echo "Rootfs size : `du -sh rootfs`"
549 echo "Rootcd size : `du -sh rootcd`"
550 echo "================================================================================"
551 echo ""
552 ;;
553 list-flavors)
554 # Show available flavors.
555 if [ ! -s /etc/tazlito/flavors.list -o "$2" == "--recharge" ]; then
556 download flavors.list -O - > /etc/tazlito/flavors.list
557 fi
558 echo ""
559 echo -e "\033[1mList of flavors\033[0m"
560 echo "================================================================================"
561 cat /etc/tazlito/flavors.list
562 echo ""
563 ;;
564 show-flavor)
565 # Show flavor description.
566 FLAVOR=$2
567 if [ ! -f "$FLAVOR.flavor" ]; then
568 echo "File $FLAVOR.flavor not found."
569 exit 1
570 fi
571 mkdir $TMP_DIR
572 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i 2> /dev/null )
573 if [ "$3" = "--brief" ]; then
574 if [ "$4" != "--noheader" ]; then
575 echo "Name Sizes Description"
576 echo "================================================================================"
577 fi
578 printf "%-15.15s %5.5s/%5.5s %-51s\n" "$FLAVOR" \
579 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
580 "$(field Rootfs $TMP_DIR/$FLAVOR.desc)" \
581 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
582 else
583 echo "================================================================================"
584 cat $TMP_DIR/$FLAVOR.desc
585 fi
586 rm -Rf $TMP_DIR
587 ;;
588 gen-liveflavor)
589 # Generate a new flavor form the live system.
590 FLAVOR=$2
591 DESC=""
592 case "$FLAVOR" in
593 '') echo -n "Flavor name : "
594 read FLAVOR
595 [ -z "$FLAVOR" ] && exit 1;;
596 -?|-h*|--help) echo -e "
598 SliTaz Live Tool - Version: $VERSION
599 \033[1mUsage: \033[0m `basename $0` gen-liveflavor flavor-name [flavor-patch-file]
600 \033[1mflavor-patch-file format: \033[0m
601 code data
602 + package to add
603 - package to remove
604 ! non-free package to add
605 ? display message
606 @ flavor description
608 \033[1mExample: \033[0m
609 @ Developer tools for slitaz maintainers
610 + slitaz-toolchain
611 + mercurial
612 "
613 exit 1;;
614 esac
615 mv /etc/tazlito/distro-packages.list \
616 /etc/tazlito/distro-packages.list.$$ 2> /dev/null
617 rm -f distro-packages.list non-free.list 2> /dev/null
618 tazpkg recharge
619 [ -n "$3" ] && while read action pkg; do
620 case "$action" in
621 +) yes | tazpkg get-install $pkg;;
622 -) yes | tazpkg remove $pkg;;
623 !) echo $pkg >> non-free.list;;
624 @) DESC="$pkg";;
625 \?) echo -en "$pkg"; read action;;
626 esac
627 done < $3
628 yes '' | tazlito gen-distro
629 echo "$DESC" | tazlito gen-flavor "$FLAVOR"
630 mv /etc/tazlito/distro-packages.list.$$ \
631 /etc/tazlito/distro-packages.list 2> /dev/null
632 ;;
633 gen-flavor)
634 # Generate a new flavor from the last iso image generation.
635 FLAVOR=$2
636 echo ""
637 echo -e "\033[1mFlavor generation\033[0m"
638 echo "================================================================================"
639 if [ -z "$FLAVOR" ]; then
640 echo -n "Flavor name : "
641 read FLAVOR
642 [ -z "$FLAVOR" ] && exit 1
643 fi
644 check_rootfs
645 FILES="$FLAVOR.pkglist"
646 echo -n "Creating file $FLAVOR.flavor..."
647 for i in rootcd rootfs; do
648 if [ -d "$ADDFILES/$i" ] ; then
649 FILES="$FILES\n$FLAVOR.$i"
650 ( cd "$ADDFILES/$i"; find . | \
651 cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
652 fi
653 done
654 status
655 answer=`grep -s ^Description $FLAVOR.desc`
656 answer=${answer#Description : }
657 if [ -z "$answer" ]; then
658 echo -n "Description : "
659 read answer
660 fi
661 echo -n "Compressing flavor $FLAVOR..."
662 echo "Flavor : $FLAVOR" > $FLAVOR.desc
663 echo "Description : $answer" >> $FLAVOR.desc
664 ( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
665 \rm -f $FLAVOR.pkglist $FLAVOR.nonfree 2> /dev/null
666 for i in $(ls $ROOTFS$INSTALLED); do
667 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
668 EXTRAVERSION=""
669 eval $(grep ^EXTRAVERSION= $ROOTFS$INSTALLED/$i/receipt)
670 eval $(grep ^CATEGORY= $ROOTFS$INSTALLED/$i/receipt)
671 if [ "$CATEGORY" = "non-free" -a "${i%%-*}" != "get" ]
672 then
673 echo "$i" >> $FLAVOR.nonfree
674 else
675 echo "$i-$VERSION$EXTRAVERSION" >> $FLAVOR.pkglist
676 fi
677 done
678 [ -s $FLAVOR.nonfree ] && $FILES="$FILES\n$FLAVOR.nonfree"
679 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
680 gzip -9 > $FLAVOR.flavor
681 rm `echo -e $FILES`
682 status
683 echo "================================================================================"
684 echo "Flavor size : `du -sh $FLAVOR.flavor`"
685 echo ""
686 ;;
687 get-flavor)
688 # Get a flavor's files and prepare for gen-distro.
689 FLAVOR=$2
690 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
691 echo -n "Cleaning $DISTRO..."
692 rm -R $DISTRO 2> /dev/null
693 mkdir -p $DISTRO
694 status
695 mkdir $TMP_DIR
696 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i 2>/dev/null )
697 echo -n "Create distro-packages.list..."
698 mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
699 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
700 status
701 for i in rootcd rootfs; do
702 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
703 mkdir -p "$ADDFILES/$i"
704 zcat $TMP_DIR/$FLAVOR.$i | \
705 ( cd "$ADDFILES/$i"; cpio -id 2> /dev/null)
706 fi
707 done
708 echo -n "Update tazlito.conf..."
709 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
710 cat tazlito.conf | grep -v "^#VOLUM_NAME" | \
711 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
712 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
713 status
714 rm -Rf $TMP_DIR
715 fi
716 ;;
717 check-list)
718 # Use current packages list in $PWD by default.
719 DISTRO_PKGS_LIST=distro-packages.list
720 [ -d "$2" ] && DISTRO_PKGS_LIST=$2/distro-packages.list
721 [ -f "$2" ] && DISTRO_PKGS_LIST=$2
722 [ ! -f $DISTRO_PKGS_LIST ] && echo "No packages list found." && exit 0
723 echo ""
724 echo -e "\033[1mLiveCD packages list check\033[0m"
725 echo "================================================================================"
726 for pkg in `cat $DISTRO_PKGS_LIST`
727 do
728 if ! grep -q "$pkg" /var/lib/tazpkg/packages.list; then
729 echo "Update: $pkg"
730 up=$(($up + 1))
731 fi
732 done
733 [ -z $up ] && echo -e "List is up-to-date\n" && exit 0
734 echo "================================================================================"
735 echo -e "Updates: $up\n" ;;
736 gen-distro)
737 # Generate a live distro tree with a set of packages.
738 #
739 check_root
740 if [ -d $ROOTFS ] ; then
741 echo -e "\nA rootfs exist in : $DISTRO"
742 echo -e "Please clean the distro tree or change directory path.\n"
743 exit 0
744 fi
745 # Check if a package list was specified on cmdline.
746 LIST_NAME="distro-packages.list"
747 CDROM=""
748 while [ -n "$2" ]; do
749 case "$2" in
750 --iso=*)
751 CDROM="-o loop ${2#--iso=}"
752 ;;
753 --cdrom)
754 CDROM="/dev/cdrom"
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
766 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
767 # Build list with installed packages
768 for i in $(ls $INSTALLED); do
769 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
770 EXTRAVERSION=""
771 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
772 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
773 done
774 fi
775 # Exit if no list name.
776 if [ ! -f "$LIST_NAME" ]; then
777 echo -e "\nNo packages list found or specified. Please read the doc.\n"
778 exit 0
779 fi
780 # Start generation.
781 echo ""
782 echo -e "\033[1mTazlito generating a distro\033[0m"
783 echo "================================================================================"
784 # Misc checks
785 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
786 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
787 # Get the list of packages using cat for a file list.
788 LIST=`cat $LIST_NAME`
789 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
790 REPACK=""
791 DOWNLOAD=""
792 for pkg in $LIST
793 do
794 [ "$pkg" = "" ] && continue
795 pkg=${pkg%.tazpkg}
796 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
797 PACKAGE=$(installed_package_name $pkg)
798 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
799 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
800 echo -e "\nUnable to find $pkg in the repository."
801 echo -e "Path : $PACKAGES_REPOSITORY\n"
802 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
803 yesorno "Repack packages from rootfs (y/N) ? "
804 REPACK="$answer"
805 [ "$answer" = "y" ] || REPACK="n"
806 [ "$DOWNLOAD" = "y" ] && break
807 fi
808 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
809 yesorno "Download packages from mirror (Y/n) ? "
810 DOWNLOAD="$answer"
811 if [ "$answer" = "n" ]; then
812 [ -z "$PACKAGE" ] && exit 1
813 else
814 DOWNLOAD="y"
815 [ -n "$REPACK" ] && break
816 fi
817 fi
818 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
819 done
821 # Mount cdrom to be able to repack boot-loader packages
822 if [ ! -e /boot -a -n "$CDROM" ]; then
823 mkdir $TMP_MNT
824 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
825 ln -s $TMP_MNT/boot /
826 if [ ! -d "$ADDFILES/rootcd" ] ; then
827 mkdir -p $ADDFILES/rootcd
828 for i in $(ls $TMP_MNT); do
829 [ "$i" = "boot" ] && continue
830 cp -a $TMP_MNT/$i $ADDFILES/rootcd
831 done
832 fi
833 else
834 rmdir $TMP_MNT
835 fi
836 fi
838 # Root fs stuff.
839 echo "Preparing the rootfs directory..."
840 mkdir -p $ROOTFS
841 sleep 2
842 for pkg in $LIST
843 do
844 [ "$pkg" = "" ] && continue
845 # First copy and extract the package in tmp dir.
846 pkg=${pkg%.tazpkg}
847 PACKAGE=$(installed_package_name $pkg)
848 mkdir -p $TMP_DIR
849 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
850 # Look for package in cache
851 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
852 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
853 # Look for package in running distribution
854 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
855 tazpkg repack $PACKAGE && \
856 mv $pkg.tazpkg $PACKAGES_REPOSITORY
857 fi
858 fi
859 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
860 # Get package from mirror
861 [ "$DOWNLOAD" = "y" ] && \
862 download $pkg.tazpkg && \
863 mv $pkg.tazpkg $PACKAGES_REPOSITORY
864 fi
865 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
866 echo "Missing package $pkg."
867 cleanup
868 exit 1
869 fi
870 done
871 if [ -f non-free.list ]; then
872 echo "Preparing non-free packages..."
873 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
874 for pkg in $(cat non-free.list); do
875 if [ ! -d $INSTALLED/$pkg ]; then
876 if [ ! -d $INSTALLED/get-$pkg ]; then
877 tazpkg get-install get-$pkg
878 fi
879 get-$pkg
880 fi
881 tazpkg repack $pkg
882 pkg=$(ls $pkg*.tazpkg)
883 grep -q "^$pkg$" $LIST_NAME || \
884 echo $pkg >>$LIST_NAME
885 mv $pkg $PACKAGES_REPOSITORY
886 done
887 fi
888 echo ""
889 cp $LIST_NAME $DISTRO/distro-packages.list
890 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/distro-packages.list > $DISTRO/list-packages
891 cd $PACKAGES_REPOSITORY
892 yes y | tazpkg install-list \
893 $DISTRO/list-packages --root=$ROOTFS
894 cd $DISTRO
895 cp distro-packages.list $ROOTFS/etc/tazlito
896 # Copy all files from $ADDFILES/rootfs to the rootfs.
897 if [ -d "$ADDFILES/rootfs" ] ; then
898 echo -n "Copying addfiles content to the rootfs... "
899 cp -a $ADDFILES/rootfs/* $ROOTFS
900 status
901 fi
902 echo "Root file system is generated..."
903 # Root CD part.
904 echo -n "Preparing the rootcd directory..."
905 mkdir -p $ROOTCD
906 status
907 # Move the boot dir with the Linux kernel from rootfs.
908 # The boot dir goes directly on the CD.
909 if [ -d "$ROOTFS/boot" ] ; then
910 echo -n "Moving the boot directory..."
911 mv $ROOTFS/boot $ROOTCD
912 cd $ROOTCD/boot
913 ln vmlinuz-* bzImage
914 status
915 fi
916 cd $DISTRO
917 # Copy all files from $ADDFILES/rootcd to the rootcd.
918 if [ -d "$ADDFILES/rootcd" ] ; then
919 echo -n "Copying addfiles content to the rootcd... "
920 cp -a $ADDFILES/rootcd/* $ROOTCD
921 status
922 fi
923 # Initramfs and ISO image stuff.
924 gen_initramfs
925 gen_livecd_isolinux
926 distro_stats
927 cleanup
928 ;;
929 clean-distro)
930 # Remove old distro tree.
931 #
932 check_root
933 echo ""
934 echo -e "\033[1mCleaning :\033[0m $DISTRO"
935 echo "================================================================================"
936 if [ -d "$DISTRO" ] ; then
937 if [ -d "$ROOTFS" ] ; then
938 echo -n "Removing the rootfs..."
939 rm -f $DISTRO/$INITRAMFS
940 rm -rf $ROOTFS
941 status
942 fi
943 if [ -d "$ROOTCD" ] ; then
944 echo -n "Removing the rootcd..."
945 rm -rf $ROOTCD
946 status
947 fi
948 echo -n "Removing eventual ISO image..."
949 rm -f $DISTRO/$ISO_NAME.iso
950 rm -f $DISTRO/$ISO_NAME.md5
951 status
952 fi
953 echo "================================================================================"
954 echo ""
955 ;;
956 check-distro)
957 # Check for a few LiveCD needed files not installed by packages.
958 #
959 check_rootfs
960 echo ""
961 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
962 echo "================================================================================"
963 # SliTaz release info.
964 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
965 echo "Missing release info : /etc/slitaz-release"
966 else
967 release=`cat $ROOTFS/etc/slitaz-release`
968 echo -n "Release : $release"
969 status
970 fi
971 # Tazpkg mirror.
972 if [ ! -f "$ROOTFS/var/lib/tazpkg/mirror" ]; then
973 echo -n "Mirror URL : Missing /var/lib/tazpkg/mirror"
974 todomsg
975 else
976 echo -n "Mirror configuration exist..."
977 status
978 fi
979 # Isolinux msg
980 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.msg; then
981 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
982 todomsg
983 else
984 echo -n "Isolinux message seems good..."
985 status
986 fi
987 echo "================================================================================"
988 echo ""
989 ;;
990 burn-iso)
991 # Guess cdrom device, ask user and burn the ISO.
992 #
993 check_root
994 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
995 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
996 # We can specify an alternative ISO from the cmdline.
997 if [ -n "$2" ] ; then
998 iso=$2
999 else
1000 iso=$DISTRO/$ISO_NAME.iso
1001 fi
1002 if [ ! -f "$iso" ]; then
1003 echo -e "\nUnable to find ISO : $iso\n"
1004 exit 0
1005 fi
1006 echo ""
1007 echo -e "\033[1mTazlito burn ISO\033[0m "
1008 echo "================================================================================"
1009 echo "Cdrom device : /dev/$DRIVE_NAME"
1010 echo "Drive speed : $DRIVE_SPEED"
1011 echo "ISO image : $iso"
1012 echo "================================================================================"
1013 echo ""
1014 yesorno "Burn ISO image (y/N) ? "
1015 if [ "$answer" == "y" ]; then
1016 echo ""
1017 echo "Starting Wodim to burn the iso..." && sleep 2
1018 echo "================================================================================"
1019 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
1020 echo "================================================================================"
1021 echo "ISO image is burned to cdrom."
1022 else
1023 echo -e "\nExiting. No ISO burned."
1024 fi
1025 echo ""
1026 ;;
1027 usage|*)
1028 # Clear and print usage also for all unknown commands.
1030 clear
1031 usage
1032 ;;
1034 esac
1036 exit 0