tazlito view tazlito @ rev 49

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