tazlito view tazlito @ rev 267

Fix messages dispay when extracting
author Christophe Lincoln <pankso@slitaz.org>
date Sat Mar 24 16:43:55 2012 +0100 (2012-03-24)
parents a6c0d01e8a9c
children dad13f80ffc3
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 status
1732 echo -n "Creating distro-packages.list..."
1733 mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
1734 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
1735 status
1736 if [ -f "$TMP_DIR/$FLAVOR-distro.sh" ]; then
1737 echo -n "Extracting distro.sh... "
1738 mv $TMP_DIR/$FLAVOR-distro.sh distro.sh 2> /dev/null
1739 status
1740 fi
1741 infos="$FLAVOR.desc"
1742 for i in rootcd rootfs; do
1743 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
1744 echo -n "Adding $i files... "
1745 mkdir -p "$ADDFILES/$i"
1746 zcat $TMP_DIR/$FLAVOR.$i | \
1747 ( cd "$ADDFILES/$i"; cpio -id > /dev/null)
1748 zcat $TMP_DIR/$FLAVOR.$i | cpio -tv 2> /dev/null \
1749 > $TMP_DIR/$FLAVOR.list$i
1750 infos="$infos\n$FLAVOR.list$i"
1751 status
1752 fi
1753 done
1754 if [ -s $TMP_DIR/$FLAVOR.mirrors ]; then
1755 n=""
1756 while read line; do
1757 mkdir -p $LOCALSTATE/undigest/$FLAVOR$n
1758 echo "$line" > $LOCALSTATE/undigest/$FLAVOR$n/mirror
1759 n=$(( $n + 1 ))
1760 done < $TMP_DIR/$FLAVOR.mirrors
1761 infos="$infos\n$FLAVOR.mirrors"
1762 tazpkg recharge
1763 fi
1764 rm -f /etc/tazlito/rootfs.list
1765 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc &&
1766 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1767 sed 's/.*: \(.*\)$/\1/' > /etc/tazlito/rootfs.list
1768 echo -n "Updating tazlito.conf..."
1769 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
1770 cat tazlito.conf | grep -v "^#VOLUM_NAME" | \
1771 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
1772 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
1773 sed -i "s/ISO_NAME=.*/ISO_NAME=\"slitaz-$FLAVOR\"/" tazlito.conf
1774 status
1775 ( cd $TMP_DIR ; echo -e $infos | cpio -o -H newc ) | \
1776 gzip -9 > /etc/tazlito/info
1777 rm -Rf $TMP_DIR
1778 fi
1779 echo "================================================================================"
1780 echo -e "Flavor is ready to be generated by: tazlito gen-distro\n"
1781 ;;
1783 iso2flavor)
1784 if [ -z "$3" -o ! -s "$2" ]; then
1785 cat <<EOT
1786 Usage : tazlito iso2flavor image.iso flavor_name
1788 Create a file flavor_name.flavor from the cdrom image file image.iso
1789 EOT
1790 exit 1
1791 fi
1792 FLAVOR=${3%.flavor}
1793 mkdir -p $TMP_DIR/iso $TMP_DIR/rootfs
1794 mount -o loop,ro $2 $TMP_DIR/iso
1795 if [ -s $TMP_DIR/iso/boot/rootfs1.gz ]; then
1796 echo "META flavors are not supported."
1797 umount -d $TMP_DIR/iso
1798 elif [ ! -s $TMP_DIR/iso/boot/rootfs.gz ]; then
1799 echo "No /boot/rootfs.gz in iso image. Needs a SliTaz iso."
1800 umount -d $TMP_DIR/iso
1801 else
1802 ( unlzma -c $TMP_DIR/iso/boot/rootfs.gz || \
1803 zcat $TMP_DIR/iso/boot/rootfs.gz ) | \
1804 ( cd $TMP_DIR/rootfs ; cpio -idmu > /dev/null 2>&1 )
1805 if [ ! -s $TMP_DIR/rootfs/etc/slitaz-release ]; then
1806 echo "No file /etc/slitaz-release in /boot/rootfs.gz of iso image. Needs a non loram SliTaz iso."
1807 umount -d $TMP_DIR/iso
1808 else
1809 ROOTFS_SIZE=$(du -hs $TMP_DIR/rootfs | awk '{ print $1 }')
1810 RAM_SIZE=$(du -s $TMP_DIR/rootfs | awk '{ print 32*int(($1+36000)/32768) "M" }')
1811 cp -a $TMP_DIR/iso $TMP_DIR/rootcd
1812 ISO_SIZE=$(df -h $TMP_DIR/iso | awk 'END { print $2 }')
1813 BUILD_DATE=$(date +%Y%m%d\ \at\ \%H:%M:%S -r $TMP_DIR/iso/md5sum)
1814 umount -d $TMP_DIR/iso
1815 INITRAMFS_SIZE=$(du -chs $TMP_DIR/rootcd/boot/rootfs.gz | awk '{ s=$1 } END { print $1 }')
1816 rm -f $TMP_DIR/rootcd/boot/rootfs.gz $TMP_DIR/rootcd/md5sum
1817 mv $TMP_DIR/rootcd/boot $TMP_DIR/rootfs
1818 sed 's/.* \(.*\).tazpkg*/\1/' > $TMP_DIR/$FLAVOR.pkglist \
1819 < $TMP_DIR/rootfs$INSTALLED.md5
1820 #[ -s $TMP_DIR/rootfs/etc/tazlito/distro-packages.list ] &&
1821 # mv $TMP_DIR/rootfs/etc/tazlito/distro-packages.list $TMP_DIR/$FLAVOR.pkglist
1822 PKGCNT=$(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l | awk '{ print $1 }')
1823 find_flavor_rootfs $TMP_DIR/rootfs
1824 [ -d $TMP_DIR/rootfs/boot ] && mv $TMP_DIR/rootfs/boot $TMP_DIR/rootcd
1825 [ -n "$(ls $TMP_DIR/rootfs)" ] && ( cd $TMP_DIR/rootfs ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootfs
1826 [ -n "$(ls $TMP_DIR/rootcd)" ] && ( cd $TMP_DIR/rootcd ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootcd
1827 rm -rf $TMP_DIR/rootcd $TMP_DIR/rootfs
1828 VERSION=""; MAINTAINER=""
1829 echo -en "Flavor short description \007: "; read -t 30 DESCRIPTION
1830 if [ -n "$DESCRIPTION" ]; then
1831 echo -en "Flavor version : "; read -t 30 VERSION
1832 echo -en "Flavor maintainer (your email) : "; read -t 30 MAINTAINER
1833 fi
1834 [ -n "$DESCRIPTION" ] || DESCRIPTION="Slitaz $FLAVOR flavor"
1835 [ -n "$VERSION" ] || VERSION="1.0"
1836 [ -n "$MAINTAINER" ] || MAINTAINER="nobody@slitaz.org"
1837 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1838 Flavor : $FLAVOR
1839 Description : $DESCRIPTION
1840 Version : $VERSION
1841 Maintainer : $MAINTAINER
1842 LiveCD RAM size : $RAM_SIZE
1843 Build date : $BUILD_DATE
1844 Packages : $PKGCNT
1845 Rootfs size : $ROOTFS_SIZE
1846 Initramfs size : $INITRAMFS_SIZE
1847 ISO image size : $ISO_SIZE
1848 ================================================================================
1850 EOT
1851 ( cd $TMP_DIR ; ls $FLAVOR.* | cpio -o -H newc ) | gzip -9 > $FLAVOR.flavor
1852 cat <<EOT
1853 Tazlito can't detect each file installed during a package post_install.
1854 You should extract this flavor (tazlito extract-flavor $FLAVOR),
1855 check the files in /home/slitaz/flavors/$(cat /etc/slitaz-release)/$FLAVOR/rootfs tree and remove
1856 files generated by post_installs.
1857 Check /home/slitaz/flavors/$(cat /etc/slitaz-release)/$FLAVOR/receipt too and repack the flavor
1858 (tazlito pack-flavor $FLAVOR)
1859 EOT
1860 fi
1861 fi
1862 rm -rf $TMP_DIR
1863 ;;
1865 check-list)
1866 # Use current packages list in $PWD by default.
1867 DISTRO_PKGS_LIST=distro-packages.list
1868 [ -d "$2" ] && DISTRO_PKGS_LIST=$2/distro-packages.list
1869 [ -f "$2" ] && DISTRO_PKGS_LIST=$2
1870 [ ! -f $DISTRO_PKGS_LIST ] && echo "No packages list found." && exit 0
1871 echo ""
1872 echo -e "\033[1mLiveCD packages list check\033[0m"
1873 echo "================================================================================"
1874 for pkg in `cat $DISTRO_PKGS_LIST`
1875 do
1876 if ! grep -q "$pkg" $LOCALSTATE/packages.list; then
1877 echo "Updating: $pkg"
1878 up=$(($up + 1))
1879 fi
1880 done
1881 [ -z $up ] && echo -e "List is up-to-date\n" && exit 0
1882 echo "================================================================================"
1883 echo -e "Updates: $up\n" ;;
1884 gen-distro)
1885 # Generate a live distro tree with a set of packages.
1887 check_root
1888 time=$(date +%s)
1890 # Check if a package list was specified on cmdline.
1891 LIST_NAME="distro-packages.list"
1892 CDROM=""
1893 while [ -n "$2" ]; do
1894 case "$2" in
1895 --iso=*)
1896 CDROM="-o loop ${2#--iso=}"
1897 ;;
1898 --cdrom)
1899 CDROM="/dev/cdrom"
1900 ;;
1901 --force)
1902 DELETE_ROOTFS="true"
1903 ;;
1904 *) if [ ! -f "$2" ] ; then
1905 echo -e "\nUnable to find the specified packages list."
1906 echo -e "List name : $2\n"
1907 exit 1
1908 fi
1909 LIST_NAME=$2
1910 ;;
1911 esac
1912 shift
1913 done
1915 if [ -d $ROOTFS ] ; then
1916 # Delete $ROOTFS if --force is set on command line
1917 if [ ! -z $DELETE_ROOTFS ]; then
1918 rm -rf $ROOTFS
1919 unset $DELETE_ROOTFS
1920 else
1921 echo -e "\nA rootfs exists in : $DISTRO"
1922 echo -e "Please clean the distro tree or change directory path.\n"
1923 exit 0
1924 fi
1925 fi
1926 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
1927 # Build list with installed packages
1928 for i in $(ls $INSTALLED); do
1929 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
1930 EXTRAVERSION=""
1931 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
1932 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
1933 done
1934 fi
1935 # Exit if no list name.
1936 if [ ! -f "$LIST_NAME" ]; then
1937 echo -e "\nNo packages list found or specified. Please read the docs.\n"
1938 exit 0
1939 fi
1940 # Start generation.
1941 echo ""
1942 echo -e "\033[1mTazlito generating a distro\033[0m"
1943 echo "================================================================================"
1944 # Misc checks
1945 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
1946 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
1947 # Get the list of packages using cat for a file list.
1948 LIST=`cat $LIST_NAME`
1949 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
1950 REPACK=""
1951 DOWNLOAD=""
1952 for pkg in $LIST
1953 do
1954 [ "$pkg" = "" ] && continue
1955 pkg=${pkg%.tazpkg}
1956 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
1957 PACKAGE=$(installed_package_name $pkg)
1958 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
1959 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
1960 echo -e "\nUnable to find $pkg in the repository."
1961 echo -e "Path : $PACKAGES_REPOSITORY\n"
1962 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
1963 yesorno "Repack packages from rootfs (y/N) ? "
1964 REPACK="$answer"
1965 [ "$answer" = "y" ] || REPACK="n"
1966 [ "$DOWNLOAD" = "y" ] && break
1967 fi
1968 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
1969 yesorno "Download packages from mirror (Y/n) ? "
1970 DOWNLOAD="$answer"
1971 if [ "$answer" = "n" ]; then
1972 [ -z "$PACKAGE" ] && exit 1
1973 else
1974 DOWNLOAD="y"
1975 [ -n "$REPACK" ] && break
1976 fi
1977 fi
1978 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
1979 done
1981 # Mount cdrom to be able to repack boot-loader packages
1982 if [ ! -e /boot -a -n "$CDROM" ]; then
1983 mkdir $TMP_MNT
1984 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
1985 ln -s $TMP_MNT/boot /
1986 if [ ! -d "$ADDFILES/rootcd" ] ; then
1987 mkdir -p $ADDFILES/rootcd
1988 for i in $(ls $TMP_MNT); do
1989 [ "$i" = "boot" ] && continue
1990 cp -a $TMP_MNT/$i $ADDFILES/rootcd
1991 done
1992 fi
1993 else
1994 rmdir $TMP_MNT
1995 fi
1996 fi
1998 # Root fs stuff.
1999 echo "Preparing the rootfs directory..."
2000 mkdir -p $ROOTFS
2001 for pkg in $LIST
2002 do
2003 [ "$pkg" = "" ] && continue
2004 # First copy and extract the package in tmp dir.
2005 pkg=${pkg%.tazpkg}
2006 PACKAGE=$(installed_package_name $pkg)
2007 mkdir -p $TMP_DIR
2008 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
2009 # Look for package in cache
2010 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
2011 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
2012 # Look for package in running distribution
2013 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
2014 tazpkg repack $PACKAGE && \
2015 mv $pkg.tazpkg $PACKAGES_REPOSITORY
2016 fi
2017 fi
2018 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
2019 # Get package from mirror
2020 [ "$DOWNLOAD" = "y" ] && \
2021 download $pkg.tazpkg && \
2022 mv $pkg.tazpkg $PACKAGES_REPOSITORY
2023 fi
2024 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
2025 echo "Missing package $pkg."
2026 cleanup
2027 exit 1
2028 fi
2029 done
2030 if [ -f non-free.list ]; then
2031 echo "Preparing non-free packages..."
2032 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
2033 for pkg in $(cat non-free.list); do
2034 if [ ! -d $INSTALLED/$pkg ]; then
2035 if [ ! -d $INSTALLED/get-$pkg ]; then
2036 tazpkg get-install get-$pkg
2037 fi
2038 get-$pkg
2039 fi
2040 tazpkg repack $pkg
2041 pkg=$(ls $pkg*.tazpkg)
2042 grep -q "^$pkg$" $LIST_NAME || \
2043 echo $pkg >>$LIST_NAME
2044 mv $pkg $PACKAGES_REPOSITORY
2045 done
2046 fi
2047 cp $LIST_NAME $DISTRO/distro-packages.list
2048 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/distro-packages.list > $DISTRO/list-packages
2049 cd $PACKAGES_REPOSITORY
2050 for pkg in $(cat $DISTRO/list-packages)
2051 do
2052 echo -n "Installing package: $pkg"
2053 yes y | tazpkg install $pkg --root=$ROOTFS 2>&1 >> $log || exit 1
2054 status
2055 done
2056 rm -f $ROOTFS/var/lib/tazpkg/packages.*
2057 cd $DISTRO
2058 cp distro-packages.list $ROOTFS/etc/tazlito
2059 # Copy all files from $ADDFILES/rootfs to the rootfs.
2060 if [ -d "$ADDFILES/rootfs" ] ; then
2061 echo -n "Copying addfiles content to the rootfs... "
2062 cp -a $ADDFILES/rootfs/* $ROOTFS
2063 status
2064 fi
2065 echo -n "Root filesystem is generated..." && status
2066 # Root CD part.
2067 echo -n "Preparing the rootcd directory..."
2068 mkdir -p $ROOTCD
2069 status
2070 # Move the boot dir with the Linux kernel from rootfs.
2071 # The boot dir goes directly on the CD.
2072 if [ -d "$ROOTFS/boot" ] ; then
2073 echo -n "Moving the boot directory..."
2074 mv $ROOTFS/boot $ROOTCD
2075 cd $ROOTCD/boot
2076 ln vmlinuz-* bzImage
2077 status
2078 fi
2079 cd $DISTRO
2080 # Copy all files from $ADDFILES/rootcd to the rootcd.
2081 if [ -d "$ADDFILES/rootcd" ] ; then
2082 echo -n "Copying addfiles content to the rootcd... "
2083 cp -a $ADDFILES/rootcd/* $ROOTCD
2084 status
2085 fi
2086 # Execute the distro script used to perform tasks in the rootfs
2087 # before compression. Give rootfs path in arg
2088 [ -z $DISTRO_SCRIPT ] && DISTRO_SCRIPT=$TOP_DIR/distro.sh
2089 if [ -x $DISTRO_SCRIPT ]; then
2090 echo "Executing distro script..."
2091 sh $DISTRO_SCRIPT $DISTRO
2092 fi
2093 if [ -s /etc/tazlito/rootfs.list ]; then
2094 FLAVOR_LIST="$(awk '{ for (i = 2; i <= NF; i+=2) \
2095 printf("%s ",$i) }' < /etc/tazlito/rootfs.list)"
2096 sed -i "s/ *//;s/)/), flavors $FLAVOR_LIST/" \
2097 $ROOTCD/boot/isolinux/isolinux.msg
2098 [ -f $ROOTCD/boot/isolinux/ifmem.c32 ] ||
2099 cp /boot/isolinux/ifmem.c32 $ROOTCD/boot/isolinux
2100 n=0
2101 last=$ROOTFS
2102 while read flavor; do
2103 n=$(($n+1))
2104 echo "Building $flavor rootfs..."
2105 [ -s $TOP_DIR/$flavor.flavor ] &&
2106 cp $TOP_DIR/$flavor.flavor .
2107 [ -s $flavor.flavor ] || download $flavor.flavor
2108 zcat $flavor.flavor | cpio -i \
2109 $flavor.pkglist $flavor.rootfs
2110 sed 's/.*/&.tazpkg/' < $flavor.pkglist \
2111 > $DISTRO/list-packages0$n
2112 mkdir ${ROOTFS}0$n
2113 cd $PACKAGES_REPOSITORY
2114 yes y | tazpkg install-list \
2115 $DISTRO/list-packages0$n --root=${ROOTFS}0$n
2116 rm -rf ${ROOTFS}0$n/boot ${ROOTFS}0$n/var/lib/tazpkg/packages.*
2117 status
2118 cd $DISTRO
2119 if [ -s $flavor.rootfs ]; then
2120 echo "Adding $flavor rootfs extra files..."
2121 zcat $flavor.rootfs | \
2122 ( cd ${ROOTFS}0$n ; cpio -idmu )
2123 fi
2124 mv $flavor.pkglist ${ROOTFS}0$n/etc/tazlito/distro-packages.list
2125 rm -f $flavor.flavor install-list
2126 mergefs ${ROOTFS}0$n $last
2127 last=${ROOTFS}0$n
2128 done <<EOT
2129 $(awk '{ for (i = 4; i <= NF; i+=2) print $i; }' < /etc/tazlito/rootfs.list)
2130 EOT
2131 i=$(($n+1))
2132 while [ $n -gt 0 ]; do
2133 mv ${ROOTFS}0$n ${ROOTFS}$i
2134 echo "Compression ${ROOTFS}0$n ($(du -hs ${ROOTFS}$i | awk '{ print $1 }')) ..."
2135 gen_initramfs ${ROOTFS}$i
2136 n=$(($n-1))
2137 i=$(($i-1))
2138 done
2139 mv $ROOTFS ${ROOTFS}$i
2140 gen_initramfs ${ROOTFS}$i
2141 update_bootconfig $ROOTCD/boot/isolinux \
2142 "$(cat /etc/tazlito/rootfs.list)"
2143 else
2144 # Initramfs and ISO image stuff.
2145 gen_initramfs $ROOTFS
2146 fi
2147 gen_livecd_isolinux
2148 distro_stats
2149 cleanup
2150 ;;
2151 clean-distro)
2152 # Remove old distro tree.
2154 check_root
2155 echo ""
2156 echo -e "\033[1mCleaning :\033[0m $DISTRO"
2157 echo "================================================================================"
2158 if [ -d "$DISTRO" ] ; then
2159 if [ -d "$ROOTFS" ] ; then
2160 echo -n "Removing the rootfs..."
2161 rm -f $DISTRO/$INITRAMFS
2162 rm -rf $ROOTFS
2163 status
2164 fi
2165 if [ -d "$ROOTCD" ] ; then
2166 echo -n "Removing the rootcd..."
2167 rm -rf $ROOTCD
2168 status
2169 fi
2170 echo -n "Removing eventual ISO image..."
2171 rm -f $DISTRO/$ISO_NAME.iso
2172 rm -f $DISTRO/$ISO_NAME.md5
2173 status
2174 fi
2175 echo "================================================================================"
2176 echo ""
2177 ;;
2178 check-distro)
2179 # Check for a few LiveCD needed files not installed by packages.
2181 check_rootfs
2182 echo ""
2183 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
2184 echo "================================================================================"
2185 # SliTaz release info.
2186 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
2187 echo "Missing release info : /etc/slitaz-release"
2188 else
2189 release=`cat $ROOTFS/etc/slitaz-release`
2190 echo -n "Release : $release"
2191 status
2192 fi
2193 # Tazpkg mirror.
2194 if [ ! -f "$ROOTFS$LOCALSTATE/mirror" ]; then
2195 echo -n "Mirror URL : Missing $LOCALSTATE/mirror"
2196 todomsg
2197 else
2198 echo -n "Mirror configuration exists..."
2199 status
2200 fi
2201 # Isolinux msg
2202 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.*g; then
2203 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
2204 todomsg
2205 else
2206 echo -n "Isolinux message seems good..."
2207 status
2208 fi
2209 echo "================================================================================"
2210 echo ""
2211 ;;
2212 writeiso)
2213 # Writefs to ISO image including /home unlike gen-distro we dont use
2214 # packages to generate a rootfs, we build a compressed rootfs with all
2215 # the current filesystem similar to 'tazusb writefs'.
2217 DISTRO="/home/slitaz/distro"
2218 ROOTCD="$DISTRO/rootcd"
2219 if [ -z $2 ]; then
2220 COMPRESSION=none
2221 else
2222 COMPRESSION=$2
2223 fi
2224 if [ -z $3 ]; then
2225 ISO_NAME="slitaz"
2226 else
2227 ISO_NAME="$3"
2228 fi
2229 check_root
2230 # Start info
2231 echo ""
2232 echo -e "\033[1mWrite filesystem to ISO\033[0m
2233 ===============================================================================
2234 The command writeiso will write the current filesystem into a suitable cpio
2235 archive (rootfs.gz) and generate a bootable ISO image (slitaz.iso).
2237 Archive compression: $COMPRESSION"
2238 echo ""
2240 # Save some space
2241 rm /var/cache/tazpkg/* -r -f
2242 rm -rf /home/slitaz/distro
2244 # Optionally remove sound card selection and screen resolution.
2245 echo "Do you wish to remove the sound card and screen configs ? "
2246 echo -n "Press ENTER to keep or answer (No|yes|exit): "
2247 read anser
2248 case $anser in
2249 e|E|"exit"|Exit)
2250 exit 0 ;;
2251 y|Y|yes|Yes)
2252 echo -n "Removing current sound card and screen configurations..."
2253 rm -f /var/lib/sound-card-driver
2254 rm -f /etc/asound.state
2255 rm -f /etc/X11/screen.conf
2256 rm -f /etc/X11/xorg.conf ;;
2257 *)
2258 echo -n "Keeping current sound card and screen configurations..." ;;
2259 esac
2260 status
2262 cd /
2263 # Create list of files including default user files since it is defined in /etc/passwd
2264 # and some new users might have been added.
2265 find bin etc init sbin var dev lib root usr home >/tmp/list
2267 for dir in proc sys tmp mnt media media/cdrom media/flash media/usbdisk
2268 do
2269 echo $dir >>/tmp/list
2270 done
2272 # Generate initramfs with specified compression and display rootfs
2273 # size in realtime.
2274 rm -f /tmp/rootfs
2275 write_initramfs &
2276 sleep 2
2277 cd - > /dev/null
2278 echo -en "\nFilesystem size:"
2279 while [ ! -f /tmp/rootfs ]
2280 do
2281 sleep 1
2282 echo -en "\\033[18G`du -sh /rootfs.gz | awk '{print $1}'` "
2283 done
2284 echo -e "\n"
2286 # Move freshly generated rootfs to the cdrom.
2287 mkdir -p $ROOTCD/boot
2288 mv -f /rootfs.gz $ROOTCD/boot
2290 # Now we need the kernel and isolinux files.
2291 if mount /dev/cdrom /media/cdrom 2>/dev/null; then
2292 cp /media/cdrom/boot/bzImage $ROOTCD/boot
2293 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
2294 unmeta_boot $ROOTCD
2295 umount /media/cdrom
2296 else
2297 echo -e "
2298 Unable to mount the cdrom to copy the Kernel and needed files. When SliTaz
2299 is running in RAM the kernel and bootloader files are kept on the cdrom.
2300 Please insert a LiveCD or unmount the current cdrom to let Tazlito handle
2301 the media.\n"
2302 echo -en "----\nENTER to continue..."; read i
2303 exit 1
2304 fi
2306 # Generate the iso image.
2307 cd $DISTRO
2308 echo "Generating ISO image..."
2309 genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
2310 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
2311 -V "SliTaz" -input-charset iso8859-1 -boot-info-table $ROOTCD
2312 if [ -x /usr/bin/isohybrid ]; then
2313 echo -n "Creating hybrid ISO..."
2314 /usr/bin/isohybrid $ISO_NAME.iso 2> /dev/null
2315 status
2316 fi
2317 echo -n "Creating the ISO md5sum..."
2318 md5sum $ISO_NAME.iso > $ISO_NAME.md5
2319 status
2321 echo "==============================================================================="
2322 echo "ISO image: `du -sh /home/slitaz/distro/$ISO_NAME.iso`"
2323 echo ""
2324 echo -n "Exit or burn ISO to cdrom (Exit|burn)? "; read anser
2325 case $anser in
2326 burn)
2327 eject
2328 echo -n "Please insert a blank cdrom and press ENTER..."
2329 read i && sleep 2
2330 tazlito burn-iso /home/slitaz/distro/$ISO_NAME.iso
2331 echo -en "----\nENTER to continue..."; read i ;;
2332 *)
2333 exit 0 ;;
2334 esac ;;
2335 burn-iso)
2336 # Guess cdrom device, ask user and burn the ISO.
2338 check_root
2339 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
2340 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
2341 # We can specify an alternative ISO from the cmdline.
2342 if [ -n "$2" ] ; then
2343 iso=$2
2344 else
2345 iso=$DISTRO/$ISO_NAME.iso
2346 fi
2347 if [ ! -f "$iso" ]; then
2348 echo -e "\nUnable to find ISO : $iso\n"
2349 exit 0
2350 fi
2351 echo ""
2352 echo -e "\033[1mTazlito burn ISO\033[0m "
2353 echo "================================================================================"
2354 echo "Cdrom device : /dev/$DRIVE_NAME"
2355 echo "Drive speed : $DRIVE_SPEED"
2356 echo "ISO image : $iso"
2357 echo "================================================================================"
2358 echo ""
2359 yesorno "Burn ISO image (y/N) ? "
2360 if [ "$answer" == "y" ]; then
2361 echo ""
2362 echo "Starting Wodim to burn the iso..." && sleep 2
2363 echo "================================================================================"
2364 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
2365 echo "================================================================================"
2366 echo "ISO image is burned to cdrom."
2367 else
2368 echo -e "\nExiting. No ISO burned."
2369 fi
2370 echo ""
2371 ;;
2372 merge)
2373 # Merge multiple rootfs into one iso.
2375 if [ -z "$2" ]; then
2376 cat << EOT
2377 Usage: tazlito merge size1 iso size2 rootfs2 [sizeN rootfsN]...
2379 Merge multiple rootfs into one iso. Rootfs are like russian dolls
2380 i.e: rootfsN is a subset of rootfsN-1
2381 rootfs1 is found in iso, sizeN is the RAM size need to launch rootfsN.
2382 The boot loader will select the rootfs according to the RAM size detected.
2384 Example:
2385 $ tazlito merge 160M slitaz-core.iso 96M rootfs-justx.gz 32M rootfs-base.gz
2387 Will start slitaz-core with 160M+ RAM, slitaz-justX with 96M-160M RAM,
2388 slitaz-base with 32M-96M RAM and display an error message if RAM < 32M.
2389 EOT
2390 exit 2
2391 fi
2393 shift # skip merge
2394 append="$1 slitaz1"
2395 shift # skip size1
2396 mkdir -p $TMP_DIR/mnt $TMP_DIR/rootfs1
2398 ISO=$1.merged
2399 # Extract filesystems
2400 echo -n "Mounting $1"
2401 mount -o loop,ro $1 $TMP_DIR/mnt 2> /dev/null
2402 status || cleanup_merge
2403 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2404 rm -f $TMP_DIR/iso/boot/bzImage
2405 ln $TMP_DIR/iso/boot/vmlinuz* $TMP_DIR/iso/boot/bzImage
2406 umount -d $TMP_DIR/mnt
2407 if [ -f $TMP_DIR/iso/boot/rootfs1.gz ]; then
2408 echo "$1 is already a merged iso. Aborting."
2409 cleanup_merge
2410 fi
2411 if [ ! -f $TMP_DIR/iso/boot/isolinux/ifmem.c32 ]; then
2412 if [ ! -f /boot/isolinux/ifmem.c32 ]; then
2413 cat <<EOT
2414 No file /boot/isolinux/ifmem.c32
2415 Please install syslinux package !
2416 EOT
2417 rm -rf $TMP_DIR
2418 exit 1
2419 fi
2420 cp /boot/isolinux/ifmem.c32 $TMP_DIR/iso/boot/isolinux
2421 fi
2423 echo -n "Extracting iso/rootfs.gz"
2424 extract_rootfs $TMP_DIR/iso/boot/rootfs.gz $TMP_DIR/rootfs1 &&
2425 [ -d $TMP_DIR/rootfs1/etc ]
2426 status || cleanup_merge
2427 n=1
2428 while [ -n "$2" ]; do
2429 shift # skip rootfs N-1
2430 p=$n
2431 n=$(($n + 1))
2432 append="$append $1 slitaz$n"
2433 shift # skip size N
2434 mkdir -p $TMP_DIR/rootfs$n
2435 echo -n "Extracting $1"
2436 extract_rootfs $1 $TMP_DIR/rootfs$n &&
2437 [ -d $TMP_DIR/rootfs$n/etc ]
2438 status || cleanup_merge
2439 mergefs $TMP_DIR/rootfs$n $TMP_DIR/rootfs$p
2440 echo "Creating rootfs$p.gz"
2441 pack_rootfs $TMP_DIR/rootfs$p $TMP_DIR/iso/boot/rootfs$p.gz
2442 status
2443 done
2444 echo "Creating rootfs$n.gz"
2445 pack_rootfs $TMP_DIR/rootfs$n $TMP_DIR/iso/boot/rootfs$n.gz
2446 status
2447 rm -f $TMP_DIR/iso/boot/rootfs.gz
2448 update_bootconfig $TMP_DIR/iso/boot/isolinux "$append"
2449 create_iso $ISO $TMP_DIR/iso
2450 rm -rf $TMP_DIR
2451 ;;
2453 repack)
2454 # Repack an iso with maximum lzma compression ratio.
2457 ISO=$2
2459 mkdir -p $TMP_DIR/mnt
2460 # Extract filesystems
2461 echo -n "Mounting $ISO"
2462 mount -o loop,ro $ISO $TMP_DIR/mnt 2> /dev/null
2463 status || cleanup_merge
2464 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2465 umount -d $TMP_DIR/mnt
2467 for i in $TMP_DIR/iso/boot/rootfs* ; do
2468 echo -n "Repacking $(basename $i)"
2469 (zcat $i 2> /dev/null || unlzma -c $i || cat $i) \
2470 2>/dev/null > $TMP_DIR/rootfs
2471 lzma e $TMP_DIR/rootfs $i \
2472 $(lzma_switches $TMP_DIR/rootfs)
2473 status
2474 done
2476 create_iso $ISO $TMP_DIR/iso
2477 rm -rf $TMP_DIR ;;
2479 build-loram)
2480 # Build a Live CD for low ram systems.
2483 ISO=$2
2484 OUTPUT=$3
2485 if [ -z "$3" ]; then
2486 echo "Usage: tazlito $1 input.iso output.iso [cdrom|smallcdrom|http|ram]"
2487 exit 1
2488 fi
2489 mkdir -p $TMP_DIR/iso
2490 mount -o loop,ro -t iso9660 $ISO $TMP_DIR/iso
2491 if ! check_iso_for_loram ; then
2492 echo "$2 is not a valid SliTaz live CD. Abort."
2493 umount -d $TMP_DIR/iso
2494 rm -rf $TMP_DIR
2495 exit 1
2496 fi
2498 case "$4" in
2499 cdrom) build_loram_cdrom ;;
2500 smallcdrom) build_loram_cdrom small ;;
2501 http) build_loram_http ;;
2502 *) build_loram_ram ;;
2503 esac
2504 umount -d $TMP_DIR/iso
2505 rm -rf $TMP_DIR ;;
2508 frugal-install|-fi)
2509 ISO_IMAGE="$2"
2510 echo ""
2511 mkdir -p /boot/frugal
2512 if [ -f "$ISO_IMAGE" ]; then
2513 echo -n "Using ISO image: $ISO_IMAGE"
2514 mkdir -p /tmp/iso && mount -o loop $ISO_IMAGE /tmp/iso
2515 status
2516 echo -n "Installing the Kernel and rootfs..."
2517 cp -a /tmp/iso/boot/bzImage /boot/frugal
2518 if [ -f $DISTRO/rootcd/boot/rootfs1.gz ]; then
2519 cd /tmp/iso/boot
2520 cat $(ls -r rootfs*.gz) > /boot/frugal/rootfs.gz
2521 else
2522 cp -a /tmp/iso/boot/rootfs.gz /boot/frugal
2523 fi
2524 umount /tmp/iso
2525 status
2526 else
2527 echo -n "Using distro: $DISTRO"
2528 cd $DISTRO && status
2529 echo -n "Installing the Kernel and rootfs..."
2530 cp -a $DISTRO/rootcd/boot/bzImage /boot/frugal
2531 if [ -f $DISTRO/rootcd/boot/rootfs1.gz ]; then
2532 cd $DISTRO/rootcd/boot
2533 cat $(ls -r rootfs*.gz) > /boot/frugal/rootfs.gz
2534 else
2535 cp -a $DISTRO/rootcd/boot/rootfs.gz /boot/frugal
2536 fi
2537 status
2538 fi
2539 # Grub entry
2540 if ! grep -q "^kernel /boot/frugal/bzImage" /boot/grub/menu.lst; then
2541 echo -n "Configuring GRUB menu list..."
2542 cat >> /boot/grub/menu.lst << EOT
2543 title SliTaz GNU/Linux (frugal)
2544 root (hd0,0)
2545 kernel /boot/frugal/bzImage root=/dev/null
2546 initrd /boot/frugal/rootfs.gz
2547 EOT
2548 else
2549 echo -n "GRUB menu list is up-to-date..."
2550 fi
2551 status
2552 echo "" ;;
2554 emu-iso)
2555 # Emulate an ISO image with Qemu.
2556 if [ -n "$2" ] ; then
2557 iso=$2
2558 else
2559 iso=$DISTRO/$ISO_NAME.iso
2560 fi
2561 if [ ! -f "$iso" ]; then
2562 echo -e "\nUnable to find ISO : $iso\n"
2563 exit 0
2564 fi
2565 if [ ! -x "/usr/bin/qemu" ]; then
2566 echo -e "\nUnable to find Qemu binary. Please install: qemu\n"
2567 exit 0
2568 fi
2569 echo -e "\nStarting Qemu emulator:\n"
2570 echo -e "qemu $QEMU_OPTS $iso\n"
2571 qemu $QEMU_OPTS $iso ;;
2573 usage|*)
2574 # Clear and print usage also for all unknown commands.
2576 clear
2577 usage ;;
2578 esac
2580 exit 0