tazlito view tazlito @ rev 30

Back to default LZMA compression
author Christophe Lincoln <pankso@slitaz.org>
date Sun Jan 13 22:07:24 2008 +0100 (2008-01-13)
parents 6e2e297649db
children 5aa9e17f7c9f
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 > $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 echo -n "Copying the rootfs..."
436 cp $TMP_DIR/boot/rootfs.?z $TARGET/rootcd/boot
437 status
438 # Exract initramfs.
439 cd $TARGET/rootfs
440 echo -n "Extracting the rootfs... "
441 ( zcat ../rootcd/boot/rootfs.gz 2>/dev/null || \
442 unlzma -c ../rootcd/boot/rootfs.?z ) | cpio -id
443 # Umount and remove temp directory and cd to $TARGET to get stats.
444 umount $TMP_DIR && rm -rf $TMP_DIR
445 cd ..
446 echo ""
447 echo "================================================================================"
448 echo "Extracted : $ISO_IMAGE ($isosize)"
449 echo "Distro tree : `pwd`"
450 echo "Rootfs size : `du -sh rootfs`"
451 echo "Rootcd size : `du -sh rootcd`"
452 echo "================================================================================"
453 echo ""
454 ;;
455 list-flavors)
456 # Show available flavors.
457 if [ ! -s /etc/tazlito/flavors.list -o "$2" == "--recharge" ]; then
458 download flavors.list -O - > /etc/tazlito/flavors.list
459 fi
460 echo ""
461 echo -e "\033[1mList of flavors\033[0m"
462 echo "================================================================================"
463 cat /etc/tazlito/flavors.list
464 echo ""
465 ;;
466 show-flavor)
467 # Show flavor description.
468 FLAVOR=$2
469 if [ ! -f "$FLAVOR.flavor" ]; then
470 echo "File $FLAVOR.flavor not found."
471 exit 1
472 fi
473 mkdir $TMP_DIR
474 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i 2> /dev/null )
475 if [ "$3" = "--brief" ]; then
476 if [ "$4" != "--noheader" ]; then
477 echo "Name Sizes Description"
478 echo "================================================================================"
479 fi
480 printf "%-15.15s %5.5s/%5.5s %-51s\n" "$FLAVOR" \
481 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
482 "$(field Rootfs $TMP_DIR/$FLAVOR.desc)" \
483 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
484 else
485 echo "================================================================================"
486 cat $TMP_DIR/$FLAVOR.desc
487 fi
488 rm -Rf $TMP_DIR
489 ;;
490 gen-flavor)
491 # Generate a new flavor form then last iso image generation.
492 FLAVOR=$2
493 if [ -z "$FLAVOR" ]; then
494 echo -n "Flavor name : "
495 read FLAVOR
496 [ -z "$FLAVOR" ] && exit 1
497 fi
498 check_rootfs
499 FILES="$FLAVOR.pkglist"
500 echo -n "Creating file $FLAVOR.flavor..."
501 for i in rootcd rootfs; do
502 if [ -d "$ADDFILES/$i" ] ; then
503 FILES="$FILES\n$FLAVOR.$i"
504 ( cd "$ADDFILES/$i"; find . | \
505 cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
506 fi
507 done
508 answer=`grep -s ^Description $FLAVOR.desc`
509 answer=${answer#Description : }
510 if [ -z "$answer" ]; then
511 echo -en "\nDescription : "
512 read answer
513 fi
514 echo "Flavor : $FLAVOR" > $FLAVOR.desc
515 echo "Description : $answer" >> $FLAVOR.desc
516 ( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
517 \rm -f $FLAVOR.pkglist 2> /dev/null
518 for i in $(ls $ROOTFS$INSTALLED); do
519 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
520 echo "$i-$VERSION" >> $FLAVOR.pkglist
521 done
522 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
523 gzip -9 > $FLAVOR.flavor
524 rm `echo -e $FILES`
525 status
526 ;;
527 get-flavor)
528 # Get a flavor's files and prepare for gen-distro.
529 FLAVOR=$2
530 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
531 echo -n "Cleaning $DISTRO..."
532 rm -R $DISTRO 2> /dev/null
533 mkdir -p $DISTRO
534 status
535 mkdir $TMP_DIR
536 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i 2>/dev/null )
537 echo -n "Create distro-packages.list..."
538 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
539 status
540 for i in rootcd rootfs; do
541 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
542 mkdir -p "$ADDFILES/$i"
543 zcat $TMP_DIR/$FLAVOR.$i | \
544 ( cd "$ADDFILES/$i"; cpio -id 2> /dev/null)
545 fi
546 done
547 echo -n "Update tazlito.conf..."
548 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
549 cat tazlito.conf | grep -v "^#VOLUM_NAME" | \
550 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
551 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
552 status
553 rm -Rf $TMP_DIR
554 fi
555 ;;
556 gen-distro)
557 # Generate a live distro tree with a set of packages.
558 #
559 check_root
560 if [ -d $ROOTFS ] ; then
561 echo "A rootfs exist in : $DISTRO"
562 echo -e "Please clean the distro tree or change directory path.\n"
563 exit 0
564 fi
565 # Check if a package list was specified on cmdline.
566 LIST_NAME="distro-packages.list"
567 CDROM=""
568 while [ -n "$2" ]; do
569 case "$2" in
570 --iso=*)
571 CDROM="-o loop ${2#--iso=}"
572 ;;
573 --cdrom)
574 CDROM="/dev/cdrom"
575 ;;
576 *) if [ ! -f "$2" ] ; then
577 echo -e "\nUnable to find the specified packages list."
578 echo -e "List name : $2\n"
579 exit 1
580 fi
581 LIST_NAME=$2
582 ;;
583 esac
584 shift
585 done
586 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
587 # Build list with installed packages
588 for i in $(ls $INSTALLED); do
589 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
590 echo "$i-$VERSION" >> $LIST_NAME
591 done
592 fi
593 # Exit if no list name.
594 if [ ! -f "$LIST_NAME" ]; then
595 echo -e "\nNo packages list found or specified. Please read the doc.\n"
596 exit 0
597 fi
598 # Start generation.
599 echo ""
600 echo -e "\033[1mTazlito generating a distro\033[0m"
601 echo "================================================================================"
602 # Misc checks
603 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
604 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
605 # Get the list of packages using cat for a file list.
606 LIST=`cat $LIST_NAME`
607 # Verify if all packages in list are presents in $PACKAGES_REPOSITORY.
608 REPACK=""
609 DOWNLOAD=""
610 for pkg in $LIST
611 do
612 [ "$pkg" = "" ] && continue
613 pkg=${pkg%.tazpkg}
614 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
615 PACKAGE=$(installed_package_name $pkg)
616 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
617 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
618 echo -e "\nUnable to find $pkg in the repository."
619 echo -e "Path : $PACKAGES_REPOSITORY\n"
620 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
621 yesorno "Repack packages from rootfs (y/N) ? "
622 REPACK="$answer"
623 [ "$answer" = "y" ] || REPACK="n"
624 [ "$DOWNLOAD" = "y" ] && break
625 fi
626 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
627 yesorno "Download packages from mirror (Y/n) ? "
628 DOWNLOAD="$answer"
629 if [ "$answer" = "n" ]; then
630 [ -z "$PACKAGE" ] && exit 1
631 else
632 DOWNLOAD="y"
633 [ -n "$REPACK" ] && break
634 fi
635 fi
636 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
637 done
639 # mount cdrom to be able to repack boot-loader packages
640 if [ ! -e /boot -a -n "$CDROM" ]; then
641 mkdir $TMP_MNT
642 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
643 ln -s $TMP_MNT/boot /
644 if [ ! -d "$ADDFILES/rootcd" ] ; then
645 mkdir -p $ADDFILES/rootcd
646 for i in $(ls $TMP_MNT); do
647 [ "$i" = "boot" ] && continue
648 cp -a $TMP_MNT/$i $ADDFILES/rootcd
649 done
650 fi
651 else
652 rmdir $TMP_MNT
653 fi
654 fi
656 # Root fs stuff.
657 echo "Preparing the rootfs directory..."
658 mkdir -p $ROOTFS
659 sleep 2
660 for pkg in $LIST
661 do
662 [ "$pkg" = "" ] && continue
663 # First copy and extract the package in tmp dir.
664 pkg=${pkg%.tazpkg}
665 PACKAGE=$(installed_package_name $pkg)
666 mkdir -p $TMP_DIR
667 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
668 # look for package in cache
669 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
670 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
671 # look for package in running distribution
672 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
673 tazpkg repack $PACKAGE && \
674 mv $pkg.tazpkg $PACKAGES_REPOSITORY
675 fi
676 fi
677 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
678 # get package from mirror
679 [ "$DOWNLOAD" = "y" ] && \
680 download $pkg.tazpkg && \
681 mv $pkg.tazpkg $PACKAGES_REPOSITORY
682 fi
683 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
684 echo "Missing package $pkg."
685 cleanup
686 exit 1
687 fi
688 yes "" | tazpkg install $PACKAGES_REPOSITORY/$pkg.tazpkg --root=$ROOTFS
689 done
690 cp $LIST_NAME $ROOTFS/etc/tazlito/distro-packages.list
691 echo ""
692 cd $DISTRO
693 # Copy all files from $ADDFILES/rootfs to the rootfs.
694 if [ -d "$ADDFILES/rootfs" ] ; then
695 echo -n "Copying addfiles content to the rootfs... "
696 cp -a $ADDFILES/rootfs/* $ROOTFS
697 status
698 fi
699 echo "Root file system is generated..."
700 # Root CD part.
701 echo -n "Preparing the rootcd directory..."
702 mkdir -p $ROOTCD
703 status
704 # Move the boot dir with the Linux kernel from rootfs.
705 # The boot dir goes directly on the CD.
706 if [ -d "$ROOTFS/boot" ] ; then
707 echo -n "Moving the boot directory..."
708 mv $ROOTFS/boot $ROOTCD
709 cd $ROOTCD/boot
710 ln vmlinuz-* bzImage
711 status
712 fi
713 cd $DISTRO
714 # Copy all files from $ADDFILES/rootcd to the rootcd.
715 if [ -d "$ADDFILES/rootcd" ] ; then
716 echo -n "Copying addfiles content to the rootcd... "
717 cp -a $ADDFILES/rootcd/* $ROOTCD
718 status
719 fi
720 # Initramfs and ISO image stuff.
721 gen_initramfs
722 gen_livecd_isolinux
723 distro_stats
724 cleanup
725 ;;
726 clean-distro)
727 # Remove old distro tree.
728 #
729 check_root
730 echo ""
731 echo -e "\033[1mCleaning :\033[0m $DISTRO"
732 echo "================================================================================"
733 if [ -d "$DISTRO" ] ; then
734 if [ -d "$ROOTFS" ] ; then
735 echo -n "Removing the rootfs..."
736 rm -f $DISTRO/$INITRAMFS
737 rm -rf $ROOTFS
738 status
739 fi
740 if [ -d "$ROOTCD" ] ; then
741 echo -n "Removing the rootcd..."
742 rm -rf $ROOTCD
743 status
744 fi
745 echo -n "Removing eventual ISO image..."
746 rm -f $DISTRO/$ISO_NAME.iso
747 status
748 fi
749 echo "================================================================================"
750 echo ""
751 ;;
752 addhacker)
753 # Without /etc/passwd...
754 #
755 check_root
756 echo ""
757 echo -e "\033[1mAdduser hacker to :\033[0m $ROOTFS"
758 echo "================================================================================"
759 if [ ! -d "$ROOTFS/etc" ] ; then
760 echo -e "\nUnable to find : $ROOTFS/etc"
761 echo -e "Users and passwords config files will not be found.\n"
762 exit 0
763 fi
764 # Go for echoing on configuration files if any hacker was found.
765 #
766 if [ ! "`cat $ROOTFS/etc/passwd | grep hacker`" ] ; then
767 echo -n "Configuring $ROOTFS/etc..."
768 echo 'hacker:x:500:500:Linux User,,,:/home/hacker:/bin/ash' >> $ROOTFS/etc/passwd
769 echo 'hacker::13646:0:99999:7:::' >> $ROOTFS/etc/shadow
770 echo 'hacker:x:500:' >> $ROOTFS/etc/group
771 echo 'hacker:!::' >> $ROOTFS/etc/gshadow
772 status
773 else
774 echo "Hacker is already in : $ROOTFS/etc/passwd"
775 fi
776 # Hacker can listen to music
777 #
778 if grep -q audio $ROOTFS/etc/group; then
779 sed -i s/'audio:x:20:'/'audio:x:20:hacker'/ $ROOTFS/etc/group
780 fi
781 # /home/hacker files.
782 #
783 echo -n "Creating default directories... "
784 mkdir -p $ROOTFS/home/hacker/Documents \
785 $ROOTFS/home/hacker/Downloads \
786 $ROOTFS/home/hacker/Images \
787 $ROOTFS/home/hacker/Public \
788 $ROOTFS/home/hacker/Templates
789 status
790 # Change permissions.
791 #
792 echo -n "Chmodig all files in /home/hacker..."
793 chown -R 500.500 $ROOTFS/home/hacker
794 status
795 echo "================================================================================"
796 echo "Linux User Hacker have an account in the distro."
797 echo ""
798 ;;
799 check-distro)
800 # Check for a few LiveCD needed files not installed by packages.
801 #
802 check_rootfs
803 echo ""
804 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
805 echo "================================================================================"
806 # SliTaz release info.
807 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
808 echo "Missing release info : /etc/slitaz-release"
809 else
810 release=`cat $ROOTFS/etc/slitaz-release`
811 echo -n "Release : $release"
812 status
813 fi
814 # Tazpkg mirror.
815 if [ ! -f "$ROOTFS/var/lib/tazpkg/mirror" ]; then
816 echo -n "Mirror URL : Missing /var/lib/tazpkg/mirror"
817 todomsg
818 else
819 echo -n "Mirror configuration exist..."
820 status
821 fi
822 # Isolinux msg
823 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.msg; then
824 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
825 todomsg
826 else
827 echo -n "Isolinux message seems good..."
828 status
829 fi
830 echo "================================================================================"
831 echo ""
832 ;;
833 burn-iso)
834 # Guess cdrom device, ask user and burn the ISO.
835 #
836 check_root
837 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
838 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
839 # We can specify an alternative ISO from the cmdline.
840 if [ -n "$2" ] ; then
841 iso=$2
842 else
843 iso=$DISTRO/$ISO_NAME.iso
844 fi
845 if [ ! -f "$iso" ]; then
846 echo -e "\nUnable to find ISO : $iso\n"
847 exit 0
848 fi
849 echo ""
850 echo -e "\033[1mTazlito burn ISO\033[0m "
851 echo "================================================================================"
852 echo "Cdrom device : /dev/$DRIVE_NAME"
853 echo "Drive speed : $DRIVE_SPEED"
854 echo "ISO image : $iso"
855 echo "================================================================================"
856 echo ""
857 yesorno "Burn ISO image (y/N) ? "
858 if [ "$answer" == "y" ]; then
859 echo ""
860 echo "Starting Wodim to burn the iso..." && sleep 2
861 echo "================================================================================"
862 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
863 echo "================================================================================"
864 echo "ISO image is burned to cdrom."
865 else
866 echo -e "\nExiting. No ISO burned."
867 fi
868 echo ""
869 ;;
870 usage|*)
871 # Clear and print usage also for all unknow commands.
872 #
873 clear
874 usage
875 ;;
877 esac
879 exit 0