tazlito view tazlito @ rev 66

md5sum for files only
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat May 10 22:25:41 2008 +0000 (2008-05-10)
parents 9dce06cbb12e
children 68bbfaa51808
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 %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) echo -e "
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 ! non-free package to add
590 ? display message
591 @ flavor description
593 \033[1mExample: \033[0m
594 @ Developper tools for slitaz maintainers
595 + slitaz-toolchain
596 + mercurial
597 "
598 exit 1;;
599 esac
600 mv /etc/tazlito/distro-packages.list \
601 /etc/tazlito/distro-packages.list.$$ 2> /dev/null
602 rm -f distro-packages.list non-free.list 2> /dev/null
603 tazpkg recharge
604 [ -n "$3" ] && while read action pkg; do
605 case "$action" in
606 +) yes | tazpkg get-install $pkg;;
607 -) yes | tazpkg remove $pkg;;
608 !) echo $pkg >> non-free.list;;
609 @) DESC="$pkg";;
610 \?) echo -en "$pkg"; read action;;
611 esac
612 done < $3
613 yes '' | tazlito gen-distro
614 echo "$DESC" | tazlito gen-flavor "$FLAVOR"
615 mv /etc/tazlito/distro-packages.list.$$ \
616 /etc/tazlito/distro-packages.list 2> /dev/null
617 ;;
618 gen-flavor)
619 # Generate a new flavor from the last iso image generation.
620 FLAVOR=$2
621 echo ""
622 echo -e "\033[1mFlavor generation\033[0m"
623 echo "================================================================================"
624 if [ -z "$FLAVOR" ]; then
625 echo -n "Flavor name : "
626 read FLAVOR
627 [ -z "$FLAVOR" ] && exit 1
628 fi
629 check_rootfs
630 FILES="$FLAVOR.pkglist $FLAVOR.nonfree"
631 echo -n "Creating file $FLAVOR.flavor..."
632 for i in rootcd rootfs; do
633 if [ -d "$ADDFILES/$i" ] ; then
634 FILES="$FILES\n$FLAVOR.$i"
635 ( cd "$ADDFILES/$i"; find . | \
636 cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
637 fi
638 done
639 status
640 answer=`grep -s ^Description $FLAVOR.desc`
641 answer=${answer#Description : }
642 if [ -z "$answer" ]; then
643 echo -n "Description : "
644 read answer
645 fi
646 echo -n "Compressing flavor $FLAVOR..."
647 echo "Flavor : $FLAVOR" > $FLAVOR.desc
648 echo "Description : $answer" >> $FLAVOR.desc
649 ( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
650 \rm -f $FLAVOR.pkglist 2> /dev/null
651 for i in $(ls $ROOTFS$INSTALLED); do
652 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
653 eval $(grep ^CATEGORY= $ROOTFS$INSTALLED/$i/receipt)
654 if [ "$CATEGORY" = "non-free" -a "${i%%-*}" != "get" ]
655 then
656 echo "$i" >> $FLAVOR.nonfree
657 else
658 echo "$i-$VERSION" >> $FLAVOR.pkglist
659 fi
660 done
661 ls $FLAVOR.desc $FILES 2>/dev/null | \
662 cpio -o -H newc 2>/dev/null | gzip -9 > $FLAVOR.flavor
663 rm `echo -e $FILES`
664 status
665 echo "================================================================================"
666 echo "Flavor size : `du -sh $FLAVOR.flavor`"
667 echo ""
668 ;;
669 get-flavor)
670 # Get a flavor's files and prepare for gen-distro.
671 FLAVOR=$2
672 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
673 echo -n "Cleaning $DISTRO..."
674 rm -R $DISTRO 2> /dev/null
675 mkdir -p $DISTRO
676 status
677 mkdir $TMP_DIR
678 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i 2>/dev/null )
679 echo -n "Create distro-packages.list..."
680 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
681 mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
682 status
683 for i in rootcd rootfs; do
684 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
685 mkdir -p "$ADDFILES/$i"
686 zcat $TMP_DIR/$FLAVOR.$i | \
687 ( cd "$ADDFILES/$i"; cpio -id 2> /dev/null)
688 fi
689 done
690 echo -n "Update tazlito.conf..."
691 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
692 cat tazlito.conf | grep -v "^#VOLUM_NAME" | \
693 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
694 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
695 status
696 rm -Rf $TMP_DIR
697 fi
698 ;;
699 gen-distro)
700 # Generate a live distro tree with a set of packages.
701 #
702 check_root
703 if [ -d $ROOTFS ] ; then
704 echo "A rootfs exist in : $DISTRO"
705 echo -e "Please clean the distro tree or change directory path.\n"
706 exit 0
707 fi
708 # Check if a package list was specified on cmdline.
709 LIST_NAME="distro-packages.list"
710 CDROM=""
711 while [ -n "$2" ]; do
712 case "$2" in
713 --iso=*)
714 CDROM="-o loop ${2#--iso=}"
715 ;;
716 --cdrom)
717 CDROM="/dev/cdrom"
718 ;;
719 *) if [ ! -f "$2" ] ; then
720 echo -e "\nUnable to find the specified packages list."
721 echo -e "List name : $2\n"
722 exit 1
723 fi
724 LIST_NAME=$2
725 ;;
726 esac
727 shift
728 done
729 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
730 # Build list with installed packages
731 for i in $(ls $INSTALLED); do
732 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
733 echo "$i-$VERSION" >> $LIST_NAME
734 done
735 fi
736 # Exit if no list name.
737 if [ ! -f "$LIST_NAME" ]; then
738 echo -e "\nNo packages list found or specified. Please read the doc.\n"
739 exit 0
740 fi
741 # Start generation.
742 echo ""
743 echo -e "\033[1mTazlito generating a distro\033[0m"
744 echo "================================================================================"
745 # Misc checks
746 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
747 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
748 # Get the list of packages using cat for a file list.
749 LIST=`cat $LIST_NAME`
750 # Verify if all packages in list are presents in $PACKAGES_REPOSITORY.
751 REPACK=""
752 DOWNLOAD=""
753 for pkg in $LIST
754 do
755 [ "$pkg" = "" ] && continue
756 pkg=${pkg%.tazpkg}
757 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
758 PACKAGE=$(installed_package_name $pkg)
759 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
760 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
761 echo -e "\nUnable to find $pkg in the repository."
762 echo -e "Path : $PACKAGES_REPOSITORY\n"
763 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
764 yesorno "Repack packages from rootfs (y/N) ? "
765 REPACK="$answer"
766 [ "$answer" = "y" ] || REPACK="n"
767 [ "$DOWNLOAD" = "y" ] && break
768 fi
769 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
770 yesorno "Download packages from mirror (Y/n) ? "
771 DOWNLOAD="$answer"
772 if [ "$answer" = "n" ]; then
773 [ -z "$PACKAGE" ] && exit 1
774 else
775 DOWNLOAD="y"
776 [ -n "$REPACK" ] && break
777 fi
778 fi
779 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
780 done
782 # mount cdrom to be able to repack boot-loader packages
783 if [ ! -e /boot -a -n "$CDROM" ]; then
784 mkdir $TMP_MNT
785 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
786 ln -s $TMP_MNT/boot /
787 if [ ! -d "$ADDFILES/rootcd" ] ; then
788 mkdir -p $ADDFILES/rootcd
789 for i in $(ls $TMP_MNT); do
790 [ "$i" = "boot" ] && continue
791 cp -a $TMP_MNT/$i $ADDFILES/rootcd
792 done
793 fi
794 else
795 rmdir $TMP_MNT
796 fi
797 fi
799 # Root fs stuff.
800 echo "Preparing the rootfs directory..."
801 mkdir -p $ROOTFS
802 sleep 2
803 for pkg in $LIST
804 do
805 [ "$pkg" = "" ] && continue
806 # First copy and extract the package in tmp dir.
807 pkg=${pkg%.tazpkg}
808 PACKAGE=$(installed_package_name $pkg)
809 mkdir -p $TMP_DIR
810 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
811 # look for package in cache
812 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
813 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
814 # look for package in running distribution
815 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
816 tazpkg repack $PACKAGE && \
817 mv $pkg.tazpkg $PACKAGES_REPOSITORY
818 fi
819 fi
820 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
821 # get package from mirror
822 [ "$DOWNLOAD" = "y" ] && \
823 download $pkg.tazpkg && \
824 mv $pkg.tazpkg $PACKAGES_REPOSITORY
825 fi
826 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
827 echo "Missing package $pkg."
828 cleanup
829 exit 1
830 fi
831 yes "" | tazpkg install $PACKAGES_REPOSITORY/$pkg.tazpkg --root=$ROOTFS
832 done
833 cp $LIST_NAME $ROOTFS/etc/tazlito/distro-packages.list
834 if [ -f non-free.list ]; then
835 echo "Preparing non-free packages..."
836 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
837 for pkg in $(cat non-free.list); do
838 if [ ! -d $INSTALLED/$pkg ]; then
839 if [ ! -d $INSTALLED/get-$pkg ]; then
840 tazpkg get-install get-$pkg
841 fi
842 get-$pkg
843 fi
844 tazpkg repack $pkg
845 yes "" | tazpkg install $pkg*.tazpkg --root=$ROOTFS
846 mv $pkg*.tazpkg $PACKAGES_REPOSITORY
847 done
848 fi
849 echo ""
850 cd $DISTRO
851 # Copy all files from $ADDFILES/rootfs to the rootfs.
852 if [ -d "$ADDFILES/rootfs" ] ; then
853 echo -n "Copying addfiles content to the rootfs... "
854 cp -a $ADDFILES/rootfs/* $ROOTFS
855 status
856 fi
857 echo "Root file system is generated..."
858 # Root CD part.
859 echo -n "Preparing the rootcd directory..."
860 mkdir -p $ROOTCD
861 status
862 # Move the boot dir with the Linux kernel from rootfs.
863 # The boot dir goes directly on the CD.
864 if [ -d "$ROOTFS/boot" ] ; then
865 echo -n "Moving the boot directory..."
866 mv $ROOTFS/boot $ROOTCD
867 cd $ROOTCD/boot
868 ln vmlinuz-* bzImage
869 status
870 fi
871 cd $DISTRO
872 # Copy all files from $ADDFILES/rootcd to the rootcd.
873 if [ -d "$ADDFILES/rootcd" ] ; then
874 echo -n "Copying addfiles content to the rootcd... "
875 cp -a $ADDFILES/rootcd/* $ROOTCD
876 status
877 fi
878 # Initramfs and ISO image stuff.
879 gen_initramfs
880 gen_livecd_isolinux
881 distro_stats
882 cleanup
883 ;;
884 clean-distro)
885 # Remove old distro tree.
886 #
887 check_root
888 echo ""
889 echo -e "\033[1mCleaning :\033[0m $DISTRO"
890 echo "================================================================================"
891 if [ -d "$DISTRO" ] ; then
892 if [ -d "$ROOTFS" ] ; then
893 echo -n "Removing the rootfs..."
894 rm -f $DISTRO/$INITRAMFS
895 rm -rf $ROOTFS
896 status
897 fi
898 if [ -d "$ROOTCD" ] ; then
899 echo -n "Removing the rootcd..."
900 rm -rf $ROOTCD
901 status
902 fi
903 echo -n "Removing eventual ISO image..."
904 rm -f $DISTRO/$ISO_NAME.iso
905 rm -f $DISTRO/$ISO_NAME.md5
906 status
907 fi
908 echo "================================================================================"
909 echo ""
910 ;;
911 addhacker)
912 # Without /etc/passwd...
913 #
914 check_root
915 echo ""
916 echo -e "\033[1mAdduser hacker to :\033[0m $ROOTFS"
917 echo "================================================================================"
918 if [ ! -d "$ROOTFS/etc" ] ; then
919 echo -e "\nUnable to find : $ROOTFS/etc"
920 echo -e "Users and passwords config files will not be found.\n"
921 exit 0
922 fi
923 # Go for echoing on configuration files if any hacker was found.
924 #
925 if ! grep -q hacker $root/etc/passwd; then
926 echo -n "Configuring $ROOTFS/etc..."
927 echo 'hacker:x:500:500:Linux User,,,:/home/hacker:/bin/ash' >> $ROOTFS/etc/passwd
928 echo 'hacker::13646:0:99999:7:::' >> $ROOTFS/etc/shadow
929 echo 'hacker:x:500:' >> $ROOTFS/etc/group
930 echo 'hacker:!::' >> $ROOTFS/etc/gshadow
931 status
932 else
933 echo "Hacker is already in : $ROOTFS/etc/passwd"
934 fi
935 # Hacker can listen to music
936 #
937 if grep -q audio $root/etc/group; then
938 if ! grep -q "audio:x:20:hacker" $root/etc/group; then
939 sed -i s/'audio:x:20:'/'audio:x:20:hacker'/ $root/etc/group
940 fi
941 fi
942 # /home/hacker directories.
943 #
944 echo -n "Creating default directories... "
945 mkdir -p $fs/home/hacker/Documents \
946 $fs/home/hacker/Downloads \
947 $fs/home/hacker/Templates \
948 $fs/home/hacker/.local/bin \
949 $fs/home/hacker/.local/share
950 status
951 # Change permissions.
952 #
953 echo -n "Chmodig all files in /home/hacker..."
954 chown -R 500.500 $ROOTFS/home/hacker
955 status
956 echo "================================================================================"
957 echo "Linux User Hacker have an account in the distro."
958 echo ""
959 ;;
960 check-distro)
961 # Check for a few LiveCD needed files not installed by packages.
962 #
963 check_rootfs
964 echo ""
965 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
966 echo "================================================================================"
967 # SliTaz release info.
968 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
969 echo "Missing release info : /etc/slitaz-release"
970 else
971 release=`cat $ROOTFS/etc/slitaz-release`
972 echo -n "Release : $release"
973 status
974 fi
975 # Tazpkg mirror.
976 if [ ! -f "$ROOTFS/var/lib/tazpkg/mirror" ]; then
977 echo -n "Mirror URL : Missing /var/lib/tazpkg/mirror"
978 todomsg
979 else
980 echo -n "Mirror configuration exist..."
981 status
982 fi
983 # Isolinux msg
984 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.msg; then
985 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
986 todomsg
987 else
988 echo -n "Isolinux message seems good..."
989 status
990 fi
991 echo "================================================================================"
992 echo ""
993 ;;
994 burn-iso)
995 # Guess cdrom device, ask user and burn the ISO.
996 #
997 check_root
998 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
999 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
1000 # We can specify an alternative ISO from the cmdline.
1001 if [ -n "$2" ] ; then
1002 iso=$2
1003 else
1004 iso=$DISTRO/$ISO_NAME.iso
1005 fi
1006 if [ ! -f "$iso" ]; then
1007 echo -e "\nUnable to find ISO : $iso\n"
1008 exit 0
1009 fi
1010 echo ""
1011 echo -e "\033[1mTazlito burn ISO\033[0m "
1012 echo "================================================================================"
1013 echo "Cdrom device : /dev/$DRIVE_NAME"
1014 echo "Drive speed : $DRIVE_SPEED"
1015 echo "ISO image : $iso"
1016 echo "================================================================================"
1017 echo ""
1018 yesorno "Burn ISO image (y/N) ? "
1019 if [ "$answer" == "y" ]; then
1020 echo ""
1021 echo "Starting Wodim to burn the iso..." && sleep 2
1022 echo "================================================================================"
1023 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
1024 echo "================================================================================"
1025 echo "ISO image is burned to cdrom."
1026 else
1027 echo -e "\nExiting. No ISO burned."
1028 fi
1029 echo ""
1030 ;;
1031 usage|*)
1032 # Clear and print usage also for all unknow commands.
1034 clear
1035 usage
1036 ;;
1038 esac
1040 exit 0