tazlito view tazlito @ rev 228

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