tazlito view tazlito @ rev 277

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