tazlito view tazlito @ rev 245

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