tazlito view tazlito @ rev 25

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