tazlito view tazlito @ rev 47

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