tazlito view tazlito @ rev 232

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