tazlito view tazlito @ rev 59

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