tazlito view tazlito @ rev 224

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