tazlito view tazlito @ rev 51

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