tazlito view tazlito @ rev 223

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