tazlito view tazlito @ rev 75

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