tazlito view tazlito @ rev 225

build loram: suggests busybox-static
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Jun 06 16:27:40 2011 +0200 (2011-06-06)
parents 27e5ee5b1aa2
children df8acad3c50b
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 )
1077 ( cd /tmp/volatile$$ ; find * -type f ) | while read file ; do
1078 [ -e $1/$file ] || continue
1079 cmp -s /tmp/volatile$$/$file $1/$file && rm -f $1/$file
1080 done
1081 rm -rf /tmp/volatile$$
1082 done
1084 # Remove other files blindly
1085 for i in $1$INSTALLED/*/files.list; do
1086 for file in $(cat $i); do
1087 [ $1$file -nt $i ] && continue
1088 [ -f $1$file -a ! -L $1$file ] && continue
1089 [ -d $1$file ] || rm -f $1$file
1090 done
1091 done
1093 # Remove tazpkg files and tmp files
1094 rm -rf $1$INSTALLED* $1/tmp $1/var/tmp
1095 rm -f $1$LOCALSTATE/*packages* $1$LOCALSTATE/files.list.lzma \
1096 $1$LOCALSTATE/mirror* $1/var/cache/*/* \
1097 $1/var/lock/* $1/var/log/* $1/var/run/* $1/var/run/*/* \
1098 $1/var/lib/* $1/var/lib/dbus/* 2> /dev/null
1100 # Cleanup directory tree
1101 cd $1
1102 find * -type d | sort -r | while read dir; do
1103 rmdir $dir 2> /dev/null
1104 done
1105 cd - > /dev/null
1108 ####################
1109 # Tazlito commands #
1110 ####################
1112 case "$COMMAND" in
1113 stats)
1114 # Tazlito general statistics from the config file.
1116 echo ""
1117 echo -e "\033[1mTazlito statistics\033[0m
1118 ===============================================================================
1119 Config file : $CONFIG_FILE
1120 ISO name : $ISO_NAME.iso
1121 Volume name : $VOLUM_NAME
1122 Prepared : $PREPARED
1123 Packages repository : $PACKAGES_REPOSITORY
1124 Distro directory : $DISTRO"
1125 if [ ! "$ADDFILES" = "" ] ; then
1126 echo -e "Additional files : $ADDFILES"
1127 fi
1128 echo "================================================================================"
1129 echo ""
1130 ;;
1131 list-addfiles)
1132 # Simple list of additional files in the rootfs
1133 echo ""
1134 cd $ADDFILES
1135 find rootfs -type f
1136 echo "" ;;
1137 gen-config)
1138 # Generate a new config file in the current dir or the specified
1139 # directory by $2.
1141 if [ -n "$2" ] ; then
1142 mkdir -p $2 && cd $2
1143 fi
1144 echo -n "Generating empty tazlito.conf..."
1145 empty_config_file
1146 status
1147 echo ""
1148 if [ -f "tazlito.conf" ] ; then
1149 echo "Configuration file is ready to edit."
1150 echo "File location : `pwd`/tazlito.conf"
1151 echo ""
1152 fi
1153 ;;
1154 configure)
1155 # Configure a tazlito.conf config file. Start by getting
1156 # a empty config file and sed it.
1158 if [ -f "tazlito.conf" ] ; then
1159 rm tazlito.conf
1160 else
1161 if test $(id -u) = 0 ; then
1162 cd /etc
1163 else
1164 echo "You must be root to configure the main config file or in"
1165 echo "the same directory of the file you want to configure."
1166 exit 0
1167 fi
1168 fi
1169 empty_config_file
1170 echo""
1171 echo -e "\033[1mConfiguring :\033[0m `pwd`/tazlito.conf"
1172 echo "================================================================================"
1173 # ISO name.
1174 echo -n "ISO name : " ; read answer
1175 sed -i s#'ISO_NAME=\"\"'#"ISO_NAME=\"$answer\""# tazlito.conf
1176 # Volume name.
1177 echo -n "Volume name : " ; read answer
1178 sed -i s/'VOLUM_NAME=\"SliTaz\"'/"VOLUM_NAME=\"$answer\""/ tazlito.conf
1179 # Packages repository.
1180 echo -n "Packages repository : " ; read answer
1181 sed -i s#'PACKAGES_REPOSITORY=\"\"'#"PACKAGES_REPOSITORY=\"$answer\""# tazlito.conf
1182 # Distro path.
1183 echo -n "Distro path : " ; read answer
1184 sed -i s#'DISTRO=\"\"'#"DISTRO=\"$answer\""# tazlito.conf
1185 echo "================================================================================"
1186 echo "Config file is ready to use."
1187 echo "You can now extract an ISO or generate a distro."
1188 echo ""
1189 ;;
1190 gen-iso)
1191 # Simply generate a new iso.
1193 check_root
1194 verify_rootcd
1195 gen_livecd_isolinux
1196 distro_stats
1197 ;;
1198 gen-initiso)
1199 # Simply generate a new initramfs with a new iso.
1201 check_root
1202 verify_rootcd
1203 gen_initramfs $ROOTFS
1204 gen_livecd_isolinux
1205 distro_stats
1206 ;;
1207 extract-distro)
1208 # Extract an ISO image to a directory and rebuild the LiveCD tree.
1210 check_root
1211 ISO_IMAGE=$2
1212 if [ -z "$ISO_IMAGE" ] ; then
1213 echo -e "\nPlease specify the path to the ISO image."
1214 echo -e "Example : `basename $0` image.iso /path/target\n"
1215 exit 0
1216 fi
1217 # Set the distro path by checking for $3 on cmdline.
1218 if [ -n "$3" ] ; then
1219 TARGET=$3
1220 else
1221 TARGET=$DISTRO
1222 fi
1223 # Exit if existing distro is found.
1224 if [ -d "$TARGET/rootfs" ] ; then
1225 echo -e "\nA rootfs exists in : $TARGET"
1226 echo -e "Please clean the distro tree or change directory path.\n"
1227 exit 0
1228 fi
1229 echo ""
1230 echo -e "\033[1mTazlito extracting :\033[0m `basename $ISO_IMAGE`"
1231 echo "================================================================================"
1232 # Start to mount the ISO.
1233 echo ""
1234 echo "Mounting ISO image..."
1235 mkdir -p $TMP_DIR
1236 # Get ISO file size.
1237 isosize=`du -sh $ISO_IMAGE | cut -f1`
1238 mount -o loop $ISO_IMAGE $TMP_DIR
1239 sleep 2
1240 # Prepare target dir, copy the kernel and the rootfs.
1241 mkdir -p $TARGET/rootfs
1242 mkdir -p $TARGET/rootcd/boot
1243 echo -n "Copying the Linux kernel..."
1244 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
1245 ln $TARGET/rootcd/boot/vmlinuz* $TARGET/rootcd/boot/bzImage
1246 else
1247 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
1248 fi
1249 status
1250 echo -n "Copying isolinux files..."
1251 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
1252 for i in $(ls $TMP_DIR); do
1253 [ "$i" = "boot" ] && continue
1254 cp -a $TMP_DIR/$i $TARGET/rootcd
1255 done
1256 status
1257 if [ -d $TMP_DIR/boot/syslinux ]; then
1258 echo -n "Copying syslinux files..."
1259 cp -a $TMP_DIR/boot/syslinux $TARGET/rootcd/boot
1260 status
1261 fi
1262 if [ -d $TMP_DIR/boot/extlinux ]; then
1263 echo -n "Copying extlinux files..."
1264 cp -a $TMP_DIR/boot/extlinux $TARGET/rootcd/boot
1265 status
1266 fi
1267 if [ -d $TMP_DIR/boot/grub ]; then
1268 echo -n "Copying GRUB files..."
1269 cp -a $TMP_DIR/boot/grub $TARGET/rootcd/boot
1270 status
1271 fi
1273 echo -n "Copying the rootfs..."
1274 cp $TMP_DIR/boot/rootfs.?z $TARGET/rootcd/boot
1275 status
1276 # Extract initramfs.
1277 cd $TARGET/rootfs
1278 echo -n "Extracting the rootfs... "
1279 extract_rootfs ../rootcd/boot/rootfs.gz $TARGET/rootfs
1280 # unpack /usr
1281 for i in etc/tazlito/*.extract; do
1282 [ -f "$i" ] && . $i ../rootcd
1283 done
1284 # Umount and remove temp directory and cd to $TARGET to get stats.
1285 umount $TMP_DIR && rm -rf $TMP_DIR
1286 cd ..
1287 echo ""
1288 echo "================================================================================"
1289 echo "Extracted : `basename $ISO_IMAGE` ($isosize)"
1290 echo "Distro tree : `pwd`"
1291 echo "Rootfs size : `du -sh rootfs`"
1292 echo "Rootcd size : `du -sh rootcd`"
1293 echo "================================================================================"
1294 echo ""
1295 ;;
1296 list-flavors)
1297 # Show available flavors.
1298 if [ ! -s /etc/tazlito/flavors.list -o "$2" == "--recharge" ]; then
1299 download flavors.list -O - > /etc/tazlito/flavors.list
1300 fi
1301 echo ""
1302 echo -e "\033[1mList of flavors\033[0m"
1303 echo "================================================================================"
1304 cat /etc/tazlito/flavors.list
1305 echo ""
1306 ;;
1307 show-flavor)
1308 # Show flavor description.
1309 FLAVOR=${2%.flavor}
1310 if [ ! -f "$FLAVOR.flavor" ]; then
1311 echo "File $FLAVOR.flavor not found."
1312 exit 1
1313 fi
1314 mkdir $TMP_DIR
1315 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i > /dev/null)
1316 if [ "$3" = "--brief" ]; then
1317 if [ "$4" != "--noheader" ]; then
1318 echo "Name ISO Rootfs Description"
1319 echo "================================================================================"
1320 fi
1321 printf "%-16.16s %6.6s %6.6s %s\n" "$FLAVOR" \
1322 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
1323 "$(field 'Rootfs size' $TMP_DIR/$FLAVOR.desc)" \
1324 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
1325 else
1326 echo "================================================================================"
1327 cat $TMP_DIR/$FLAVOR.desc
1328 fi
1329 rm -Rf $TMP_DIR
1330 ;;
1331 gen-liveflavor)
1332 # Generate a new flavor from the live system.
1333 FLAVOR=${2%.flavor}
1334 DESC=""
1335 case "$FLAVOR" in
1336 '') echo -n "Flavor name : "
1337 read FLAVOR
1338 [ -z "$FLAVOR" ] && exit 1;;
1339 -?|-h*|--help) echo -e "
1341 SliTaz Live Tool - Version: $VERSION
1342 \033[1mUsage: \033[0m `basename $0` gen-liveflavor flavor-name [flavor-patch-file]
1343 \033[1mflavor-patch-file format: \033[0m
1344 code data
1345 + package to add
1346 - package to remove
1347 ! non-free package to add
1348 ? display message
1349 @ flavor description
1351 \033[1mExample: \033[0m
1352 @ Developer tools for slitaz maintainers
1353 + slitaz-toolchain
1354 + mercurial
1356 exit 1;;
1357 esac
1358 mv /etc/tazlito/distro-packages.list \
1359 /etc/tazlito/distro-packages.list.$$ 2> /dev/null
1360 rm -f distro-packages.list non-free.list 2> /dev/null
1361 tazpkg recharge
1362 [ -n "$3" ] && while read action pkg; do
1363 case "$action" in
1364 +) yes | tazpkg get-install $pkg 2>&1 >> $log || exit 1 ;;
1365 -) yes | tazpkg remove $pkg ;;
1366 !) echo $pkg >> non-free.list ;;
1367 @) DESC="$pkg" ;;
1368 \?) echo -en "$pkg"; read action ;;
1369 esac
1370 done < $3
1371 yes '' | tazlito gen-distro
1372 echo "$DESC" | tazlito gen-flavor "$FLAVOR"
1373 mv /etc/tazlito/distro-packages.list.$$ \
1374 /etc/tazlito/distro-packages.list 2> /dev/null
1375 ;;
1376 gen-flavor)
1377 # Generate a new flavor from the last iso image generated.
1378 FLAVOR=${2%.flavor}
1379 echo ""
1380 echo -e "\033[1mFlavor generation\033[0m"
1381 echo "================================================================================"
1382 if [ -z "$FLAVOR" ]; then
1383 echo -n "Flavor name : "
1384 read FLAVOR
1385 [ -z "$FLAVOR" ] && exit 1
1386 fi
1387 check_rootfs
1388 FILES="$FLAVOR.pkglist"
1389 echo -n "Creating file $FLAVOR.flavor..."
1390 for i in rootcd rootfs; do
1391 if [ -d "$ADDFILES/$i" ] ; then
1392 FILES="$FILES\n$FLAVOR.$i"
1393 ( cd "$ADDFILES/$i"; find . | \
1394 cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
1395 fi
1396 done
1397 status
1398 answer=`grep -s ^Description $FLAVOR.desc`
1399 answer=${answer#Description : }
1400 if [ -z "$answer" ]; then
1401 echo -n "Description : "
1402 read answer
1403 fi
1404 echo -n "Compressing flavor $FLAVOR..."
1405 echo "Flavor : $FLAVOR" > $FLAVOR.desc
1406 echo "Description : $answer" >> $FLAVOR.desc
1407 ( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
1408 \rm -f $FLAVOR.pkglist $FLAVOR.nonfree 2> /dev/null
1409 for i in $(ls $ROOTFS$INSTALLED); do
1410 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
1411 EXTRAVERSION=""
1412 eval $(grep ^EXTRAVERSION= $ROOTFS$INSTALLED/$i/receipt)
1413 eval $(grep ^CATEGORY= $ROOTFS$INSTALLED/$i/receipt)
1414 if [ "$CATEGORY" = "non-free" -a "${i%%-*}" != "get" ]
1415 then
1416 echo "$i" >> $FLAVOR.nonfree
1417 else
1418 echo "$i-$VERSION$EXTRAVERSION" >> $FLAVOR.pkglist
1419 fi
1420 done
1421 [ -s $FLAVOR.nonfree ] && $FILES="$FILES\n$FLAVOR.nonfree"
1422 for i in $LOCALSTATE/undigest/*/mirror ; do
1423 [ -s $i ] && cat $i >> $FLAVOR.mirrors
1424 done
1425 [ -s $FLAVOR.mirrors ] && $FILES="$FILES\n$FLAVOR.mirrors"
1426 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
1427 gzip -9 > $FLAVOR.flavor
1428 rm `echo -e $FILES`
1429 status
1430 echo "================================================================================"
1431 echo "Flavor size : `du -sh $FLAVOR.flavor`"
1432 echo ""
1433 ;;
1434 upgrade-flavor)
1435 # Update package list to the latest versions available.
1436 FLAVOR=${2%.flavor}
1437 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1438 mkdir $TMP_DIR
1439 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1440 echo -n "Updating $FLAVOR package list..."
1441 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1442 packed_size=0; unpacked_size=0
1443 while read org; do
1444 i=0
1445 pkg=$org
1446 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
1447 pkg=${pkg%-*}
1448 i=$(($i + 1))
1449 [ $i -gt 5 ] && break;
1450 done
1451 set -- $(get_size $pkg)
1452 packed_size=$(( $packed_size + $1 ))
1453 unpacked_size=$(( $unpacked_size + $2 ))
1454 for i in $(grep ^$pkg $LOCALSTATE/packages.list); do
1455 echo $i
1456 break
1457 done
1458 done < $TMP_DIR/$FLAVOR.pkglist \
1459 > $TMP_DIR/$FLAVOR.pkglist.$$
1460 mv -f $TMP_DIR/$FLAVOR.pkglist.$$ $TMP_DIR/$FLAVOR.pkglist
1461 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1462 packed_size=$(($packed_size \
1463 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1464 unpacked_size=$(($unpacked_size \
1465 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1466 fi
1467 # Estimate lzma
1468 packed_size=$(($packed_size * 2 / 3))
1469 iso_size=$(( $packed_size + 26000 ))
1470 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1471 iso_size=$(($iso_size \
1472 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1473 fi
1474 sed -i -e '/Image is ready/d' \
1475 -e "s/Rootfs size\( *:\) \(.*\)/Rootfs size\1 $(cent2human $unpacked_size) (estimated)/" \
1476 -e "s/Initramfs size\( *:\) \(.*\)/Initramfs size\1 $(cent2human $packed_size) (estimated)/" \
1477 -e "s/ISO image size\( *:\) \(.*\)/ISO image size\1 $(cent2human $iso_size) (estimated)/" \
1478 -e "s/date\( *:\) \(.*\)/date\1 $(date +%Y%m%d\ \at\ \%H:%M:%S)/" \
1479 $TMP_DIR/$FLAVOR.desc
1480 ( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
1481 $FLAVOR.flavor
1482 status
1483 rm -Rf $TMP_DIR
1484 fi
1485 ;;
1486 extract-flavor)
1487 # Extract a flavor into $FLAVORS_REPOSITORY.
1488 FLAVOR=${2%.flavor}
1489 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1490 mkdir $TMP_DIR
1491 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1492 echo -n "Extracting $FLAVOR..."
1493 rm -rf $FLAVORS_REPOSITORY/$FLAVOR 2> /dev/null
1494 mkdir -p $FLAVORS_REPOSITORY/$FLAVOR
1495 echo "FLAVOR=\"$FLAVOR\"" > $FLAVORS_REPOSITORY/$FLAVOR/receipt
1496 grep ^Description $TMP_DIR/$FLAVOR.desc | \
1497 sed 's/.*: \(.*\)$/SHORT_DESC="\1"/' >> \
1498 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1499 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc && \
1500 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1501 sed 's/.*: \(.*\)$/ROOTFS_SELECTION="\1"/' >> \
1502 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1503 grep '^Rootfs size' $TMP_DIR/$FLAVOR.desc | \
1504 sed 's/.*: \(.*\)$/ROOTFS_SIZE="\1"/' >> \
1505 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1506 grep ^Initramfs $TMP_DIR/$FLAVOR.desc | \
1507 sed 's/.*: \(.*\)$/INITRAMFS_SIZE="\1"/' >> \
1508 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1509 grep ^ISO $TMP_DIR/$FLAVOR.desc | \
1510 sed 's/.*: \(.*\)$/ISO_SIZE="\1"/' >> \
1511 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1512 for i in rootcd rootfs; do
1513 [ -f $TMP_DIR/$FLAVOR.$i ] || continue
1514 mkdir $FLAVORS_REPOSITORY/$FLAVOR/$i
1515 zcat $TMP_DIR/$FLAVOR.$i | \
1516 (cd $FLAVORS_REPOSITORY/$FLAVOR/$i; \
1517 cpio -idm > /dev/null)
1518 done
1519 [ -s $TMP_DIR/$FLAVOR.mirrors ] &&
1520 cp $TMP_DIR/$FLAVOR.mirrors \
1521 $FLAVORS_REPOSITORY/$FLAVOR/mirrors
1522 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1523 while read org; do
1524 i=0
1525 pkg=$org
1526 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
1527 pkg=${pkg%-*}
1528 i=$(($i + 1))
1529 [ $i -gt 5 ] && break;
1530 done
1531 echo $pkg
1532 done < $TMP_DIR/$FLAVOR.pkglist \
1533 > $FLAVORS_REPOSITORY/$FLAVOR/packages.list
1534 status
1535 rm -Rf $TMP_DIR
1536 fi
1537 ;;
1538 pack-flavor)
1539 # Create a flavor from $FLAVORS_REPOSITORY.
1540 FLAVOR=${2%.flavor}
1541 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/receipt ]; then
1542 mkdir $TMP_DIR
1543 echo -n "Creating flavor $FLAVOR..."
1544 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1545 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/mirrors ]; then
1546 cp $FLAVORS_REPOSITORY/$FLAVOR/mirrors \
1547 $TMP_DIR/$FLAVOR.mirrors
1548 for i in $(cat $TMP_DIR/$FLAVOR.mirrors); do
1549 wget -O - $i/packages.list >> $TMP_DIR/packages.list
1550 done
1551 fi
1552 [ -s $FLAVORS_REPOSITORY/$FLAVOR/packages.list ] &&
1553 get_pkglist $FLAVOR > $TMP_DIR/$FLAVOR.pkglist
1554 if grep -q ^ROOTFS_SELECTION \
1555 $FLAVORS_REPOSITORY/$FLAVOR/receipt; then
1556 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1557 set -- $ROOTFS_SELECTION
1558 [ -n "$FRUGAL_RAM" ] || FRUGAL_RAM=$1
1559 [ -f $FLAVORS_REPOSITORY/$2/packages.list ] ||
1560 tazlito extract-flavor $2
1561 get_pkglist $2 > $TMP_DIR/$FLAVOR.pkglist
1562 for i in rootcd rootfs; do
1563 mkdir $TMP_DIR/$i
1564 # Copy extra files from the first flavor
1565 [ -d $FLAVORS_REPOSITORY/$2/$i ] &&
1566 cp -a $FLAVORS_REPOSITORY/$2/$i $TMP_DIR
1567 # Overload extra files by meta flavor
1568 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] &&
1569 cp -a $FLAVORS_REPOSITORY/$FLAVOR/$i $TMP_DIR
1570 [ -n "$(ls $TMP_DIR/$i)" ] &&
1571 ( cd $TMP_DIR/$i ; find . | cpio -o -H newc 2> /dev/null ) | \
1572 gzip -9 >$TMP_DIR/$FLAVOR.$i
1573 rm -rf $TMP_DIR/$i
1574 done
1575 else
1576 for i in rootcd rootfs; do
1577 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] || \
1578 continue
1579 ( cd $FLAVORS_REPOSITORY/$FLAVOR/$i ; \
1580 find . | cpio -o -H newc 2> /dev/null ) | \
1581 gzip -9 >$TMP_DIR/$FLAVOR.$i
1582 done
1583 fi
1584 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1585 packed_size=$(($packed_size \
1586 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1587 unpacked_size=$(($unpacked_size \
1588 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1589 fi
1590 # Estimate lzma
1591 packed_size=$(($packed_size * 2 / 3))
1592 iso_size=$(( $packed_size + 26000 ))
1593 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1594 iso_size=$(($iso_size \
1595 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1596 fi
1597 VERSION=""
1598 MAINTAINER=""
1599 ROOTFS_SELECTION=""
1600 ROOTFS_SIZE="$(cent2human $unpacked_size) (estimated)"
1601 INITRAMFS_SIZE="$(cent2human $packed_size) (estimated)"
1602 ISO_SIZE="$(cent2human $iso_size) (estimated)"
1603 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1604 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1605 Flavor : $FLAVOR
1606 Description : $SHORT_DESC
1607 EOT
1608 [ -n "$VERSION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1609 Version : $VERSION
1610 EOT
1611 [ -n "$MAINTAINER" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1612 Maintainer : $MAINTAINER
1613 EOT
1614 [ -n "$FRUGAL_RAM" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1615 LiveCD RAM size : $FRUGAL_RAM
1616 EOT
1617 [ -n "$ROOTFS_SELECTION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1618 Rootfs list : $ROOTFS_SELECTION
1619 EOT
1620 cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1621 Build date : $(date +%Y%m%d\ \at\ \%H:%M:%S)
1622 Packages : $(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l)
1623 Rootfs size : $ROOTFS_SIZE
1624 Initramfs size : $INITRAMFS_SIZE
1625 ISO image size : $ISO_SIZE
1626 ================================================================================
1628 EOT
1629 rm -f $TMP_DIR/packages.list
1630 ( cd $TMP_DIR ; ls | cpio -o -H newc 2> /dev/null) | \
1631 gzip -9 > $FLAVOR.flavor
1632 status
1633 rm -Rf $TMP_DIR
1634 else
1635 echo "No $FLAVOR flavor in $FLAVORS_REPOSITORY."
1636 fi
1637 ;;
1638 get-flavor)
1639 # Get a flavor's files and prepare for gen-distro.
1640 FLAVOR=${2%.flavor}
1641 echo -e "\n\033[1mPreparing $FLAVOR distro flavor\033[0m"
1642 echo "================================================================================"
1643 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1644 echo -n "Cleaning $DISTRO..."
1645 rm -R $DISTRO 2> /dev/null
1646 mkdir -p $DISTRO
1647 status
1648 mkdir $TMP_DIR
1649 echo -n "Extracting flavor $FLAVOR.flavor... "
1650 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1651 echo -n "Creating distro-packages.list..."
1652 mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
1653 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
1654 status
1655 infos="$FLAVOR.desc"
1656 for i in rootcd rootfs; do
1657 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
1658 echo -n "Adding $i files... "
1659 mkdir -p "$ADDFILES/$i"
1660 zcat $TMP_DIR/$FLAVOR.$i | \
1661 ( cd "$ADDFILES/$i"; cpio -id > /dev/null)
1662 zcat $TMP_DIR/$FLAVOR.$i | cpio -tv \
1663 > $TMP_DIR/$FLAVOR.list$i
1664 infos="$infos\n$FLAVOR.list$i"
1665 fi
1666 done
1667 if [ -s $TMP_DIR/$FLAVOR.mirrors ]; then
1668 n=""
1669 while read line; do
1670 mkdir -p $LOCALSTATE/undigest/$FLAVOR$n
1671 echo "$line" > $LOCALSTATE/undigest/$FLAVOR$n/mirror
1672 n=$(( $n + 1 ))
1673 done < $TMP_DIR/$FLAVOR.mirrors
1674 infos="$infos\n$FLAVOR.mirrors"
1675 tazpkg recharge
1676 fi
1677 rm -f /etc/tazlito/rootfs.list
1678 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc &&
1679 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1680 sed 's/.*: \(.*\)$/\1/' > /etc/tazlito/rootfs.list
1681 echo -n "Updating tazlito.conf..."
1682 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
1683 cat tazlito.conf | grep -v "^#VOLUM_NAME" | \
1684 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
1685 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
1686 sed -i "s/ISO_NAME=.*/ISO_NAME=\"slitaz-$FLAVOR\"/" tazlito.conf
1687 status
1688 ( cd $TMP_DIR ; echo -e $infos | cpio -o -H newc ) | \
1689 gzip -9 > /etc/tazlito/info
1690 rm -Rf $TMP_DIR
1691 fi
1692 echo "================================================================================"
1693 echo -e "Flavor is ready to be generated by: tazlito gen-distro\n"
1694 ;;
1696 iso2flavor)
1697 if [ -z "$3" -o ! -s "$2" ]; then
1698 cat <<EOT
1699 Usage : tazlito iso2flavor image.iso flavor_name
1701 Create a file flavor_name.flavor from the cdrom image file image.iso
1702 EOT
1703 exit 1
1704 fi
1705 FLAVOR=${3%.flavor}
1706 mkdir -p $TMP_DIR/iso $TMP_DIR/rootfs
1707 mount -o loop,ro $2 $TMP_DIR/iso
1708 if [ -s $TMP_DIR/iso/boot/rootfs1.gz ]; then
1709 echo "META flavors are not supported."
1710 umount -d $TMP_DIR/iso
1711 elif [ ! -s $TMP_DIR/iso/boot/rootfs.gz ]; then
1712 echo "No /boot/rootfs.gz in iso image. Needs a SliTaz iso."
1713 umount -d $TMP_DIR/iso
1714 else
1715 ( unlzma -c $TMP_DIR/iso/boot/rootfs.gz || \
1716 zcat $TMP_DIR/iso/boot/rootfs.gz ) | \
1717 ( cd $TMP_DIR/rootfs ; cpio -idmu > /dev/null )
1718 if [ ! -s $TMP_DIR/rootfs/etc/slitaz-release ]; then
1719 echo "No file /etc/slitaz-release in /boot/rootfs.gz of iso image. Needs a non loram SliTaz iso."
1720 umount -d $TMP_DIR/iso
1721 else
1722 ROOTFS_SIZE=$(du -hs $TMP_DIR/rootfs | awk '{ print $1 }')
1723 RAM_SIZE=$(du -s $TMP_DIR/rootfs | awk '{ print 32*int(($1+36000)/32768) "M" }')
1724 cp -a $TMP_DIR/iso $TMP_DIR/rootcd
1725 ISO_SIZE=$(df -h $TMP_DIR/iso | awk 'END { print $2 }')
1726 BUILD_DATE=$(date +%Y%m%d\ \at\ \%H:%M:%S -r $TMP_DIR/iso/md5sum)
1727 umount -d $TMP_DIR/iso
1728 INITRAMFS_SIZE=$(du -chs $TMP_DIR/rootcd/boot/rootfs.gz | awk '{ s=$1 } END { print $1 }')
1729 rm -f $TMP_DIR/rootcd/boot/rootfs.gz $TMP_DIR/rootcd/md5sum
1730 mv $TMP_DIR/rootcd/boot $TMP_DIR/rootfs
1731 sed 's/.* \(.*\).tazpkg*/\1/' > $TMP_DIR/$FLAVOR.pkglist \
1732 < $TMP_DIR/rootfs$INSTALLED.md5
1733 #[ -s $TMP_DIR/rootfs/etc/tazlito/distro-packages.list ] &&
1734 # mv $TMP_DIR/rootfs/etc/tazlito/distro-packages.list $TMP_DIR/$FLAVOR.pkglist
1735 PKGCNT=$(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l | awk '{ print $1 }')
1736 find_flavor_rootfs $TMP_DIR/rootfs
1737 [ -d $TMP_DIR/rootfs/boot ] && mv $TMP_DIR/rootfs/boot $TMP_DIR/rootcd
1738 [ -n "$(ls $TMP_DIR/rootfs)" ] && ( cd $TMP_DIR/rootfs ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootfs
1739 [ -n "$(ls $TMP_DIR/rootcd)" ] && ( cd $TMP_DIR/rootcd ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootcd
1740 rm -rf $TMP_DIR/rootcd $TMP_DIR/rootfs
1741 VERSION=""; MAINTAINER=""
1742 echo -en "Flavor short description \007: "; read -t 30 DESCRIPTION
1743 if [ -n "$DESCRIPTION" ]; then
1744 echo -en "Flavor version : "; read -t 30 VERSION
1745 echo -en "Flavor maintainer (your email) : "; read -t 30 MAINTAINER
1746 fi
1747 [ -n "$DESCRIPTION" ] || DESCRIPTION="Slitaz $FLAVOR flavor"
1748 [ -n "$VERSION" ] || VERSION="1.0"
1749 [ -n "$MAINTAINER" ] || MAINTAINER="nobody@slitaz.org"
1750 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1751 Flavor : $FLAVOR
1752 Description : $DESCRIPTION
1753 Version : $VERSION
1754 Maintainer : $MAINTAINER
1755 LiveCD RAM size : $RAM_SIZE
1756 Build date : $BUILD_DATE
1757 Packages : $PKGCNT
1758 Rootfs size : $ROOTFS_SIZE
1759 Initramfs size : $INITRAMFS_SIZE
1760 ISO image size : $ISO_SIZE
1761 ================================================================================
1763 EOT
1764 ( cd $TMP_DIR ; ls $FLAVOR.* | cpio -o -H newc ) | gzip -9 > $FLAVOR.flavor
1765 cat <<EOT
1766 Tazlito can't detect each file installed during a package post_install.
1767 You should extract this flavor (tazlito extract-flavor $FLAVOR),
1768 check the files in /home/slitaz/flavors/$FLAVOR/rootfs tree and remove
1769 files generated by post_installs.
1770 Check /home/slitaz/flavors/$FLAVOR/receipt too and repack the flavor
1771 (tazlito pack-flavor $FLAVOR)
1772 EOT
1773 fi
1774 fi
1775 rm -rf $TMP_DIR
1776 ;;
1778 check-list)
1779 # Use current packages list in $PWD by default.
1780 DISTRO_PKGS_LIST=distro-packages.list
1781 [ -d "$2" ] && DISTRO_PKGS_LIST=$2/distro-packages.list
1782 [ -f "$2" ] && DISTRO_PKGS_LIST=$2
1783 [ ! -f $DISTRO_PKGS_LIST ] && echo "No packages list found." && exit 0
1784 echo ""
1785 echo -e "\033[1mLiveCD packages list check\033[0m"
1786 echo "================================================================================"
1787 for pkg in `cat $DISTRO_PKGS_LIST`
1788 do
1789 if ! grep -q "$pkg" $LOCALSTATE/packages.list; then
1790 echo "Updating: $pkg"
1791 up=$(($up + 1))
1792 fi
1793 done
1794 [ -z $up ] && echo -e "List is up-to-date\n" && exit 0
1795 echo "================================================================================"
1796 echo -e "Updates: $up\n" ;;
1797 gen-distro)
1798 # Generate a live distro tree with a set of packages.
1800 check_root
1802 # Check if a package list was specified on cmdline.
1803 LIST_NAME="distro-packages.list"
1804 CDROM=""
1805 while [ -n "$2" ]; do
1806 case "$2" in
1807 --iso=*)
1808 CDROM="-o loop ${2#--iso=}"
1809 ;;
1810 --cdrom)
1811 CDROM="/dev/cdrom"
1812 ;;
1813 --force)
1814 DELETE_ROOTFS="true"
1815 ;;
1816 *) if [ ! -f "$2" ] ; then
1817 echo -e "\nUnable to find the specified packages list."
1818 echo -e "List name : $2\n"
1819 exit 1
1820 fi
1821 LIST_NAME=$2
1822 ;;
1823 esac
1824 shift
1825 done
1827 if [ -d $ROOTFS ] ; then
1828 # Delete $ROOTFS if --force is set on command line
1829 if [ ! -z $DELETE_ROOTFS ]; then
1830 rm -rf $ROOTFS
1831 unset $DELETE_ROOTFS
1832 else
1833 echo -e "\nA rootfs exists in : $DISTRO"
1834 echo -e "Please clean the distro tree or change directory path.\n"
1835 exit 0
1836 fi
1837 fi
1838 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
1839 # Build list with installed packages
1840 for i in $(ls $INSTALLED); do
1841 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
1842 EXTRAVERSION=""
1843 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
1844 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
1845 done
1846 fi
1847 # Exit if no list name.
1848 if [ ! -f "$LIST_NAME" ]; then
1849 echo -e "\nNo packages list found or specified. Please read the docs.\n"
1850 exit 0
1851 fi
1852 # Start generation.
1853 echo ""
1854 echo -e "\033[1mTazlito generating a distro\033[0m"
1855 echo "================================================================================"
1856 # Misc checks
1857 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
1858 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
1859 # Get the list of packages using cat for a file list.
1860 LIST=`cat $LIST_NAME`
1861 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
1862 REPACK=""
1863 DOWNLOAD=""
1864 for pkg in $LIST
1865 do
1866 [ "$pkg" = "" ] && continue
1867 pkg=${pkg%.tazpkg}
1868 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
1869 PACKAGE=$(installed_package_name $pkg)
1870 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
1871 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
1872 echo -e "\nUnable to find $pkg in the repository."
1873 echo -e "Path : $PACKAGES_REPOSITORY\n"
1874 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
1875 yesorno "Repack packages from rootfs (y/N) ? "
1876 REPACK="$answer"
1877 [ "$answer" = "y" ] || REPACK="n"
1878 [ "$DOWNLOAD" = "y" ] && break
1879 fi
1880 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
1881 yesorno "Download packages from mirror (Y/n) ? "
1882 DOWNLOAD="$answer"
1883 if [ "$answer" = "n" ]; then
1884 [ -z "$PACKAGE" ] && exit 1
1885 else
1886 DOWNLOAD="y"
1887 [ -n "$REPACK" ] && break
1888 fi
1889 fi
1890 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
1891 done
1893 # Mount cdrom to be able to repack boot-loader packages
1894 if [ ! -e /boot -a -n "$CDROM" ]; then
1895 mkdir $TMP_MNT
1896 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
1897 ln -s $TMP_MNT/boot /
1898 if [ ! -d "$ADDFILES/rootcd" ] ; then
1899 mkdir -p $ADDFILES/rootcd
1900 for i in $(ls $TMP_MNT); do
1901 [ "$i" = "boot" ] && continue
1902 cp -a $TMP_MNT/$i $ADDFILES/rootcd
1903 done
1904 fi
1905 else
1906 rmdir $TMP_MNT
1907 fi
1908 fi
1910 # Root fs stuff.
1911 echo "Preparing the rootfs directory..."
1912 mkdir -p $ROOTFS
1913 for pkg in $LIST
1914 do
1915 [ "$pkg" = "" ] && continue
1916 # First copy and extract the package in tmp dir.
1917 pkg=${pkg%.tazpkg}
1918 PACKAGE=$(installed_package_name $pkg)
1919 mkdir -p $TMP_DIR
1920 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1921 # Look for package in cache
1922 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
1923 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
1924 # Look for package in running distribution
1925 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
1926 tazpkg repack $PACKAGE && \
1927 mv $pkg.tazpkg $PACKAGES_REPOSITORY
1928 fi
1929 fi
1930 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1931 # Get package from mirror
1932 [ "$DOWNLOAD" = "y" ] && \
1933 download $pkg.tazpkg && \
1934 mv $pkg.tazpkg $PACKAGES_REPOSITORY
1935 fi
1936 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1937 echo "Missing package $pkg."
1938 cleanup
1939 exit 1
1940 fi
1941 done
1942 if [ -f non-free.list ]; then
1943 echo "Preparing non-free packages..."
1944 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
1945 for pkg in $(cat non-free.list); do
1946 if [ ! -d $INSTALLED/$pkg ]; then
1947 if [ ! -d $INSTALLED/get-$pkg ]; then
1948 tazpkg get-install get-$pkg
1949 fi
1950 get-$pkg
1951 fi
1952 tazpkg repack $pkg
1953 pkg=$(ls $pkg*.tazpkg)
1954 grep -q "^$pkg$" $LIST_NAME || \
1955 echo $pkg >>$LIST_NAME
1956 mv $pkg $PACKAGES_REPOSITORY
1957 done
1958 fi
1959 cp $LIST_NAME $DISTRO/distro-packages.list
1960 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/distro-packages.list > $DISTRO/list-packages
1961 cd $PACKAGES_REPOSITORY
1962 for pkg in $(cat $DISTRO/list-packages)
1963 do
1964 echo -n "Installing package: $pkg"
1965 yes y | tazpkg install $pkg --root=$ROOTFS 2>&1 >> $log || exit 1
1966 status
1967 done
1968 cd $DISTRO
1969 cp distro-packages.list $ROOTFS/etc/tazlito
1970 # Copy all files from $ADDFILES/rootfs to the rootfs.
1971 if [ -d "$ADDFILES/rootfs" ] ; then
1972 echo -n "Copying addfiles content to the rootfs... "
1973 cp -a $ADDFILES/rootfs/* $ROOTFS
1974 status
1975 fi
1976 echo -n "Root filesystem is generated..." && status
1977 # Root CD part.
1978 echo -n "Preparing the rootcd directory..."
1979 mkdir -p $ROOTCD
1980 status
1981 # Move the boot dir with the Linux kernel from rootfs.
1982 # The boot dir goes directly on the CD.
1983 if [ -d "$ROOTFS/boot" ] ; then
1984 echo -n "Moving the boot directory..."
1985 mv $ROOTFS/boot $ROOTCD
1986 cd $ROOTCD/boot
1987 ln vmlinuz-* bzImage
1988 status
1989 fi
1990 cd $DISTRO
1991 # Copy all files from $ADDFILES/rootcd to the rootcd.
1992 if [ -d "$ADDFILES/rootcd" ] ; then
1993 echo -n "Copying addfiles content to the rootcd... "
1994 cp -a $ADDFILES/rootcd/* $ROOTCD
1995 status
1996 fi
1997 # Execute the distro script used to perform tasks in the rootfs
1998 # before compression. Give rootfs path in arg
1999 [ -z $DISTRO_SCRIPT ] && DISTRO_SCRIPT=$TOP_DIR/distro.sh
2000 if [ -x $DISTRO_SCRIPT ]; then
2001 echo "Executing distro script..."
2002 sh $DISTRO_SCRIPT $DISTRO
2003 fi
2004 if [ -s /etc/tazlito/rootfs.list ]; then
2005 FLAVOR_LIST="$(awk '{ for (i = 2; i <= NF; i+=2) \
2006 printf("%s ",$i) }' < /etc/tazlito/rootfs.list)"
2007 sed -i "s/ *//;s/)/), flavors $FLAVOR_LIST/" \
2008 $ROOTCD/boot/isolinux/isolinux.msg
2009 [ -f $ROOTCD/boot/isolinux/ifmem.c32 ] ||
2010 cp /boot/isolinux/ifmem.c32 $ROOTCD/boot/isolinux
2011 n=0
2012 last=$ROOTFS
2013 while read flavor; do
2014 n=$(($n+1))
2015 echo "Building $flavor rootfs..."
2016 download $flavor.flavor
2017 zcat $flavor.flavor | cpio -i \
2018 $flavor.pkglist $flavor.rootfs
2019 sed 's/.*/&.tazpkg/' < $flavor.pkglist \
2020 > $DISTRO/list-packages0$n
2021 mkdir ${ROOTFS}0$n
2022 cd $PACKAGES_REPOSITORY
2023 yes y | tazpkg install-list \
2024 $DISTRO/list-packages0$n --root=${ROOTFS}0$n
2025 rm -rf ${ROOTFS}0$n/boot
2026 status
2027 cd $DISTRO
2028 if [ -s $flavor.rootfs ]; then
2029 echo "Adding $flavor rootfs extra files..."
2030 zcat $flavor.rootfs | \
2031 ( cd ${ROOTFS}0$n ; cpio -idmu )
2032 fi
2033 mv $flavor.pkglist ${ROOTFS}0$n/etc/tazlito/distro-packages.list
2034 rm -f $flavor.flavor install-list
2035 mergefs ${ROOTFS}0$n $last
2036 last=${ROOTFS}0$n
2037 done <<EOT
2038 $(awk '{ for (i = 4; i <= NF; i+=2) print $i; }' < /etc/tazlito/rootfs.list)
2039 EOT
2040 i=$(($n+1))
2041 while [ $n -gt 0 ]; do
2042 mv ${ROOTFS}0$n ${ROOTFS}$i
2043 echo "Compression ${ROOTFS}0$n ($(du -hs ${ROOTFS}$i | awk '{ print $1 }')) ..."
2044 gen_initramfs ${ROOTFS}$i
2045 n=$(($n-1))
2046 i=$(($i-1))
2047 done
2048 mv $ROOTFS ${ROOTFS}$i
2049 gen_initramfs ${ROOTFS}$i
2050 update_bootconfig $ROOTCD/boot/isolinux \
2051 "$(cat /etc/tazlito/rootfs.list)"
2052 else
2053 # Initramfs and ISO image stuff.
2054 gen_initramfs $ROOTFS
2055 fi
2056 gen_livecd_isolinux
2057 distro_stats
2058 cleanup
2059 ;;
2060 clean-distro)
2061 # Remove old distro tree.
2063 check_root
2064 echo ""
2065 echo -e "\033[1mCleaning :\033[0m $DISTRO"
2066 echo "================================================================================"
2067 if [ -d "$DISTRO" ] ; then
2068 if [ -d "$ROOTFS" ] ; then
2069 echo -n "Removing the rootfs..."
2070 rm -f $DISTRO/$INITRAMFS
2071 rm -rf $ROOTFS
2072 status
2073 fi
2074 if [ -d "$ROOTCD" ] ; then
2075 echo -n "Removing the rootcd..."
2076 rm -rf $ROOTCD
2077 status
2078 fi
2079 echo -n "Removing eventual ISO image..."
2080 rm -f $DISTRO/$ISO_NAME.iso
2081 rm -f $DISTRO/$ISO_NAME.md5
2082 status
2083 fi
2084 echo "================================================================================"
2085 echo ""
2086 ;;
2087 check-distro)
2088 # Check for a few LiveCD needed files not installed by packages.
2090 check_rootfs
2091 echo ""
2092 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
2093 echo "================================================================================"
2094 # SliTaz release info.
2095 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
2096 echo "Missing release info : /etc/slitaz-release"
2097 else
2098 release=`cat $ROOTFS/etc/slitaz-release`
2099 echo -n "Release : $release"
2100 status
2101 fi
2102 # Tazpkg mirror.
2103 if [ ! -f "$ROOTFS$LOCALSTATE/mirror" ]; then
2104 echo -n "Mirror URL : Missing $LOCALSTATE/mirror"
2105 todomsg
2106 else
2107 echo -n "Mirror configuration exists..."
2108 status
2109 fi
2110 # Isolinux msg
2111 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.msg; then
2112 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
2113 todomsg
2114 else
2115 echo -n "Isolinux message seems good..."
2116 status
2117 fi
2118 echo "================================================================================"
2119 echo ""
2120 ;;
2121 writeiso)
2122 # Writefs to ISO image including /home unlike gen-distro we dont use
2123 # packages to generate a rootfs, we build a compressed rootfs with all
2124 # the current filesystem similar to 'tazusb writefs'.
2126 DISTRO="/home/slitaz/distro"
2127 ROOTCD="$DISTRO/rootcd"
2128 if [ -z $2 ]; then
2129 COMPRESSION=none
2130 else
2131 COMPRESSION=$2
2132 fi
2133 if [ -z $3 ]; then
2134 ISO_NAME="slitaz"
2135 else
2136 ISO_NAME="$3"
2137 fi
2138 check_root
2139 # Start info
2140 echo ""
2141 echo -e "\033[1mWrite filesystem to ISO\033[0m
2142 ===============================================================================
2143 The command writeiso will write the current filesystem into a suitable cpio
2144 archive (rootfs.gz) and generate a bootable ISO image (slitaz.iso).
2146 Archive compression: $COMPRESSION"
2147 echo ""
2149 # Save some space
2150 rm /var/cache/tazpkg/* -r -f
2151 rm -rf /home/slitaz/distro
2153 # Optionally remove sound card selection and screen resolution.
2154 echo "Do you wish to remove the sound card and screen configs ? "
2155 echo -n "Press ENTER to keep or answer (No|yes|exit): "
2156 read anser
2157 case $anser in
2158 e|E|"exit"|Exit)
2159 exit 0 ;;
2160 y|Y|yes|Yes)
2161 echo -n "Removing current sound card and screen configurations..."
2162 rm -f /var/lib/sound-card-driver
2163 rm -f /etc/asound.state
2164 rm -f /etc/X11/screen.conf
2165 rm -f /etc/X11/xorg.conf ;;
2166 *)
2167 echo -n "Keeping current sound card and screen configurations..." ;;
2168 esac
2169 status
2171 cd /
2172 # Create list of files including default user files since it is defined in /etc/passwd
2173 # and some new users might have been added.
2174 find bin etc init sbin var dev lib root usr home >/tmp/list
2176 for dir in proc sys tmp mnt media media/cdrom media/flash media/usbdisk
2177 do
2178 echo $dir >>/tmp/list
2179 done
2181 # Generate initramfs with specified compression and display rootfs
2182 # size in realtime.
2183 rm -f /tmp/rootfs
2184 write_initramfs &
2185 sleep 2
2186 cd - > /dev/null
2187 echo -en "\nFilesystem size:"
2188 while [ ! -f /tmp/rootfs ]
2189 do
2190 sleep 1
2191 echo -en "\\033[18G`du -sh /rootfs.gz | awk '{print $1}'` "
2192 done
2193 echo -e "\n"
2195 # Move freshly generated rootfs to the cdrom.
2196 mkdir -p $ROOTCD/boot
2197 mv -f /rootfs.gz $ROOTCD/boot
2199 # Now we need the kernel and isolinux files.
2200 if mount /dev/cdrom /media/cdrom 2>/dev/null; then
2201 cp /media/cdrom/boot/bzImage $ROOTCD/boot
2202 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
2203 umount /media/cdrom
2204 else
2205 echo -e "
2206 Unable to mount the cdrom to copy the Kernel and needed files. When SliTaz
2207 is running in RAM the kernel and bootloader files are kept on the cdrom.
2208 Please insert a LiveCD or unmount the current cdrom to let Tazlito handle
2209 the media.\n"
2210 echo -en "----\nENTER to continue..."; read i
2211 exit 1
2212 fi
2214 # Generate the iso image.
2215 cd $DISTRO
2216 echo "Generating ISO image..."
2217 genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
2218 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
2219 -V "SliTaz" -input-charset iso8859-1 -boot-info-table $ROOTCD
2220 if [ -x /usr/bin/isohybrid ]; then
2221 echo -n "Creating hybrid ISO..."
2222 /usr/bin/isohybrid $ISO_NAME.iso 2> /dev/null
2223 status
2224 fi
2225 echo -n "Creating the ISO md5sum..."
2226 md5sum $ISO_NAME.iso > $ISO_NAME.md5
2227 status
2229 echo "==============================================================================="
2230 echo "ISO image: `du -sh /home/slitaz/distro/$ISO_NAME.iso`"
2231 echo ""
2232 echo -n "Exit or burn ISO to cdrom (Exit|burn)? "; read anser
2233 case $anser in
2234 burn)
2235 eject
2236 echo -n "Please insert a blank cdrom and press ENTER..."
2237 read i && sleep 2
2238 tazlito burn-iso /home/slitaz/distro/$ISO_NAME.iso
2239 echo -en "----\nENTER to continue..."; read i ;;
2240 *)
2241 exit 0 ;;
2242 esac ;;
2243 burn-iso)
2244 # Guess cdrom device, ask user and burn the ISO.
2246 check_root
2247 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
2248 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
2249 # We can specify an alternative ISO from the cmdline.
2250 if [ -n "$2" ] ; then
2251 iso=$2
2252 else
2253 iso=$DISTRO/$ISO_NAME.iso
2254 fi
2255 if [ ! -f "$iso" ]; then
2256 echo -e "\nUnable to find ISO : $iso\n"
2257 exit 0
2258 fi
2259 echo ""
2260 echo -e "\033[1mTazlito burn ISO\033[0m "
2261 echo "================================================================================"
2262 echo "Cdrom device : /dev/$DRIVE_NAME"
2263 echo "Drive speed : $DRIVE_SPEED"
2264 echo "ISO image : $iso"
2265 echo "================================================================================"
2266 echo ""
2267 yesorno "Burn ISO image (y/N) ? "
2268 if [ "$answer" == "y" ]; then
2269 echo ""
2270 echo "Starting Wodim to burn the iso..." && sleep 2
2271 echo "================================================================================"
2272 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
2273 echo "================================================================================"
2274 echo "ISO image is burned to cdrom."
2275 else
2276 echo -e "\nExiting. No ISO burned."
2277 fi
2278 echo ""
2279 ;;
2280 merge)
2281 # Merge multiple rootfs into one iso.
2283 if [ -z "$2" ]; then
2284 cat << EOT
2285 Usage: tazlito merge size1 iso size2 rootfs2 [sizeN rootfsN]...
2287 Merge multiple rootfs into one iso. Rootfs are like russian dolls
2288 i.e: rootfsN is a subset of rootfsN-1
2289 rootfs1 is found in iso, sizeN is the RAM size need to launch rootfsN.
2290 The boot loader will select the rootfs according to the RAM size detected.
2292 Example:
2293 $ tazlito merge 160M slitaz-core.iso 96M rootfs-justx.gz 32M rootfs-base.gz
2295 Will start slitaz-core with 160M+ RAM, slitaz-justX with 96M-160M RAM,
2296 slitaz-base with 32M-96M RAM and display an error message if RAM < 32M.
2297 EOT
2298 exit 2
2299 fi
2301 shift # skip merge
2302 append="$1 slitaz1"
2303 shift # skip size1
2304 mkdir -p $TMP_DIR/mnt $TMP_DIR/rootfs1
2306 ISO=$1.merged
2307 # Extract filesystems
2308 echo -n "Mounting $1"
2309 mount -o loop,ro $1 $TMP_DIR/mnt 2> /dev/null
2310 status || cleanup_merge
2311 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2312 rm -f $TMP_DIR/iso/boot/bzImage
2313 ln $TMP_DIR/iso/boot/vmlinuz* $TMP_DIR/iso/boot/bzImage
2314 umount -d $TMP_DIR/mnt
2315 if [ -f $TMP_DIR/iso/boot/rootfs1.gz ]; then
2316 echo "$1 is already a merged iso. Aborting."
2317 cleanup_merge
2318 fi
2319 if [ ! -f $TMP_DIR/iso/boot/isolinux/ifmem.c32 ]; then
2320 if [ ! -f /boot/isolinux/ifmem.c32 ]; then
2321 cat <<EOT
2322 No file /boot/isolinux/ifmem.c32
2323 Please install syslinux package !
2324 EOT
2325 rm -rf $TMP_DIR
2326 exit 1
2327 fi
2328 cp /boot/isolinux/ifmem.c32 $TMP_DIR/iso/boot/isolinux
2329 fi
2331 echo -n "Extracting iso/rootfs.gz"
2332 extract_rootfs $TMP_DIR/iso/boot/rootfs.gz $TMP_DIR/rootfs1 &&
2333 [ -d $TMP_DIR/rootfs1/etc ]
2334 status || cleanup_merge
2335 n=1
2336 while [ -n "$2" ]; do
2337 shift # skip rootfs N-1
2338 p=$n
2339 n=$(($n + 1))
2340 append="$append $1 slitaz$n"
2341 shift # skip size N
2342 mkdir -p $TMP_DIR/rootfs$n
2343 echo -n "Extracting $1"
2344 extract_rootfs $1 $TMP_DIR/rootfs$n &&
2345 [ -d $TMP_DIR/rootfs$n/etc ]
2346 status || cleanup_merge
2347 mergefs $TMP_DIR/rootfs$n $TMP_DIR/rootfs$p
2348 echo "Creating rootfs$p.gz"
2349 pack_rootfs $TMP_DIR/rootfs$p $TMP_DIR/iso/boot/rootfs$p.gz
2350 status
2351 done
2352 echo "Creating rootfs$n.gz"
2353 pack_rootfs $TMP_DIR/rootfs$n $TMP_DIR/iso/boot/rootfs$n.gz
2354 status
2355 rm -f $TMP_DIR/iso/boot/rootfs.gz
2356 update_bootconfig $TMP_DIR/iso/boot/isolinux "$append"
2357 create_iso $ISO $TMP_DIR/iso
2358 rm -rf $TMP_DIR
2359 ;;
2361 repack)
2362 # Repack an iso with maximum lzma compression ratio.
2365 ISO=$2
2367 mkdir -p $TMP_DIR/mnt
2368 # Extract filesystems
2369 echo -n "Mounting $ISO"
2370 mount -o loop,ro $ISO $TMP_DIR/mnt 2> /dev/null
2371 status || cleanup_merge
2372 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2373 umount -d $TMP_DIR/mnt
2375 for i in $TMP_DIR/iso/boot/rootfs* ; do
2376 echo -n "Repacking $(basename $i)"
2377 (zcat $i 2> /dev/null || unlzma -c $i || cat $i) \
2378 2>/dev/null > $TMP_DIR/rootfs
2379 lzma e $TMP_DIR/rootfs $i \
2380 $(lzma_switches $TMP_DIR/rootfs)
2381 status
2382 done
2384 create_iso $ISO $TMP_DIR/iso
2385 rm -rf $TMP_DIR ;;
2387 build-loram)
2388 # Build a Live CD for low ram systems.
2391 ISO=$2
2392 OUTPUT=$3
2393 mkdir -p $TMP_DIR/iso
2394 mount -o loop,ro -t iso9660 $ISO $TMP_DIR/iso
2395 if ! check_iso_for_loram ; then
2396 echo "$2 is not a valid SliTaz live CD. Abort."
2397 umount -d $TMP_DIR/iso
2398 rm -rf $TMP_DIR
2399 exit 1
2400 fi
2402 case "$4" in
2403 cdrom) build_loram_cdrom ;;
2404 smallcdrom) build_loram_cdrom small ;;
2405 http) build_loram_http ;;
2406 *) build_loram_ram ;;
2407 esac
2408 umount -d $TMP_DIR/iso
2409 rm -rf $TMP_DIR ;;
2412 frugal-install|-fi)
2413 ISO_IMAGE="$2"
2414 echo ""
2415 mkdir -p /boot/frugal
2416 if [ -f "$ISO_IMAGE" ]; then
2417 echo -n "Using ISO image: $ISO_IMAGE"
2418 mkdir -p /tmp/iso && mount -o loop $ISO_IMAGE /tmp/iso
2419 status
2420 echo -n "Installing the Kernel and rootfs..."
2421 cp -a /tmp/iso/boot/bzImage /boot/frugal
2422 cp -a /tmp/iso/boot/rootfs.gz /boot/frugal
2423 umount /tmp/iso
2424 status
2425 else
2426 echo -n "Using distro: $DISTRO"
2427 cd $DISTRO && status
2428 echo -n "Installing the Kernel and rootfs..."
2429 cp -a $DISTRO/rootcd/boot/bzImage /boot/frugal
2430 cp -a $DISTRO/rootcd/boot/rootfs.gz /boot/frugal
2431 status
2432 fi
2433 # Grub entry
2434 if ! grep -q "^kernel /boot/frugal/bzImage" /boot/grub/menu.lst; then
2435 echo -n "Configuring GRUB menu list..."
2436 cat >> /boot/grub/menu.lst << EOT
2437 title SliTaz GNU/Linux (frugal)
2438 root (hd0,0)
2439 kernel /boot/frugal/bzImage root=/dev/null
2440 initrd /boot/frugal/rootfs.gz
2441 EOT
2442 else
2443 echo -n "GRUB menu list is up-to-date..."
2444 fi
2445 status
2446 echo "" ;;
2448 emu-iso)
2449 # Emulate an ISO image with Qemu.
2450 if [ -n "$2" ] ; then
2451 iso=$2
2452 else
2453 iso=$DISTRO/$ISO_NAME.iso
2454 fi
2455 if [ ! -f "$iso" ]; then
2456 echo -e "\nUnable to find ISO : $iso\n"
2457 exit 0
2458 fi
2459 if [ ! -x "/usr/bin/qemu" ]; then
2460 echo -e "\nUnable to find Qemu binary. Please install: qemu\n"
2461 exit 0
2462 fi
2463 echo -e "\nStarting Qemu emulator:\n"
2464 echo -e "qemu $QEMU_OPTS $iso\n"
2465 qemu $QEMU_OPTS $iso ;;
2467 usage|*)
2468 # Clear and print usage also for all unknown commands.
2470 clear
2471 usage ;;
2472 esac
2474 exit 0