tazlito view tazlito @ rev 227

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