tazlito view tazlito @ rev 214

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