tazlito view tazlito @ rev 56

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