tazlito view tazlito @ rev 53

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