tazlito view tazlito @ rev 92

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