tazlito view tazlito @ rev 299

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