tazlito view tazlito @ rev 64

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