tazlito view tazlito @ rev 57

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