tazlito view tazlito @ rev 60

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