tazlito view tazlito @ rev 79

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