tazlito view tazlito @ rev 34

Uncompressed rootfs support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Feb 14 18:43:29 2008 +0100 (2008-02-14)
parents 755be6c917cf
children f0550dba4738
line source
1 #!/bin/sh
2 # TazLito - SliTaz Live Tool.
3 #
4 # Tazlito is a tool to help generating and configuring SliTaz LiveCD
5 # ISO images. You can creat a custom distro in one command from a list of
6 # packages, extract a existing ISO image to hack it, creat new initramfs
7 # and/or new ISO. Most commands must be run by root, expect the stats
8 # and the configuration file manipulation.
9 #
10 # (C) 2007-2008 SliTaz - GNU General Public License.
11 #
12 # Authors : Christophe Lincoln <pankso@slitaz.org>
13 # Pascal Bellard <pascal.bellard@slitaz.org>
14 #
15 VERSION=1.4
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
30 # Try to include config file, continue if command is gen-config or exit.
31 # The main config used by default is in /etc/tazlito.
32 if [ -f "/etc/tazlito/tazlito.conf" ] ; then
33 CONFIG_FILE="/etc/tazlito/tazlito.conf"
34 fi
35 # Specific distro config file can be put in a distro tree.
36 if [ -f "$TOP_DIR/tazlito.conf" ] ; then
37 CONFIG_FILE="$TOP_DIR/tazlito.conf"
38 fi
39 if [ ! "$CONFIG_FILE" = "" ] ; then
40 . $CONFIG_FILE
41 else
42 if [ "$COMMAND" = "gen-config" ] ; then
43 continue
44 else
45 echo "Unable to find any configuration file. Please read the doc"
46 echo "or run '`basename $0` gen-config' to get an empty config file."
47 exit 0
48 fi
49 fi
51 # Set the rootfs and rootcd path with $DISTRO
52 # configuration variable.
53 ROOTFS=$DISTRO/rootfs
54 ROOTCD=$DISTRO/rootcd
56 #####################
57 # Tazlito functions #
58 #####################
60 # Print the usage.
61 usage ()
62 {
63 echo -e "\nSliTaz Live Tool - Version: $VERSION\n
64 \033[1mUsage: \033[0m `basename $0` [command] [list|iso|flavor] [dir]
65 \033[1mCommands: \033[0m\n
66 usage Print this short usage.
67 stats View Tazlito and distro configuration statistics.
68 gen-config Generate a new configuration file for a distro.
69 configure Configure the main config file or a specific tazlito.conf.
70 gen-iso Generate a new ISO from a distro tree.
71 gen-initiso Generate a new initramfs and ISO from the distro tree.
72 list-flavors List all available package lists on the mirror.
73 gen-flavor Generate a new live-CD description.
74 show-flavor Show live-CD description.
75 get-flavor Get a flavor's list of packages.
76 extract-distro Extract and ISO to a directory and rebuild LiveCD tree.
77 gen-distro Generated a Live distro and ISO from a list of packages.
78 clean-distro Remove all files generated by gen-distro.
79 addhacker Add Linux User Hacker to the current distro.
80 check-distro Help to check if distro is ready to release.
81 burn-iso Burn ISO image to a cdrom using Wodim.\n"
82 }
84 # Status function.
85 status()
86 {
87 local CHECK=$?
88 echo -en "\\033[70G[ "
89 if [ $CHECK = 0 ]; then
90 echo -en "\\033[1;33mOK"
91 else
92 echo -en "\\033[1;31mFailed"
93 fi
94 echo -e "\\033[0;39m ]"
95 }
97 yesorno()
98 {
99 echo -n "$1"
100 case "$DEFAULT_ANSWER" in
101 Y|y) answer="y";;
102 N|n) answer="n";;
103 *) read answer;;
104 esac
105 }
107 field()
108 {
109 grep "^$1" "$2" | sed 's/.*: \([0-9KMG\.]*\).*/\1/'
110 }
112 todomsg()
113 {
114 echo -e "\\033[70G[ \\033[1;31mTODO\\033[0;39m ]"
115 }
117 # Download a file trying each mirror
118 download()
119 {
120 for i in $(cat $MIRROR); do
121 wget $i$@
122 done
123 }
125 # exec hooks provided by some packages
126 genisohooks()
127 {
128 local here=`pwd`
129 cd $ROOTFS
130 for i in $(ls etc/tazlito/*.$1 2> /dev/null); do
131 . $i $ROOTCD
132 done
133 cd $here
134 }
136 cleanup()
137 {
138 if [ -d $TMP_MNT ]; then
139 umount $TMP_MNT
140 rmdir $TMP_MNT
141 rm -f /boot
142 fi
143 }
145 # echo the package name if the tazpkg is already installed
146 installed_package_name()
147 {
148 local tazpkg
149 local package
150 local VERSION
151 tazpkg=$1
152 # try du find package name and version to be able
153 # to repack it from installation
154 # a dash (-) can exist in name *and* in version
155 package=${tazpkg%-*}
156 i=$package
157 while true; do
158 VERSION=""
159 eval $(grep -s ^VERSION= $INSTALLED/$i/receipt)
160 if [ "$i-$VERSION" = "$tazpkg" ]; then
161 echo $i
162 break
163 fi
164 case "$i" in
165 *-*);;
166 *) break;;
167 esac
168 i=${i%-*}
169 done
170 }
172 # Check if user is root.
173 check_root()
174 {
175 if test $(id -u) != 0 ; then
176 echo -e "\nYou must be root to run `basename $0` with this option."
177 echo -e "Please type 'su' and root password to become super-user.\n"
178 exit 0
179 fi
180 }
182 # Check for the rootfs tree.
183 check_rootfs()
184 {
185 if [ ! -d "$ROOTFS/etc" ] ; then
186 echo -e "\nUnable to find a distro rootfs...\n"
187 exit 0
188 fi
189 }
191 # Check for the boot dir into the root CD tree.
192 verify_rootcd()
193 {
194 if [ ! -d "$ROOTCD/boot" ] ; then
195 echo -e "\nUnable to find the rootcd boot directory...\n"
196 exit 0
197 fi
198 }
200 # Gen a new ISO image using isolinux.
201 gen_livecd_isolinux()
202 {
203 # Some packages may want to alter iso
204 genisohooks iso
205 if [ ! -f "$ROOTCD/boot/isolinux/isolinux.bin" ] ; then
206 echo -e "\nUnable to find isolinux binary.\n"
207 cleanup
208 exit 0
209 fi
210 cd $DISTRO
211 echo ""
212 echo -e "\033[1mGenerating ISO image\033[0m"
213 echo "================================================================================"
214 genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
215 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
216 -V "$VOLUM_NAME" -p "$PREPARED" -input-charset iso8859-1 \
217 -boot-info-table $ROOTCD
218 echo "================================================================================"
219 }
221 # Gen a new initramfs from the root file system.
222 gen_initramfs()
223 {
224 # Some packages may want to alter rootfs
225 genisohooks rootfs
226 cd $ROOTFS
227 echo ""
228 # Use lzma if installed
229 if [ "$COMPRESSION" = "none" ]; then
230 echo -n "Generating uncompressed initramfs... "
231 find . -print | cpio -o -H newc > $DISTRO/$INITRAMFS
232 elif [ -x /usr/bin/lzma -a "$COMPRESSION" != "gzip" ]; then
233 echo -n "Generating lzma'ed initramfs... "
234 find . -print | cpio -o -H newc | lzma e -si -so > $DISTRO/$INITRAMFS
235 else
236 echo -n "Generating gziped initramfs... "
237 find . -print | cpio -o -H newc | gzip -9 > $DISTRO/$INITRAMFS
238 fi
239 cd $DISTRO
240 mv $INITRAMFS $ROOTCD/boot
241 }
243 distro_sizes()
244 {
245 echo "Build date : `date +%Y%m%d\ \at\ \%H:%M:%S`"
246 echo "Packages : `ls -1 $ROOTFS$INSTALLED | wc -l`"
247 echo "Rootfs size : `du -sh $ROOTFS`"
248 echo "Initramfs size : `du -sh $ROOTCD/boot/$INITRAMFS`"
249 echo "ISO image size : `du -sh $ISO_NAME.iso`"
250 echo "================================================================================"
251 echo ""
252 }
254 # Print ISO and rootfs size.
255 distro_stats()
256 {
257 echo ""
258 echo -e "\033[1mDistro statistics\033[0m"
259 echo "================================================================================"
260 distro_sizes
261 }
263 # Creat an empty configuration file.
264 empty_config_file()
265 {
266 cat >> tazlito.conf << "EOF"
267 # tazlito.conf: Tazlito (SliTaz Live Tool)
268 # configuration file.
269 #
271 # Name of the ISO image to generate.
272 ISO_NAME=""
274 # ISO image volum name.
275 VOLUM_NAME="SliTaz"
277 # Name of the preparator.
278 PREPARED="$USER"
280 # Path to the packages repository and the packages.list.
281 PACKAGES_REPOSITORY=""
283 # Path to the distro tree to gen-distro from a
284 # list of packages.
285 DISTRO=""
287 # Path to the directory contening additional files
288 # to copy into the rootfs and rootcd of the LiveCD.
289 ADDFILES="$DISTRO/addfiles"
291 # Default answer for binary question (Y or N)
292 DEFAULT_ANSWER="ASK"
294 # Compression utility (lzma or gzip)
295 COMPRESSION="lzma"
296 EOF
297 }
299 ####################
300 # Tazlito commands #
301 ####################
303 case "$COMMAND" in
304 stats)
305 # Tazlito general statistics from the config file.
306 #
307 echo ""
308 echo -e "\033[1mTazlito statistics\033[0m
309 ===============================================================================
310 Config file : $CONFIG_FILE
311 ISO name : $ISO_NAME.iso
312 Volum name : $VOLUM_NAME
313 Prepared : $PREPARED
314 Packages repository : $PACKAGES_REPOSITORY
315 Distro directory : $DISTRO"
316 if [ ! "$ADDFILES" = "" ] ; then
317 echo -e "Additional files : $ADDFILES"
318 fi
319 echo "================================================================================"
320 echo ""
321 ;;
322 gen-config)
323 # Gen a new config file in the current dir or the specified
324 # directory by $2.
325 #
326 if [ -n "$2" ] ; then
327 mkdir -p $2 && cd $2
328 fi
329 echo -n "Generating empty tazlito.conf..."
330 empty_config_file
331 status
332 echo ""
333 if [ -f "tazlito.conf" ] ; then
334 echo "Configuration file is ready to edit."
335 echo "File location : `pwd`/tazlito.conf"
336 echo ""
337 fi
338 ;;
339 configure)
340 # Configure a tazlito.conf config file. Start by getting
341 # a empty config file and sed it.
342 #
343 if [ -f "tazlito.conf" ] ; then
344 rm tazlito.conf
345 else
346 if test $(id -u) = 0 ; then
347 cd /etc
348 else
349 echo "You must be root to configure the main config file or in"
350 echo "the same directory of the file you want to configure."
351 exit 0
352 fi
353 fi
354 empty_config_file
355 echo""
356 echo -e "\033[1mConfiguring :\033[0m `pwd`/tazlito.conf"
357 echo "================================================================================"
358 # ISO name.
359 echo -n "ISO name : " ; read answer
360 sed -i s#'ISO_NAME=\"\"'#"ISO_NAME=\"$answer\""# tazlito.conf
361 # Volume name.
362 echo -n "Volume name : " ; read answer
363 sed -i s/'VOLUM_NAME=\"SliTaz\"'/"VOLUM_NAME=\"$answer\""/ tazlito.conf
364 # Packages repository.
365 echo -n "Packages repository : " ; read answer
366 sed -i s#'PACKAGES_REPOSITORY=\"\"'#"PACKAGES_REPOSITORY=\"$answer\""# tazlito.conf
367 # Distro path.
368 echo -n "Distro path : " ; read answer
369 sed -i s#'DISTRO=\"\"'#"DISTRO=\"$answer\""# tazlito.conf
370 echo "================================================================================"
371 echo "Config file is ready to use."
372 echo "You can now extract an ISO or generate a distro."
373 echo ""
374 ;;
375 gen-iso)
376 # Simply generated a new iso.
377 #
378 check_root
379 verify_rootcd
380 gen_livecd_isolinux
381 distro_stats
382 ;;
383 gen-initiso)
384 # Simply generated a new initramfs with a new iso.
385 #
386 check_root
387 verify_rootcd
388 gen_initramfs
389 gen_livecd_isolinux
390 distro_stats
391 ;;
392 extract-distro)
393 # Extract a ISO image to a directory and rebuild the LiveCD tree.
394 #
395 check_root
396 ISO_IMAGE=$2
397 if [ -z "$ISO_IMAGE" ] ; then
398 echo -e "\nPlease specify the path to the ISO image."
399 echo -e "Example : `basename $0` image.iso /path/target\n"
400 exit 0
401 fi
402 # Set the distro path by checking for $3 on cmdline.
403 if [ -n "$3" ] ; then
404 TARGET=$3
405 else
406 TARGET=$DISTRO
407 fi
408 # Exit if existing distro is found.
409 if [ -d "$TARGET/rootfs" ] ; then
410 echo -e "\nA rootfs exist in : $TARGET"
411 echo -e "Please clean the distro tree or change directory path.\n"
412 exit 0
413 fi
414 echo ""
415 echo -e "\033[1mTazlito extracting :\033[0m $ISO_IMAGE"
416 echo "================================================================================"
417 # Start to mount the ISO.
418 echo ""
419 echo "Mounting ISO image..."
420 mkdir -p $TMP_DIR
421 # Get ISO file size.
422 isosize=`du -sh $ISO_IMAGE`
423 mount -o loop $ISO_IMAGE $TMP_DIR
424 sleep 2
425 # Prepare target dir, copy the kernel and the rootfs.
426 mkdir -p $TARGET/rootfs
427 mkdir -p $TARGET/rootcd/boot
428 echo -n "Copying the Linux kernel..."
429 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
430 ln $TARGET/rootcd/boot/vmlinuz* $TARGET/rootcd/boot/bzImage
431 else
432 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
433 fi
434 status
435 echo -n "Copying isolinux files..."
436 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
437 status
438 if [ -d $TMP_DIR/boot/syslinux ]; then
439 echo -n "Copying syslinux files..."
440 cp -a $TMP_DIR/boot/syslinux $TARGET/rootcd/boot
441 status
442 fi
443 if [ -d $TMP_DIR/boot/extlinux ]; then
444 echo -n "Copying extlinux files..."
445 cp -a $TMP_DIR/boot/extlinux $TARGET/rootcd/boot
446 status
447 fi
448 if [ -d $TMP_DIR/boot/grub ]; then
449 echo -n "Copying GRUB files..."
450 cp -a $TMP_DIR/boot/grub $TARGET/rootcd/boot
451 status
452 fi
454 echo -n "Copying the rootfs..."
455 cp $TMP_DIR/boot/rootfs.?z $TARGET/rootcd/boot
456 status
457 # Exract initramfs.
458 cd $TARGET/rootfs
459 echo -n "Extracting the rootfs... "
460 ( zcat ../rootcd/boot/rootfs.gz 2>/dev/null || \
461 unlzma -c ../rootcd/boot/rootfs.?z ) | cpio -id
462 # Umount and remove temp directory and cd to $TARGET to get stats.
463 umount $TMP_DIR && rm -rf $TMP_DIR
464 cd ..
465 echo ""
466 echo "================================================================================"
467 echo "Extracted : $ISO_IMAGE ($isosize)"
468 echo "Distro tree : `pwd`"
469 echo "Rootfs size : `du -sh rootfs`"
470 echo "Rootcd size : `du -sh rootcd`"
471 echo "================================================================================"
472 echo ""
473 ;;
474 list-flavors)
475 # Show available flavors.
476 if [ ! -s /etc/tazlito/flavors.list -o "$2" == "--recharge" ]; then
477 download flavors.list -O - > /etc/tazlito/flavors.list
478 fi
479 echo ""
480 echo -e "\033[1mList of flavors\033[0m"
481 echo "================================================================================"
482 cat /etc/tazlito/flavors.list
483 echo ""
484 ;;
485 show-flavor)
486 # Show flavor description.
487 FLAVOR=$2
488 if [ ! -f "$FLAVOR.flavor" ]; then
489 echo "File $FLAVOR.flavor not found."
490 exit 1
491 fi
492 mkdir $TMP_DIR
493 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i 2> /dev/null )
494 if [ "$3" = "--brief" ]; then
495 if [ "$4" != "--noheader" ]; then
496 echo "Name Sizes Description"
497 echo "================================================================================"
498 fi
499 printf "%-15.15s %5.5s/%5.5s %-51s\n" "$FLAVOR" \
500 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
501 "$(field Rootfs $TMP_DIR/$FLAVOR.desc)" \
502 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
503 else
504 echo "================================================================================"
505 cat $TMP_DIR/$FLAVOR.desc
506 fi
507 rm -Rf $TMP_DIR
508 ;;
509 gen-flavor)
510 # Generate a new flavor form then last iso image generation.
511 FLAVOR=$2
512 if [ -z "$FLAVOR" ]; then
513 echo -n "Flavor name : "
514 read FLAVOR
515 [ -z "$FLAVOR" ] && exit 1
516 fi
517 check_rootfs
518 FILES="$FLAVOR.pkglist"
519 echo -n "Creating file $FLAVOR.flavor..."
520 for i in rootcd rootfs; do
521 if [ -d "$ADDFILES/$i" ] ; then
522 FILES="$FILES\n$FLAVOR.$i"
523 ( cd "$ADDFILES/$i"; find . | \
524 cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
525 fi
526 done
527 answer=`grep -s ^Description $FLAVOR.desc`
528 answer=${answer#Description : }
529 if [ -z "$answer" ]; then
530 echo -en "\nDescription : "
531 read answer
532 fi
533 echo "Flavor : $FLAVOR" > $FLAVOR.desc
534 echo "Description : $answer" >> $FLAVOR.desc
535 ( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
536 \rm -f $FLAVOR.pkglist 2> /dev/null
537 for i in $(ls $ROOTFS$INSTALLED); do
538 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
539 echo "$i-$VERSION" >> $FLAVOR.pkglist
540 done
541 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
542 gzip -9 > $FLAVOR.flavor
543 rm `echo -e $FILES`
544 status
545 ;;
546 get-flavor)
547 # Get a flavor's files and prepare for gen-distro.
548 FLAVOR=$2
549 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
550 echo -n "Cleaning $DISTRO..."
551 rm -R $DISTRO 2> /dev/null
552 mkdir -p $DISTRO
553 status
554 mkdir $TMP_DIR
555 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i 2>/dev/null )
556 echo -n "Create distro-packages.list..."
557 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
558 status
559 for i in rootcd rootfs; do
560 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
561 mkdir -p "$ADDFILES/$i"
562 zcat $TMP_DIR/$FLAVOR.$i | \
563 ( cd "$ADDFILES/$i"; cpio -id 2> /dev/null)
564 fi
565 done
566 echo -n "Update tazlito.conf..."
567 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
568 cat tazlito.conf | grep -v "^#VOLUM_NAME" | \
569 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
570 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
571 status
572 rm -Rf $TMP_DIR
573 fi
574 ;;
575 gen-distro)
576 # Generate a live distro tree with a set of packages.
577 #
578 check_root
579 if [ -d $ROOTFS ] ; then
580 echo "A rootfs exist in : $DISTRO"
581 echo -e "Please clean the distro tree or change directory path.\n"
582 exit 0
583 fi
584 # Check if a package list was specified on cmdline.
585 LIST_NAME="distro-packages.list"
586 CDROM=""
587 while [ -n "$2" ]; do
588 case "$2" in
589 --iso=*)
590 CDROM="-o loop ${2#--iso=}"
591 ;;
592 --cdrom)
593 CDROM="/dev/cdrom"
594 ;;
595 *) if [ ! -f "$2" ] ; then
596 echo -e "\nUnable to find the specified packages list."
597 echo -e "List name : $2\n"
598 exit 1
599 fi
600 LIST_NAME=$2
601 ;;
602 esac
603 shift
604 done
605 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
606 # Build list with installed packages
607 for i in $(ls $INSTALLED); do
608 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
609 echo "$i-$VERSION" >> $LIST_NAME
610 done
611 fi
612 # Exit if no list name.
613 if [ ! -f "$LIST_NAME" ]; then
614 echo -e "\nNo packages list found or specified. Please read the doc.\n"
615 exit 0
616 fi
617 # Start generation.
618 echo ""
619 echo -e "\033[1mTazlito generating a distro\033[0m"
620 echo "================================================================================"
621 # Misc checks
622 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
623 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
624 # Get the list of packages using cat for a file list.
625 LIST=`cat $LIST_NAME`
626 # Verify if all packages in list are presents in $PACKAGES_REPOSITORY.
627 REPACK=""
628 DOWNLOAD=""
629 for pkg in $LIST
630 do
631 [ "$pkg" = "" ] && continue
632 pkg=${pkg%.tazpkg}
633 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
634 PACKAGE=$(installed_package_name $pkg)
635 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
636 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
637 echo -e "\nUnable to find $pkg in the repository."
638 echo -e "Path : $PACKAGES_REPOSITORY\n"
639 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
640 yesorno "Repack packages from rootfs (y/N) ? "
641 REPACK="$answer"
642 [ "$answer" = "y" ] || REPACK="n"
643 [ "$DOWNLOAD" = "y" ] && break
644 fi
645 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
646 yesorno "Download packages from mirror (Y/n) ? "
647 DOWNLOAD="$answer"
648 if [ "$answer" = "n" ]; then
649 [ -z "$PACKAGE" ] && exit 1
650 else
651 DOWNLOAD="y"
652 [ -n "$REPACK" ] && break
653 fi
654 fi
655 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
656 done
658 # mount cdrom to be able to repack boot-loader packages
659 if [ ! -e /boot -a -n "$CDROM" ]; then
660 mkdir $TMP_MNT
661 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
662 ln -s $TMP_MNT/boot /
663 if [ ! -d "$ADDFILES/rootcd" ] ; then
664 mkdir -p $ADDFILES/rootcd
665 for i in $(ls $TMP_MNT); do
666 [ "$i" = "boot" ] && continue
667 cp -a $TMP_MNT/$i $ADDFILES/rootcd
668 done
669 fi
670 else
671 rmdir $TMP_MNT
672 fi
673 fi
675 # Root fs stuff.
676 echo "Preparing the rootfs directory..."
677 mkdir -p $ROOTFS
678 sleep 2
679 for pkg in $LIST
680 do
681 [ "$pkg" = "" ] && continue
682 # First copy and extract the package in tmp dir.
683 pkg=${pkg%.tazpkg}
684 PACKAGE=$(installed_package_name $pkg)
685 mkdir -p $TMP_DIR
686 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
687 # look for package in cache
688 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
689 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
690 # look for package in running distribution
691 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
692 tazpkg repack $PACKAGE && \
693 mv $pkg.tazpkg $PACKAGES_REPOSITORY
694 fi
695 fi
696 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
697 # get package from mirror
698 [ "$DOWNLOAD" = "y" ] && \
699 download $pkg.tazpkg && \
700 mv $pkg.tazpkg $PACKAGES_REPOSITORY
701 fi
702 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
703 echo "Missing package $pkg."
704 cleanup
705 exit 1
706 fi
707 yes "" | tazpkg install $PACKAGES_REPOSITORY/$pkg.tazpkg --root=$ROOTFS
708 done
709 cp $LIST_NAME $ROOTFS/etc/tazlito/distro-packages.list
710 echo ""
711 cd $DISTRO
712 # Copy all files from $ADDFILES/rootfs to the rootfs.
713 if [ -d "$ADDFILES/rootfs" ] ; then
714 echo -n "Copying addfiles content to the rootfs... "
715 cp -a $ADDFILES/rootfs/* $ROOTFS
716 status
717 fi
718 echo "Root file system is generated..."
719 # Root CD part.
720 echo -n "Preparing the rootcd directory..."
721 mkdir -p $ROOTCD
722 status
723 # Move the boot dir with the Linux kernel from rootfs.
724 # The boot dir goes directly on the CD.
725 if [ -d "$ROOTFS/boot" ] ; then
726 echo -n "Moving the boot directory..."
727 mv $ROOTFS/boot $ROOTCD
728 cd $ROOTCD/boot
729 ln vmlinuz-* bzImage
730 status
731 fi
732 cd $DISTRO
733 # Copy all files from $ADDFILES/rootcd to the rootcd.
734 if [ -d "$ADDFILES/rootcd" ] ; then
735 echo -n "Copying addfiles content to the rootcd... "
736 cp -a $ADDFILES/rootcd/* $ROOTCD
737 status
738 fi
739 # Initramfs and ISO image stuff.
740 gen_initramfs
741 gen_livecd_isolinux
742 distro_stats
743 cleanup
744 ;;
745 clean-distro)
746 # Remove old distro tree.
747 #
748 check_root
749 echo ""
750 echo -e "\033[1mCleaning :\033[0m $DISTRO"
751 echo "================================================================================"
752 if [ -d "$DISTRO" ] ; then
753 if [ -d "$ROOTFS" ] ; then
754 echo -n "Removing the rootfs..."
755 rm -f $DISTRO/$INITRAMFS
756 rm -rf $ROOTFS
757 status
758 fi
759 if [ -d "$ROOTCD" ] ; then
760 echo -n "Removing the rootcd..."
761 rm -rf $ROOTCD
762 status
763 fi
764 echo -n "Removing eventual ISO image..."
765 rm -f $DISTRO/$ISO_NAME.iso
766 status
767 fi
768 echo "================================================================================"
769 echo ""
770 ;;
771 addhacker)
772 # Without /etc/passwd...
773 #
774 check_root
775 echo ""
776 echo -e "\033[1mAdduser hacker to :\033[0m $ROOTFS"
777 echo "================================================================================"
778 if [ ! -d "$ROOTFS/etc" ] ; then
779 echo -e "\nUnable to find : $ROOTFS/etc"
780 echo -e "Users and passwords config files will not be found.\n"
781 exit 0
782 fi
783 # Go for echoing on configuration files if any hacker was found.
784 #
785 if [ ! "`cat $ROOTFS/etc/passwd | grep hacker`" ] ; then
786 echo -n "Configuring $ROOTFS/etc..."
787 echo 'hacker:x:500:500:Linux User,,,:/home/hacker:/bin/ash' >> $ROOTFS/etc/passwd
788 echo 'hacker::13646:0:99999:7:::' >> $ROOTFS/etc/shadow
789 echo 'hacker:x:500:' >> $ROOTFS/etc/group
790 echo 'hacker:!::' >> $ROOTFS/etc/gshadow
791 status
792 else
793 echo "Hacker is already in : $ROOTFS/etc/passwd"
794 fi
795 # Hacker can listen to music
796 #
797 if grep -q audio $ROOTFS/etc/group; then
798 sed -i s/'audio:x:20:'/'audio:x:20:hacker'/ $ROOTFS/etc/group
799 fi
800 # /home/hacker files.
801 #
802 echo -n "Creating default directories... "
803 mkdir -p $ROOTFS/home/hacker/Documents \
804 $ROOTFS/home/hacker/Downloads \
805 $ROOTFS/home/hacker/Images \
806 $ROOTFS/home/hacker/Public \
807 $ROOTFS/home/hacker/Templates
808 status
809 # Change permissions.
810 #
811 echo -n "Chmodig all files in /home/hacker..."
812 chown -R 500.500 $ROOTFS/home/hacker
813 status
814 echo "================================================================================"
815 echo "Linux User Hacker have an account in the distro."
816 echo ""
817 ;;
818 check-distro)
819 # Check for a few LiveCD needed files not installed by packages.
820 #
821 check_rootfs
822 echo ""
823 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
824 echo "================================================================================"
825 # SliTaz release info.
826 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
827 echo "Missing release info : /etc/slitaz-release"
828 else
829 release=`cat $ROOTFS/etc/slitaz-release`
830 echo -n "Release : $release"
831 status
832 fi
833 # Tazpkg mirror.
834 if [ ! -f "$ROOTFS/var/lib/tazpkg/mirror" ]; then
835 echo -n "Mirror URL : Missing /var/lib/tazpkg/mirror"
836 todomsg
837 else
838 echo -n "Mirror configuration exist..."
839 status
840 fi
841 # Isolinux msg
842 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.msg; then
843 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
844 todomsg
845 else
846 echo -n "Isolinux message seems good..."
847 status
848 fi
849 echo "================================================================================"
850 echo ""
851 ;;
852 burn-iso)
853 # Guess cdrom device, ask user and burn the ISO.
854 #
855 check_root
856 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
857 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
858 # We can specify an alternative ISO from the cmdline.
859 if [ -n "$2" ] ; then
860 iso=$2
861 else
862 iso=$DISTRO/$ISO_NAME.iso
863 fi
864 if [ ! -f "$iso" ]; then
865 echo -e "\nUnable to find ISO : $iso\n"
866 exit 0
867 fi
868 echo ""
869 echo -e "\033[1mTazlito burn ISO\033[0m "
870 echo "================================================================================"
871 echo "Cdrom device : /dev/$DRIVE_NAME"
872 echo "Drive speed : $DRIVE_SPEED"
873 echo "ISO image : $iso"
874 echo "================================================================================"
875 echo ""
876 yesorno "Burn ISO image (y/N) ? "
877 if [ "$answer" == "y" ]; then
878 echo ""
879 echo "Starting Wodim to burn the iso..." && sleep 2
880 echo "================================================================================"
881 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
882 echo "================================================================================"
883 echo "ISO image is burned to cdrom."
884 else
885 echo -e "\nExiting. No ISO burned."
886 fi
887 echo ""
888 ;;
889 usage|*)
890 # Clear and print usage also for all unknow commands.
891 #
892 clear
893 usage
894 ;;
896 esac
898 exit 0