tazlito view tazlito @ rev 69

Link duplicate links
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu May 22 15:41:01 2008 +0000 (2008-05-22)
parents 68bbfaa51808
children 504b8e5ba288
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 gen-liveflavor Generate a live-CD description from current system.
84 show-flavor Show live-CD description.
85 get-flavor Get a flavor's list of packages.
86 extract-distro Extract and ISO to a directory and rebuild LiveCD tree.
87 gen-distro Generated a Live distro and ISO from a list of packages.
88 clean-distro Remove all files generated by gen-distro.
89 addhacker Add Linux User Hacker to the current distro.
90 check-distro Help to check if distro is ready to release.
91 burn-iso Burn ISO image to a cdrom using Wodim.\n"
92 }
94 # Status function.
95 status()
96 {
97 local CHECK=$?
98 echo -en "\\033[70G[ "
99 if [ $CHECK = 0 ]; then
100 echo -en "\\033[1;33mOK"
101 else
102 echo -en "\\033[1;31mFailed"
103 fi
104 echo -e "\\033[0;39m ]"
105 }
107 yesorno()
108 {
109 echo -n "$1"
110 case "$DEFAULT_ANSWER" in
111 Y|y) answer="y";;
112 N|n) answer="n";;
113 *) read answer;;
114 esac
115 }
117 field()
118 {
119 grep "^$1" "$2" | sed 's/.*: \([0-9KMG\.]*\).*/\1/'
120 }
122 todomsg()
123 {
124 echo -e "\\033[70G[ \\033[1;31mTODO\\033[0;39m ]"
125 }
127 # Download a file trying each mirror
128 download()
129 {
130 for i in $(cat $MIRROR); do
131 wget $i$@
132 done
133 }
135 # exec hooks provided by some packages
136 genisohooks()
137 {
138 local here=`pwd`
139 cd $ROOTFS
140 for i in $(ls etc/tazlito/*.$1 2> /dev/null); do
141 . $i $ROOTCD
142 done
143 cd $here
144 }
146 cleanup()
147 {
148 if [ -d $TMP_MNT ]; then
149 umount $TMP_MNT
150 rmdir $TMP_MNT
151 rm -f /boot
152 fi
153 }
155 # echo the package name if the tazpkg is already installed
156 installed_package_name()
157 {
158 local tazpkg
159 local package
160 local VERSION
161 tazpkg=$1
162 # try du find package name and version to be able
163 # to repack it from installation
164 # a dash (-) can exist in name *and* in version
165 package=${tazpkg%-*}
166 i=$package
167 while true; do
168 VERSION=""
169 eval $(grep -s ^VERSION= $INSTALLED/$i/receipt)
170 if [ "$i-$VERSION" = "$tazpkg" ]; then
171 echo $i
172 break
173 fi
174 case "$i" in
175 *-*);;
176 *) break;;
177 esac
178 i=${i%-*}
179 done
180 }
182 # Check if user is root.
183 check_root()
184 {
185 if test $(id -u) != 0 ; then
186 echo -e "\nYou must be root to run `basename $0` with this option."
187 echo -e "Please type 'su' and root password to become super-user.\n"
188 exit 0
189 fi
190 }
192 # Check for the rootfs tree.
193 check_rootfs()
194 {
195 if [ ! -d "$ROOTFS/etc" ] ; then
196 echo -e "\nUnable to find a distro rootfs...\n"
197 exit 0
198 fi
199 }
201 # Check for the boot dir into the root CD tree.
202 verify_rootcd()
203 {
204 if [ ! -d "$ROOTCD/boot" ] ; then
205 echo -e "\nUnable to find the rootcd boot directory...\n"
206 exit 0
207 fi
208 }
210 # Gen a new ISO image using isolinux.
211 gen_livecd_isolinux()
212 {
213 # Some packages may want to alter iso
214 genisohooks iso
215 if [ ! -f "$ROOTCD/boot/isolinux/isolinux.bin" ]; then
216 echo -e "\nUnable to find isolinux binary.\n"
217 cleanup
218 exit 0
219 fi
220 # Set date for boot msg.
221 if grep -q 'XXXXXXXX' $ROOTCD/boot/isolinux/isolinux.msg; then
222 DATE=`date +%Y%m%d`
223 echo -n "Setting build date to: $DATE..."
224 sed -i s/'XXXXXXXX'/"$DATE"/ $ROOTCD/boot/isolinux/isolinux.msg
225 status
226 fi
227 cd $ROOTCD
228 echo -n "Computing md5..."
229 find * -type f ! -name md5sum -exec md5sum {} \; > md5sum
230 status
231 cd $DISTRO
232 echo ""
233 echo -e "\033[1mGenerating ISO image\033[0m"
234 echo "================================================================================"
235 genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
236 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
237 -V "$VOLUM_NAME" -p "$PREPARED" -input-charset iso8859-1 \
238 -boot-info-table $ROOTCD
239 echo -n "Creating the ISO md5sum..."
240 md5sum $ISO_NAME.iso > $ISO_NAME.md5
241 status
242 echo "================================================================================"
243 # Some packages may want to alter final iso
244 genisohooks final
245 }
247 # Gen a new initramfs from the root file system.
248 gen_initramfs()
249 {
250 # Just in case CTRL+c
251 rm -f $DISTRO/gen
252 # Some packages may want to alter rootfs
253 genisohooks rootfs
254 cd $ROOTFS
255 echo ""
257 # Link duplicate files
258 find . -type f -size +0c -exec stat -c '%s-%a-%u-%g %i %h %n' {} \; | \
259 sort | ( save=0; old_attr=""; old_inode=""; old_link=""; old_file=""
260 while read attr inode link file; do
261 if [ "$attr" = "$old_attr" -a "$inode" != "$old_inode" ]; then
262 if cmp "$file" "$old_file" >/dev/null; then
263 rm -f "$file"
264 ln "$old_file" "$file"
265 [ "$link" = "1" ] && save="$(expr $save + ${attr%%-*})"
266 fi
267 fi
268 old_attr="$attr" ; old_inode="$inode" ; old_file="$file"
269 done
270 echo "$save bytes saved in duplicate files."
271 )
273 # Link duplicate links
274 find . -type l -size +0c -exec stat -c '%s-%a-%u-%g %i %h %n' {} \; | \
275 sort | ( save=0; old_attr=""; old_inode=""; old_link=""; old_file=""
276 while read attr inode link file; do
277 if [ "$attr" = "$old_attr" -a "$inode" != "$old_inode" ]; then
278 if [ "$(readlink $file)" = "$(readlink $old_file)" ]; then
279 rm -f "$file"
280 ln "$old_file" "$file"
281 [ "$link" = "1" ] && save="$(expr $save + ${attr%%-*})"
282 fi
283 fi
284 old_attr="$attr" ; old_inode="$inode" ; old_file="$file"
285 done
286 echo "$save bytes saved in duplicate links."
287 )
289 # Use lzma if installed
290 if [ "$COMPRESSION" = "none" ]; then
291 echo -n "Generating uncompressed initramfs... "
292 find . -print | cpio -o -H newc > $DISTRO/$INITRAMFS
293 elif [ -x /usr/bin/lzma -a "$COMPRESSION" != "gzip" ]; then
294 echo -n "Generating lzma'ed initramfs... "
295 find . -print | cpio -o -H newc | lzma e -si -so > $DISTRO/$INITRAMFS
296 echo -n "set uncompressed size... "
297 echo -en "$(lzma d $DISTRO/$INITRAMFS -so 2> /dev/null | wc -c \
298 | awk '{ n=512+$0; for (i=0;i<8;i++) { printf("\\x%02X",n%256); n/=256 }}')" \
299 | dd bs=1 seek=5 conv=notrunc of=$DISTRO/$INITRAMFS 2> /dev/null
300 else
301 echo -n "Generating gziped initramfs... "
302 find . -print | cpio -o -H newc | gzip -9 > $DISTRO/$INITRAMFS
303 fi
304 cd $DISTRO
305 mv $INITRAMFS $ROOTCD/boot
306 }
308 distro_sizes()
309 {
310 echo "Build date : `date +%Y%m%d\ \at\ \%H:%M:%S`"
311 echo "Packages : `ls -1 $ROOTFS$INSTALLED | wc -l`"
312 echo "Rootfs size : `du -sh $ROOTFS`"
313 echo "Initramfs size : `du -sh $ROOTCD/boot/$INITRAMFS`"
314 echo "ISO image size : `du -sh $ISO_NAME.iso`"
315 echo "================================================================================"
316 echo ""
317 }
319 # Print ISO and rootfs size.
320 distro_stats()
321 {
322 echo ""
323 echo -e "\033[1mDistro statistics\033[0m"
324 echo "================================================================================"
325 distro_sizes
326 }
328 # Creat an empty configuration file.
329 empty_config_file()
330 {
331 cat >> tazlito.conf << "EOF"
332 # tazlito.conf: Tazlito (SliTaz Live Tool)
333 # configuration file.
334 #
336 # Name of the ISO image to generate.
337 ISO_NAME=""
339 # ISO image volum name.
340 VOLUM_NAME="SliTaz"
342 # Name of the preparator.
343 PREPARED="$USER"
345 # Path to the packages repository and the packages.list.
346 PACKAGES_REPOSITORY=""
348 # Path to the distro tree to gen-distro from a
349 # list of packages.
350 DISTRO=""
352 # Path to the directory contening additional files
353 # to copy into the rootfs and rootcd of the LiveCD.
354 ADDFILES="$DISTRO/addfiles"
356 # Default answer for binary question (Y or N)
357 DEFAULT_ANSWER="ASK"
359 # Compression utility (lzma, gzip or none)
360 COMPRESSION="lzma"
361 EOF
362 }
364 ####################
365 # Tazlito commands #
366 ####################
368 case "$COMMAND" in
369 stats)
370 # Tazlito general statistics from the config file.
371 #
372 echo ""
373 echo -e "\033[1mTazlito statistics\033[0m
374 ===============================================================================
375 Config file : $CONFIG_FILE
376 ISO name : $ISO_NAME.iso
377 Volum name : $VOLUM_NAME
378 Prepared : $PREPARED
379 Packages repository : $PACKAGES_REPOSITORY
380 Distro directory : $DISTRO"
381 if [ ! "$ADDFILES" = "" ] ; then
382 echo -e "Additional files : $ADDFILES"
383 fi
384 echo "================================================================================"
385 echo ""
386 ;;
387 gen-config)
388 # Gen a new config file in the current dir or the specified
389 # directory by $2.
390 #
391 if [ -n "$2" ] ; then
392 mkdir -p $2 && cd $2
393 fi
394 echo -n "Generating empty tazlito.conf..."
395 empty_config_file
396 status
397 echo ""
398 if [ -f "tazlito.conf" ] ; then
399 echo "Configuration file is ready to edit."
400 echo "File location : `pwd`/tazlito.conf"
401 echo ""
402 fi
403 ;;
404 configure)
405 # Configure a tazlito.conf config file. Start by getting
406 # a empty config file and sed it.
407 #
408 if [ -f "tazlito.conf" ] ; then
409 rm tazlito.conf
410 else
411 if test $(id -u) = 0 ; then
412 cd /etc
413 else
414 echo "You must be root to configure the main config file or in"
415 echo "the same directory of the file you want to configure."
416 exit 0
417 fi
418 fi
419 empty_config_file
420 echo""
421 echo -e "\033[1mConfiguring :\033[0m `pwd`/tazlito.conf"
422 echo "================================================================================"
423 # ISO name.
424 echo -n "ISO name : " ; read answer
425 sed -i s#'ISO_NAME=\"\"'#"ISO_NAME=\"$answer\""# tazlito.conf
426 # Volume name.
427 echo -n "Volume name : " ; read answer
428 sed -i s/'VOLUM_NAME=\"SliTaz\"'/"VOLUM_NAME=\"$answer\""/ tazlito.conf
429 # Packages repository.
430 echo -n "Packages repository : " ; read answer
431 sed -i s#'PACKAGES_REPOSITORY=\"\"'#"PACKAGES_REPOSITORY=\"$answer\""# tazlito.conf
432 # Distro path.
433 echo -n "Distro path : " ; read answer
434 sed -i s#'DISTRO=\"\"'#"DISTRO=\"$answer\""# tazlito.conf
435 echo "================================================================================"
436 echo "Config file is ready to use."
437 echo "You can now extract an ISO or generate a distro."
438 echo ""
439 ;;
440 gen-iso)
441 # Simply generated a new iso.
442 #
443 check_root
444 verify_rootcd
445 gen_livecd_isolinux
446 distro_stats
447 ;;
448 gen-initiso)
449 # Simply generated a new initramfs with a new iso.
450 #
451 check_root
452 verify_rootcd
453 gen_initramfs
454 gen_livecd_isolinux
455 distro_stats
456 ;;
457 extract-distro)
458 # Extract a ISO image to a directory and rebuild the LiveCD tree.
459 #
460 check_root
461 ISO_IMAGE=$2
462 if [ -z "$ISO_IMAGE" ] ; then
463 echo -e "\nPlease specify the path to the ISO image."
464 echo -e "Example : `basename $0` image.iso /path/target\n"
465 exit 0
466 fi
467 # Set the distro path by checking for $3 on cmdline.
468 if [ -n "$3" ] ; then
469 TARGET=$3
470 else
471 TARGET=$DISTRO
472 fi
473 # Exit if existing distro is found.
474 if [ -d "$TARGET/rootfs" ] ; then
475 echo -e "\nA rootfs exist in : $TARGET"
476 echo -e "Please clean the distro tree or change directory path.\n"
477 exit 0
478 fi
479 echo ""
480 echo -e "\033[1mTazlito extracting :\033[0m $ISO_IMAGE"
481 echo "================================================================================"
482 # Start to mount the ISO.
483 echo ""
484 echo "Mounting ISO image..."
485 mkdir -p $TMP_DIR
486 # Get ISO file size.
487 isosize=`du -sh $ISO_IMAGE`
488 mount -o loop $ISO_IMAGE $TMP_DIR
489 sleep 2
490 # Prepare target dir, copy the kernel and the rootfs.
491 mkdir -p $TARGET/rootfs
492 mkdir -p $TARGET/rootcd/boot
493 echo -n "Copying the Linux kernel..."
494 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
495 ln $TARGET/rootcd/boot/vmlinuz* $TARGET/rootcd/boot/bzImage
496 else
497 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
498 fi
499 status
500 echo -n "Copying isolinux files..."
501 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
502 for i in $(ls $TMP_DIR); do
503 [ "$i" = "boot" ] && continue
504 cp -a $TMP_DIR/$i $TARGET/rootcd
505 done
506 status
507 if [ -d $TMP_DIR/boot/syslinux ]; then
508 echo -n "Copying syslinux files..."
509 cp -a $TMP_DIR/boot/syslinux $TARGET/rootcd/boot
510 status
511 fi
512 if [ -d $TMP_DIR/boot/extlinux ]; then
513 echo -n "Copying extlinux files..."
514 cp -a $TMP_DIR/boot/extlinux $TARGET/rootcd/boot
515 status
516 fi
517 if [ -d $TMP_DIR/boot/grub ]; then
518 echo -n "Copying GRUB files..."
519 cp -a $TMP_DIR/boot/grub $TARGET/rootcd/boot
520 status
521 fi
523 echo -n "Copying the rootfs..."
524 cp $TMP_DIR/boot/rootfs.?z $TARGET/rootcd/boot
525 status
526 # Exract initramfs.
527 cd $TARGET/rootfs
528 echo -n "Extracting the rootfs... "
529 ( zcat ../rootcd/boot/rootfs.gz 2>/dev/null || \
530 lzma d ../rootcd/boot/rootfs.?z -so 2>/dev/null || \
531 cat ../rootcd/boot/rootfs.gz ) | cpio -id
532 # unpack /usr
533 for i in etc/tazlito/*.extract; do
534 [ -f "$i" ] && . $i ../rootcd
535 done
536 # Umount and remove temp directory and cd to $TARGET to get stats.
537 umount $TMP_DIR && rm -rf $TMP_DIR
538 cd ..
539 echo ""
540 echo "================================================================================"
541 echo "Extracted : $ISO_IMAGE ($isosize)"
542 echo "Distro tree : `pwd`"
543 echo "Rootfs size : `du -sh rootfs`"
544 echo "Rootcd size : `du -sh rootcd`"
545 echo "================================================================================"
546 echo ""
547 ;;
548 list-flavors)
549 # Show available flavors.
550 if [ ! -s /etc/tazlito/flavors.list -o "$2" == "--recharge" ]; then
551 download flavors.list -O - > /etc/tazlito/flavors.list
552 fi
553 echo ""
554 echo -e "\033[1mList of flavors\033[0m"
555 echo "================================================================================"
556 cat /etc/tazlito/flavors.list
557 echo ""
558 ;;
559 show-flavor)
560 # Show flavor description.
561 FLAVOR=$2
562 if [ ! -f "$FLAVOR.flavor" ]; then
563 echo "File $FLAVOR.flavor not found."
564 exit 1
565 fi
566 mkdir $TMP_DIR
567 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i 2> /dev/null )
568 if [ "$3" = "--brief" ]; then
569 if [ "$4" != "--noheader" ]; then
570 echo "Name Sizes Description"
571 echo "================================================================================"
572 fi
573 printf "%-15.15s %5.5s/%5.5s %-51s\n" "$FLAVOR" \
574 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
575 "$(field Rootfs $TMP_DIR/$FLAVOR.desc)" \
576 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
577 else
578 echo "================================================================================"
579 cat $TMP_DIR/$FLAVOR.desc
580 fi
581 rm -Rf $TMP_DIR
582 ;;
583 gen-liveflavor)
584 # Generate a new flavor form the live system.
585 FLAVOR=$2
586 DESC=""
587 case "$FLAVOR" in
588 '') echo -n "Flavor name : "
589 read FLAVOR
590 [ -z "$FLAVOR" ] && exit 1;;
591 -?|-h*|--help) echo -e "
593 SliTaz Live Tool - Version: $VERSION
594 \033[1mUsage: \033[0m `basename $0` gen-liveflavor flavor-name [flavor-patch-file]
595 \033[1mflavor-patch-file format: \033[0m
596 code data
597 + package to add
598 - package to remove
599 ! non-free package to add
600 ? display message
601 @ flavor description
603 \033[1mExample: \033[0m
604 @ Developper tools for slitaz maintainers
605 + slitaz-toolchain
606 + mercurial
607 "
608 exit 1;;
609 esac
610 mv /etc/tazlito/distro-packages.list \
611 /etc/tazlito/distro-packages.list.$$ 2> /dev/null
612 rm -f distro-packages.list non-free.list 2> /dev/null
613 tazpkg recharge
614 [ -n "$3" ] && while read action pkg; do
615 case "$action" in
616 +) yes | tazpkg get-install $pkg;;
617 -) yes | tazpkg remove $pkg;;
618 !) echo $pkg >> non-free.list;;
619 @) DESC="$pkg";;
620 \?) echo -en "$pkg"; read action;;
621 esac
622 done < $3
623 yes '' | tazlito gen-distro
624 echo "$DESC" | tazlito gen-flavor "$FLAVOR"
625 mv /etc/tazlito/distro-packages.list.$$ \
626 /etc/tazlito/distro-packages.list 2> /dev/null
627 ;;
628 gen-flavor)
629 # Generate a new flavor from the last iso image generation.
630 FLAVOR=$2
631 echo ""
632 echo -e "\033[1mFlavor generation\033[0m"
633 echo "================================================================================"
634 if [ -z "$FLAVOR" ]; then
635 echo -n "Flavor name : "
636 read FLAVOR
637 [ -z "$FLAVOR" ] && exit 1
638 fi
639 check_rootfs
640 FILES="$FLAVOR.pkglist"
641 echo -n "Creating file $FLAVOR.flavor..."
642 for i in rootcd rootfs; do
643 if [ -d "$ADDFILES/$i" ] ; then
644 FILES="$FILES\n$FLAVOR.$i"
645 ( cd "$ADDFILES/$i"; find . | \
646 cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
647 fi
648 done
649 status
650 answer=`grep -s ^Description $FLAVOR.desc`
651 answer=${answer#Description : }
652 if [ -z "$answer" ]; then
653 echo -n "Description : "
654 read answer
655 fi
656 echo -n "Compressing flavor $FLAVOR..."
657 echo "Flavor : $FLAVOR" > $FLAVOR.desc
658 echo "Description : $answer" >> $FLAVOR.desc
659 ( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
660 \rm -f $FLAVOR.pkglist $FLAVOR.nonfree 2> /dev/null
661 for i in $(ls $ROOTFS$INSTALLED); do
662 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
663 eval $(grep ^CATEGORY= $ROOTFS$INSTALLED/$i/receipt)
664 if [ "$CATEGORY" = "non-free" -a "${i%%-*}" != "get" ]
665 then
666 echo "$i" >> $FLAVOR.nonfree
667 else
668 echo "$i-$VERSION" >> $FLAVOR.pkglist
669 fi
670 done
671 [ -s $FLAVOR.nonfree ] && $FILES="$FILES\n$FLAVOR.nonfree"
672 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
673 gzip -9 > $FLAVOR.flavor
674 rm `echo -e $FILES`
675 status
676 echo "================================================================================"
677 echo "Flavor size : `du -sh $FLAVOR.flavor`"
678 echo ""
679 ;;
680 get-flavor)
681 # Get a flavor's files and prepare for gen-distro.
682 FLAVOR=$2
683 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
684 echo -n "Cleaning $DISTRO..."
685 rm -R $DISTRO 2> /dev/null
686 mkdir -p $DISTRO
687 status
688 mkdir $TMP_DIR
689 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i 2>/dev/null )
690 echo -n "Create distro-packages.list..."
691 mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
692 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
693 status
694 for i in rootcd rootfs; do
695 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
696 mkdir -p "$ADDFILES/$i"
697 zcat $TMP_DIR/$FLAVOR.$i | \
698 ( cd "$ADDFILES/$i"; cpio -id 2> /dev/null)
699 fi
700 done
701 echo -n "Update tazlito.conf..."
702 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
703 cat tazlito.conf | grep -v "^#VOLUM_NAME" | \
704 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
705 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
706 status
707 rm -Rf $TMP_DIR
708 fi
709 ;;
710 gen-distro)
711 # Generate a live distro tree with a set of packages.
712 #
713 check_root
714 if [ -d $ROOTFS ] ; then
715 echo "A rootfs exist in : $DISTRO"
716 echo -e "Please clean the distro tree or change directory path.\n"
717 exit 0
718 fi
719 # Check if a package list was specified on cmdline.
720 LIST_NAME="distro-packages.list"
721 CDROM=""
722 while [ -n "$2" ]; do
723 case "$2" in
724 --iso=*)
725 CDROM="-o loop ${2#--iso=}"
726 ;;
727 --cdrom)
728 CDROM="/dev/cdrom"
729 ;;
730 *) if [ ! -f "$2" ] ; then
731 echo -e "\nUnable to find the specified packages list."
732 echo -e "List name : $2\n"
733 exit 1
734 fi
735 LIST_NAME=$2
736 ;;
737 esac
738 shift
739 done
740 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
741 # Build list with installed packages
742 for i in $(ls $INSTALLED); do
743 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
744 echo "$i-$VERSION" >> $LIST_NAME
745 done
746 fi
747 # Exit if no list name.
748 if [ ! -f "$LIST_NAME" ]; then
749 echo -e "\nNo packages list found or specified. Please read the doc.\n"
750 exit 0
751 fi
752 # Start generation.
753 echo ""
754 echo -e "\033[1mTazlito generating a distro\033[0m"
755 echo "================================================================================"
756 # Misc checks
757 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
758 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
759 # Get the list of packages using cat for a file list.
760 LIST=`cat $LIST_NAME`
761 # Verify if all packages in list are presents in $PACKAGES_REPOSITORY.
762 REPACK=""
763 DOWNLOAD=""
764 for pkg in $LIST
765 do
766 [ "$pkg" = "" ] && continue
767 pkg=${pkg%.tazpkg}
768 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
769 PACKAGE=$(installed_package_name $pkg)
770 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
771 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
772 echo -e "\nUnable to find $pkg in the repository."
773 echo -e "Path : $PACKAGES_REPOSITORY\n"
774 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
775 yesorno "Repack packages from rootfs (y/N) ? "
776 REPACK="$answer"
777 [ "$answer" = "y" ] || REPACK="n"
778 [ "$DOWNLOAD" = "y" ] && break
779 fi
780 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
781 yesorno "Download packages from mirror (Y/n) ? "
782 DOWNLOAD="$answer"
783 if [ "$answer" = "n" ]; then
784 [ -z "$PACKAGE" ] && exit 1
785 else
786 DOWNLOAD="y"
787 [ -n "$REPACK" ] && break
788 fi
789 fi
790 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
791 done
793 # mount cdrom to be able to repack boot-loader packages
794 if [ ! -e /boot -a -n "$CDROM" ]; then
795 mkdir $TMP_MNT
796 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
797 ln -s $TMP_MNT/boot /
798 if [ ! -d "$ADDFILES/rootcd" ] ; then
799 mkdir -p $ADDFILES/rootcd
800 for i in $(ls $TMP_MNT); do
801 [ "$i" = "boot" ] && continue
802 cp -a $TMP_MNT/$i $ADDFILES/rootcd
803 done
804 fi
805 else
806 rmdir $TMP_MNT
807 fi
808 fi
810 # Root fs stuff.
811 echo "Preparing the rootfs directory..."
812 mkdir -p $ROOTFS
813 sleep 2
814 for pkg in $LIST
815 do
816 [ "$pkg" = "" ] && continue
817 # First copy and extract the package in tmp dir.
818 pkg=${pkg%.tazpkg}
819 PACKAGE=$(installed_package_name $pkg)
820 mkdir -p $TMP_DIR
821 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
822 # look for package in cache
823 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
824 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
825 # look for package in running distribution
826 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
827 tazpkg repack $PACKAGE && \
828 mv $pkg.tazpkg $PACKAGES_REPOSITORY
829 fi
830 fi
831 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
832 # get package from mirror
833 [ "$DOWNLOAD" = "y" ] && \
834 download $pkg.tazpkg && \
835 mv $pkg.tazpkg $PACKAGES_REPOSITORY
836 fi
837 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
838 echo "Missing package $pkg."
839 cleanup
840 exit 1
841 fi
842 yes "" | tazpkg install $PACKAGES_REPOSITORY/$pkg.tazpkg --root=$ROOTFS
843 done
844 cp $LIST_NAME $ROOTFS/etc/tazlito/distro-packages.list
845 if [ -f non-free.list ]; then
846 echo "Preparing non-free packages..."
847 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
848 for pkg in $(cat non-free.list); do
849 if [ ! -d $INSTALLED/$pkg ]; then
850 if [ ! -d $INSTALLED/get-$pkg ]; then
851 tazpkg get-install get-$pkg
852 fi
853 get-$pkg
854 fi
855 tazpkg repack $pkg
856 yes "" | tazpkg install $pkg*.tazpkg --root=$ROOTFS
857 mv $pkg*.tazpkg $PACKAGES_REPOSITORY
858 done
859 fi
860 echo ""
861 cd $DISTRO
862 # Copy all files from $ADDFILES/rootfs to the rootfs.
863 if [ -d "$ADDFILES/rootfs" ] ; then
864 echo -n "Copying addfiles content to the rootfs... "
865 cp -a $ADDFILES/rootfs/* $ROOTFS
866 status
867 fi
868 echo "Root file system is generated..."
869 # Root CD part.
870 echo -n "Preparing the rootcd directory..."
871 mkdir -p $ROOTCD
872 status
873 # Move the boot dir with the Linux kernel from rootfs.
874 # The boot dir goes directly on the CD.
875 if [ -d "$ROOTFS/boot" ] ; then
876 echo -n "Moving the boot directory..."
877 mv $ROOTFS/boot $ROOTCD
878 cd $ROOTCD/boot
879 ln vmlinuz-* bzImage
880 status
881 fi
882 cd $DISTRO
883 # Copy all files from $ADDFILES/rootcd to the rootcd.
884 if [ -d "$ADDFILES/rootcd" ] ; then
885 echo -n "Copying addfiles content to the rootcd... "
886 cp -a $ADDFILES/rootcd/* $ROOTCD
887 status
888 fi
889 # Initramfs and ISO image stuff.
890 gen_initramfs
891 gen_livecd_isolinux
892 distro_stats
893 cleanup
894 ;;
895 clean-distro)
896 # Remove old distro tree.
897 #
898 check_root
899 echo ""
900 echo -e "\033[1mCleaning :\033[0m $DISTRO"
901 echo "================================================================================"
902 if [ -d "$DISTRO" ] ; then
903 if [ -d "$ROOTFS" ] ; then
904 echo -n "Removing the rootfs..."
905 rm -f $DISTRO/$INITRAMFS
906 rm -rf $ROOTFS
907 status
908 fi
909 if [ -d "$ROOTCD" ] ; then
910 echo -n "Removing the rootcd..."
911 rm -rf $ROOTCD
912 status
913 fi
914 echo -n "Removing eventual ISO image..."
915 rm -f $DISTRO/$ISO_NAME.iso
916 rm -f $DISTRO/$ISO_NAME.md5
917 status
918 fi
919 echo "================================================================================"
920 echo ""
921 ;;
922 addhacker)
923 # Without /etc/passwd...
924 #
925 check_root
926 echo ""
927 echo -e "\033[1mAdduser hacker to :\033[0m $ROOTFS"
928 echo "================================================================================"
929 if [ ! -d "$ROOTFS/etc" ] ; then
930 echo -e "\nUnable to find : $ROOTFS/etc"
931 echo -e "Users and passwords config files will not be found.\n"
932 exit 0
933 fi
934 # Go for echoing on configuration files if any hacker was found.
935 #
936 if ! grep -q hacker $root/etc/passwd; then
937 echo -n "Configuring $ROOTFS/etc..."
938 echo 'hacker:x:500:500:Linux User,,,:/home/hacker:/bin/ash' >> $ROOTFS/etc/passwd
939 echo 'hacker::13646:0:99999:7:::' >> $ROOTFS/etc/shadow
940 echo 'hacker:x:500:' >> $ROOTFS/etc/group
941 echo 'hacker:!::' >> $ROOTFS/etc/gshadow
942 status
943 else
944 echo "Hacker is already in : $ROOTFS/etc/passwd"
945 fi
946 # Hacker can listen to music
947 #
948 if grep -q audio $root/etc/group; then
949 if ! grep -q "audio:x:20:hacker" $root/etc/group; then
950 sed -i s/'audio:x:20:'/'audio:x:20:hacker'/ $root/etc/group
951 fi
952 fi
953 # /home/hacker directories.
954 #
955 echo -n "Creating default directories... "
956 mkdir -p $fs/home/hacker/Documents \
957 $fs/home/hacker/Downloads \
958 $fs/home/hacker/Templates \
959 $fs/home/hacker/.local/bin \
960 $fs/home/hacker/.local/share
961 status
962 # Change permissions.
963 #
964 echo -n "Chmodig all files in /home/hacker..."
965 chown -R 500.500 $ROOTFS/home/hacker
966 status
967 echo "================================================================================"
968 echo "Linux User Hacker have an account in the distro."
969 echo ""
970 ;;
971 check-distro)
972 # Check for a few LiveCD needed files not installed by packages.
973 #
974 check_rootfs
975 echo ""
976 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
977 echo "================================================================================"
978 # SliTaz release info.
979 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
980 echo "Missing release info : /etc/slitaz-release"
981 else
982 release=`cat $ROOTFS/etc/slitaz-release`
983 echo -n "Release : $release"
984 status
985 fi
986 # Tazpkg mirror.
987 if [ ! -f "$ROOTFS/var/lib/tazpkg/mirror" ]; then
988 echo -n "Mirror URL : Missing /var/lib/tazpkg/mirror"
989 todomsg
990 else
991 echo -n "Mirror configuration exist..."
992 status
993 fi
994 # Isolinux msg
995 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.msg; then
996 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
997 todomsg
998 else
999 echo -n "Isolinux message seems good..."
1000 status
1001 fi
1002 echo "================================================================================"
1003 echo ""
1004 ;;
1005 burn-iso)
1006 # Guess cdrom device, ask user and burn the ISO.
1008 check_root
1009 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
1010 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
1011 # We can specify an alternative ISO from the cmdline.
1012 if [ -n "$2" ] ; then
1013 iso=$2
1014 else
1015 iso=$DISTRO/$ISO_NAME.iso
1016 fi
1017 if [ ! -f "$iso" ]; then
1018 echo -e "\nUnable to find ISO : $iso\n"
1019 exit 0
1020 fi
1021 echo ""
1022 echo -e "\033[1mTazlito burn ISO\033[0m "
1023 echo "================================================================================"
1024 echo "Cdrom device : /dev/$DRIVE_NAME"
1025 echo "Drive speed : $DRIVE_SPEED"
1026 echo "ISO image : $iso"
1027 echo "================================================================================"
1028 echo ""
1029 yesorno "Burn ISO image (y/N) ? "
1030 if [ "$answer" == "y" ]; then
1031 echo ""
1032 echo "Starting Wodim to burn the iso..." && sleep 2
1033 echo "================================================================================"
1034 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
1035 echo "================================================================================"
1036 echo "ISO image is burned to cdrom."
1037 else
1038 echo -e "\nExiting. No ISO burned."
1039 fi
1040 echo ""
1041 ;;
1042 usage|*)
1043 # Clear and print usage also for all unknow commands.
1045 clear
1046 usage
1047 ;;
1049 esac
1051 exit 0