tazlito view tazlito @ rev 31

Adding copy of syslinux, Grub and extlinux in extract-distro
author Eric Joseph-Alexandre <erjo@pimentvert.com>
date Mon Jan 14 22:29:43 2008 +0100 (2008-01-14)
parents fc4903b76419
children bda5158e6335
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 [ -x /usr/bin/lzma -a "$COMPRESSION" != "gzip" ]; then
230 echo -n "Generating lzma'ed initramfs... "
231 find . -print | cpio -o -H newc | lzma e -si -so -d26 > $DISTRO/$INITRAMFS
232 else
233 echo -n "Generating gziped initramfs... "
234 find . -print | cpio -o -H newc | gzip -9 > $DISTRO/$INITRAMFS
235 fi
236 cd $DISTRO
237 mv $INITRAMFS $ROOTCD/boot
238 }
240 distro_sizes()
241 {
242 echo "Build date : `date +%Y%m%d\ \at\ \%H:%M:%S`"
243 echo "Packages : `ls -1 $ROOTFS$INSTALLED | wc -l`"
244 echo "Rootfs size : `du -sh $ROOTFS`"
245 echo "Initramfs size : `du -sh $ROOTCD/boot/$INITRAMFS`"
246 echo "ISO image size : `du -sh $ISO_NAME.iso`"
247 echo "================================================================================"
248 echo ""
249 }
251 # Print ISO and rootfs size.
252 distro_stats()
253 {
254 echo ""
255 echo -e "\033[1mDistro statistics\033[0m"
256 echo "================================================================================"
257 distro_sizes
258 }
260 # Creat an empty configuration file.
261 empty_config_file()
262 {
263 cat >> tazlito.conf << "EOF"
264 # tazlito.conf: Tazlito (SliTaz Live Tool)
265 # configuration file.
266 #
268 # Name of the ISO image to generate.
269 ISO_NAME=""
271 # ISO image volum name.
272 VOLUM_NAME="SliTaz"
274 # Name of the preparator.
275 PREPARED="$USER"
277 # Path to the packages repository and the packages.list.
278 PACKAGES_REPOSITORY=""
280 # Path to the distro tree to gen-distro from a
281 # list of packages.
282 DISTRO=""
284 # Path to the directory contening additional files
285 # to copy into the rootfs and rootcd of the LiveCD.
286 ADDFILES="$DISTRO/addfiles"
288 # Default answer for binary question (Y or N)
289 DEFAULT_ANSWER="ASK"
291 # Compression utility (lzma or gzip)
292 COMPRESSION="lzma"
293 EOF
294 }
296 ####################
297 # Tazlito commands #
298 ####################
300 case "$COMMAND" in
301 stats)
302 # Tazlito general statistics from the config file.
303 #
304 echo ""
305 echo -e "\033[1mTazlito statistics\033[0m
306 ===============================================================================
307 Config file : $CONFIG_FILE
308 ISO name : $ISO_NAME.iso
309 Volum name : $VOLUM_NAME
310 Prepared : $PREPARED
311 Packages repository : $PACKAGES_REPOSITORY
312 Distro directory : $DISTRO"
313 if [ ! "$ADDFILES" = "" ] ; then
314 echo -e "Additional files : $ADDFILES"
315 fi
316 echo "================================================================================"
317 echo ""
318 ;;
319 gen-config)
320 # Gen a new config file in the current dir or the specified
321 # directory by $2.
322 #
323 if [ -n "$2" ] ; then
324 mkdir -p $2 && cd $2
325 fi
326 echo -n "Generating empty tazlito.conf..."
327 empty_config_file
328 status
329 echo ""
330 if [ -f "tazlito.conf" ] ; then
331 echo "Configuration file is ready to edit."
332 echo "File location : `pwd`/tazlito.conf"
333 echo ""
334 fi
335 ;;
336 configure)
337 # Configure a tazlito.conf config file. Start by getting
338 # a empty config file and sed it.
339 #
340 if [ -f "tazlito.conf" ] ; then
341 rm tazlito.conf
342 else
343 if test $(id -u) = 0 ; then
344 cd /etc
345 else
346 echo "You must be root to configure the main config file or in"
347 echo "the same directory of the file you want to configure."
348 exit 0
349 fi
350 fi
351 empty_config_file
352 echo""
353 echo -e "\033[1mConfiguring :\033[0m `pwd`/tazlito.conf"
354 echo "================================================================================"
355 # ISO name.
356 echo -n "ISO name : " ; read answer
357 sed -i s#'ISO_NAME=\"\"'#"ISO_NAME=\"$answer\""# tazlito.conf
358 # Volume name.
359 echo -n "Volume name : " ; read answer
360 sed -i s/'VOLUM_NAME=\"SliTaz\"'/"VOLUM_NAME=\"$answer\""/ tazlito.conf
361 # Packages repository.
362 echo -n "Packages repository : " ; read answer
363 sed -i s#'PACKAGES_REPOSITORY=\"\"'#"PACKAGES_REPOSITORY=\"$answer\""# tazlito.conf
364 # Distro path.
365 echo -n "Distro path : " ; read answer
366 sed -i s#'DISTRO=\"\"'#"DISTRO=\"$answer\""# tazlito.conf
367 echo "================================================================================"
368 echo "Config file is ready to use."
369 echo "You can now extract an ISO or generate a distro."
370 echo ""
371 ;;
372 gen-iso)
373 # Simply generated a new iso.
374 #
375 check_root
376 verify_rootcd
377 gen_livecd_isolinux
378 distro_stats
379 ;;
380 gen-initiso)
381 # Simply generated a new initramfs with a new iso.
382 #
383 check_root
384 verify_rootcd
385 gen_initramfs
386 gen_livecd_isolinux
387 distro_stats
388 ;;
389 extract-distro)
390 # Extract a ISO image to a directory and rebuild the LiveCD tree.
391 #
392 check_root
393 ISO_IMAGE=$2
394 if [ -z "$ISO_IMAGE" ] ; then
395 echo -e "\nPlease specify the path to the ISO image."
396 echo -e "Example : `basename $0` image.iso /path/target\n"
397 exit 0
398 fi
399 # Set the distro path by checking for $3 on cmdline.
400 if [ -n "$3" ] ; then
401 TARGET=$3
402 else
403 TARGET=$DISTRO
404 fi
405 # Exit if existing distro is found.
406 if [ -d "$TARGET/rootfs" ] ; then
407 echo -e "\nA rootfs exist in : $TARGET"
408 echo -e "Please clean the distro tree or change directory path.\n"
409 exit 0
410 fi
411 echo ""
412 echo -e "\033[1mTazlito extracting :\033[0m $ISO_IMAGE"
413 echo "================================================================================"
414 # Start to mount the ISO.
415 echo ""
416 echo "Mounting ISO image..."
417 mkdir -p $TMP_DIR
418 # Get ISO file size.
419 isosize=`du -sh $ISO_IMAGE`
420 mount -o loop $ISO_IMAGE $TMP_DIR
421 sleep 2
422 # Prepare target dir, copy the kernel and the rootfs.
423 mkdir -p $TARGET/rootfs
424 mkdir -p $TARGET/rootcd/boot
425 echo -n "Copying the Linux kernel..."
426 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
427 ln $TARGET/rootcd/boot/vmlinuz* $TARGET/rootcd/boot/bzImage
428 else
429 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
430 fi
431 status
432 echo -n "Copying isolinux files..."
433 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
434 status
435 if [ -d $TMP_DIR/boot/syslinux ]; then
436 cp -a $TMP_DIR/boot/syslinux $TARGET/rootcd/boot
437 status
438 fi
439 if [ -d $TMP_DIR/boot/extlinux ]; then
440 cp -a $TMP_DIR/boot/extlinux $TARGET/rootcd/boot
441 status
442 fi
443 if [ -d $TMP_DIR/boot/grub ]; then
444 cp -a $TMP_DIR/boot/grub $TARGET/rootcd/boot
445 status
446 fi
448 echo -n "Copying the rootfs..."
449 cp $TMP_DIR/boot/rootfs.?z $TARGET/rootcd/boot
450 status
451 # Exract initramfs.
452 cd $TARGET/rootfs
453 echo -n "Extracting the rootfs... "
454 ( zcat ../rootcd/boot/rootfs.gz 2>/dev/null || \
455 unlzma -c ../rootcd/boot/rootfs.?z ) | cpio -id
456 # Umount and remove temp directory and cd to $TARGET to get stats.
457 umount $TMP_DIR && rm -rf $TMP_DIR
458 cd ..
459 echo ""
460 echo "================================================================================"
461 echo "Extracted : $ISO_IMAGE ($isosize)"
462 echo "Distro tree : `pwd`"
463 echo "Rootfs size : `du -sh rootfs`"
464 echo "Rootcd size : `du -sh rootcd`"
465 echo "================================================================================"
466 echo ""
467 ;;
468 list-flavors)
469 # Show available flavors.
470 if [ ! -s /etc/tazlito/flavors.list -o "$2" == "--recharge" ]; then
471 download flavors.list -O - > /etc/tazlito/flavors.list
472 fi
473 echo ""
474 echo -e "\033[1mList of flavors\033[0m"
475 echo "================================================================================"
476 cat /etc/tazlito/flavors.list
477 echo ""
478 ;;
479 show-flavor)
480 # Show flavor description.
481 FLAVOR=$2
482 if [ ! -f "$FLAVOR.flavor" ]; then
483 echo "File $FLAVOR.flavor not found."
484 exit 1
485 fi
486 mkdir $TMP_DIR
487 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i 2> /dev/null )
488 if [ "$3" = "--brief" ]; then
489 if [ "$4" != "--noheader" ]; then
490 echo "Name Sizes Description"
491 echo "================================================================================"
492 fi
493 printf "%-15.15s %5.5s/%5.5s %-51s\n" "$FLAVOR" \
494 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
495 "$(field Rootfs $TMP_DIR/$FLAVOR.desc)" \
496 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
497 else
498 echo "================================================================================"
499 cat $TMP_DIR/$FLAVOR.desc
500 fi
501 rm -Rf $TMP_DIR
502 ;;
503 gen-flavor)
504 # Generate a new flavor form then last iso image generation.
505 FLAVOR=$2
506 if [ -z "$FLAVOR" ]; then
507 echo -n "Flavor name : "
508 read FLAVOR
509 [ -z "$FLAVOR" ] && exit 1
510 fi
511 check_rootfs
512 FILES="$FLAVOR.pkglist"
513 echo -n "Creating file $FLAVOR.flavor..."
514 for i in rootcd rootfs; do
515 if [ -d "$ADDFILES/$i" ] ; then
516 FILES="$FILES\n$FLAVOR.$i"
517 ( cd "$ADDFILES/$i"; find . | \
518 cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
519 fi
520 done
521 answer=`grep -s ^Description $FLAVOR.desc`
522 answer=${answer#Description : }
523 if [ -z "$answer" ]; then
524 echo -en "\nDescription : "
525 read answer
526 fi
527 echo "Flavor : $FLAVOR" > $FLAVOR.desc
528 echo "Description : $answer" >> $FLAVOR.desc
529 ( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
530 \rm -f $FLAVOR.pkglist 2> /dev/null
531 for i in $(ls $ROOTFS$INSTALLED); do
532 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
533 echo "$i-$VERSION" >> $FLAVOR.pkglist
534 done
535 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
536 gzip -9 > $FLAVOR.flavor
537 rm `echo -e $FILES`
538 status
539 ;;
540 get-flavor)
541 # Get a flavor's files and prepare for gen-distro.
542 FLAVOR=$2
543 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
544 echo -n "Cleaning $DISTRO..."
545 rm -R $DISTRO 2> /dev/null
546 mkdir -p $DISTRO
547 status
548 mkdir $TMP_DIR
549 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i 2>/dev/null )
550 echo -n "Create distro-packages.list..."
551 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
552 status
553 for i in rootcd rootfs; do
554 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
555 mkdir -p "$ADDFILES/$i"
556 zcat $TMP_DIR/$FLAVOR.$i | \
557 ( cd "$ADDFILES/$i"; cpio -id 2> /dev/null)
558 fi
559 done
560 echo -n "Update tazlito.conf..."
561 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
562 cat tazlito.conf | grep -v "^#VOLUM_NAME" | \
563 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
564 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
565 status
566 rm -Rf $TMP_DIR
567 fi
568 ;;
569 gen-distro)
570 # Generate a live distro tree with a set of packages.
571 #
572 check_root
573 if [ -d $ROOTFS ] ; then
574 echo "A rootfs exist in : $DISTRO"
575 echo -e "Please clean the distro tree or change directory path.\n"
576 exit 0
577 fi
578 # Check if a package list was specified on cmdline.
579 LIST_NAME="distro-packages.list"
580 CDROM=""
581 while [ -n "$2" ]; do
582 case "$2" in
583 --iso=*)
584 CDROM="-o loop ${2#--iso=}"
585 ;;
586 --cdrom)
587 CDROM="/dev/cdrom"
588 ;;
589 *) if [ ! -f "$2" ] ; then
590 echo -e "\nUnable to find the specified packages list."
591 echo -e "List name : $2\n"
592 exit 1
593 fi
594 LIST_NAME=$2
595 ;;
596 esac
597 shift
598 done
599 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
600 # Build list with installed packages
601 for i in $(ls $INSTALLED); do
602 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
603 echo "$i-$VERSION" >> $LIST_NAME
604 done
605 fi
606 # Exit if no list name.
607 if [ ! -f "$LIST_NAME" ]; then
608 echo -e "\nNo packages list found or specified. Please read the doc.\n"
609 exit 0
610 fi
611 # Start generation.
612 echo ""
613 echo -e "\033[1mTazlito generating a distro\033[0m"
614 echo "================================================================================"
615 # Misc checks
616 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
617 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
618 # Get the list of packages using cat for a file list.
619 LIST=`cat $LIST_NAME`
620 # Verify if all packages in list are presents in $PACKAGES_REPOSITORY.
621 REPACK=""
622 DOWNLOAD=""
623 for pkg in $LIST
624 do
625 [ "$pkg" = "" ] && continue
626 pkg=${pkg%.tazpkg}
627 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
628 PACKAGE=$(installed_package_name $pkg)
629 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
630 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
631 echo -e "\nUnable to find $pkg in the repository."
632 echo -e "Path : $PACKAGES_REPOSITORY\n"
633 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
634 yesorno "Repack packages from rootfs (y/N) ? "
635 REPACK="$answer"
636 [ "$answer" = "y" ] || REPACK="n"
637 [ "$DOWNLOAD" = "y" ] && break
638 fi
639 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
640 yesorno "Download packages from mirror (Y/n) ? "
641 DOWNLOAD="$answer"
642 if [ "$answer" = "n" ]; then
643 [ -z "$PACKAGE" ] && exit 1
644 else
645 DOWNLOAD="y"
646 [ -n "$REPACK" ] && break
647 fi
648 fi
649 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
650 done
652 # mount cdrom to be able to repack boot-loader packages
653 if [ ! -e /boot -a -n "$CDROM" ]; then
654 mkdir $TMP_MNT
655 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
656 ln -s $TMP_MNT/boot /
657 if [ ! -d "$ADDFILES/rootcd" ] ; then
658 mkdir -p $ADDFILES/rootcd
659 for i in $(ls $TMP_MNT); do
660 [ "$i" = "boot" ] && continue
661 cp -a $TMP_MNT/$i $ADDFILES/rootcd
662 done
663 fi
664 else
665 rmdir $TMP_MNT
666 fi
667 fi
669 # Root fs stuff.
670 echo "Preparing the rootfs directory..."
671 mkdir -p $ROOTFS
672 sleep 2
673 for pkg in $LIST
674 do
675 [ "$pkg" = "" ] && continue
676 # First copy and extract the package in tmp dir.
677 pkg=${pkg%.tazpkg}
678 PACKAGE=$(installed_package_name $pkg)
679 mkdir -p $TMP_DIR
680 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
681 # look for package in cache
682 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
683 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
684 # look for package in running distribution
685 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
686 tazpkg repack $PACKAGE && \
687 mv $pkg.tazpkg $PACKAGES_REPOSITORY
688 fi
689 fi
690 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
691 # get package from mirror
692 [ "$DOWNLOAD" = "y" ] && \
693 download $pkg.tazpkg && \
694 mv $pkg.tazpkg $PACKAGES_REPOSITORY
695 fi
696 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
697 echo "Missing package $pkg."
698 cleanup
699 exit 1
700 fi
701 yes "" | tazpkg install $PACKAGES_REPOSITORY/$pkg.tazpkg --root=$ROOTFS
702 done
703 cp $LIST_NAME $ROOTFS/etc/tazlito/distro-packages.list
704 echo ""
705 cd $DISTRO
706 # Copy all files from $ADDFILES/rootfs to the rootfs.
707 if [ -d "$ADDFILES/rootfs" ] ; then
708 echo -n "Copying addfiles content to the rootfs... "
709 cp -a $ADDFILES/rootfs/* $ROOTFS
710 status
711 fi
712 echo "Root file system is generated..."
713 # Root CD part.
714 echo -n "Preparing the rootcd directory..."
715 mkdir -p $ROOTCD
716 status
717 # Move the boot dir with the Linux kernel from rootfs.
718 # The boot dir goes directly on the CD.
719 if [ -d "$ROOTFS/boot" ] ; then
720 echo -n "Moving the boot directory..."
721 mv $ROOTFS/boot $ROOTCD
722 cd $ROOTCD/boot
723 ln vmlinuz-* bzImage
724 status
725 fi
726 cd $DISTRO
727 # Copy all files from $ADDFILES/rootcd to the rootcd.
728 if [ -d "$ADDFILES/rootcd" ] ; then
729 echo -n "Copying addfiles content to the rootcd... "
730 cp -a $ADDFILES/rootcd/* $ROOTCD
731 status
732 fi
733 # Initramfs and ISO image stuff.
734 gen_initramfs
735 gen_livecd_isolinux
736 distro_stats
737 cleanup
738 ;;
739 clean-distro)
740 # Remove old distro tree.
741 #
742 check_root
743 echo ""
744 echo -e "\033[1mCleaning :\033[0m $DISTRO"
745 echo "================================================================================"
746 if [ -d "$DISTRO" ] ; then
747 if [ -d "$ROOTFS" ] ; then
748 echo -n "Removing the rootfs..."
749 rm -f $DISTRO/$INITRAMFS
750 rm -rf $ROOTFS
751 status
752 fi
753 if [ -d "$ROOTCD" ] ; then
754 echo -n "Removing the rootcd..."
755 rm -rf $ROOTCD
756 status
757 fi
758 echo -n "Removing eventual ISO image..."
759 rm -f $DISTRO/$ISO_NAME.iso
760 status
761 fi
762 echo "================================================================================"
763 echo ""
764 ;;
765 addhacker)
766 # Without /etc/passwd...
767 #
768 check_root
769 echo ""
770 echo -e "\033[1mAdduser hacker to :\033[0m $ROOTFS"
771 echo "================================================================================"
772 if [ ! -d "$ROOTFS/etc" ] ; then
773 echo -e "\nUnable to find : $ROOTFS/etc"
774 echo -e "Users and passwords config files will not be found.\n"
775 exit 0
776 fi
777 # Go for echoing on configuration files if any hacker was found.
778 #
779 if [ ! "`cat $ROOTFS/etc/passwd | grep hacker`" ] ; then
780 echo -n "Configuring $ROOTFS/etc..."
781 echo 'hacker:x:500:500:Linux User,,,:/home/hacker:/bin/ash' >> $ROOTFS/etc/passwd
782 echo 'hacker::13646:0:99999:7:::' >> $ROOTFS/etc/shadow
783 echo 'hacker:x:500:' >> $ROOTFS/etc/group
784 echo 'hacker:!::' >> $ROOTFS/etc/gshadow
785 status
786 else
787 echo "Hacker is already in : $ROOTFS/etc/passwd"
788 fi
789 # Hacker can listen to music
790 #
791 if grep -q audio $ROOTFS/etc/group; then
792 sed -i s/'audio:x:20:'/'audio:x:20:hacker'/ $ROOTFS/etc/group
793 fi
794 # /home/hacker files.
795 #
796 echo -n "Creating default directories... "
797 mkdir -p $ROOTFS/home/hacker/Documents \
798 $ROOTFS/home/hacker/Downloads \
799 $ROOTFS/home/hacker/Images \
800 $ROOTFS/home/hacker/Public \
801 $ROOTFS/home/hacker/Templates
802 status
803 # Change permissions.
804 #
805 echo -n "Chmodig all files in /home/hacker..."
806 chown -R 500.500 $ROOTFS/home/hacker
807 status
808 echo "================================================================================"
809 echo "Linux User Hacker have an account in the distro."
810 echo ""
811 ;;
812 check-distro)
813 # Check for a few LiveCD needed files not installed by packages.
814 #
815 check_rootfs
816 echo ""
817 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
818 echo "================================================================================"
819 # SliTaz release info.
820 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
821 echo "Missing release info : /etc/slitaz-release"
822 else
823 release=`cat $ROOTFS/etc/slitaz-release`
824 echo -n "Release : $release"
825 status
826 fi
827 # Tazpkg mirror.
828 if [ ! -f "$ROOTFS/var/lib/tazpkg/mirror" ]; then
829 echo -n "Mirror URL : Missing /var/lib/tazpkg/mirror"
830 todomsg
831 else
832 echo -n "Mirror configuration exist..."
833 status
834 fi
835 # Isolinux msg
836 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.msg; then
837 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
838 todomsg
839 else
840 echo -n "Isolinux message seems good..."
841 status
842 fi
843 echo "================================================================================"
844 echo ""
845 ;;
846 burn-iso)
847 # Guess cdrom device, ask user and burn the ISO.
848 #
849 check_root
850 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
851 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
852 # We can specify an alternative ISO from the cmdline.
853 if [ -n "$2" ] ; then
854 iso=$2
855 else
856 iso=$DISTRO/$ISO_NAME.iso
857 fi
858 if [ ! -f "$iso" ]; then
859 echo -e "\nUnable to find ISO : $iso\n"
860 exit 0
861 fi
862 echo ""
863 echo -e "\033[1mTazlito burn ISO\033[0m "
864 echo "================================================================================"
865 echo "Cdrom device : /dev/$DRIVE_NAME"
866 echo "Drive speed : $DRIVE_SPEED"
867 echo "ISO image : $iso"
868 echo "================================================================================"
869 echo ""
870 yesorno "Burn ISO image (y/N) ? "
871 if [ "$answer" == "y" ]; then
872 echo ""
873 echo "Starting Wodim to burn the iso..." && sleep 2
874 echo "================================================================================"
875 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
876 echo "================================================================================"
877 echo "ISO image is burned to cdrom."
878 else
879 echo -e "\nExiting. No ISO burned."
880 fi
881 echo ""
882 ;;
883 usage|*)
884 # Clear and print usage also for all unknow commands.
885 #
886 clear
887 usage
888 ;;
890 esac
892 exit 0