tazlito view tazlito @ rev 86

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