tazlito view tazlito @ rev 252

tazlito: simple status to tail gen-distro output in GTK box and TazPanel (sed pipe dont make progress realtime)
author Christophe Lincoln <pankso@slitaz.org>
date Tue Mar 13 21:38:18 2012 +0100 (2012-03-13)
parents acbb83316a37
children 24b1f91ec9b2
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-2011 SliTaz - GNU General Public License.
11 #
12 # Authors : Christophe Lincoln <pankso@slitaz.org>
13 # Pascal Bellard <pascal.bellard@slitaz.org>
14 #
15 VERSION=4.3.1
17 # Tazlito configuration variables to be shorter
18 # and to use words rather 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 log=/var/log/tazlito.log
32 echo "" > $log
34 # Try to include config file, continue if command is gen-config or exit.
35 # The main config used by default is in /etc/tazlito.
36 if [ -f "/etc/tazlito/tazlito.conf" ] ; then
37 CONFIG_FILE="/etc/tazlito/tazlito.conf"
38 fi
39 # Specific distro config file can be put in a distro tree.
40 if [ -f "$TOP_DIR/tazlito.conf" ] ; then
41 CONFIG_FILE="$TOP_DIR/tazlito.conf"
42 fi
43 if [ ! "$CONFIG_FILE" = "" ] ; then
44 . $CONFIG_FILE
45 else
46 if [ "$COMMAND" = "gen-config" ] ; then
47 continue
48 else
49 echo "Unable to find any configuration file. Please read the docs"
50 echo "or run '`basename $0` gen-config' to get an empty config file."
51 exit 0
52 fi
53 fi
55 # While Tazpkg is not used the default mirror url file does not exist
56 # and user can't recharge the list of flavors.
57 if test $(id -u) = 0 ; then
58 if [ ! -f "$MIRROR" ]; then
59 echo "$DEFAULT_MIRROR" > $MIRROR
60 fi
61 fi
63 # Set the rootfs and rootcd path with $DISTRO
64 # configuration variable.
65 ROOTFS=$DISTRO/rootfs
66 ROOTCD=$DISTRO/rootcd
68 #####################
69 # Tazlito functions #
70 #####################
72 # Print the usage.
73 usage ()
74 {
75 echo -e "\nSliTaz Live Tool - Version: $VERSION\n
76 \033[1mUsage: \033[0m `basename $0` [command] [list|iso|flavor|compression] [dir|iso]
77 \033[1mCommands: \033[0m\n
78 usage Print this short usage.
79 stats View Tazlito and distro configuration statistics.
80 gen-config Generate a new configuration file for a distro.
81 configure Configure the main config file or a specific tazlito.conf.
82 gen-iso Generate a new ISO from a distro tree.
83 gen-initiso Generate a new initramfs and ISO from the distro tree.
84 list-flavors List all available package lists on the mirror.
85 gen-flavor Generate a new live-CD description.
86 gen-liveflavor Generate a live-CD description from current system.
87 show-flavor Show live-CD description.
88 get-flavor Get a flavor's list of packages.
89 upgrade-flavor Update package list to the latest available versions.
90 extract-flavor Extract a (*.flavor) flavor into $FLAVORS_REPOSITORY.
91 pack-flavor Pack (and update) a flavor from $FLAVORS_REPOSITORY.
92 iso2flavor Create a flavor file from a SliTaz iso image.
93 check-list Check a distro-packages.list for updates.
94 extract-distro Extract an ISO to a directory and rebuild LiveCD tree.
95 gen-distro Generate a Live distro and ISO from a list of packages.
96 clean-distro Remove all files generated by gen-distro.
97 check-distro Help to check if distro is ready to release.
98 writeiso Use running system to generate a bootable ISO (with /home).
99 merge Merge multiple rootfs into one iso.
100 repack Recompress rootfs into iso with maximum ratio.
101 build-loram Generate a live-CD for low ram systems.
102 frugal-install Frugal install in /boot/frugal from a distro or ISO.
103 emu-iso Emulate an ISO image with Qemu.
104 burn-iso Burn ISO image to a cdrom using Wodim.\n"
105 }
107 # Status function.
108 status() {
109 if [ $? = 0 ]; then
110 echo " OK"
111 else
112 echo " Failed"
113 fi
114 }
116 yesorno()
117 {
118 echo -n "$1"
119 case "$DEFAULT_ANSWER" in
120 Y|y) answer="y";;
121 N|n) answer="n";;
122 *) read answer;;
123 esac
124 }
126 field()
127 {
128 grep "^$1" "$2" | sed 's/.*: \([0-9KMG\.]*\).*/\1/'
129 }
131 todomsg()
132 {
133 echo -e "\\033[70G[ \\033[1;31mTODO\\033[0;39m ]"
134 }
136 # Download a file from this mirror
137 download_from()
138 {
139 local i
140 local mirrors
141 mirrors="$1"
142 shift
143 for i in $mirrors; do
144 case "$i" in
145 http://*|ftp://*) wget -c $i$@ && break;;
146 *) cp $i/$1 . && break;;
147 esac
148 done
149 }
151 # Download a file trying all mirrors
152 download()
153 {
154 local i
155 for i in $(cat $MIRROR $LOCALSTATE/undigest/*/mirror 2> /dev/null); do
156 download_from "$i" "$@" && break
157 done
158 }
160 # Execute hooks provided by some packages
161 genisohooks()
162 {
163 local here=`pwd`
164 for i in $(ls $ROOTFS/etc/tazlito/*.$1 2> /dev/null); do
165 cd $ROOTFS
166 . $i $ROOTCD
167 done
168 cd $here
169 }
171 cleanup()
172 {
173 if [ -d $TMP_MNT ]; then
174 umount $TMP_MNT
175 rmdir $TMP_MNT
176 rm -f /boot
177 fi
178 }
180 # Echo the package name if the tazpkg is already installed
181 installed_package_name()
182 {
183 local tazpkg
184 local package
185 local VERSION
186 local EXTRAVERSION
187 tazpkg=$1
188 # Try to find package name and version to be able
189 # to repack it from installation
190 # A dash (-) can exist in name *and* in version
191 package=${tazpkg%-*}
192 i=$package
193 while true; do
194 VERSION=""
195 eval $(grep -s ^VERSION= $INSTALLED/$i/receipt)
196 EXTRAVERSION=""
197 eval $(grep -s ^EXTRAVERSION= $INSTALLED/$i/receipt)
198 if [ "$i-$VERSION$EXTRAVERSION" = "$tazpkg" ]; then
199 echo $i
200 break
201 fi
202 case "$i" in
203 *-*);;
204 *) break;;
205 esac
206 i=${i%-*}
207 done
208 }
210 # Check if user is root.
211 check_root()
212 {
213 if test $(id -u) != 0 ; then
214 echo -e "\nYou must be root to run `basename $0` with this option."
215 echo -e "Please type 'su' and root password to become super-user.\n"
216 exit 0
217 fi
218 }
220 # Check for the rootfs tree.
221 check_rootfs()
222 {
223 if [ ! -d "$ROOTFS/etc" ] ; then
224 echo -e "\nUnable to find a distro rootfs...\n"
225 exit 0
226 fi
227 }
229 # Check for the boot dir into the root CD tree.
230 verify_rootcd()
231 {
232 if [ ! -d "$ROOTCD/boot" ] ; then
233 echo -e "\nUnable to find the rootcd boot directory...\n"
234 exit 0
235 fi
236 }
238 create_iso()
239 {
240 echo "Generating $1"
241 if [ $(ls $2/boot/vmlinuz* $2/boot/bzImage | wc -l) -eq 2 ]; then
242 if cmp $2/boot/vmlinuz* $2/boot/bzImage > /dev/null; then
243 rm -f $2/boot/bzImage
244 ln $2/boot/vmlinuz* $2/boot/bzImage
245 fi
246 fi
247 genisoimage -R -o $1 -b boot/isolinux/isolinux.bin \
248 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
249 -V "$VOLUM_NAME" -p "$PREPARED" -input-charset iso8859-1 \
250 -boot-info-table $2
251 if [ -x /usr/bin/isohybrid ]; then
252 echo -n "Creating hybrid ISO..."
253 /usr/bin/isohybrid $1 -entry 2 2> /dev/null
254 status
255 fi
256 if [ -s /etc/tazlito/info ]; then
257 if [ $(stat -c %s /etc/tazlito/info) -lt $(( 31*1024 )) ]; then
258 echo -n "Storing ISO info..."
259 dd if=/etc/tazlito/info bs=1k seek=1 of=$1 \
260 conv=notrunc 2> /dev/null
261 status
262 fi
263 fi
264 }
266 # Generate a new ISO image using isolinux.
267 gen_livecd_isolinux()
268 {
269 # Some packages may want to alter iso
270 genisohooks iso
271 if [ ! -f "$ROOTCD/boot/isolinux/isolinux.bin" ]; then
272 echo -e "\nUnable to find isolinux binary.\n"
273 cleanup
274 exit 0
275 fi
276 # Set date for boot msg.
277 if grep -q 'XXXXXXXX' $ROOTCD/boot/isolinux/isolinux.*g; then
278 DATE=`date +%Y%m%d`
279 echo -n "Setting build date to: $DATE..."
280 sed -i "s/XXXXXXXX/$DATE/" $ROOTCD/boot/isolinux/isolinux.*g
281 status
282 fi
283 cd $ROOTCD
284 echo -n "Computing md5..."
285 find * -type f ! -name md5sum -exec md5sum {} \; > md5sum
286 sed -i '/ boot\/isolinux\/isolinux.bin$/d' md5sum
287 status
288 cd $DISTRO
289 echo ""
290 echo -e "\033[1mGenerating ISO image\033[0m"
291 echo "================================================================================"
292 create_iso $ISO_NAME.iso $ROOTCD
293 echo -n "Creating the ISO md5sum..."
294 md5sum $ISO_NAME.iso > $ISO_NAME.md5
295 status
296 echo "================================================================================"
297 # Some packages may want to alter final iso
298 genisohooks final
299 }
301 lzma_history_bits()
302 {
303 #
304 # This generates an ISO which boots with Qemu but gives
305 # rootfs errors in frugal or liveUSB mode.
306 #
307 #local n
308 #local sz
309 #n=20 # 1Mb
310 #sz=$(du -sk $1 | cut -f1)
311 #while [ $sz -gt 1024 -a $n -lt 28 ]; do
312 #n=$(( $n + 1 ))
313 #sz=$(( $sz / 2 ))
314 #done
315 #echo $n
316 echo 24
317 }
319 lzma_switches()
320 {
321 echo "-d$(lzma_history_bits $1) -mt$(grep '^processor' < /proc/cpuinfo | wc -l)"
322 }
324 lzma_set_size()
325 {
326 # Update size field for lzma'd file packed using -si switch
327 local n
328 local i
329 return # Need to fix kernel code ?
330 n=$(unlzma -c $1 | wc -c)
331 for i in $(seq 1 8); do
332 printf '\\\\x%02X' $(($n & 255))
333 n=$(($n >> 8))
334 done | xargs echo -en | dd of=$1 conv=notrunc bs=1 seek=5 2> /dev/null
335 }
337 # Pack rootfs
338 pack_rootfs()
339 {
340 ( cd $1 ; find . -print | cpio -o -H newc ) | \
341 if [ "$COMPRESSION" = "none" ]; then
342 echo "Generating uncompressed initramfs... "
343 cat > $2
344 elif [ -x /usr/bin/lzma -a "$COMPRESSION" != "gzip" ]; then
345 echo -n "Generating lzma'ed initramfs... "
346 lzma e -si -so $(lzma_switches $1) > $2
347 lzma_set_size $2
348 else
349 echo "Generating gziped initramfs... "
350 gzip -9 > $2
351 fi
352 echo 1 > /tmp/rootfs
353 }
355 # Compression functions for writeiso.
356 write_initramfs()
357 {
358 if [ "$COMPRESSION" = "lzma" ]; then
359 echo -n "Creating rootfs.gz with lzma compression... "
360 cat /tmp/list | cpio -o -H newc | lzma e -si -so > /rootfs.gz
361 lzma_set_size /rootfs.gz
362 elif [ "$COMPRESSION" = "gzip" ]; then
363 echo "Creating rootfs.gz with gzip compression... "
364 cat /tmp/list | cpio -o -H newc | gzip -9 > /rootfs.gz
365 else
366 echo "Creating rootfs.gz without compression... "
367 cat /tmp/list | cpio -o -H newc > /rootfs.gz
368 fi
369 echo 1 > /tmp/rootfs
370 }
372 # Generate a new initramfs from the root filesystem.
373 gen_initramfs()
374 {
375 # Just in case CTRL+c
376 rm -f $DISTRO/gen
378 # Some packages may want to alter rootfs
379 genisohooks rootfs
380 cd $1
382 # Link duplicate files
383 find . -type f -size +0c -exec stat -c '%s-%a-%u-%g %i %h %n' {} \; | \
384 sort | ( save=0; old_attr=""; old_inode=""; old_link=""; old_file=""
385 while read attr inode link file; do
386 if [ "$attr" = "$old_attr" -a "$inode" != "$old_inode" ]; then
387 if cmp "$file" "$old_file" >/dev/null; then
388 rm -f "$file"
389 ln "$old_file" "$file"
390 inode="$old_inode"
391 [ "$link" = "1" ] && save="$(expr $save + ${attr%%-*})"
392 fi
393 fi
394 old_attr="$attr" ; old_inode="$inode" ; old_file="$file"
395 done
396 echo "$save bytes saved in duplicate files."
397 )
399 # Use lzma if installed. Display rootfs size in realtime.
400 rm -f /tmp/rootfs
401 pack_rootfs . $DISTRO/$(basename $1).gz &
402 sleep 2
403 echo -en "\nFilesystem size:"
404 while [ ! -f /tmp/rootfs ]
405 do
406 sleep 1
407 echo -en "\\033[18G`du -sh $DISTRO/$(basename $1).gz | awk '{print $1}'` "
408 done
409 echo -e "\n"
410 cd $DISTRO
411 mv $(basename $1).gz $ROOTCD/boot
412 }
414 distro_sizes()
415 {
416 echo "Build date : `date +%Y%m%d\ \at\ \%H:%M:%S`"
417 echo "Packages : `ls -1 $ROOTFS*$INSTALLED/*/receipt | wc -l`"
418 echo "Rootfs size : `du -csh $ROOTFS*/ | awk '{ s=$1 } END { print s }'`"
419 echo "Initramfs size : `du -csh $ROOTCD/boot/rootfs*.gz | awk '{ s=$1 } END { print s }'`"
420 echo "ISO image size : `du -sh $ISO_NAME.iso | awk '{ print $1 }'`"
421 echo "================================================================================"
422 echo "Image is ready: $ISO_NAME.iso"
423 echo ""
424 }
426 # Print ISO and rootfs size.
427 distro_stats()
428 {
429 echo ""
430 echo -e "\033[1mDistro statistics\033[0m ($DISTRO)"
431 echo "================================================================================"
432 distro_sizes
433 }
435 # Create an empty configuration file.
436 empty_config_file()
437 {
438 cat >> tazlito.conf << "EOF"
439 # tazlito.conf: Tazlito (SliTaz Live Tool)
440 # configuration file.
441 #
443 # Name of the ISO image to generate.
444 ISO_NAME=""
446 # ISO image volume name.
447 VOLUM_NAME="SliTaz"
449 # Name of the preparer.
450 PREPARED="$USER"
452 # Path to the packages repository and the packages.list.
453 PACKAGES_REPOSITORY=""
455 # Path to the distro tree to gen-distro from a
456 # list of packages.
457 DISTRO=""
459 # Path to the directory containing additional files
460 # to copy into the rootfs and rootcd of the LiveCD.
461 ADDFILES="$DISTRO/addfiles"
463 # Default answer for binary question (Y or N)
464 DEFAULT_ANSWER="ASK"
466 # Compression utility (lzma, gzip or none)
467 COMPRESSION="lzma"
468 EOF
469 }
471 # extract rootfs.gz somewhere
472 extract_rootfs()
473 {
474 (zcat $1 || unlzma -c $1 || cat $1) 2>/dev/null | \
475 (cd $2; cpio -idm > /dev/null)
476 }
478 # Remove duplicate files
479 mergefs()
480 {
481 echo -n "Merge $(basename $1) ($(du -hs $1 | awk '{ print $1}')) into "
482 echo -n "$(basename $2) ($(du -hs $2 | awk '{ print $1}'))"
483 # merge symlinks files and devices
484 ( cd $1; find ) | while read file; do
485 if [ -L $1/$file ]; then
486 [ -L $2/$file ] &&
487 [ "$(readlink $1/$file)" == "$(readlink $2/$file)" ] &&
488 rm -f $2/$file
489 elif [ -f $1/$file ]; then
490 [ -f $2/$file ] &&
491 cmp $1/$file $2/$file > /dev/null 2>&1 && rm -f $2/$file
492 [ -f $2/$file ] &&
493 [ "$(basename $file)" == "volatile.cpio.gz" ] &&
494 [ "$(dirname $(dirname $file))" == \
495 ".$INSTALLED" ] && rm -f $2/$file
496 elif [ -b $1/$file ]; then
497 [ -b $2/$file ] &&
498 [ "$(stat -c '%a:%u:%g:%t:%T' $1/$file)" == \
499 "$(stat -c '%a:%u:%g:%t:%T' $2/$file)" ] &&
500 rm -f $2/$file
501 elif [ -c $1/$file ]; then
502 [ -c $2/$file ] &&
503 [ "$(stat -c '%a:%u:%g:%t:%T' $1/$file)" == \
504 "$(stat -c '%a:%u:%g:%t:%T' $2/$file)" ] &&
505 rm -f $2/$file
506 fi
507 done
509 # cleanup directories
510 ( cd $1; find -type d ) | sed '1!G;h;$!d' | while read file; do
511 [ -d $2/$file ] && rmdir $2/$file 2> /dev/null
512 done
513 true
514 status
515 }
517 cleanup_merge()
518 {
519 rm -rf $TMP_DIR
520 exit 1
521 }
523 human2cent()
524 {
525 case "$1" in
526 *k) echo $1 | sed 's/\(.*\).\(.\)k/\1\2/';;
527 *M) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)M/\1\2/') * 1024));;
528 *G) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)G/\1\2/') * 1024 * 1024));;
529 esac
530 }
532 cent2human()
533 {
534 if [ $1 -lt 10000 ]; then
535 echo "$(($1 / 10)).$(($1 % 10))k"
536 elif [ $1 -lt 10000000 ]; then
537 echo "$(($1 / 10240)).$(( ($1/1024) % 10))M"
538 else
539 echo "$(($1 / 10485760)).$(( ($1/1048576) % 10))G"
540 fi
541 }
543 get_size()
544 {
545 cat $LOCALSTATE/packages.list $TMP_DIR/packages.list 2>/dev/null | awk "{ \
546 if (/^$(echo $1 | sed 's/[$+.\]/\\&/g')$/) get=1; \
547 if (/installed/ && get == 1) { print ; get++ } \
548 }
549 END { if (get < 2) print \" 0.0k (0.0k installed)\" }" | \
550 sed 's/ *\(.*\) .\(.*\) installed./\1 \2/' | while read packed unpacked; do
551 echo "$(human2cent $packed) $(human2cent $unpacked)"
552 done
553 }
555 # Display package list with version, set packed_size and unpacked_size
556 get_pkglist()
557 {
558 packed_size=0; unpacked_size=0
559 grep -v ^# $FLAVORS_REPOSITORY/$1/packages.list > $TMP_DIR/flavor.pkg
560 while read pkg; do
561 set -- $(get_size $pkg)
562 packed_size=$(( $packed_size + $1 ))
563 unpacked_size=$(( $unpacked_size + $2 ))
564 for i in $(grep -hs ^$pkg $LOCALSTATE/packages.list \
565 $TMP_DIR/packages.list); do
566 echo $i
567 break
568 done
569 done < $TMP_DIR/flavor.pkg
570 rm -f $TMP_DIR/flavor.pkg
571 }
573 # Update isolinux config files for multiple rootfs
574 update_bootconfig()
575 {
576 local files
577 echo -n "Updating boot config files..."
578 files="$(grep -l 'include common' $1/*.cfg)"
579 for file in $files ; do
580 awk -v n=$(echo $2 | awk '{ print NF/2 }') '{
581 if (/label/) label=$0;
582 else if (/kernel/) kernel=$0;
583 else if (/append/) {
584 i=index($0,"rootfs.gz");
585 append=substr($0,i+9);
586 }
587 else if (/include/) {
588 for (i = 1; i <= n; i++) {
589 print label i
590 print kernel;
591 initrd="initrd=/boot/rootfs" n ".gz"
592 for (j = n - 1; j >= i; j--) {
593 initrd=initrd ",/boot/rootfs" j ".gz";
594 }
595 printf "\tappend %s%s\n",initrd,append;
596 print "";
597 }
598 print;
599 }
600 else print;
601 }' < $file > $file.$$
602 mv -f $file.$$ $file
603 done
604 sel="$(echo $2 | awk '{
605 for (i=1; i<=NF; i++)
606 if (i % 2 == 0) printf " slitaz%d",i/2
607 else printf " %s",$i
608 }')"
609 cat >> $1/common.cfg <<EOT
611 label slitaz
612 kernel /boot/isolinux/ifmem.c32
613 append$sel noram
615 label noram
616 config noram.cfg
618 EOT
619 # Update vesamenu
620 if [ -s $1/isolinux.cfg ]; then
621 files="$files $1/isolinux.cfg"
622 awk -v n=$(echo $2 | awk '{ print NF/2 }') -v "sel=$sel" '{
623 if (/ROWS/) print "MENU ROW " n+$3;
624 else if (/TIMEOUTROW/) print "MENU TIMEOUTROW " n+$3;
625 else if (/TABMSGROW/) print "MENU TABMSGROW " n+$3;
626 else if (/CMDLINEROW/) print "MENU CMDLINEROW " n+$3;
627 else if (/VSHIFT/) {
628 x=$3-n;
629 if (x < 0) x=0;
630 print "MENU VSHIFT " x;
631 }
632 else if (/bzImage/) kernel=$0;
633 else if (/rootfs.gz/) {
634 i=index($0,"rootfs.gz");
635 append=substr($0,i+9);
636 print " kernel /boot/isolinux/ifmem.c32"
637 print " append" sel " noram"
638 print ""
639 print "label noram"
640 print " MENU HIDE"
641 print " config noram.cfg"
642 print ""
643 for (i = 1; i <= n; i++) {
644 print "LABEL slitaz" i
645 print " MENU LABEL SliTaz slitaz" i " Live"
646 print kernel;
647 initrd="initrd=/boot/rootfs" n ".gz"
648 for (j = n - 1; j >= i; j--) {
649 initrd=initrd ",/boot/rootfs" j ".gz";
650 }
651 printf "\tappend %s%s\n",initrd,append;
652 print "";
653 }
654 }
655 else print;
656 }' < $1/isolinux.cfg > $1/isolinux.cfg.$$
657 mv $1/isolinux.cfg.$$ $1/isolinux.cfg
658 fi
659 cat > $1/noram.cfg <<EOT
660 display isolinux.msg
661 say Not enough RAM to boot slitaz. Give http://tiny.slitaz.org/ a try ?
662 default reboot
663 label reboot
664 com32 reboot.c32
666 implicit 0
667 prompt 1
668 timeout 80
669 F1 help.txt
670 F2 options.txt
671 F3 isolinux.msg
672 F4 display.txt
673 F5 enhelp.txt
674 F6 enopts.txt
675 EOT
676 # Restore real label names
677 echo $2 | awk '{ for (i=NF; i>1; i-=2) printf "%d/%s\n",i/2,$i }' | \
678 while read pat; do
679 sed -i "s/slitaz$pat/" $1/common.cfg $files
680 done
681 status
682 }
684 # Install a missing package
685 install_package()
686 {
687 echo -n "Install package $1 "
688 [ -n "$2" ] && echo -n "for kernel $2 "
689 echo -n "?"
690 read answer
691 case "$answer" in
692 y*|Y*|o*|O*)
693 # We dont want package on host cache.
694 echo -n "Getting and installing package: $1"
695 yes y | tazpkg get-install $1 2>&1 >> $log || exit 1
696 status ;;
697 *)
698 return 1 ;;
699 esac
700 }
702 # Check iso for loram transformation
703 check_iso_for_loram()
704 {
705 [ -s $TMP_DIR/iso/boot/rootfs.gz ] ||
706 [ -s $TMP_DIR/iso/boot/rootfs1.gz ]
707 }
709 # Build initial rootfs for loram ISO ram/cdrom/http
710 build_initfs()
711 {
712 urliso="mirror.slitaz.org mirror.switch.ch/ftp/mirror/slitaz \
713 download.tuxfamily.org/slitaz slitaz.c3sl.ufpr.br"
714 version=$(ls $TMP_DIR/iso/boot/vmlinuz-* | sed 's/.*vmlinuz-//')
715 [ -s /usr/share/boot/busybox-static ] || install_package busybox-static
716 need_lib=false
717 mkdir -p $TMP_DIR/initfs/bin $TMP_DIR/initfs/dev $TMP_DIR/initfs/lib \
718 $TMP_DIR/initfs/mnt $TMP_DIR/initfs/proc $TMP_DIR/initfs/tmp \
719 $TMP_DIR/initfs/sys
720 while [ ! -f /lib/modules/$version/kernel/fs/aufs/aufs.ko.gz ]; do
721 install_package aufs $version || return 1
722 done
723 # bootfloppybox will need floppy.ko.gz, /dev/fd0, /dev/tty0
724 cp /lib/modules/$version/kernel/drivers/block/floppy.ko.gz \
725 $TMP_DIR/initfs/lib 2> /dev/null
726 cp -a /dev/tty0 /dev/fd0 $TMP_DIR/initfs/dev 2> /dev/null
727 cp /lib/modules/$version/kernel/fs/aufs/aufs.ko.gz \
728 $TMP_DIR/initfs/lib
729 if [ -f /bin/cromfs-driver ]; then
730 cp /bin/cromfs-driver $TMP_DIR/initfs/bin
731 ls /bin/unmkcromfs | \
732 cpio -o -H newc > $TMP_DIR/initfs/extractfs.cpio
733 else
734 [ ! -f /usr/sbin/mksquashfs ] && ! install_package squashfs && return 1
735 while [ ! -f /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.gz ]; do
736 install_package linux-squashfs $version || return 1
737 done
738 cp /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.gz \
739 $TMP_DIR/initfs/lib
740 ls /sbin/unsquashfs /usr/lib/liblzma.so* $INSTALLED/squashfs/* | \
741 cpio -o -H newc > $TMP_DIR/initfs/extractfs.cpio
742 fi
743 if [ "$1" == "cdrom" ]; then
744 for i in $(ls /dev/[hs]d[a-f]*); do
745 cp -a $i $TMP_DIR/initfs/dev
746 done
747 fi
748 if [ "$1" == "http" ]; then
749 mkdir $TMP_DIR/initfs/etc
750 ln -s /proc/mounts $TMP_DIR/initfs/etc/mtab
751 cp /usr/share/udhcpc/default.script $TMP_DIR/initfs/lib/udhcpc
752 sed -i 's|/sbin/||' $TMP_DIR/initfs/lib/udhcpc
753 cp -a /dev/fuse $TMP_DIR/initfs/dev
754 if ! $need_lib && [ -x /usr/share/boot/fusermount-static ]; then
755 cp /usr/share/boot/fusermount-static $TMP_DIR/initfs/bin/httpfs
756 else
757 cp /usr/bin/fusermount $TMP_DIR/initfs/bin
758 need_lib=true
759 fi
760 if ! $need_lib && [ -x /usr/share/boot/httpfs-static ]; then
761 cp /usr/share/boot/httpfs-static $TMP_DIR/initfs/bin/httpfs
762 else
763 [ ! -f /usr/bin/httpfs ] && ! install_package httpfs-fuse && return 1
764 cp /usr/bin/httpfs $TMP_DIR/initfs/bin
765 cp -a /lib/librt* $TMP_DIR/initfs/lib
766 cp -a /lib/libdl* $TMP_DIR/initfs/lib
767 cp -a /lib/libpthread* $TMP_DIR/initfs/lib
768 cp -a /usr/lib/libfuse* $TMP_DIR/initfs/lib
769 cp -a /lib/libresolv* $TMP_DIR/initfs/lib
770 cp -a /lib/libnss_dns* $TMP_DIR/initfs/lib
771 need_lib=true
772 fi
773 cd $TMP_DIR/initfs
774 echo "Getting slitaz-release..."
775 for i in $TMP_DIR/iso/boot/rootfs*.gz; do
776 ( zcat $i 2> /dev/null || unlzma -c $i) | \
777 cpio -idmu etc/slitaz-release > /dev/null
778 done
779 cd - > /dev/null
780 echo "Default urls for /iso/$(cat $TMP_DIR/initfs/etc/slitaz-release)/flavors/slitaz-loram-cdrom.iso /iso/$(cat $TMP_DIR/initfs/etc/slitaz-release)/flavors/slitaz-$(cat $TMP_DIR/initfs/etc/slitaz-release)-loram-cdrom.iso: $urliso"
781 echo -n "List of urls to insert: "
782 read -t 30 urliso2
783 urliso="$urliso2 $urliso"
784 fi
785 if ! $need_lib && [ -x /usr/share/boot/busybox-static ]; then
786 cp /usr/share/boot/busybox-static $TMP_DIR/initfs/bin/busybox
787 else
788 cp /bin/busybox $TMP_DIR/initfs/bin
789 need_lib=true
790 fi
791 for i in $($TMP_DIR/initfs/bin/busybox | awk \
792 '{ if (s) printf "%s",$0 } /Currently/ { s=1 }' | sed 's/,//g'); do
793 ln $TMP_DIR/initfs/bin/busybox $TMP_DIR/initfs/bin/$i
794 done
795 for i in /dev/console /dev/loop* /dev/null /dev/tty /dev/zero \
796 /dev/kmem /dev/mem /dev/random /dev/urandom; do
797 cp -a $i $TMP_DIR/initfs/dev
798 done
799 $need_lib && for i in /lib/ld-* /lib/lib[cm].so* /lib/lib[cm]-* ; do
800 cp -a $i $TMP_DIR/initfs/lib
801 done
802 cat > $TMP_DIR/initfs/init <<EOTEOT
803 #!/bin/sh
805 getarg()
806 {
807 grep -q " \$1=" /proc/cmdline || return 1
808 eval \$2=\$(sed "s/.* \$1=\\\\([^ ]*\\\\).*/\\\\1/" < /proc/cmdline)
809 return 0
810 }
812 copy_rootfs()
813 {
814 total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g')
815 need=\$(du -c \${path}rootfs* | tail -n 1 | cut -f1)
816 [ \$(( \$total / \$need )) -gt 1 ] || return 1
817 if ! grep -q " keep-loram" /proc/cmdline && cp \${path}rootfs* /mnt; then
818 path=/mnt/
819 return 0
820 else
821 rm -f /mnt/rootfs*
822 return 1
823 fi
824 }
826 echo "Switching / to tmpfs..."
827 mount -t proc proc /proc
828 size="\$(grep rootfssize= < /proc/cmdline | \\
829 sed 's/.*rootfssize=\\([0-9]*[kmg%]\\).*/-o size=\\1/')"
830 [ -n "\$size" ] || size="-o size=90%"
832 if [ -x /bin/httpfs ]; then # loram-http
834 while read var default; do
835 eval \$var=\$default
836 getarg \$var \$var
837 done <<EOT
838 eth eth0
839 dns 208.67.222.222,208.67.220.220
840 netmask 255.255.255.0
841 gw
842 ip
843 EOT
844 if [ -n "\$ip" ]; then
845 ifconfig \$eth \$ip netmask \$netmask up
846 route add default gateway \$gw
847 for i in \$(echo \$dns | sed 's/,/ /g'); do
848 echo "nameserver \$i" >> /etc/resolv.conf
849 done
850 else
851 udhcpc -f -q -s /lib/udhcpc -i \$eth
852 fi
853 for i in $urliso ; do
854 [ -n "\$URLISO" ] && URLISO="\$URLISO,"
855 URLISO="\${URLISO}http://\$i/iso/\$(cat /etc/slitaz-release)/flavors/slitaz-loram-cdrom.iso,http://\$i/iso/\$(cat /etc/slitaz-release)/flavors/slitaz-\$(cat /etc/slitaz-release)-loram-cdrom.iso"
856 done
857 getarg urliso URLISO
858 DIR=fs
859 if getarg loram DIR; then
860 DEVICE=\${DIR%,*}
861 DIR=/\${DIR#*,}
862 fi
863 mount -t tmpfs \$size tmpfs /mnt
864 path2=/mnt/.httpfs/
865 path=/mnt/.cdrom/
866 mkdir -p /mnt/.rw \$path \$path2
867 while [ ! -d \$path/boot ]; do
868 for i in \$(echo \$URLISO | sed 's/,/ /g'); do
869 httpfs \$i \$path2 && break
870 done
871 mount -o loop,ro -t iso9660 \$path2/*.iso \$path
872 done
873 #copy_rootfs && umount -d \$path && umount -d \$path2
875 elif [ -f \$(echo /rootfs*.gz | cut -f1 -d' ') ]; then # loram-ram
877 total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g')
878 free=\$(grep MemFree /proc/meminfo | sed 's/[^0-9]//g')
879 if [ \$(( \$total/\$free )) -gt 1 ] || ! mount -t tmpfs \$size tmpfs /mnt; then
880 echo "No tmpfs for /mnt"
881 mkdir -p /mnt/.rw
882 mount -t tmpfs tmpfs /mnt/.rw
883 mkdir -p /mnt/.rw/mnt/.rw
884 path=/
885 else
886 mkdir -p /mnt/.rw
887 path=/mnt/.
888 for i in rootfs* ; do
889 mv /\$i \$path\$i
890 done
891 fi
893 else # loram-cdrom
895 getarg cdrom DRIVE_NAME ||
896 DRIVE_NAME=\$(grep "drive name" < /proc/sys/dev/cdrom/info | cut -f 3)
897 DEVICE=/dev/\$DRIVE_NAME
898 DIR=fs
899 if getarg loram DIR; then
900 DEVICE=\${DIR%,*}
901 DIR=/\${DIR#*,}
902 fi
903 mount -t tmpfs \$size tmpfs /mnt
904 mkdir -p /mnt/.rw /mnt/.cdrom /mnt/mnt/.cdrom
905 i=0
906 while [ \$i -lt 5 ] && ! mount -r \$DEVICE /mnt/.cdrom; do
907 case "\$DEVICE" in
908 /dev/sd*|UUID=*|LABEL=*)
909 mount -t sysfs sysfs /sys
910 USBDELAY=\$(cat /sys/module/usb_storage/parameters/delay_use)
911 umount /sys
912 sleep \$((1+\$USBDELAY)) ;;
913 esac
914 i=\$((i+1))
915 done
916 path=/mnt/.cdrom/
917 copy_rootfs && umount -d /mnt/.cdrom
919 fi
921 memfree=\$(grep MemFree /proc/meminfo | sed 's/[^0-9]//g')
922 umount /proc
923 branch=br=/mnt/.rw:/mnt/.cdrom/\$DIR
924 if [ ! -d /mnt/.cdrom/\$DIR/etc ]; then
925 branch=br=/mnt/.rw
926 for i in \${path}rootfs* ; do
927 fs=\${i#*root}
928 branch=\$branch:/mnt/.\$fs
929 mkdir -p /mnt/.rw/mnt/.\$fs /mnt/.\$fs /mnt/.rw/mnt/.cdrom
930 if [ -f /bin/cromfs-driver ]; then
931 cromfs-driver \${path}root\$fs /mnt/.\$fs -o ro,dev,suid,allow_other
932 else
933 insmod /lib/squashfs.ko.gz 2> /dev/null
934 mount -o loop,ro -t squashfs \${path}root\$fs /mnt/.\$fs
935 fi
936 done
937 else
938 mkdir -p /mnt/.rw/mnt/.httpfs
939 fi
940 insmod /lib/aufs.ko.gz
941 mount -t aufs -o \$branch none /mnt
942 [ -x /bin/httpfs ] && sed -i 's/DHCP="yes"/DHCP="no"/' /mnt/etc/network.conf
943 [ \$memfree -lt 30000 ] && sed -i 's/ slim//' /mnt/etc/rcS.conf
944 [ -x /mnt/sbin/init ] && exec /bin/switch_root mnt /sbin/init || sh
945 EOTEOT
946 chmod +x $TMP_DIR/initfs/init
947 ( cd $TMP_DIR/initfs ; find | busybox cpio -o -H newc 2> /dev/null) | \
948 lzma e $TMP_DIR/initfs.gz -si
949 lzma_set_size $TMP_DIR/initfs.gz
950 rm -rf $TMP_DIR/initfs
951 rem=$(( $(stat -c "%s" $TMP_DIR/initfs.gz) % 4 ))
952 [ $rem -ne 0 ] &&
953 dd if=/dev/zero bs=1 count=$(( 4 - $rem )) >> $TMP_DIR/initfs.gz 2> /dev/null
954 return 0
955 }
957 # Move each initramfs to squashfs (or cromfs)
958 build_loram_rootfs()
959 {
960 rootfs_sizes=""
961 for i in $TMP_DIR/iso/boot/rootfs*.gz; do
962 mkdir -p $TMP_DIR/fs
963 cd $TMP_DIR/fs
964 ( zcat $i 2> /dev/null || unlzma -c $i) | cpio -idm
965 cd - > /dev/null
966 rootfs=$TMP_DIR/$(basename $i)
967 if [ -x /usr/bin/mkcromfs ]; then
968 /usr/bin/mkcromfs -qq -f 262144 -b 16384 $TMP_DIR/fs $rootfs
969 else
970 /usr/sbin/mksquashfs $TMP_DIR/fs $rootfs -comp xz -Xbcj x86
971 fi
972 cd $TMP_DIR
973 rootfs_sizes="$rootfs_sizes $(( $(du -s $TMP_DIR/fs | cut -f1) - $(du -s $rootfs | cut -f1) ))"
974 ( cd $(dirname $rootfs); echo $(basename $rootfs) | \
975 cpio -o -H newc ) > $rootfs.cpio
976 rm -f $rootfs
977 mv $rootfs.cpio $rootfs
978 cd - > /dev/null
979 rm -rf $TMP_DIR/fs
980 done
981 }
983 # Move each initramfs to squashfs (or cromfs)
984 build_loram_rootfs_cdrom()
985 {
986 mkdir -p $TMP_DIR/fs
987 cd $TMP_DIR/fs
988 for i in $TMP_DIR/iso/boot/rootfs*.gz; do
989 ( zcat $i 2> /dev/null || unlzma -c $i) | cpio -idm
990 done
991 rootfs=$TMP_DIR/rootfs.gz
992 if [ -x /usr/bin/mkcromfs ]; then
993 /usr/bin/mkcromfs -qq -f 262144 -b 16384 $TMP_DIR/fs $rootfs
994 else
995 /usr/sbin/mksquashfs $TMP_DIR/fs $rootfs -comp xz -Xbcj x86
996 fi
997 rm -rf $TMP_DIR/fs
998 cd $TMP_DIR
999 }
1001 # Move meta boot configuration files to basic configuration files
1002 # because meta loram flavor is useless when rootfs is not loaded in ram
1003 unmeta_boot()
1005 local root=${1:-$TMP_DIR/loramiso}
1006 if [ -f $root/boot/isolinux/noram.cfg ]; then
1007 # We keep enough information to do unloram...
1008 sed -i 's/label slitaz/label orgslitaz/' \
1009 $root/boot/isolinux/common.cfg
1010 sed -i '/ifmem/{NNNNNNNNd};/^LABEL/{N;/LABEL SliTaz [^L]/{NNNd}}' \
1011 $root/boot/isolinux/isolinux.cfg
1012 set -- $(grep 'append [0-9]' $root/boot/isolinux/common.cfg)
1013 sed -i "s/label $3\$/label slitaz/;s|=/boot/rootfs\(.*\).gz |=/boot/rootfs.gz |" \
1014 $root/boot/isolinux/*.cfg
1015 fi
1018 # Move rootfs to squashfs filesystem(s) to the cdrom writeable with aufs.
1019 # These squashfs may be loaded in ram a boot time.
1020 # Rootfs are also copied to cdrom for tiny ramsize systems.
1021 # Meta flavors are converted to normal flavors.
1022 build_loram_cdrom()
1024 build_initfs cdrom || return 1
1025 build_loram_rootfs_cdrom
1026 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1027 if [ "$1" == "small" ]; then
1028 rm -f $TMP_DIR/loramiso/boot/root*
1029 else
1030 mkdir $TMP_DIR/loramiso/fs
1031 cd $TMP_DIR/loramiso/fs
1032 for i in $( ls ../boot/root* | sort -r ) ; do
1033 ( zcat $i 2> /dev/null || unlzma -c $i ) | cpio -idmu
1034 rm -f $i
1035 done
1036 mkdir -p $TMP_DIR/loramiso/fs/mnt/.cdrom
1037 cd - > /dev/null
1038 fi
1039 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
1040 mv $TMP_DIR/rootfs*.gz $TMP_DIR/loramiso
1041 unmeta_boot
1042 VOLUM_NAME="SliTaz_LoRAM_CDROM"
1043 sed -i "s/root=/loram=LABEL=$VOLUM_NAME,fs &/" \
1044 $TMP_DIR/loramiso/boot/isolinux/*.cfg
1045 create_iso $OUTPUT $TMP_DIR/loramiso
1048 # Create http bootstrap to load and remove loram_cdrom
1049 # Meta flavors are converted to normal flavors.
1050 build_loram_http()
1052 build_initfs http || return 1
1053 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1054 rm -f $TMP_DIR/loramiso/boot/rootfs*
1055 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
1056 unmeta_boot
1057 create_iso $OUTPUT $TMP_DIR/loramiso
1060 # Update meta flavor selection sizes.
1061 # Reduce sizes with rootfs gains.
1062 update_metaiso_sizes()
1064 for cfg in $(grep -l 'append [0-9]' $TMP_DIR/loramiso/boot/isolinux/*.cfg)
1065 do
1066 local append="$(grep 'append [0-9]' $cfg)"
1067 local sizes="$rootfs_sizes"
1068 local new
1069 set -- $append
1070 shift
1071 new=""
1072 while [ -n "$2" ]; do
1073 local s
1074 case "$1" in
1075 *G) s=$(( ${1%G} * 1024 * 1024 ));;
1076 *M) s=$(( ${1%M} * 1024 ));;
1077 *) s=${1%K};;
1078 esac
1079 sizes=${sizes#* }
1080 for i in $sizes ; do
1081 s=$(( $s - $i ))
1082 done
1083 new="$new $s $2"
1084 shift 2
1085 done
1086 sed -i "/append [0-9]/s/append .*/append$new $1/" $cfg
1087 done
1090 # Move rootfs to a squashfs filesystem into the initramfs writeable with aufs.
1091 # Meta flavor selection sizes are updated.
1092 build_loram_ram()
1094 build_initfs ram || return 1
1095 build_loram_rootfs
1096 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1097 rm -f $TMP_DIR/loramiso/boot/bzImage
1098 ln $TMP_DIR/loramiso/boot/vmlinuz* $TMP_DIR/loramiso/boot/bzImage
1099 rootfs=$(ls $TMP_DIR/rootfs* | sort | tail -n 1)
1100 cat $rootfs >> $TMP_DIR/initfs.gz
1101 mv $TMP_DIR/initfs.gz $rootfs
1102 cp $TMP_DIR/rootfs* $TMP_DIR/loramiso/boot
1103 update_metaiso_sizes
1104 create_iso $OUTPUT $TMP_DIR/loramiso
1107 # Remove files installed by packages
1108 find_flavor_rootfs()
1110 for i in $1/etc/tazlito/*.extract; do
1111 [ -e $i ] || continue
1112 chroot $1 /bin/sh ${i#$1}
1113 done
1115 # Clean hardlinks and files patched by genisofs in /boot
1116 for i in isolinux/isolinux.bin isolinux/boot.cat bzImage ; do
1117 rm -f $1/boot/$i
1118 done
1120 # Clean files generated in post_install
1121 rm -f $1/lib/modules/*/modules.* $1/etc/mtab \
1122 $1/dev/core $1/dev/fd $1/dev/std*
1124 # Verify md5
1125 cat $1$INSTALLED/*/md5sum | \
1126 while read md5 file; do
1127 [ -e $1$file ] || continue
1128 [ "$(cat $1$file | md5sum)" == "$md5 -" ] &&
1129 rm -f $1$file
1130 done
1132 # Check configuration files
1133 for i in $1$INSTALLED/*/volatile.cpio.gz; do
1134 [ -e $i ] || continue
1135 mkdir /tmp/volatile$$
1136 zcat $i | ( cd /tmp/volatile$$ ; cpio -idmu > /dev/null 2>&1 )
1137 ( cd /tmp/volatile$$ ; find * -type f 2> /dev/null) | \
1138 while read file ; do
1139 [ -e $1/$file ] || continue
1140 cmp -s /tmp/volatile$$/$file $1/$file && rm -f $1/$file
1141 done
1142 rm -rf /tmp/volatile$$
1143 done
1145 # Remove other files blindly
1146 for i in $1$INSTALLED/*/files.list; do
1147 for file in $(cat $i); do
1148 [ $1$file -nt $i ] && continue
1149 [ -f $1$file -a ! -L $1$file ] && continue
1150 [ -d $1$file ] || rm -f $1$file
1151 done
1152 done
1154 # Remove tazpkg files and tmp files
1155 rm -rf $1$INSTALLED* $1/tmp $1/var/tmp
1156 rm -f $1$LOCALSTATE/*packages* $1$LOCALSTATE/files.list.lzma \
1157 $1$LOCALSTATE/mirror* $1/var/cache/*/* \
1158 $1/var/lock/* $1/var/log/* $1/var/run/* $1/var/run/*/* \
1159 $1/var/lib/* $1/var/lib/dbus/* 2> /dev/null
1161 # Cleanup directory tree
1162 cd $1
1163 find * -type d | sort -r | while read dir; do
1164 rmdir $dir 2> /dev/null
1165 done
1166 cd - > /dev/null
1169 ####################
1170 # Tazlito commands #
1171 ####################
1173 case "$COMMAND" in
1174 stats)
1175 # Tazlito general statistics from the config file.
1177 echo ""
1178 echo -e "\033[1mTazlito statistics\033[0m
1179 ===============================================================================
1180 Config file : $CONFIG_FILE
1181 ISO name : $ISO_NAME.iso
1182 Volume name : $VOLUM_NAME
1183 Prepared : $PREPARED
1184 Packages repository : $PACKAGES_REPOSITORY
1185 Distro directory : $DISTRO"
1186 if [ ! "$ADDFILES" = "" ] ; then
1187 echo -e "Additional files : $ADDFILES"
1188 fi
1189 echo "================================================================================"
1190 echo ""
1191 ;;
1192 list-addfiles)
1193 # Simple list of additional files in the rootfs
1194 echo ""
1195 cd $ADDFILES
1196 find rootfs -type f
1197 echo "" ;;
1198 gen-config)
1199 # Generate a new config file in the current dir or the specified
1200 # directory by $2.
1202 if [ -n "$2" ] ; then
1203 mkdir -p $2 && cd $2
1204 fi
1205 echo -n "Generating empty tazlito.conf..."
1206 empty_config_file
1207 status
1208 echo ""
1209 if [ -f "tazlito.conf" ] ; then
1210 echo "Configuration file is ready to edit."
1211 echo "File location : `pwd`/tazlito.conf"
1212 echo ""
1213 fi
1214 ;;
1215 configure)
1216 # Configure a tazlito.conf config file. Start by getting
1217 # a empty config file and sed it.
1219 if [ -f "tazlito.conf" ] ; then
1220 rm tazlito.conf
1221 else
1222 if test $(id -u) = 0 ; then
1223 cd /etc
1224 else
1225 echo "You must be root to configure the main config file or in"
1226 echo "the same directory of the file you want to configure."
1227 exit 0
1228 fi
1229 fi
1230 empty_config_file
1231 echo""
1232 echo -e "\033[1mConfiguring :\033[0m `pwd`/tazlito.conf"
1233 echo "================================================================================"
1234 # ISO name.
1235 echo -n "ISO name : " ; read answer
1236 sed -i s#'ISO_NAME=\"\"'#"ISO_NAME=\"$answer\""# tazlito.conf
1237 # Volume name.
1238 echo -n "Volume name : " ; read answer
1239 sed -i s/'VOLUM_NAME=\"SliTaz\"'/"VOLUM_NAME=\"$answer\""/ tazlito.conf
1240 # Packages repository.
1241 echo -n "Packages repository : " ; read answer
1242 sed -i s#'PACKAGES_REPOSITORY=\"\"'#"PACKAGES_REPOSITORY=\"$answer\""# tazlito.conf
1243 # Distro path.
1244 echo -n "Distro path : " ; read answer
1245 sed -i s#'DISTRO=\"\"'#"DISTRO=\"$answer\""# tazlito.conf
1246 echo "================================================================================"
1247 echo "Config file is ready to use."
1248 echo "You can now extract an ISO or generate a distro."
1249 echo ""
1250 ;;
1251 gen-iso)
1252 # Simply generate a new iso.
1254 check_root
1255 verify_rootcd
1256 gen_livecd_isolinux
1257 distro_stats
1258 ;;
1259 gen-initiso)
1260 # Simply generate a new initramfs with a new iso.
1262 check_root
1263 verify_rootcd
1264 gen_initramfs $ROOTFS
1265 gen_livecd_isolinux
1266 distro_stats
1267 ;;
1268 extract-distro)
1269 # Extract an ISO image to a directory and rebuild the LiveCD tree.
1271 check_root
1272 ISO_IMAGE=$2
1273 if [ -z "$ISO_IMAGE" ] ; then
1274 echo -e "\nPlease specify the path to the ISO image."
1275 echo -e "Example : `basename $0` image.iso /path/target\n"
1276 exit 0
1277 fi
1278 # Set the distro path by checking for $3 on cmdline.
1279 if [ -n "$3" ] ; then
1280 TARGET=$3
1281 else
1282 TARGET=$DISTRO
1283 fi
1284 # Exit if existing distro is found.
1285 if [ -d "$TARGET/rootfs" ] ; then
1286 echo -e "\nA rootfs exists in : $TARGET"
1287 echo -e "Please clean the distro tree or change directory path.\n"
1288 exit 0
1289 fi
1290 echo ""
1291 echo -e "\033[1mTazlito extracting :\033[0m `basename $ISO_IMAGE`"
1292 echo "================================================================================"
1293 # Start to mount the ISO.
1294 echo ""
1295 echo "Mounting ISO image..."
1296 mkdir -p $TMP_DIR
1297 # Get ISO file size.
1298 isosize=`du -sh $ISO_IMAGE | cut -f1`
1299 mount -o loop $ISO_IMAGE $TMP_DIR
1300 sleep 2
1301 # Prepare target dir, copy the kernel and the rootfs.
1302 mkdir -p $TARGET/rootfs
1303 mkdir -p $TARGET/rootcd/boot
1304 echo -n "Copying the Linux kernel..."
1305 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
1306 ln $TARGET/rootcd/boot/vmlinuz* $TARGET/rootcd/boot/bzImage
1307 else
1308 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
1309 fi
1310 status
1311 echo -n "Copying isolinux files..."
1312 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
1313 for i in $(ls $TMP_DIR); do
1314 [ "$i" = "boot" ] && continue
1315 cp -a $TMP_DIR/$i $TARGET/rootcd
1316 done
1317 status
1318 if [ -d $TMP_DIR/boot/syslinux ]; then
1319 echo -n "Copying syslinux files..."
1320 cp -a $TMP_DIR/boot/syslinux $TARGET/rootcd/boot
1321 status
1322 fi
1323 if [ -d $TMP_DIR/boot/extlinux ]; then
1324 echo -n "Copying extlinux files..."
1325 cp -a $TMP_DIR/boot/extlinux $TARGET/rootcd/boot
1326 status
1327 fi
1328 if [ -d $TMP_DIR/boot/grub ]; then
1329 echo -n "Copying GRUB files..."
1330 cp -a $TMP_DIR/boot/grub $TARGET/rootcd/boot
1331 status
1332 fi
1334 echo -n "Copying the rootfs..."
1335 cp $TMP_DIR/boot/rootfs.?z $TARGET/rootcd/boot
1336 status
1337 # Extract initramfs.
1338 cd $TARGET/rootfs
1339 echo -n "Extracting the rootfs... "
1340 extract_rootfs ../rootcd/boot/rootfs.gz $TARGET/rootfs
1341 # unpack /usr
1342 for i in etc/tazlito/*.extract; do
1343 [ -f "$i" ] && . $i ../rootcd
1344 done
1345 # Umount and remove temp directory and cd to $TARGET to get stats.
1346 umount $TMP_DIR && rm -rf $TMP_DIR
1347 cd ..
1348 echo ""
1349 echo "================================================================================"
1350 echo "Extracted : `basename $ISO_IMAGE` ($isosize)"
1351 echo "Distro tree : `pwd`"
1352 echo "Rootfs size : `du -sh rootfs`"
1353 echo "Rootcd size : `du -sh rootcd`"
1354 echo "================================================================================"
1355 echo ""
1356 ;;
1357 list-flavors)
1358 # Show available flavors.
1359 if [ ! -s /etc/tazlito/flavors.list -o "$2" == "--recharge" ]; then
1360 download flavors.list -O - > /etc/tazlito/flavors.list
1361 fi
1362 echo ""
1363 echo -e "\033[1mList of flavors\033[0m"
1364 echo "================================================================================"
1365 cat /etc/tazlito/flavors.list
1366 echo ""
1367 ;;
1368 show-flavor)
1369 # Show flavor description.
1370 FLAVOR=${2%.flavor}
1371 if [ ! -f "$FLAVOR.flavor" ]; then
1372 echo "File $FLAVOR.flavor not found."
1373 exit 1
1374 fi
1375 mkdir $TMP_DIR
1376 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i > /dev/null)
1377 if [ "$3" = "--brief" ]; then
1378 if [ "$4" != "--noheader" ]; then
1379 echo "Name ISO Rootfs Description"
1380 echo "================================================================================"
1381 fi
1382 printf "%-16.16s %6.6s %6.6s %s\n" "$FLAVOR" \
1383 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
1384 "$(field 'Rootfs size' $TMP_DIR/$FLAVOR.desc)" \
1385 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
1386 else
1387 echo "================================================================================"
1388 cat $TMP_DIR/$FLAVOR.desc
1389 fi
1390 rm -Rf $TMP_DIR
1391 ;;
1392 gen-liveflavor)
1393 # Generate a new flavor from the live system.
1394 FLAVOR=${2%.flavor}
1395 DESC=""
1396 case "$FLAVOR" in
1397 '') echo -n "Flavor name : "
1398 read FLAVOR
1399 [ -z "$FLAVOR" ] && exit 1;;
1400 -?|-h*|--help) echo -e "
1402 SliTaz Live Tool - Version: $VERSION
1403 \033[1mUsage: \033[0m `basename $0` gen-liveflavor flavor-name [flavor-patch-file]
1404 \033[1mflavor-patch-file format: \033[0m
1405 code data
1406 + package to add
1407 - package to remove
1408 ! non-free package to add
1409 ? display message
1410 @ flavor description
1412 \033[1mExample: \033[0m
1413 @ Developer tools for slitaz maintainers
1414 + slitaz-toolchain
1415 + mercurial
1417 exit 1;;
1418 esac
1419 mv /etc/tazlito/distro-packages.list \
1420 /etc/tazlito/distro-packages.list.$$ 2> /dev/null
1421 rm -f distro-packages.list non-free.list 2> /dev/null
1422 tazpkg recharge
1423 [ -n "$3" ] && while read action pkg; do
1424 case "$action" in
1425 +) yes | tazpkg get-install $pkg 2>&1 >> $log || exit 1 ;;
1426 -) yes | tazpkg remove $pkg ;;
1427 !) echo $pkg >> non-free.list ;;
1428 @) DESC="$pkg" ;;
1429 \?) echo -en "$pkg"; read action ;;
1430 esac
1431 done < $3
1432 yes '' | tazlito gen-distro
1433 echo "$DESC" | tazlito gen-flavor "$FLAVOR"
1434 mv /etc/tazlito/distro-packages.list.$$ \
1435 /etc/tazlito/distro-packages.list 2> /dev/null
1436 ;;
1437 gen-flavor)
1438 # Generate a new flavor from the last iso image generated.
1439 FLAVOR=${2%.flavor}
1440 echo ""
1441 echo -e "\033[1mFlavor generation\033[0m"
1442 echo "================================================================================"
1443 if [ -z "$FLAVOR" ]; then
1444 echo -n "Flavor name : "
1445 read FLAVOR
1446 [ -z "$FLAVOR" ] && exit 1
1447 fi
1448 check_rootfs
1449 FILES="$FLAVOR.pkglist"
1450 echo -n "Creating file $FLAVOR.flavor..."
1451 for i in rootcd rootfs; do
1452 if [ -d "$ADDFILES/$i" ] ; then
1453 FILES="$FILES\n$FLAVOR.$i"
1454 ( cd "$ADDFILES/$i"; find . | \
1455 cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
1456 fi
1457 done
1458 status
1459 answer=`grep -s ^Description $FLAVOR.desc`
1460 answer=${answer#Description : }
1461 if [ -z "$answer" ]; then
1462 echo -n "Description : "
1463 read answer
1464 fi
1465 echo -n "Compressing flavor $FLAVOR..."
1466 echo "Flavor : $FLAVOR" > $FLAVOR.desc
1467 echo "Description : $answer" >> $FLAVOR.desc
1468 ( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
1469 \rm -f $FLAVOR.pkglist $FLAVOR.nonfree 2> /dev/null
1470 for i in $(ls $ROOTFS$INSTALLED); do
1471 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
1472 EXTRAVERSION=""
1473 eval $(grep ^EXTRAVERSION= $ROOTFS$INSTALLED/$i/receipt)
1474 eval $(grep ^CATEGORY= $ROOTFS$INSTALLED/$i/receipt)
1475 if [ "$CATEGORY" = "non-free" -a "${i%%-*}" != "get" ]
1476 then
1477 echo "$i" >> $FLAVOR.nonfree
1478 else
1479 echo "$i-$VERSION$EXTRAVERSION" >> $FLAVOR.pkglist
1480 fi
1481 done
1482 [ -s $FLAVOR.nonfree ] && $FILES="$FILES\n$FLAVOR.nonfree"
1483 for i in $LOCALSTATE/undigest/*/mirror ; do
1484 [ -s $i ] && cat $i >> $FLAVOR.mirrors
1485 done
1486 [ -s $FLAVOR.mirrors ] && $FILES="$FILES\n$FLAVOR.mirrors"
1487 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
1488 gzip -9 > $FLAVOR.flavor
1489 rm `echo -e $FILES`
1490 status
1491 echo "================================================================================"
1492 echo "Flavor size : `du -sh $FLAVOR.flavor`"
1493 echo ""
1494 ;;
1495 upgrade-flavor)
1496 # Update package list to the latest versions available.
1497 FLAVOR=${2%.flavor}
1498 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1499 mkdir $TMP_DIR
1500 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1501 echo -n "Updating $FLAVOR package list..."
1502 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1503 packed_size=0; unpacked_size=0
1504 while read org; do
1505 i=0
1506 pkg=$org
1507 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
1508 pkg=${pkg%-*}
1509 i=$(($i + 1))
1510 [ $i -gt 5 ] && break;
1511 done
1512 set -- $(get_size $pkg)
1513 packed_size=$(( $packed_size + $1 ))
1514 unpacked_size=$(( $unpacked_size + $2 ))
1515 for i in $(grep ^$pkg $LOCALSTATE/packages.list); do
1516 echo $i
1517 break
1518 done
1519 done < $TMP_DIR/$FLAVOR.pkglist \
1520 > $TMP_DIR/$FLAVOR.pkglist.$$
1521 mv -f $TMP_DIR/$FLAVOR.pkglist.$$ $TMP_DIR/$FLAVOR.pkglist
1522 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1523 packed_size=$(($packed_size \
1524 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1525 unpacked_size=$(($unpacked_size \
1526 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1527 fi
1528 # Estimate lzma
1529 packed_size=$(($packed_size * 2 / 3))
1530 iso_size=$(( $packed_size + 26000 ))
1531 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1532 iso_size=$(($iso_size \
1533 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1534 fi
1535 sed -i -e '/Image is ready/d' \
1536 -e "s/Rootfs size\( *:\) \(.*\)/Rootfs size\1 $(cent2human $unpacked_size) (estimated)/" \
1537 -e "s/Initramfs size\( *:\) \(.*\)/Initramfs size\1 $(cent2human $packed_size) (estimated)/" \
1538 -e "s/ISO image size\( *:\) \(.*\)/ISO image size\1 $(cent2human $iso_size) (estimated)/" \
1539 -e "s/date\( *:\) \(.*\)/date\1 $(date +%Y%m%d\ \at\ \%H:%M:%S)/" \
1540 $TMP_DIR/$FLAVOR.desc
1541 ( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
1542 $FLAVOR.flavor
1543 status
1544 rm -Rf $TMP_DIR
1545 fi
1546 ;;
1547 extract-flavor)
1548 # Extract a flavor into $FLAVORS_REPOSITORY.
1549 FLAVOR=${2%.flavor}
1550 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1551 mkdir $TMP_DIR
1552 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1553 echo -n "Extracting $FLAVOR..."
1554 rm -rf $FLAVORS_REPOSITORY/$FLAVOR 2> /dev/null
1555 mkdir -p $FLAVORS_REPOSITORY/$FLAVOR
1556 echo "FLAVOR=\"$FLAVOR\"" > $FLAVORS_REPOSITORY/$FLAVOR/receipt
1557 grep ^Description $TMP_DIR/$FLAVOR.desc | \
1558 sed 's/.*: \(.*\)$/SHORT_DESC="\1"/' >> \
1559 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1560 grep ^Version $TMP_DIR/$FLAVOR.desc | \
1561 sed 's/.*: \(.*\)$/VERSION="\1"/' >> \
1562 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1563 grep ^Maintainer $TMP_DIR/$FLAVOR.desc | \
1564 sed 's/.*: \(.*\)$/MAINTAINER="\1"/' >> \
1565 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1566 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc && \
1567 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1568 sed 's/.*: \(.*\)$/ROOTFS_SELECTION="\1"/' >> \
1569 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1570 grep '^Rootfs size' $TMP_DIR/$FLAVOR.desc | \
1571 sed 's/.*: \(.*\)$/ROOTFS_SIZE="\1"/' >> \
1572 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1573 grep ^Initramfs $TMP_DIR/$FLAVOR.desc | \
1574 sed 's/.*: \(.*\)$/INITRAMFS_SIZE="\1"/' >> \
1575 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1576 grep ^ISO $TMP_DIR/$FLAVOR.desc | \
1577 sed 's/.*: \(.*\)$/ISO_SIZE="\1"/' >> \
1578 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1579 for i in rootcd rootfs; do
1580 [ -f $TMP_DIR/$FLAVOR.$i ] || continue
1581 mkdir $FLAVORS_REPOSITORY/$FLAVOR/$i
1582 zcat $TMP_DIR/$FLAVOR.$i | \
1583 (cd $FLAVORS_REPOSITORY/$FLAVOR/$i; \
1584 cpio -idm > /dev/null)
1585 done
1586 [ -s $TMP_DIR/$FLAVOR.mirrors ] &&
1587 cp $TMP_DIR/$FLAVOR.mirrors \
1588 $FLAVORS_REPOSITORY/$FLAVOR/mirrors
1589 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1590 while read org; do
1591 i=0
1592 pkg=$org
1593 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
1594 pkg=${pkg%-*}
1595 i=$(($i + 1))
1596 [ $i -gt 5 ] && break;
1597 done
1598 echo $pkg
1599 done < $TMP_DIR/$FLAVOR.pkglist \
1600 > $FLAVORS_REPOSITORY/$FLAVOR/packages.list
1601 status
1602 rm -Rf $TMP_DIR
1603 fi
1604 ;;
1605 pack-flavor)
1606 # Create a flavor from $FLAVORS_REPOSITORY.
1607 FLAVOR=${2%.flavor}
1608 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/receipt ]; then
1609 mkdir $TMP_DIR
1610 echo -n "Creating flavor $FLAVOR..."
1611 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1612 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/mirrors ]; then
1613 cp $FLAVORS_REPOSITORY/$FLAVOR/mirrors \
1614 $TMP_DIR/$FLAVOR.mirrors
1615 for i in $(cat $TMP_DIR/$FLAVOR.mirrors); do
1616 wget -O - $i/packages.list >> $TMP_DIR/packages.list
1617 done
1618 fi
1619 #add distro;sh if exist
1620 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/distro.sh ]; then
1621 cp $FLAVORS_REPOSITORY/$FLAVOR/distro.sh $TMP_DIR/$FLAVOR-distro.sh
1622 fi
1623 [ -s $FLAVORS_REPOSITORY/$FLAVOR/packages.list ] &&
1624 get_pkglist $FLAVOR > $TMP_DIR/$FLAVOR.pkglist
1625 if grep -q ^ROOTFS_SELECTION \
1626 $FLAVORS_REPOSITORY/$FLAVOR/receipt; then
1627 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1628 set -- $ROOTFS_SELECTION
1629 [ -n "$FRUGAL_RAM" ] || FRUGAL_RAM=$1
1630 [ -f $FLAVORS_REPOSITORY/$2/packages.list ] ||
1631 tazlito extract-flavor $2
1632 get_pkglist $2 > $TMP_DIR/$FLAVOR.pkglist
1633 for i in rootcd rootfs; do
1634 mkdir $TMP_DIR/$i
1635 # Copy extra files from the first flavor
1636 [ -d $FLAVORS_REPOSITORY/$2/$i ] &&
1637 cp -a $FLAVORS_REPOSITORY/$2/$i $TMP_DIR
1638 # Overload extra files by meta flavor
1639 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] &&
1640 cp -a $FLAVORS_REPOSITORY/$FLAVOR/$i $TMP_DIR
1641 [ -n "$(ls $TMP_DIR/$i)" ] &&
1642 ( cd $TMP_DIR/$i ; find . | cpio -o -H newc 2> /dev/null ) | \
1643 gzip -9 >$TMP_DIR/$FLAVOR.$i
1644 rm -rf $TMP_DIR/$i
1645 done
1646 else
1647 for i in rootcd rootfs; do
1648 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] || \
1649 continue
1650 ( cd $FLAVORS_REPOSITORY/$FLAVOR/$i ; \
1651 find . | cpio -o -H newc 2> /dev/null ) | \
1652 gzip -9 >$TMP_DIR/$FLAVOR.$i
1653 done
1654 fi
1655 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1656 packed_size=$(($packed_size \
1657 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1658 unpacked_size=$(($unpacked_size \
1659 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1660 fi
1661 # Estimate lzma
1662 packed_size=$(($packed_size * 2 / 3))
1663 iso_size=$(( $packed_size + 26000 ))
1664 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1665 iso_size=$(($iso_size \
1666 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1667 fi
1668 VERSION=""
1669 MAINTAINER=""
1670 ROOTFS_SELECTION=""
1671 ROOTFS_SIZE="$(cent2human $unpacked_size) (estimated)"
1672 INITRAMFS_SIZE="$(cent2human $packed_size) (estimated)"
1673 ISO_SIZE="$(cent2human $iso_size) (estimated)"
1674 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1675 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1676 Flavor : $FLAVOR
1677 Description : $SHORT_DESC
1678 EOT
1679 [ -n "$VERSION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1680 Version : $VERSION
1681 EOT
1682 [ -n "$MAINTAINER" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1683 Maintainer : $MAINTAINER
1684 EOT
1685 [ -n "$FRUGAL_RAM" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1686 LiveCD RAM size : $FRUGAL_RAM
1687 EOT
1688 [ -n "$ROOTFS_SELECTION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1689 Rootfs list : $ROOTFS_SELECTION
1690 EOT
1691 cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1692 Build date : $(date +%Y%m%d\ \at\ \%H:%M:%S)
1693 Packages : $(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l)
1694 Rootfs size : $ROOTFS_SIZE
1695 Initramfs size : $INITRAMFS_SIZE
1696 ISO image size : $ISO_SIZE
1697 ================================================================================
1699 EOT
1700 rm -f $TMP_DIR/packages.list
1701 ( cd $TMP_DIR ; ls | cpio -o -H newc 2> /dev/null) | \
1702 gzip -9 > $FLAVOR.flavor
1703 status
1704 rm -Rf $TMP_DIR
1705 else
1706 echo "No $FLAVOR flavor in $FLAVORS_REPOSITORY."
1707 fi
1708 ;;
1709 get-flavor)
1710 # Get a flavor's files and prepare for gen-distro.
1711 FLAVOR=${2%.flavor}
1712 echo -e "\n\033[1mPreparing $FLAVOR distro flavor\033[0m"
1713 echo "================================================================================"
1714 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1715 echo -n "Cleaning $DISTRO..."
1716 rm -R $DISTRO 2> /dev/null
1717 mkdir -p $DISTRO
1718 status
1719 mkdir $TMP_DIR
1720 echo -n "Extracting flavor $FLAVOR.flavor... "
1721 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1722 echo -n "Creating distro-packages.list..."
1723 mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
1724 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
1725 echo -n "Extracting distro.sh... "
1726 mv $TMP_DIR/$FLAVOR-distro.sh distro.sh 2> /dev/null
1727 status
1728 infos="$FLAVOR.desc"
1729 for i in rootcd rootfs; do
1730 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
1731 echo -n "Adding $i files... "
1732 mkdir -p "$ADDFILES/$i"
1733 zcat $TMP_DIR/$FLAVOR.$i | \
1734 ( cd "$ADDFILES/$i"; cpio -id > /dev/null)
1735 zcat $TMP_DIR/$FLAVOR.$i | cpio -tv \
1736 > $TMP_DIR/$FLAVOR.list$i
1737 infos="$infos\n$FLAVOR.list$i"
1738 fi
1739 done
1740 if [ -s $TMP_DIR/$FLAVOR.mirrors ]; then
1741 n=""
1742 while read line; do
1743 mkdir -p $LOCALSTATE/undigest/$FLAVOR$n
1744 echo "$line" > $LOCALSTATE/undigest/$FLAVOR$n/mirror
1745 n=$(( $n + 1 ))
1746 done < $TMP_DIR/$FLAVOR.mirrors
1747 infos="$infos\n$FLAVOR.mirrors"
1748 tazpkg recharge
1749 fi
1750 rm -f /etc/tazlito/rootfs.list
1751 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc &&
1752 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1753 sed 's/.*: \(.*\)$/\1/' > /etc/tazlito/rootfs.list
1754 echo -n "Updating tazlito.conf..."
1755 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
1756 cat tazlito.conf | grep -v "^#VOLUM_NAME" | \
1757 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
1758 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
1759 sed -i "s/ISO_NAME=.*/ISO_NAME=\"slitaz-$FLAVOR\"/" tazlito.conf
1760 status
1761 ( cd $TMP_DIR ; echo -e $infos | cpio -o -H newc ) | \
1762 gzip -9 > /etc/tazlito/info
1763 rm -Rf $TMP_DIR
1764 fi
1765 echo "================================================================================"
1766 echo -e "Flavor is ready to be generated by: tazlito gen-distro\n"
1767 ;;
1769 iso2flavor)
1770 if [ -z "$3" -o ! -s "$2" ]; then
1771 cat <<EOT
1772 Usage : tazlito iso2flavor image.iso flavor_name
1774 Create a file flavor_name.flavor from the cdrom image file image.iso
1775 EOT
1776 exit 1
1777 fi
1778 FLAVOR=${3%.flavor}
1779 mkdir -p $TMP_DIR/iso $TMP_DIR/rootfs
1780 mount -o loop,ro $2 $TMP_DIR/iso
1781 if [ -s $TMP_DIR/iso/boot/rootfs1.gz ]; then
1782 echo "META flavors are not supported."
1783 umount -d $TMP_DIR/iso
1784 elif [ ! -s $TMP_DIR/iso/boot/rootfs.gz ]; then
1785 echo "No /boot/rootfs.gz in iso image. Needs a SliTaz iso."
1786 umount -d $TMP_DIR/iso
1787 else
1788 ( unlzma -c $TMP_DIR/iso/boot/rootfs.gz || \
1789 zcat $TMP_DIR/iso/boot/rootfs.gz ) | \
1790 ( cd $TMP_DIR/rootfs ; cpio -idmu > /dev/null 2>&1 )
1791 if [ ! -s $TMP_DIR/rootfs/etc/slitaz-release ]; then
1792 echo "No file /etc/slitaz-release in /boot/rootfs.gz of iso image. Needs a non loram SliTaz iso."
1793 umount -d $TMP_DIR/iso
1794 else
1795 ROOTFS_SIZE=$(du -hs $TMP_DIR/rootfs | awk '{ print $1 }')
1796 RAM_SIZE=$(du -s $TMP_DIR/rootfs | awk '{ print 32*int(($1+36000)/32768) "M" }')
1797 cp -a $TMP_DIR/iso $TMP_DIR/rootcd
1798 ISO_SIZE=$(df -h $TMP_DIR/iso | awk 'END { print $2 }')
1799 BUILD_DATE=$(date +%Y%m%d\ \at\ \%H:%M:%S -r $TMP_DIR/iso/md5sum)
1800 umount -d $TMP_DIR/iso
1801 INITRAMFS_SIZE=$(du -chs $TMP_DIR/rootcd/boot/rootfs.gz | awk '{ s=$1 } END { print $1 }')
1802 rm -f $TMP_DIR/rootcd/boot/rootfs.gz $TMP_DIR/rootcd/md5sum
1803 mv $TMP_DIR/rootcd/boot $TMP_DIR/rootfs
1804 sed 's/.* \(.*\).tazpkg*/\1/' > $TMP_DIR/$FLAVOR.pkglist \
1805 < $TMP_DIR/rootfs$INSTALLED.md5
1806 #[ -s $TMP_DIR/rootfs/etc/tazlito/distro-packages.list ] &&
1807 # mv $TMP_DIR/rootfs/etc/tazlito/distro-packages.list $TMP_DIR/$FLAVOR.pkglist
1808 PKGCNT=$(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l | awk '{ print $1 }')
1809 find_flavor_rootfs $TMP_DIR/rootfs
1810 [ -d $TMP_DIR/rootfs/boot ] && mv $TMP_DIR/rootfs/boot $TMP_DIR/rootcd
1811 [ -n "$(ls $TMP_DIR/rootfs)" ] && ( cd $TMP_DIR/rootfs ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootfs
1812 [ -n "$(ls $TMP_DIR/rootcd)" ] && ( cd $TMP_DIR/rootcd ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootcd
1813 rm -rf $TMP_DIR/rootcd $TMP_DIR/rootfs
1814 VERSION=""; MAINTAINER=""
1815 echo -en "Flavor short description \007: "; read -t 30 DESCRIPTION
1816 if [ -n "$DESCRIPTION" ]; then
1817 echo -en "Flavor version : "; read -t 30 VERSION
1818 echo -en "Flavor maintainer (your email) : "; read -t 30 MAINTAINER
1819 fi
1820 [ -n "$DESCRIPTION" ] || DESCRIPTION="Slitaz $FLAVOR flavor"
1821 [ -n "$VERSION" ] || VERSION="1.0"
1822 [ -n "$MAINTAINER" ] || MAINTAINER="nobody@slitaz.org"
1823 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1824 Flavor : $FLAVOR
1825 Description : $DESCRIPTION
1826 Version : $VERSION
1827 Maintainer : $MAINTAINER
1828 LiveCD RAM size : $RAM_SIZE
1829 Build date : $BUILD_DATE
1830 Packages : $PKGCNT
1831 Rootfs size : $ROOTFS_SIZE
1832 Initramfs size : $INITRAMFS_SIZE
1833 ISO image size : $ISO_SIZE
1834 ================================================================================
1836 EOT
1837 ( cd $TMP_DIR ; ls $FLAVOR.* | cpio -o -H newc ) | gzip -9 > $FLAVOR.flavor
1838 cat <<EOT
1839 Tazlito can't detect each file installed during a package post_install.
1840 You should extract this flavor (tazlito extract-flavor $FLAVOR),
1841 check the files in /home/slitaz/flavors/$(cat /etc/slitaz-release)/$FLAVOR/rootfs tree and remove
1842 files generated by post_installs.
1843 Check /home/slitaz/flavors/$(cat /etc/slitaz-release)/$FLAVOR/receipt too and repack the flavor
1844 (tazlito pack-flavor $FLAVOR)
1845 EOT
1846 fi
1847 fi
1848 rm -rf $TMP_DIR
1849 ;;
1851 check-list)
1852 # Use current packages list in $PWD by default.
1853 DISTRO_PKGS_LIST=distro-packages.list
1854 [ -d "$2" ] && DISTRO_PKGS_LIST=$2/distro-packages.list
1855 [ -f "$2" ] && DISTRO_PKGS_LIST=$2
1856 [ ! -f $DISTRO_PKGS_LIST ] && echo "No packages list found." && exit 0
1857 echo ""
1858 echo -e "\033[1mLiveCD packages list check\033[0m"
1859 echo "================================================================================"
1860 for pkg in `cat $DISTRO_PKGS_LIST`
1861 do
1862 if ! grep -q "$pkg" $LOCALSTATE/packages.list; then
1863 echo "Updating: $pkg"
1864 up=$(($up + 1))
1865 fi
1866 done
1867 [ -z $up ] && echo -e "List is up-to-date\n" && exit 0
1868 echo "================================================================================"
1869 echo -e "Updates: $up\n" ;;
1870 gen-distro)
1871 # Generate a live distro tree with a set of packages.
1873 check_root
1875 # Check if a package list was specified on cmdline.
1876 LIST_NAME="distro-packages.list"
1877 CDROM=""
1878 while [ -n "$2" ]; do
1879 case "$2" in
1880 --iso=*)
1881 CDROM="-o loop ${2#--iso=}"
1882 ;;
1883 --cdrom)
1884 CDROM="/dev/cdrom"
1885 ;;
1886 --force)
1887 DELETE_ROOTFS="true"
1888 ;;
1889 *) if [ ! -f "$2" ] ; then
1890 echo -e "\nUnable to find the specified packages list."
1891 echo -e "List name : $2\n"
1892 exit 1
1893 fi
1894 LIST_NAME=$2
1895 ;;
1896 esac
1897 shift
1898 done
1900 if [ -d $ROOTFS ] ; then
1901 # Delete $ROOTFS if --force is set on command line
1902 if [ ! -z $DELETE_ROOTFS ]; then
1903 rm -rf $ROOTFS
1904 unset $DELETE_ROOTFS
1905 else
1906 echo -e "\nA rootfs exists in : $DISTRO"
1907 echo -e "Please clean the distro tree or change directory path.\n"
1908 exit 0
1909 fi
1910 fi
1911 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
1912 # Build list with installed packages
1913 for i in $(ls $INSTALLED); do
1914 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
1915 EXTRAVERSION=""
1916 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
1917 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
1918 done
1919 fi
1920 # Exit if no list name.
1921 if [ ! -f "$LIST_NAME" ]; then
1922 echo -e "\nNo packages list found or specified. Please read the docs.\n"
1923 exit 0
1924 fi
1925 # Start generation.
1926 echo ""
1927 echo -e "\033[1mTazlito generating a distro\033[0m"
1928 echo "================================================================================"
1929 # Misc checks
1930 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
1931 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
1932 # Get the list of packages using cat for a file list.
1933 LIST=`cat $LIST_NAME`
1934 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
1935 REPACK=""
1936 DOWNLOAD=""
1937 for pkg in $LIST
1938 do
1939 [ "$pkg" = "" ] && continue
1940 pkg=${pkg%.tazpkg}
1941 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
1942 PACKAGE=$(installed_package_name $pkg)
1943 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
1944 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
1945 echo -e "\nUnable to find $pkg in the repository."
1946 echo -e "Path : $PACKAGES_REPOSITORY\n"
1947 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
1948 yesorno "Repack packages from rootfs (y/N) ? "
1949 REPACK="$answer"
1950 [ "$answer" = "y" ] || REPACK="n"
1951 [ "$DOWNLOAD" = "y" ] && break
1952 fi
1953 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
1954 yesorno "Download packages from mirror (Y/n) ? "
1955 DOWNLOAD="$answer"
1956 if [ "$answer" = "n" ]; then
1957 [ -z "$PACKAGE" ] && exit 1
1958 else
1959 DOWNLOAD="y"
1960 [ -n "$REPACK" ] && break
1961 fi
1962 fi
1963 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
1964 done
1966 # Mount cdrom to be able to repack boot-loader packages
1967 if [ ! -e /boot -a -n "$CDROM" ]; then
1968 mkdir $TMP_MNT
1969 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
1970 ln -s $TMP_MNT/boot /
1971 if [ ! -d "$ADDFILES/rootcd" ] ; then
1972 mkdir -p $ADDFILES/rootcd
1973 for i in $(ls $TMP_MNT); do
1974 [ "$i" = "boot" ] && continue
1975 cp -a $TMP_MNT/$i $ADDFILES/rootcd
1976 done
1977 fi
1978 else
1979 rmdir $TMP_MNT
1980 fi
1981 fi
1983 # Root fs stuff.
1984 echo "Preparing the rootfs directory..."
1985 mkdir -p $ROOTFS
1986 for pkg in $LIST
1987 do
1988 [ "$pkg" = "" ] && continue
1989 # First copy and extract the package in tmp dir.
1990 pkg=${pkg%.tazpkg}
1991 PACKAGE=$(installed_package_name $pkg)
1992 mkdir -p $TMP_DIR
1993 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1994 # Look for package in cache
1995 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
1996 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
1997 # Look for package in running distribution
1998 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
1999 tazpkg repack $PACKAGE && \
2000 mv $pkg.tazpkg $PACKAGES_REPOSITORY
2001 fi
2002 fi
2003 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
2004 # Get package from mirror
2005 [ "$DOWNLOAD" = "y" ] && \
2006 download $pkg.tazpkg && \
2007 mv $pkg.tazpkg $PACKAGES_REPOSITORY
2008 fi
2009 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
2010 echo "Missing package $pkg."
2011 cleanup
2012 exit 1
2013 fi
2014 done
2015 if [ -f non-free.list ]; then
2016 echo "Preparing non-free packages..."
2017 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
2018 for pkg in $(cat non-free.list); do
2019 if [ ! -d $INSTALLED/$pkg ]; then
2020 if [ ! -d $INSTALLED/get-$pkg ]; then
2021 tazpkg get-install get-$pkg
2022 fi
2023 get-$pkg
2024 fi
2025 tazpkg repack $pkg
2026 pkg=$(ls $pkg*.tazpkg)
2027 grep -q "^$pkg$" $LIST_NAME || \
2028 echo $pkg >>$LIST_NAME
2029 mv $pkg $PACKAGES_REPOSITORY
2030 done
2031 fi
2032 cp $LIST_NAME $DISTRO/distro-packages.list
2033 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/distro-packages.list > $DISTRO/list-packages
2034 cd $PACKAGES_REPOSITORY
2035 for pkg in $(cat $DISTRO/list-packages)
2036 do
2037 echo -n "Installing package: $pkg"
2038 yes y | tazpkg install $pkg --root=$ROOTFS 2>&1 >> $log || exit 1
2039 status
2040 done
2041 rm -f $ROOTFS/var/lib/tazpkg/packages.*
2042 cd $DISTRO
2043 cp distro-packages.list $ROOTFS/etc/tazlito
2044 # Copy all files from $ADDFILES/rootfs to the rootfs.
2045 if [ -d "$ADDFILES/rootfs" ] ; then
2046 echo -n "Copying addfiles content to the rootfs... "
2047 cp -a $ADDFILES/rootfs/* $ROOTFS
2048 status
2049 fi
2050 echo -n "Root filesystem is generated..." && status
2051 # Root CD part.
2052 echo -n "Preparing the rootcd directory..."
2053 mkdir -p $ROOTCD
2054 status
2055 # Move the boot dir with the Linux kernel from rootfs.
2056 # The boot dir goes directly on the CD.
2057 if [ -d "$ROOTFS/boot" ] ; then
2058 echo -n "Moving the boot directory..."
2059 mv $ROOTFS/boot $ROOTCD
2060 cd $ROOTCD/boot
2061 ln vmlinuz-* bzImage
2062 status
2063 fi
2064 cd $DISTRO
2065 # Copy all files from $ADDFILES/rootcd to the rootcd.
2066 if [ -d "$ADDFILES/rootcd" ] ; then
2067 echo -n "Copying addfiles content to the rootcd... "
2068 cp -a $ADDFILES/rootcd/* $ROOTCD
2069 status
2070 fi
2071 # Execute the distro script used to perform tasks in the rootfs
2072 # before compression. Give rootfs path in arg
2073 [ -z $DISTRO_SCRIPT ] && DISTRO_SCRIPT=$TOP_DIR/distro.sh
2074 if [ -x $DISTRO_SCRIPT ]; then
2075 echo "Executing distro script..."
2076 sh $DISTRO_SCRIPT $DISTRO
2077 fi
2078 if [ -s /etc/tazlito/rootfs.list ]; then
2079 FLAVOR_LIST="$(awk '{ for (i = 2; i <= NF; i+=2) \
2080 printf("%s ",$i) }' < /etc/tazlito/rootfs.list)"
2081 sed -i "s/ *//;s/)/), flavors $FLAVOR_LIST/" \
2082 $ROOTCD/boot/isolinux/isolinux.msg
2083 [ -f $ROOTCD/boot/isolinux/ifmem.c32 ] ||
2084 cp /boot/isolinux/ifmem.c32 $ROOTCD/boot/isolinux
2085 n=0
2086 last=$ROOTFS
2087 while read flavor; do
2088 n=$(($n+1))
2089 echo "Building $flavor rootfs..."
2090 [ -s $TOP_DIR/$flavor.flavor ] &&
2091 cp $TOP_DIR/$flavor.flavor .
2092 [ -s $flavor.flavor ] || download $flavor.flavor
2093 zcat $flavor.flavor | cpio -i \
2094 $flavor.pkglist $flavor.rootfs
2095 sed 's/.*/&.tazpkg/' < $flavor.pkglist \
2096 > $DISTRO/list-packages0$n
2097 mkdir ${ROOTFS}0$n
2098 cd $PACKAGES_REPOSITORY
2099 yes y | tazpkg install-list \
2100 $DISTRO/list-packages0$n --root=${ROOTFS}0$n
2101 rm -rf ${ROOTFS}0$n/boot ${ROOTFS}0$n/var/lib/tazpkg/packages.*
2102 status
2103 cd $DISTRO
2104 if [ -s $flavor.rootfs ]; then
2105 echo "Adding $flavor rootfs extra files..."
2106 zcat $flavor.rootfs | \
2107 ( cd ${ROOTFS}0$n ; cpio -idmu )
2108 fi
2109 mv $flavor.pkglist ${ROOTFS}0$n/etc/tazlito/distro-packages.list
2110 rm -f $flavor.flavor install-list
2111 mergefs ${ROOTFS}0$n $last
2112 last=${ROOTFS}0$n
2113 done <<EOT
2114 $(awk '{ for (i = 4; i <= NF; i+=2) print $i; }' < /etc/tazlito/rootfs.list)
2115 EOT
2116 i=$(($n+1))
2117 while [ $n -gt 0 ]; do
2118 mv ${ROOTFS}0$n ${ROOTFS}$i
2119 echo "Compression ${ROOTFS}0$n ($(du -hs ${ROOTFS}$i | awk '{ print $1 }')) ..."
2120 gen_initramfs ${ROOTFS}$i
2121 n=$(($n-1))
2122 i=$(($i-1))
2123 done
2124 mv $ROOTFS ${ROOTFS}$i
2125 gen_initramfs ${ROOTFS}$i
2126 update_bootconfig $ROOTCD/boot/isolinux \
2127 "$(cat /etc/tazlito/rootfs.list)"
2128 else
2129 # Initramfs and ISO image stuff.
2130 gen_initramfs $ROOTFS
2131 fi
2132 gen_livecd_isolinux
2133 distro_stats
2134 cleanup
2135 ;;
2136 clean-distro)
2137 # Remove old distro tree.
2139 check_root
2140 echo ""
2141 echo -e "\033[1mCleaning :\033[0m $DISTRO"
2142 echo "================================================================================"
2143 if [ -d "$DISTRO" ] ; then
2144 if [ -d "$ROOTFS" ] ; then
2145 echo -n "Removing the rootfs..."
2146 rm -f $DISTRO/$INITRAMFS
2147 rm -rf $ROOTFS
2148 status
2149 fi
2150 if [ -d "$ROOTCD" ] ; then
2151 echo -n "Removing the rootcd..."
2152 rm -rf $ROOTCD
2153 status
2154 fi
2155 echo -n "Removing eventual ISO image..."
2156 rm -f $DISTRO/$ISO_NAME.iso
2157 rm -f $DISTRO/$ISO_NAME.md5
2158 status
2159 fi
2160 echo "================================================================================"
2161 echo ""
2162 ;;
2163 check-distro)
2164 # Check for a few LiveCD needed files not installed by packages.
2166 check_rootfs
2167 echo ""
2168 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
2169 echo "================================================================================"
2170 # SliTaz release info.
2171 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
2172 echo "Missing release info : /etc/slitaz-release"
2173 else
2174 release=`cat $ROOTFS/etc/slitaz-release`
2175 echo -n "Release : $release"
2176 status
2177 fi
2178 # Tazpkg mirror.
2179 if [ ! -f "$ROOTFS$LOCALSTATE/mirror" ]; then
2180 echo -n "Mirror URL : Missing $LOCALSTATE/mirror"
2181 todomsg
2182 else
2183 echo -n "Mirror configuration exists..."
2184 status
2185 fi
2186 # Isolinux msg
2187 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.*g; then
2188 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
2189 todomsg
2190 else
2191 echo -n "Isolinux message seems good..."
2192 status
2193 fi
2194 echo "================================================================================"
2195 echo ""
2196 ;;
2197 writeiso)
2198 # Writefs to ISO image including /home unlike gen-distro we dont use
2199 # packages to generate a rootfs, we build a compressed rootfs with all
2200 # the current filesystem similar to 'tazusb writefs'.
2202 DISTRO="/home/slitaz/distro"
2203 ROOTCD="$DISTRO/rootcd"
2204 if [ -z $2 ]; then
2205 COMPRESSION=none
2206 else
2207 COMPRESSION=$2
2208 fi
2209 if [ -z $3 ]; then
2210 ISO_NAME="slitaz"
2211 else
2212 ISO_NAME="$3"
2213 fi
2214 check_root
2215 # Start info
2216 echo ""
2217 echo -e "\033[1mWrite filesystem to ISO\033[0m
2218 ===============================================================================
2219 The command writeiso will write the current filesystem into a suitable cpio
2220 archive (rootfs.gz) and generate a bootable ISO image (slitaz.iso).
2222 Archive compression: $COMPRESSION"
2223 echo ""
2225 # Save some space
2226 rm /var/cache/tazpkg/* -r -f
2227 rm -rf /home/slitaz/distro
2229 # Optionally remove sound card selection and screen resolution.
2230 echo "Do you wish to remove the sound card and screen configs ? "
2231 echo -n "Press ENTER to keep or answer (No|yes|exit): "
2232 read anser
2233 case $anser in
2234 e|E|"exit"|Exit)
2235 exit 0 ;;
2236 y|Y|yes|Yes)
2237 echo -n "Removing current sound card and screen configurations..."
2238 rm -f /var/lib/sound-card-driver
2239 rm -f /etc/asound.state
2240 rm -f /etc/X11/screen.conf
2241 rm -f /etc/X11/xorg.conf ;;
2242 *)
2243 echo -n "Keeping current sound card and screen configurations..." ;;
2244 esac
2245 status
2247 cd /
2248 # Create list of files including default user files since it is defined in /etc/passwd
2249 # and some new users might have been added.
2250 find bin etc init sbin var dev lib root usr home >/tmp/list
2252 for dir in proc sys tmp mnt media media/cdrom media/flash media/usbdisk
2253 do
2254 echo $dir >>/tmp/list
2255 done
2257 # Generate initramfs with specified compression and display rootfs
2258 # size in realtime.
2259 rm -f /tmp/rootfs
2260 write_initramfs &
2261 sleep 2
2262 cd - > /dev/null
2263 echo -en "\nFilesystem size:"
2264 while [ ! -f /tmp/rootfs ]
2265 do
2266 sleep 1
2267 echo -en "\\033[18G`du -sh /rootfs.gz | awk '{print $1}'` "
2268 done
2269 echo -e "\n"
2271 # Move freshly generated rootfs to the cdrom.
2272 mkdir -p $ROOTCD/boot
2273 mv -f /rootfs.gz $ROOTCD/boot
2275 # Now we need the kernel and isolinux files.
2276 if mount /dev/cdrom /media/cdrom 2>/dev/null; then
2277 cp /media/cdrom/boot/bzImage $ROOTCD/boot
2278 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
2279 unmeta_boot $ROOTCD
2280 umount /media/cdrom
2281 else
2282 echo -e "
2283 Unable to mount the cdrom to copy the Kernel and needed files. When SliTaz
2284 is running in RAM the kernel and bootloader files are kept on the cdrom.
2285 Please insert a LiveCD or unmount the current cdrom to let Tazlito handle
2286 the media.\n"
2287 echo -en "----\nENTER to continue..."; read i
2288 exit 1
2289 fi
2291 # Generate the iso image.
2292 cd $DISTRO
2293 echo "Generating ISO image..."
2294 genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
2295 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
2296 -V "SliTaz" -input-charset iso8859-1 -boot-info-table $ROOTCD
2297 if [ -x /usr/bin/isohybrid ]; then
2298 echo -n "Creating hybrid ISO..."
2299 /usr/bin/isohybrid $ISO_NAME.iso 2> /dev/null
2300 status
2301 fi
2302 echo -n "Creating the ISO md5sum..."
2303 md5sum $ISO_NAME.iso > $ISO_NAME.md5
2304 status
2306 echo "==============================================================================="
2307 echo "ISO image: `du -sh /home/slitaz/distro/$ISO_NAME.iso`"
2308 echo ""
2309 echo -n "Exit or burn ISO to cdrom (Exit|burn)? "; read anser
2310 case $anser in
2311 burn)
2312 eject
2313 echo -n "Please insert a blank cdrom and press ENTER..."
2314 read i && sleep 2
2315 tazlito burn-iso /home/slitaz/distro/$ISO_NAME.iso
2316 echo -en "----\nENTER to continue..."; read i ;;
2317 *)
2318 exit 0 ;;
2319 esac ;;
2320 burn-iso)
2321 # Guess cdrom device, ask user and burn the ISO.
2323 check_root
2324 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
2325 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
2326 # We can specify an alternative ISO from the cmdline.
2327 if [ -n "$2" ] ; then
2328 iso=$2
2329 else
2330 iso=$DISTRO/$ISO_NAME.iso
2331 fi
2332 if [ ! -f "$iso" ]; then
2333 echo -e "\nUnable to find ISO : $iso\n"
2334 exit 0
2335 fi
2336 echo ""
2337 echo -e "\033[1mTazlito burn ISO\033[0m "
2338 echo "================================================================================"
2339 echo "Cdrom device : /dev/$DRIVE_NAME"
2340 echo "Drive speed : $DRIVE_SPEED"
2341 echo "ISO image : $iso"
2342 echo "================================================================================"
2343 echo ""
2344 yesorno "Burn ISO image (y/N) ? "
2345 if [ "$answer" == "y" ]; then
2346 echo ""
2347 echo "Starting Wodim to burn the iso..." && sleep 2
2348 echo "================================================================================"
2349 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
2350 echo "================================================================================"
2351 echo "ISO image is burned to cdrom."
2352 else
2353 echo -e "\nExiting. No ISO burned."
2354 fi
2355 echo ""
2356 ;;
2357 merge)
2358 # Merge multiple rootfs into one iso.
2360 if [ -z "$2" ]; then
2361 cat << EOT
2362 Usage: tazlito merge size1 iso size2 rootfs2 [sizeN rootfsN]...
2364 Merge multiple rootfs into one iso. Rootfs are like russian dolls
2365 i.e: rootfsN is a subset of rootfsN-1
2366 rootfs1 is found in iso, sizeN is the RAM size need to launch rootfsN.
2367 The boot loader will select the rootfs according to the RAM size detected.
2369 Example:
2370 $ tazlito merge 160M slitaz-core.iso 96M rootfs-justx.gz 32M rootfs-base.gz
2372 Will start slitaz-core with 160M+ RAM, slitaz-justX with 96M-160M RAM,
2373 slitaz-base with 32M-96M RAM and display an error message if RAM < 32M.
2374 EOT
2375 exit 2
2376 fi
2378 shift # skip merge
2379 append="$1 slitaz1"
2380 shift # skip size1
2381 mkdir -p $TMP_DIR/mnt $TMP_DIR/rootfs1
2383 ISO=$1.merged
2384 # Extract filesystems
2385 echo -n "Mounting $1"
2386 mount -o loop,ro $1 $TMP_DIR/mnt 2> /dev/null
2387 status || cleanup_merge
2388 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2389 rm -f $TMP_DIR/iso/boot/bzImage
2390 ln $TMP_DIR/iso/boot/vmlinuz* $TMP_DIR/iso/boot/bzImage
2391 umount -d $TMP_DIR/mnt
2392 if [ -f $TMP_DIR/iso/boot/rootfs1.gz ]; then
2393 echo "$1 is already a merged iso. Aborting."
2394 cleanup_merge
2395 fi
2396 if [ ! -f $TMP_DIR/iso/boot/isolinux/ifmem.c32 ]; then
2397 if [ ! -f /boot/isolinux/ifmem.c32 ]; then
2398 cat <<EOT
2399 No file /boot/isolinux/ifmem.c32
2400 Please install syslinux package !
2401 EOT
2402 rm -rf $TMP_DIR
2403 exit 1
2404 fi
2405 cp /boot/isolinux/ifmem.c32 $TMP_DIR/iso/boot/isolinux
2406 fi
2408 echo -n "Extracting iso/rootfs.gz"
2409 extract_rootfs $TMP_DIR/iso/boot/rootfs.gz $TMP_DIR/rootfs1 &&
2410 [ -d $TMP_DIR/rootfs1/etc ]
2411 status || cleanup_merge
2412 n=1
2413 while [ -n "$2" ]; do
2414 shift # skip rootfs N-1
2415 p=$n
2416 n=$(($n + 1))
2417 append="$append $1 slitaz$n"
2418 shift # skip size N
2419 mkdir -p $TMP_DIR/rootfs$n
2420 echo -n "Extracting $1"
2421 extract_rootfs $1 $TMP_DIR/rootfs$n &&
2422 [ -d $TMP_DIR/rootfs$n/etc ]
2423 status || cleanup_merge
2424 mergefs $TMP_DIR/rootfs$n $TMP_DIR/rootfs$p
2425 echo "Creating rootfs$p.gz"
2426 pack_rootfs $TMP_DIR/rootfs$p $TMP_DIR/iso/boot/rootfs$p.gz
2427 status
2428 done
2429 echo "Creating rootfs$n.gz"
2430 pack_rootfs $TMP_DIR/rootfs$n $TMP_DIR/iso/boot/rootfs$n.gz
2431 status
2432 rm -f $TMP_DIR/iso/boot/rootfs.gz
2433 update_bootconfig $TMP_DIR/iso/boot/isolinux "$append"
2434 create_iso $ISO $TMP_DIR/iso
2435 rm -rf $TMP_DIR
2436 ;;
2438 repack)
2439 # Repack an iso with maximum lzma compression ratio.
2442 ISO=$2
2444 mkdir -p $TMP_DIR/mnt
2445 # Extract filesystems
2446 echo -n "Mounting $ISO"
2447 mount -o loop,ro $ISO $TMP_DIR/mnt 2> /dev/null
2448 status || cleanup_merge
2449 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2450 umount -d $TMP_DIR/mnt
2452 for i in $TMP_DIR/iso/boot/rootfs* ; do
2453 echo -n "Repacking $(basename $i)"
2454 (zcat $i 2> /dev/null || unlzma -c $i || cat $i) \
2455 2>/dev/null > $TMP_DIR/rootfs
2456 lzma e $TMP_DIR/rootfs $i \
2457 $(lzma_switches $TMP_DIR/rootfs)
2458 status
2459 done
2461 create_iso $ISO $TMP_DIR/iso
2462 rm -rf $TMP_DIR ;;
2464 build-loram)
2465 # Build a Live CD for low ram systems.
2468 ISO=$2
2469 OUTPUT=$3
2470 if [ -z "$3" ]; then
2471 echo "Usage: tazlito $1 input.iso output.iso [cdrom|smallcdrom|http|ram]"
2472 exit 1
2473 fi
2474 mkdir -p $TMP_DIR/iso
2475 mount -o loop,ro -t iso9660 $ISO $TMP_DIR/iso
2476 if ! check_iso_for_loram ; then
2477 echo "$2 is not a valid SliTaz live CD. Abort."
2478 umount -d $TMP_DIR/iso
2479 rm -rf $TMP_DIR
2480 exit 1
2481 fi
2483 case "$4" in
2484 cdrom) build_loram_cdrom ;;
2485 smallcdrom) build_loram_cdrom small ;;
2486 http) build_loram_http ;;
2487 *) build_loram_ram ;;
2488 esac
2489 umount -d $TMP_DIR/iso
2490 rm -rf $TMP_DIR ;;
2493 frugal-install|-fi)
2494 ISO_IMAGE="$2"
2495 echo ""
2496 mkdir -p /boot/frugal
2497 if [ -f "$ISO_IMAGE" ]; then
2498 echo -n "Using ISO image: $ISO_IMAGE"
2499 mkdir -p /tmp/iso && mount -o loop $ISO_IMAGE /tmp/iso
2500 status
2501 echo -n "Installing the Kernel and rootfs..."
2502 cp -a /tmp/iso/boot/bzImage /boot/frugal
2503 if [ -f $DISTRO/rootcd/boot/rootfs1.gz ]; then
2504 cd /tmp/iso/boot
2505 cat $(ls -r rootfs*.gz) > /boot/frugal/rootfs.gz
2506 else
2507 cp -a /tmp/iso/boot/rootfs.gz /boot/frugal
2508 fi
2509 umount /tmp/iso
2510 status
2511 else
2512 echo -n "Using distro: $DISTRO"
2513 cd $DISTRO && status
2514 echo -n "Installing the Kernel and rootfs..."
2515 cp -a $DISTRO/rootcd/boot/bzImage /boot/frugal
2516 if [ -f $DISTRO/rootcd/boot/rootfs1.gz ]; then
2517 cd $DISTRO/rootcd/boot
2518 cat $(ls -r rootfs*.gz) > /boot/frugal/rootfs.gz
2519 else
2520 cp -a $DISTRO/rootcd/boot/rootfs.gz /boot/frugal
2521 fi
2522 status
2523 fi
2524 # Grub entry
2525 if ! grep -q "^kernel /boot/frugal/bzImage" /boot/grub/menu.lst; then
2526 echo -n "Configuring GRUB menu list..."
2527 cat >> /boot/grub/menu.lst << EOT
2528 title SliTaz GNU/Linux (frugal)
2529 root (hd0,0)
2530 kernel /boot/frugal/bzImage root=/dev/null
2531 initrd /boot/frugal/rootfs.gz
2532 EOT
2533 else
2534 echo -n "GRUB menu list is up-to-date..."
2535 fi
2536 status
2537 echo "" ;;
2539 emu-iso)
2540 # Emulate an ISO image with Qemu.
2541 if [ -n "$2" ] ; then
2542 iso=$2
2543 else
2544 iso=$DISTRO/$ISO_NAME.iso
2545 fi
2546 if [ ! -f "$iso" ]; then
2547 echo -e "\nUnable to find ISO : $iso\n"
2548 exit 0
2549 fi
2550 if [ ! -x "/usr/bin/qemu" ]; then
2551 echo -e "\nUnable to find Qemu binary. Please install: qemu\n"
2552 exit 0
2553 fi
2554 echo -e "\nStarting Qemu emulator:\n"
2555 echo -e "qemu $QEMU_OPTS $iso\n"
2556 qemu $QEMU_OPTS $iso ;;
2558 usage|*)
2559 # Clear and print usage also for all unknown commands.
2561 clear
2562 usage ;;
2563 esac
2565 exit 0