tazlito view tazlito @ rev 85

Default mirror is mirror.slitaz.org
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Nov 04 09:09:12 2008 +0000 (2008-11-04)
parents 8b29b5b304b1
children 50d20092f45c
line source
1 #!/bin/sh
2 # TazLito - SliTaz Live Tool.
3 #
4 # Tazlito is a tool to help generate and configure SliTaz LiveCD
5 # ISO images. You can create a custom distro in one command from a list of
6 # packages, extract an existing ISO image to hack it, create a new initramfs
7 # and/or a new ISO. Most commands must be run by root, except 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.8
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://mirror.slitaz.org/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 an 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$@ && break
132 done
133 }
135 # Execute 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 to 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 # Generate 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 # Generate 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 # Create 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 volume name.
324 VOLUM_NAME="SliTaz"
326 # Name of the preparer.
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 containing 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 # Generate 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 an 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 `basename $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 | cut -f1`
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 : `basename $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 @ Developer 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 present 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 $DISTRO/distro-packages.list
850 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/distro-packages.list > $DISTRO/list-packages
851 cd $PACKAGES_REPOSITORY
852 yes y | tazpkg install-list \
853 $DISTRO/list-packages --root=$ROOTFS
854 cd $DISTRO
855 cp distro-packages.list $ROOTFS/etc/tazlito
856 # Copy all files from $ADDFILES/rootfs to the rootfs.
857 if [ -d "$ADDFILES/rootfs" ] ; then
858 echo -n "Copying addfiles content to the rootfs... "
859 cp -a $ADDFILES/rootfs/* $ROOTFS
860 status
861 fi
862 echo "Root file system is generated..."
863 # Root CD part.
864 echo -n "Preparing the rootcd directory..."
865 mkdir -p $ROOTCD
866 status
867 # Move the boot dir with the Linux kernel from rootfs.
868 # The boot dir goes directly on the CD.
869 if [ -d "$ROOTFS/boot" ] ; then
870 echo -n "Moving the boot directory..."
871 mv $ROOTFS/boot $ROOTCD
872 cd $ROOTCD/boot
873 ln vmlinuz-* bzImage
874 status
875 fi
876 cd $DISTRO
877 # Copy all files from $ADDFILES/rootcd to the rootcd.
878 if [ -d "$ADDFILES/rootcd" ] ; then
879 echo -n "Copying addfiles content to the rootcd... "
880 cp -a $ADDFILES/rootcd/* $ROOTCD
881 status
882 fi
883 # Initramfs and ISO image stuff.
884 gen_initramfs
885 gen_livecd_isolinux
886 distro_stats
887 cleanup
888 ;;
889 clean-distro)
890 # Remove old distro tree.
891 #
892 check_root
893 echo ""
894 echo -e "\033[1mCleaning :\033[0m $DISTRO"
895 echo "================================================================================"
896 if [ -d "$DISTRO" ] ; then
897 if [ -d "$ROOTFS" ] ; then
898 echo -n "Removing the rootfs..."
899 rm -f $DISTRO/$INITRAMFS
900 rm -rf $ROOTFS
901 status
902 fi
903 if [ -d "$ROOTCD" ] ; then
904 echo -n "Removing the rootcd..."
905 rm -rf $ROOTCD
906 status
907 fi
908 echo -n "Removing eventual ISO image..."
909 rm -f $DISTRO/$ISO_NAME.iso
910 rm -f $DISTRO/$ISO_NAME.md5
911 status
912 fi
913 echo "================================================================================"
914 echo ""
915 ;;
916 addhacker)
917 # Without /etc/passwd...
918 #
919 check_root
920 echo ""
921 echo -e "\033[1mAdduser hacker to :\033[0m $ROOTFS"
922 echo "================================================================================"
923 if [ ! -d "$ROOTFS/etc" ] ; then
924 echo -e "\nUnable to find : $ROOTFS/etc"
925 echo -e "Users and passwords config files will not be found.\n"
926 exit 0
927 fi
928 # Go for echoing on configuration files if any hacker was found.
929 #
930 if ! grep -q hacker $root/etc/passwd; then
931 echo -n "Configuring $ROOTFS/etc..."
932 echo 'hacker:x:500:500:Linux User,,,:/home/hacker:/bin/ash' >> $ROOTFS/etc/passwd
933 echo 'hacker::13646:0:99999:7:::' >> $ROOTFS/etc/shadow
934 echo 'hacker:x:500:' >> $ROOTFS/etc/group
935 echo 'hacker:!::' >> $ROOTFS/etc/gshadow
936 status
937 else
938 echo "Hacker is already in : $ROOTFS/etc/passwd"
939 fi
940 # Hacker can listen to music
941 #
942 if grep -q audio $root/etc/group; then
943 if ! grep -q "audio:x:20:hacker" $root/etc/group; then
944 sed -i s/'audio:x:20:'/'audio:x:20:hacker'/ $root/etc/group
945 fi
946 fi
947 # /home/hacker directories.
948 #
949 echo -n "Creating default directories... "
950 mkdir -p $fs/home/hacker/Documents \
951 $fs/home/hacker/Downloads \
952 $fs/home/hacker/Templates \
953 $fs/home/hacker/.local/bin \
954 $fs/home/hacker/.local/share
955 status
956 # Change permissions.
957 #
958 echo -n "Chmoding all files in /home/hacker..."
959 chown -R 500.500 $ROOTFS/home/hacker
960 status
961 echo "================================================================================"
962 echo "Linux User Hacker have an account in the distro."
963 echo ""
964 ;;
965 check-distro)
966 # Check for a few LiveCD needed files not installed by packages.
967 #
968 check_rootfs
969 echo ""
970 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
971 echo "================================================================================"
972 # SliTaz release info.
973 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
974 echo "Missing release info : /etc/slitaz-release"
975 else
976 release=`cat $ROOTFS/etc/slitaz-release`
977 echo -n "Release : $release"
978 status
979 fi
980 # Tazpkg mirror.
981 if [ ! -f "$ROOTFS/var/lib/tazpkg/mirror" ]; then
982 echo -n "Mirror URL : Missing /var/lib/tazpkg/mirror"
983 todomsg
984 else
985 echo -n "Mirror configuration exist..."
986 status
987 fi
988 # Isolinux msg
989 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.msg; then
990 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
991 todomsg
992 else
993 echo -n "Isolinux message seems good..."
994 status
995 fi
996 echo "================================================================================"
997 echo ""
998 ;;
999 burn-iso)
1000 # Guess cdrom device, ask user and burn the ISO.
1002 check_root
1003 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
1004 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
1005 # We can specify an alternative ISO from the cmdline.
1006 if [ -n "$2" ] ; then
1007 iso=$2
1008 else
1009 iso=$DISTRO/$ISO_NAME.iso
1010 fi
1011 if [ ! -f "$iso" ]; then
1012 echo -e "\nUnable to find ISO : $iso\n"
1013 exit 0
1014 fi
1015 echo ""
1016 echo -e "\033[1mTazlito burn ISO\033[0m "
1017 echo "================================================================================"
1018 echo "Cdrom device : /dev/$DRIVE_NAME"
1019 echo "Drive speed : $DRIVE_SPEED"
1020 echo "ISO image : $iso"
1021 echo "================================================================================"
1022 echo ""
1023 yesorno "Burn ISO image (y/N) ? "
1024 if [ "$answer" == "y" ]; then
1025 echo ""
1026 echo "Starting Wodim to burn the iso..." && sleep 2
1027 echo "================================================================================"
1028 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
1029 echo "================================================================================"
1030 echo "ISO image is burned to cdrom."
1031 else
1032 echo -e "\nExiting. No ISO burned."
1033 fi
1034 echo ""
1035 ;;
1036 usage|*)
1037 # Clear and print usage also for all unknown commands.
1039 clear
1040 usage
1041 ;;
1043 esac
1045 exit 0