tazlito view tazlito @ rev 91

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