tazlito view tazlito @ rev 264

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