tazlito view tazlito @ rev 285

Add tazlito deduplicate
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Jul 09 11:50:22 2012 +0200 (2012-07-09)
parents ce45f609782c
children f9f9ab92b556
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 }
262 # Generate a new ISO image using isolinux.
263 gen_livecd_isolinux()
264 {
265 # Some packages may want to alter iso
266 genisohooks iso
267 if [ ! -f "$ROOTCD/boot/isolinux/isolinux.bin" ]; then
268 echo -e "\nUnable to find isolinux binary.\n"
269 cleanup
270 exit 0
271 fi
272 # Set date for boot msg.
273 if grep -q 'XXXXXXXX' $ROOTCD/boot/isolinux/isolinux.*g; then
274 DATE=`date +%Y%m%d`
275 echo -n "Setting build date to: $DATE..."
276 sed -i "s/XXXXXXXX/$DATE/" $ROOTCD/boot/isolinux/isolinux.*g
277 status
278 fi
279 cd $DISTRO
280 create_iso $ISO_NAME.iso $ROOTCD
281 echo -n "Creating the ISO md5sum..."
282 md5sum $ISO_NAME.iso > $ISO_NAME.md5
283 status
284 separator
285 # Some packages may want to alter final iso
286 genisohooks final
287 }
289 lzma_history_bits()
290 {
291 #
292 # This generates an ISO which boots with Qemu but gives
293 # rootfs errors in frugal or liveUSB mode.
294 #
295 #local n
296 #local sz
297 #n=20 # 1Mb
298 #sz=$(du -sk $1 | cut -f1)
299 #while [ $sz -gt 1024 -a $n -lt 28 ]; do
300 #n=$(( $n + 1 ))
301 #sz=$(( $sz / 2 ))
302 #done
303 #echo $n
304 echo 24
305 }
307 lzma_switches()
308 {
309 local proc=$(grep -s '^processor' < /proc/cpuinfo | wc -l)
310 echo "-d$(lzma_history_bits $1) -mt${proc:-1}"
311 }
313 lzma_set_size()
314 {
315 # Update size field for lzma'd file packed using -si switch
316 local n
317 local i
318 return # Need to fix kernel code ?
319 n=$(unlzma -c $1 | wc -c)
320 for i in $(seq 1 8); do
321 printf '\\\\x%02X' $(($n & 255))
322 n=$(($n >> 8))
323 done | xargs echo -en | dd of=$1 conv=notrunc bs=1 seek=5 2> /dev/null
324 }
326 # Pack rootfs
327 pack_rootfs()
328 {
329 ( cd $1 ; find . -print | cpio -o -H newc ) | \
330 if [ "$COMPRESSION" = "none" ]; then
331 echo "Generating uncompressed initramfs... "
332 cat > $2
333 elif [ -x /usr/bin/lzma -a "$COMPRESSION" != "gzip" ]; then
334 echo -n "Generating lzma'ed initramfs... "
335 lzma e -si -so $(lzma_switches $1) > $2
336 lzma_set_size $2
337 else
338 echo "Generating gziped initramfs... "
339 gzip -9 > $2
340 fi
341 echo 1 > /tmp/rootfs
342 }
344 # Compression functions for writeiso.
345 write_initramfs()
346 {
347 if [ "$COMPRESSION" = "lzma" ]; then
348 echo -n "Creating rootfs.gz with lzma compression... "
349 cat /tmp/list | cpio -o -H newc | lzma e -si -so > /rootfs.gz
350 lzma_set_size /rootfs.gz
351 elif [ "$COMPRESSION" = "gzip" ]; then
352 echo "Creating rootfs.gz with gzip compression... "
353 cat /tmp/list | cpio -o -H newc | gzip -9 > /rootfs.gz
354 else
355 echo "Creating rootfs.gz without compression... "
356 cat /tmp/list | cpio -o -H newc > /rootfs.gz
357 fi
358 echo 1 > /tmp/rootfs
359 }
361 # Deduplicate files (MUST be on the same filesystem).
362 deduplicate()
363 {
364 find "$@" -type f -size +0c -exec stat -c '%s-%a-%u-%g %i %h %n' {} \; | \
365 sort | ( save=0; old_attr=""; old_inode=""; old_link=""; old_file=""
366 while read attr inode link file; do
367 if [ "$attr" = "$old_attr" -a "$inode" != "$old_inode" ]; then
368 if cmp "$file" "$old_file" >/dev/null; then
369 rm -f "$file"
370 ln "$old_file" "$file"
371 inode="$old_inode"
372 [ "$link" = "1" ] && save="$(expr $save + ${attr%%-*})"
373 fi
374 fi
375 old_attr="$attr" ; old_inode="$inode" ; old_file="$file"
376 done
377 echo "$save bytes saved in duplicate files."
378 )
379 }
381 # Generate a new initramfs from the root filesystem.
382 gen_initramfs()
383 {
384 # Just in case CTRL+c
385 rm -f $DISTRO/gen
387 # Some packages may want to alter rootfs
388 genisohooks rootfs
389 cd $1
391 # Link duplicate files
392 deduplicate .
394 # Use lzma if installed. Display rootfs size in realtime.
395 rm -f /tmp/rootfs
396 pack_rootfs . $DISTRO/$(basename $1).gz &
397 sleep 2
398 echo -en "\nFilesystem size:"
399 while [ ! -f /tmp/rootfs ]
400 do
401 sleep 1
402 echo -en "\\033[18G`du -sh $DISTRO/$(basename $1).gz | awk '{print $1}'` "
403 done
404 echo -e "\n"
405 cd $DISTRO
406 mv $(basename $1).gz $ROOTCD/boot
407 }
409 distro_sizes()
410 {
411 if [ "$time" ]; then
412 time=$(($(date +%s) - $time))
413 sec=$time
414 div=$(( ($time + 30) / 60))
415 [ "$div" != 0 ] && min="~ ${div}m"
416 echo "Build time : ${sec}s $min"
417 fi
418 cat << EOT
419 Build date : $(date +%Y%m%d)
420 Packages : $(ls -1 $ROOTFS*$INSTALLED/*/receipt | wc -l)
421 Rootfs size : $(du -csh $ROOTFS*/ | awk '{ s=$1 } END { print s }')
422 Initramfs size : $(du -csh $ROOTCD/boot/rootfs*.gz | awk '{ s=$1 } END { print s }')
423 ISO image size : $(du -sh $ISO_NAME.iso | awk '{ print $1 }')
424 ================================================================================
425 Image is ready: $ISO_NAME.iso
427 EOT
428 }
430 # Print ISO and rootfs size.
431 distro_stats()
432 {
433 echo ""
434 echo -e "\033[1mDistro statistics\033[0m ($DISTRO)"
435 separator
436 distro_sizes
437 }
439 # Create an empty configuration file.
440 empty_config_file()
441 {
442 cat >> tazlito.conf << "EOF"
443 # tazlito.conf: Tazlito (SliTaz Live Tool)
444 # configuration file.
445 #
447 # Name of the ISO image to generate.
448 ISO_NAME=""
450 # ISO image volume name.
451 VOLUM_NAME="SliTaz"
453 # Name of the preparer.
454 PREPARED="$USER"
456 # Path to the packages repository and the packages.list.
457 PACKAGES_REPOSITORY=""
459 # Path to the distro tree to gen-distro from a
460 # list of packages.
461 DISTRO=""
463 # Path to the directory containing additional files
464 # to copy into the rootfs and rootcd of the LiveCD.
465 ADDFILES="$DISTRO/addfiles"
467 # Default answer for binary question (Y or N)
468 DEFAULT_ANSWER="ASK"
470 # Compression utility (lzma, gzip or none)
471 COMPRESSION="lzma"
472 EOF
473 }
475 # extract rootfs.gz somewhere
476 extract_rootfs()
477 {
478 (zcat $1 || unlzma -c $1 || cat $1) 2>/dev/null | \
479 (cd $2; cpio -idm > /dev/null)
480 }
482 # Remove duplicate files
483 mergefs()
484 {
485 echo -n "Merge $(basename $1) ($(du -hs $1 | awk '{ print $1}')) into "
486 echo -n "$(basename $2) ($(du -hs $2 | awk '{ print $1}'))"
487 # merge symlinks files and devices
488 ( cd $1; find ) | while read file; do
489 if [ -L $1/$file ]; then
490 [ -L $2/$file ] &&
491 [ "$(readlink $1/$file)" == "$(readlink $2/$file)" ] &&
492 rm -f $2/$file
493 elif [ -f $1/$file ]; then
494 [ -f $2/$file ] &&
495 cmp $1/$file $2/$file > /dev/null 2>&1 && rm -f $2/$file
496 [ -f $2/$file ] &&
497 [ "$(basename $file)" == "volatile.cpio.gz" ] &&
498 [ "$(dirname $(dirname $file))" == \
499 ".$INSTALLED" ] && rm -f $2/$file
500 elif [ -b $1/$file ]; then
501 [ -b $2/$file ] &&
502 [ "$(stat -c '%a:%u:%g:%t:%T' $1/$file)" == \
503 "$(stat -c '%a:%u:%g:%t:%T' $2/$file)" ] &&
504 rm -f $2/$file
505 elif [ -c $1/$file ]; then
506 [ -c $2/$file ] &&
507 [ "$(stat -c '%a:%u:%g:%t:%T' $1/$file)" == \
508 "$(stat -c '%a:%u:%g:%t:%T' $2/$file)" ] &&
509 rm -f $2/$file
510 fi
511 done
513 # cleanup directories
514 ( cd $1; find -type d ) | sed '1!G;h;$!d' | while read file; do
515 [ -d $2/$file ] && rmdir $2/$file 2> /dev/null
516 done
517 true
518 status
519 }
521 cleanup_merge()
522 {
523 rm -rf $TMP_DIR
524 exit 1
525 }
527 human2cent()
528 {
529 case "$1" in
530 *k) echo $1 | sed 's/\(.*\).\(.\)k/\1\2/';;
531 *M) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)M/\1\2/') * 1024));;
532 *G) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)G/\1\2/') * 1024 * 1024));;
533 esac
534 }
536 cent2human()
537 {
538 if [ $1 -lt 10000 ]; then
539 echo "$(($1 / 10)).$(($1 % 10))k"
540 elif [ $1 -lt 10000000 ]; then
541 echo "$(($1 / 10240)).$(( ($1/1024) % 10))M"
542 else
543 echo "$(($1 / 10485760)).$(( ($1/1048576) % 10))G"
544 fi
545 }
547 get_size()
548 {
549 cat $LOCALSTATE/packages.list $TMP_DIR/packages.list 2>/dev/null | awk "{ \
550 if (/^$(echo $1 | sed 's/[$+.\]/\\&/g')$/) get=1; \
551 if (/installed/ && get == 1) { print ; get++ } \
552 }
553 END { if (get < 2) print \" 0.0k (0.0k installed)\" }" | \
554 sed 's/ *\(.*\) .\(.*\) installed./\1 \2/' | while read packed unpacked; do
555 echo "$(human2cent $packed) $(human2cent $unpacked)"
556 done
557 }
559 # Display package list with version, set packed_size and unpacked_size
560 get_pkglist()
561 {
562 packed_size=0; unpacked_size=0
563 grep -v ^# $FLAVORS_REPOSITORY/$1/packages.list > $TMP_DIR/flavor.pkg
564 while read pkg; do
565 set -- $(get_size $pkg)
566 packed_size=$(( $packed_size + $1 ))
567 unpacked_size=$(( $unpacked_size + $2 ))
568 for i in $(grep -hs ^$pkg $LOCALSTATE/packages.list \
569 $TMP_DIR/packages.list); do
570 echo $i
571 break
572 done
573 done < $TMP_DIR/flavor.pkg
574 rm -f $TMP_DIR/flavor.pkg
575 }
577 # Update isolinux config files for multiple rootfs
578 update_bootconfig()
579 {
580 local files
581 echo -n "Updating boot config files..."
582 files="$(grep -l 'include common' $1/*.cfg)"
583 for file in $files ; do
584 awk -v n=$(echo $2 | awk '{ print NF/2 }') '{
585 if (/label/) label=$0;
586 else if (/kernel/) kernel=$0;
587 else if (/append/) {
588 i=index($0,"rootfs.gz");
589 append=substr($0,i+9);
590 }
591 else if (/include/) {
592 for (i = 1; i <= n; i++) {
593 print label i
594 print kernel;
595 initrd="initrd=/boot/rootfs" n ".gz"
596 for (j = n - 1; j >= i; j--) {
597 initrd=initrd ",/boot/rootfs" j ".gz";
598 }
599 printf "\tappend %s%s\n",initrd,append;
600 print "";
601 }
602 print;
603 }
604 else print;
605 }' < $file > $file.$$
606 mv -f $file.$$ $file
607 done
608 sel="$(echo $2 | awk '{
609 for (i=1; i<=NF; i++)
610 if (i % 2 == 0) printf " slitaz%d",i/2
611 else printf " %s",$i
612 }')"
613 [ -s $1/common.cfg ] && cat >> $1/common.cfg <<EOT
615 label slitaz
616 kernel /boot/isolinux/ifmem.c32
617 append$sel noram
619 label noram
620 config noram.cfg
622 EOT
623 # Update vesamenu
624 if [ -s $1/isolinux.cfg ]; then
625 files="$files $1/isolinux.cfg"
626 awk -v n=$(echo $2 | awk '{ print NF/2 }') -v "sel=$sel" '
627 BEGIN {
628 kernel=" COM32 c32box.c32"
629 }
630 {
631 if (/ROWS/) print "MENU ROW " n+$3;
632 else if (/TIMEOUTROW/) print "MENU TIMEOUTROW " n+$3;
633 else if (/TABMSGROW/) print "MENU TABMSGROW " n+$3;
634 else if (/CMDLINEROW/) print "MENU CMDLINEROW " n+$3;
635 else if (/VSHIFT/) {
636 x=$3-n;
637 if (x < 0) x=0;
638 print "MENU VSHIFT " x;
639 }
640 else if (/rootfs.gz/) {
641 linux=""
642 if (/bzImage/) {
643 linux="linux /boot/bzImage "
644 }
645 i=index($0,"rootfs.gz");
646 append=substr($0,i+9);
647 print " kernel /boot/isolinux/ifmem.c32"
648 print " append" sel " noram"
649 print ""
650 print "label noram"
651 print " MENU HIDE"
652 print " config noram.cfg"
653 print ""
654 for (i = 1; i <= n; i++) {
655 print "LABEL slitaz" i
656 print " MENU LABEL SliTaz slitaz" i " Live"
657 print kernel;
658 initrd="initrd=/boot/rootfs" n ".gz"
659 for (j = n - 1; j >= i; j--) {
660 initrd=initrd ",/boot/rootfs" j ".gz";
661 }
662 printf "\tappend %s%s%s\n",linux,initrd,append;
663 print "";
664 }
665 }
666 else if (/bzImage/) kernel=$0;
667 else print;
668 }' < $1/isolinux.cfg > $1/isolinux.cfg.$$
669 mv $1/isolinux.cfg.$$ $1/isolinux.cfg
670 fi
671 [ -s $1/c32box.c32 ] && sed -i -e '/kernel.*ifmem/d' \
672 -e 's/append \([0-9]\)/append ifmem \1/' $1/isolinux.cfg
673 cat > $1/noram.cfg <<EOT
674 implicit 0
675 prompt 1
676 timeout 80
677 F1 help.txt
678 F2 options.txt
679 F3 isolinux.msg
680 F4 display.txt
681 F5 enhelp.txt
682 F6 enopts.txt
684 display isolinux.msg
685 say Not enough RAM to boot slitaz. Give http://tiny.slitaz.org/ a try ?
686 default reboot
687 label reboot
688 EOT
689 if [ -s $1/c32box.c32 ]; then
690 cat >> $1/noram.cfg <<EOT
691 COM32 c32box.c32
692 append reboot
694 label poweroff
695 COM32 c32box.c32
696 append poweroff
698 EOT
699 else
700 echo " com32 reboot.c32" >> $1/noram.cfg
701 fi
702 # Restore real label names
703 [ -s $1/common.cfg ] && files="$1/common.cfg $files"
704 echo $2 | awk '{ for (i=NF; i>1; i-=2) printf "%d/%s\n",i/2,$i }' | \
705 while read pat; do
706 sed -i "s/slitaz$pat/" $files
707 done
708 status
709 }
711 # Install a missing package
712 install_package()
713 {
714 echo -n "Install package $1 "
715 [ -n "$2" ] && echo -n "for kernel $2 "
716 echo -n "?"
717 read answer
718 case "$answer" in
719 y*|Y*|o*|O*)
720 # We dont want package on host cache.
721 echo -n "Getting and installing package: $1"
722 yes y | tazpkg get-install $1 2>&1 >> $log || exit 1
723 status ;;
724 *)
725 return 1 ;;
726 esac
727 }
729 # Check iso for loram transformation
730 check_iso_for_loram()
731 {
732 [ -s $TMP_DIR/iso/boot/rootfs.gz ] ||
733 [ -s $TMP_DIR/iso/boot/rootfs1.gz ]
734 }
736 # Build initial rootfs for loram ISO ram/cdrom/http
737 build_initfs()
738 {
739 urliso="mirror.slitaz.org mirror.switch.ch/ftp/mirror/slitaz \
740 download.tuxfamily.org/slitaz slitaz.c3sl.ufpr.br"
741 version=$(ls $TMP_DIR/iso/boot/vmlinuz-* | sed 's/.*vmlinuz-//')
742 if [ -z "$version" ]; then
743 cat <<EOT
744 Can't find the kernel version.
745 No file /boot/vmlinuz-<version> in ISO image.
746 Abort.
747 EOT
748 exit 1
749 fi
750 [ -s /usr/share/boot/busybox-static ] || install_package busybox-static
751 need_lib=false
752 mkdir -p $TMP_DIR/initfs/bin $TMP_DIR/initfs/dev $TMP_DIR/initfs/lib \
753 $TMP_DIR/initfs/mnt $TMP_DIR/initfs/proc $TMP_DIR/initfs/tmp \
754 $TMP_DIR/initfs/sys
755 while [ ! -f /lib/modules/$version/kernel/fs/aufs/aufs.ko.gz ]; do
756 install_package aufs $version || return 1
757 done
758 # bootfloppybox will need floppy.ko.gz, /dev/fd0, /dev/tty0
759 cp /lib/modules/$version/kernel/drivers/block/floppy.ko.gz \
760 $TMP_DIR/initfs/lib 2> /dev/null
761 cp -a /dev/tty0 /dev/fd0 $TMP_DIR/initfs/dev 2> /dev/null
762 cp /lib/modules/$version/kernel/fs/aufs/aufs.ko.gz \
763 $TMP_DIR/initfs/lib
764 if [ -f /bin/cromfs-driver ]; then
765 cp /bin/cromfs-driver $TMP_DIR/initfs/bin
766 ls /bin/unmkcromfs | \
767 cpio -o -H newc > $TMP_DIR/initfs/extractfs.cpio
768 else
769 [ ! -f /usr/sbin/mksquashfs ] && ! install_package squashfs && return 1
770 while [ ! -f /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.gz ]; do
771 install_package linux-squashfs $version || return 1
772 done
773 cp /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.gz \
774 $TMP_DIR/initfs/lib
775 ls /sbin/unsquashfs /usr/lib/liblzma.so* $INSTALLED/squashfs/* | \
776 cpio -o -H newc > $TMP_DIR/initfs/extractfs.cpio
777 fi
778 if [ "$1" == "cdrom" ]; then
779 for i in $(ls /dev/[hs]d[a-f]*); do
780 cp -a $i $TMP_DIR/initfs/dev
781 done
782 fi
783 if [ "$1" == "http" ]; then
784 mkdir $TMP_DIR/initfs/etc
785 ln -s /proc/mounts $TMP_DIR/initfs/etc/mtab
786 cp /usr/share/udhcpc/default.script $TMP_DIR/initfs/lib/udhcpc
787 sed -i 's|/sbin/||' $TMP_DIR/initfs/lib/udhcpc
788 cp -a /dev/fuse $TMP_DIR/initfs/dev
789 if ! $need_lib && [ -x /usr/share/boot/fusermount-static ]; then
790 cp /usr/share/boot/fusermount-static $TMP_DIR/initfs/bin/httpfs
791 else
792 cp /usr/bin/fusermount $TMP_DIR/initfs/bin
793 need_lib=true
794 fi
795 if ! $need_lib && [ -x /usr/share/boot/httpfs-static ]; then
796 cp /usr/share/boot/httpfs-static $TMP_DIR/initfs/bin/httpfs
797 else
798 [ ! -f /usr/bin/httpfs ] && ! install_package httpfs-fuse && return 1
799 cp /usr/bin/httpfs $TMP_DIR/initfs/bin
800 cp -a /lib/librt* $TMP_DIR/initfs/lib
801 cp -a /lib/libdl* $TMP_DIR/initfs/lib
802 cp -a /lib/libpthread* $TMP_DIR/initfs/lib
803 cp -a /usr/lib/libfuse* $TMP_DIR/initfs/lib
804 cp -a /lib/libresolv* $TMP_DIR/initfs/lib
805 cp -a /lib/libnss_dns* $TMP_DIR/initfs/lib
806 need_lib=true
807 fi
808 cd $TMP_DIR/initfs
809 echo "Getting slitaz-release..."
810 for i in $TMP_DIR/iso/boot/rootfs*.gz; do
811 ( zcat $i 2> /dev/null || unlzma -c $i) | \
812 cpio -idmu etc/slitaz-release > /dev/null
813 done
814 cd - > /dev/null
815 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"
816 echo -n "List of urls to insert: "
817 read -t 30 urliso2
818 urliso="$urliso2 $urliso"
819 fi
820 if ! $need_lib && [ -x /usr/share/boot/busybox-static ]; then
821 cp /usr/share/boot/busybox-static $TMP_DIR/initfs/bin/busybox
822 else
823 cp /bin/busybox $TMP_DIR/initfs/bin
824 need_lib=true
825 fi
826 for i in $($TMP_DIR/initfs/bin/busybox | awk \
827 '{ if (s) printf "%s",$0 } /Currently/ { s=1 }' | sed 's/,//g'); do
828 ln $TMP_DIR/initfs/bin/busybox $TMP_DIR/initfs/bin/$i
829 done
830 for i in /dev/console /dev/loop* /dev/null /dev/tty /dev/zero \
831 /dev/kmem /dev/mem /dev/random /dev/urandom; do
832 cp -a $i $TMP_DIR/initfs/dev
833 done
834 $need_lib && for i in /lib/ld-* /lib/lib[cm].so* /lib/lib[cm]-* ; do
835 cp -a $i $TMP_DIR/initfs/lib
836 done
837 cat > $TMP_DIR/initfs/init <<EOTEOT
838 #!/bin/sh
840 getarg()
841 {
842 grep -q " \$1=" /proc/cmdline || return 1
843 eval \$2=\$(sed "s/.* \$1=\\\\([^ ]*\\\\).*/\\\\1/" < /proc/cmdline)
844 return 0
845 }
847 copy_rootfs()
848 {
849 total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g')
850 need=\$(du -c \${path}rootfs* | tail -n 1 | cut -f1)
851 [ \$(( \$total / \$need )) -gt 1 ] || return 1
852 if ! grep -q " keep-loram" /proc/cmdline && cp \${path}rootfs* /mnt; then
853 path=/mnt/
854 return 0
855 else
856 rm -f /mnt/rootfs*
857 return 1
858 fi
859 }
861 echo "Switching / to tmpfs..."
862 mount -t proc proc /proc
863 size="\$(grep rootfssize= < /proc/cmdline | \\
864 sed 's/.*rootfssize=\\([0-9]*[kmg%]\\).*/-o size=\\1/')"
865 [ -n "\$size" ] || size="-o size=90%"
867 if [ -x /bin/httpfs ]; then # loram-http
869 while read var default; do
870 eval \$var=\$default
871 getarg \$var \$var
872 done <<EOT
873 eth eth0
874 dns 208.67.222.222,208.67.220.220
875 netmask 255.255.255.0
876 gw
877 ip
878 EOT
879 if [ -n "\$ip" ]; then
880 ifconfig \$eth \$ip netmask \$netmask up
881 route add default gateway \$gw
882 for i in \$(echo \$dns | sed 's/,/ /g'); do
883 echo "nameserver \$i" >> /etc/resolv.conf
884 done
885 else
886 udhcpc -f -q -s /lib/udhcpc -i \$eth
887 fi
888 for i in $urliso ; do
889 [ -n "\$URLISO" ] && URLISO="\$URLISO,"
890 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"
891 done
892 getarg urliso URLISO
893 DIR=fs
894 if getarg loram DIR; then
895 DEVICE=\${DIR%,*}
896 DIR=/\${DIR#*,}
897 fi
898 mount -t tmpfs \$size tmpfs /mnt
899 path2=/mnt/.httpfs/
900 path=/mnt/.cdrom/
901 mkdir -p /mnt/.rw \$path \$path2
902 while [ ! -d \$path/boot ]; do
903 for i in \$(echo \$URLISO | sed 's/,/ /g'); do
904 httpfs \$i \$path2 && break
905 done
906 mount -o loop,ro -t iso9660 \$path2/*.iso \$path
907 done
908 #copy_rootfs && umount -d \$path && umount -d \$path2
910 elif [ -f \$(echo /rootfs*.gz | cut -f1 -d' ') ]; then # loram-ram
912 total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g')
913 free=\$(grep MemFree /proc/meminfo | sed 's/[^0-9]//g')
914 if [ \$(( \$total/\$free )) -gt 1 ] || ! mount -t tmpfs \$size tmpfs /mnt; then
915 echo "No tmpfs for /mnt"
916 mkdir -p /mnt/.rw
917 mount -t tmpfs tmpfs /mnt/.rw
918 mkdir -p /mnt/.rw/mnt/.rw
919 path=/
920 else
921 mkdir -p /mnt/.rw
922 path=/mnt/.
923 for i in rootfs* ; do
924 mv /\$i \$path\$i
925 done
926 fi
928 else # loram-cdrom
930 getarg cdrom DRIVE_NAME ||
931 DRIVE_NAME=\$(grep "drive name" < /proc/sys/dev/cdrom/info | cut -f 3)
932 DEVICE=/dev/\$DRIVE_NAME
933 DIR=fs
934 if getarg loram DIR; then
935 DEVICE=\${DIR%,*}
936 DIR=/\${DIR#*,}
937 fi
938 mount -t tmpfs \$size tmpfs /mnt
939 mkdir -p /mnt/.rw /mnt/.cdrom /mnt/mnt/.cdrom
940 i=0
941 while [ \$i -lt 5 ] && ! mount -r \$DEVICE /mnt/.cdrom; do
942 case "\$DEVICE" in
943 /dev/sd*|UUID=*|LABEL=*)
944 mount -t sysfs sysfs /sys
945 USBDELAY=\$(cat /sys/module/usb_storage/parameters/delay_use)
946 umount /sys
947 sleep \$((1+\$USBDELAY)) ;;
948 esac
949 i=\$((i+1))
950 done
951 path=/mnt/.cdrom/
952 copy_rootfs && umount -d /mnt/.cdrom
954 fi
956 memfree=\$(grep MemFree /proc/meminfo | sed 's/[^0-9]//g')
957 umount /proc
958 branch=br=/mnt/.rw:/mnt/.cdrom/\$DIR
959 if [ ! -d /mnt/.cdrom/\$DIR/etc ]; then
960 branch=br=/mnt/.rw
961 for i in \${path}rootfs* ; do
962 fs=\${i#*root}
963 branch=\$branch:/mnt/.\$fs
964 mkdir -p /mnt/.rw/mnt/.\$fs /mnt/.\$fs /mnt/.rw/mnt/.cdrom
965 if [ -f /bin/cromfs-driver ]; then
966 cromfs-driver \${path}root\$fs /mnt/.\$fs -o ro,dev,suid,allow_other
967 else
968 insmod /lib/squashfs.ko.gz 2> /dev/null
969 mount -o loop,ro -t squashfs \${path}root\$fs /mnt/.\$fs
970 fi
971 done
972 else
973 mkdir -p /mnt/.rw/mnt/.httpfs
974 fi
975 insmod /lib/aufs.ko.gz
976 mount -t aufs -o \$branch none /mnt
977 [ -x /bin/httpfs ] && sed -i 's/DHCP="yes"/DHCP="no"/' /mnt/etc/network.conf
978 [ \$memfree -lt 30000 ] && sed -i 's/ slim//' /mnt/etc/rcS.conf
979 [ -x /mnt/sbin/init ] && exec /bin/switch_root mnt /sbin/init || sh
980 EOTEOT
981 chmod +x $TMP_DIR/initfs/init
982 ( cd $TMP_DIR/initfs ; find | busybox cpio -o -H newc 2> /dev/null) | \
983 lzma e $TMP_DIR/initfs.gz -si
984 lzma_set_size $TMP_DIR/initfs.gz
985 rm -rf $TMP_DIR/initfs
986 rem=$(( $(stat -c "%s" $TMP_DIR/initfs.gz) % 4 ))
987 [ $rem -ne 0 ] &&
988 dd if=/dev/zero bs=1 count=$(( 4 - $rem )) >> $TMP_DIR/initfs.gz 2> /dev/null
989 return 0
990 }
992 # Move each initramfs to squashfs (or cromfs)
993 build_loram_rootfs()
994 {
995 rootfs_sizes=""
996 for i in $TMP_DIR/iso/boot/rootfs*.gz; do
997 mkdir -p $TMP_DIR/fs
998 cd $TMP_DIR/fs
999 ( zcat $i 2> /dev/null || unlzma -c $i) | cpio -idm
1000 cd - > /dev/null
1001 rootfs=$TMP_DIR/$(basename $i)
1002 if [ -x /usr/bin/mkcromfs ]; then
1003 /usr/bin/mkcromfs -qq -f 262144 -b 16384 $TMP_DIR/fs $rootfs
1004 else
1005 /usr/sbin/mksquashfs $TMP_DIR/fs $rootfs -comp xz -Xbcj x86
1006 fi
1007 cd $TMP_DIR
1008 rootfs_sizes="$rootfs_sizes $(( $(du -s $TMP_DIR/fs | cut -f1) - $(du -s $rootfs | cut -f1) ))"
1009 ( cd $(dirname $rootfs); echo $(basename $rootfs) | \
1010 cpio -o -H newc ) > $rootfs.cpio
1011 rm -f $rootfs
1012 mv $rootfs.cpio $rootfs
1013 cd - > /dev/null
1014 rm -rf $TMP_DIR/fs
1015 done
1018 # Move each initramfs to squashfs (or cromfs)
1019 build_loram_rootfs_cdrom()
1021 mkdir -p $TMP_DIR/fs
1022 cd $TMP_DIR/fs
1023 for i in $(ls -r $TMP_DIR/iso/boot/rootfs*.gz); do
1024 ( zcat $i 2> /dev/null || unlzma -c $i) | cpio -idmu
1025 done
1026 rootfs=$TMP_DIR/rootfs.gz
1027 if [ -x /usr/bin/mkcromfs ]; then
1028 /usr/bin/mkcromfs -qq -f 262144 -b 16384 $TMP_DIR/fs $rootfs
1029 else
1030 /usr/sbin/mksquashfs $TMP_DIR/fs $rootfs -comp xz -Xbcj x86
1031 fi
1032 rm -rf $TMP_DIR/fs
1033 cd - > /dev/null
1036 # Move meta boot configuration files to basic configuration files
1037 # because meta loram flavor is useless when rootfs is not loaded in ram
1038 unmeta_boot()
1040 local root=${1:-$TMP_DIR/loramiso}
1041 if [ -f $root/boot/isolinux/noram.cfg ]; then
1042 # We keep enough information to do unloram...
1043 [ -s $root/boot/isolinux/common.cfg ] &&
1044 sed -i 's/label slitaz/label orgslitaz/' \
1045 $root/boot/isolinux/common.cfg
1046 set -- $(grep 'append ifmem [0-9]' $root/boot/isolinux/isolinux.cfg)
1047 shift
1048 sed -i '/ifmem/{NNNNNNNNd};/^LABEL/{N;/LABEL SliTaz [^L]/{NNNd}}' \
1049 $root/boot/isolinux/isolinux.cfg
1050 [ -n "$3" ] || set -- $(grep 'append [0-9]' $root/boot/isolinux/common.cfg)
1051 sed -i "s/label $3\$/label slitaz/;s|=/boot/rootfs\(.*\).gz |=/boot/rootfs.gz |" \
1052 $root/boot/isolinux/*.cfg
1053 fi
1056 # Move rootfs to squashfs filesystem(s) to the cdrom writeable with aufs.
1057 # These squashfs may be loaded in ram a boot time.
1058 # Rootfs are also copied to cdrom for tiny ramsize systems.
1059 # Meta flavors are converted to normal flavors.
1060 build_loram_cdrom()
1062 build_initfs cdrom || return 1
1063 build_loram_rootfs_cdrom
1064 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1065 if [ "$1" == "small" ]; then
1066 rm -f $TMP_DIR/loramiso/boot/root*
1067 else
1068 mkdir $TMP_DIR/loramiso/fs
1069 cd $TMP_DIR/loramiso/fs
1070 for i in $( ls ../boot/root* | sort -r ) ; do
1071 ( zcat $i 2> /dev/null || unlzma -c $i ) | cpio -idmu
1072 rm -f $i
1073 done
1074 mkdir -p $TMP_DIR/loramiso/fs/mnt/.cdrom
1075 cd - > /dev/null
1076 fi
1077 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
1078 mv $TMP_DIR/rootfs*.gz $TMP_DIR/loramiso
1079 unmeta_boot
1080 VOLUM_NAME="SliTaz_LoRAM_CDROM"
1081 sed -i "s/root=/loram=LABEL=$VOLUM_NAME,fs &/" \
1082 $TMP_DIR/loramiso/boot/isolinux/*.cfg
1083 create_iso $OUTPUT $TMP_DIR/loramiso
1086 # Create http bootstrap to load and remove loram_cdrom
1087 # Meta flavors are converted to normal flavors.
1088 build_loram_http()
1090 build_initfs http || return 1
1091 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1092 rm -f $TMP_DIR/loramiso/boot/rootfs*
1093 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
1094 unmeta_boot
1095 create_iso $OUTPUT $TMP_DIR/loramiso
1098 # Update meta flavor selection sizes.
1099 # Reduce sizes with rootfs gains.
1100 update_metaiso_sizes()
1102 for cfg in $(grep -El '(append|ifmem) [0-9]' $TMP_DIR/loramiso/boot/isolinux/*.cfg)
1103 do
1104 local append="$(grep -E '(append|ifmem) [0-9]' $cfg)"
1105 local sizes="$rootfs_sizes"
1106 local new
1107 set -- $append
1108 shift
1109 [ "$1" == "ifmem" ] && shift
1110 new=""
1111 while [ -n "$2" ]; do
1112 local s
1113 case "$1" in
1114 *G) s=$(( ${1%G} * 1024 * 1024 ));;
1115 *M) s=$(( ${1%M} * 1024 ));;
1116 *) s=${1%K};;
1117 esac
1118 sizes=${sizes#* }
1119 for i in $sizes ; do
1120 s=$(( $s - $i ))
1121 done
1122 new="$new $s $2"
1123 shift 2
1124 done
1125 sed -i -e "/append [0-9]/s/append .*/append$new $1/" -e \
1126 "/append ifmem [0-9]/s/append .*/append ifmem$new $1/" $cfg
1127 done
1130 # Move rootfs to a squashfs filesystem into the initramfs writeable with aufs.
1131 # Meta flavor selection sizes are updated.
1132 build_loram_ram()
1134 build_initfs ram || return 1
1135 build_loram_rootfs
1136 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1137 rm -f $TMP_DIR/loramiso/boot/bzImage
1138 ln $TMP_DIR/loramiso/boot/vmlinuz* $TMP_DIR/loramiso/boot/bzImage
1139 rootfs=$(ls $TMP_DIR/rootfs* | sort | tail -n 1)
1140 cat $rootfs >> $TMP_DIR/initfs.gz
1141 mv $TMP_DIR/initfs.gz $rootfs
1142 cp $TMP_DIR/rootfs* $TMP_DIR/loramiso/boot
1143 update_metaiso_sizes
1144 create_iso $OUTPUT $TMP_DIR/loramiso
1147 # Remove files installed by packages
1148 find_flavor_rootfs()
1150 for i in $1/etc/tazlito/*.extract; do
1151 [ -e $i ] || continue
1152 chroot $1 /bin/sh ${i#$1}
1153 done
1155 # Clean hardlinks and files patched by genisofs in /boot
1156 for i in isolinux/isolinux.bin isolinux/boot.cat bzImage ; do
1157 rm -f $1/boot/$i
1158 done
1160 # Clean files generated in post_install
1161 rm -f $1/lib/modules/*/modules.* $1/etc/mtab \
1162 $1/dev/core $1/dev/fd $1/dev/std*
1164 # Verify md5
1165 cat $1$INSTALLED/*/md5sum | \
1166 while read md5 file; do
1167 [ -e $1$file ] || continue
1168 [ "$(cat $1$file | md5sum)" == "$md5 -" ] &&
1169 rm -f $1$file
1170 done
1172 # Check configuration files
1173 for i in $1$INSTALLED/*/volatile.cpio.gz; do
1174 [ -e $i ] || continue
1175 mkdir /tmp/volatile$$
1176 zcat $i | ( cd /tmp/volatile$$ ; cpio -idmu > /dev/null 2>&1 )
1177 ( cd /tmp/volatile$$ ; find * -type f 2> /dev/null) | \
1178 while read file ; do
1179 [ -e $1/$file ] || continue
1180 cmp -s /tmp/volatile$$/$file $1/$file && rm -f $1/$file
1181 done
1182 rm -rf /tmp/volatile$$
1183 done
1185 # Remove other files blindly
1186 for i in $1$INSTALLED/*/files.list; do
1187 for file in $(cat $i); do
1188 [ $1$file -nt $i ] && continue
1189 [ -f $1$file -a ! -L $1$file ] && continue
1190 [ -d $1$file ] || rm -f $1$file
1191 done
1192 done
1194 # Remove tazpkg files and tmp files
1195 rm -rf $1$INSTALLED* $1/tmp $1/var/tmp
1196 rm -f $1$LOCALSTATE/*packages* $1$LOCALSTATE/files.list.lzma \
1197 $1$LOCALSTATE/mirror* $1/var/cache/*/* \
1198 $1/var/lock/* $1/var/log/* $1/var/run/* $1/var/run/*/* \
1199 $1/var/lib/* $1/var/lib/dbus/* 2> /dev/null
1201 # Cleanup directory tree
1202 cd $1
1203 find * -type d | sort -r | while read dir; do
1204 rmdir $dir 2> /dev/null
1205 done
1206 cd - > /dev/null
1209 ####################
1210 # Tazlito commands #
1211 ####################
1213 case "$COMMAND" in
1214 stats)
1215 # Tazlito general statistics from the config file.
1217 echo ""
1218 echo -e "\033[1mTazlito statistics\033[0m
1219 ===============================================================================
1220 Config file : $CONFIG_FILE
1221 ISO name : $ISO_NAME.iso
1222 Volume name : $VOLUM_NAME
1223 Prepared : $PREPARED
1224 Packages repository : $PACKAGES_REPOSITORY
1225 Distro directory : $DISTRO"
1226 if [ ! "$ADDFILES" = "" ] ; then
1227 echo -e "Additional files : $ADDFILES"
1228 fi
1229 separator
1230 echo ""
1231 ;;
1232 list-addfiles)
1233 # Simple list of additional files in the rootfs
1234 echo ""
1235 cd $ADDFILES
1236 find rootfs -type f
1237 echo "" ;;
1238 gen-config)
1239 # Generate a new config file in the current dir or the specified
1240 # directory by $2.
1242 if [ -n "$2" ] ; then
1243 mkdir -p $2 && cd $2
1244 fi
1245 echo -n "Generating empty tazlito.conf..."
1246 empty_config_file
1247 status
1248 echo ""
1249 if [ -f "tazlito.conf" ] ; then
1250 echo "Configuration file is ready to edit."
1251 echo "File location : `pwd`/tazlito.conf"
1252 echo ""
1253 fi
1254 ;;
1255 configure)
1256 # Configure a tazlito.conf config file. Start by getting
1257 # a empty config file and sed it.
1259 if [ -f "tazlito.conf" ] ; then
1260 rm tazlito.conf
1261 else
1262 if test $(id -u) = 0 ; then
1263 cd /etc
1264 else
1265 echo "You must be root to configure the main config file or in"
1266 echo "the same directory of the file you want to configure."
1267 exit 0
1268 fi
1269 fi
1270 empty_config_file
1271 echo""
1272 echo -e "\033[1mConfiguring :\033[0m `pwd`/tazlito.conf"
1273 separator
1274 # ISO name.
1275 echo -n "ISO name : " ; read answer
1276 sed -i s#'ISO_NAME=\"\"'#"ISO_NAME=\"$answer\""# tazlito.conf
1277 # Volume name.
1278 echo -n "Volume name : " ; read answer
1279 sed -i s/'VOLUM_NAME=\"SliTaz\"'/"VOLUM_NAME=\"$answer\""/ tazlito.conf
1280 # Packages repository.
1281 echo -n "Packages repository : " ; read answer
1282 sed -i s#'PACKAGES_REPOSITORY=\"\"'#"PACKAGES_REPOSITORY=\"$answer\""# tazlito.conf
1283 # Distro path.
1284 echo -n "Distro path : " ; read answer
1285 sed -i s#'DISTRO=\"\"'#"DISTRO=\"$answer\""# tazlito.conf
1286 separator
1287 echo "Config file is ready to use."
1288 echo "You can now extract an ISO or generate a distro."
1289 echo ""
1290 ;;
1291 gen-iso)
1292 # Simply generate a new iso.
1294 check_root
1295 verify_rootcd
1296 gen_livecd_isolinux
1297 distro_stats
1298 ;;
1299 gen-initiso)
1300 # Simply generate a new initramfs with a new iso.
1302 check_root
1303 verify_rootcd
1304 gen_initramfs $ROOTFS
1305 gen_livecd_isolinux
1306 distro_stats
1307 ;;
1308 extract-distro)
1309 # Extract an ISO image to a directory and rebuild the LiveCD tree.
1311 check_root
1312 ISO_IMAGE=$2
1313 if [ -z "$ISO_IMAGE" ] ; then
1314 echo -e "\nPlease specify the path to the ISO image."
1315 echo -e "Example : `basename $0` image.iso /path/target\n"
1316 exit 0
1317 fi
1318 # Set the distro path by checking for $3 on cmdline.
1319 if [ -n "$3" ] ; then
1320 TARGET=$3
1321 else
1322 TARGET=$DISTRO
1323 fi
1324 # Exit if existing distro is found.
1325 if [ -d "$TARGET/rootfs" ] ; then
1326 echo -e "\nA rootfs exists in : $TARGET"
1327 echo -e "Please clean the distro tree or change directory path.\n"
1328 exit 0
1329 fi
1330 echo ""
1331 echo -e "\033[1mTazlito extracting :\033[0m `basename $ISO_IMAGE`"
1332 separator
1333 # Start to mount the ISO.
1334 echo ""
1335 echo "Mounting ISO image..."
1336 mkdir -p $TMP_DIR
1337 # Get ISO file size.
1338 isosize=`du -sh $ISO_IMAGE | cut -f1`
1339 mount -o loop $ISO_IMAGE $TMP_DIR
1340 sleep 2
1341 # Prepare target dir, copy the kernel and the rootfs.
1342 mkdir -p $TARGET/rootfs
1343 mkdir -p $TARGET/rootcd/boot
1344 echo -n "Copying the Linux kernel..."
1345 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
1346 ln $TARGET/rootcd/boot/vmlinuz* $TARGET/rootcd/boot/bzImage
1347 else
1348 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
1349 fi
1350 status
1351 echo -n "Copying isolinux files..."
1352 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
1353 for i in $(ls $TMP_DIR); do
1354 [ "$i" = "boot" ] && continue
1355 cp -a $TMP_DIR/$i $TARGET/rootcd
1356 done
1357 status
1358 if [ -d $TMP_DIR/boot/syslinux ]; then
1359 echo -n "Copying syslinux files..."
1360 cp -a $TMP_DIR/boot/syslinux $TARGET/rootcd/boot
1361 status
1362 fi
1363 if [ -d $TMP_DIR/boot/extlinux ]; then
1364 echo -n "Copying extlinux files..."
1365 cp -a $TMP_DIR/boot/extlinux $TARGET/rootcd/boot
1366 status
1367 fi
1368 if [ -d $TMP_DIR/boot/grub ]; then
1369 echo -n "Copying GRUB files..."
1370 cp -a $TMP_DIR/boot/grub $TARGET/rootcd/boot
1371 status
1372 fi
1374 echo -n "Copying the rootfs..."
1375 cp $TMP_DIR/boot/rootfs.?z $TARGET/rootcd/boot
1376 status
1377 # Extract initramfs.
1378 cd $TARGET/rootfs
1379 echo -n "Extracting the rootfs... "
1380 extract_rootfs ../rootcd/boot/rootfs.gz $TARGET/rootfs
1381 # unpack /usr
1382 for i in etc/tazlito/*.extract; do
1383 [ -f "$i" ] && . $i ../rootcd
1384 done
1385 # Umount and remove temp directory and cd to $TARGET to get stats.
1386 umount $TMP_DIR && rm -rf $TMP_DIR
1387 cd ..
1388 echo ""
1389 separator
1390 echo "Extracted : `basename $ISO_IMAGE` ($isosize)"
1391 echo "Distro tree : `pwd`"
1392 echo "Rootfs size : `du -sh rootfs`"
1393 echo "Rootcd size : `du -sh rootcd`"
1394 separator
1395 echo ""
1396 ;;
1397 list-flavors)
1398 # Show available flavors.
1399 if [ ! -s /etc/tazlito/flavors.list -o "$2" == "--recharge" ]; then
1400 download flavors.list -O - > /etc/tazlito/flavors.list
1401 fi
1402 echo ""
1403 echo -e "\033[1mList of flavors\033[0m"
1404 separator
1405 cat /etc/tazlito/flavors.list
1406 echo ""
1407 ;;
1408 show-flavor)
1409 # Show flavor description.
1410 FLAVOR=${2%.flavor}
1411 if [ ! -f "$FLAVOR.flavor" ]; then
1412 echo "File $FLAVOR.flavor not found."
1413 exit 1
1414 fi
1415 mkdir $TMP_DIR
1416 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i > /dev/null)
1417 if [ "$3" = "--brief" ]; then
1418 if [ "$4" != "--noheader" ]; then
1419 echo "Name ISO Rootfs Description"
1420 separator
1421 fi
1422 printf "%-16.16s %6.6s %6.6s %s\n" "$FLAVOR" \
1423 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
1424 "$(field 'Rootfs size' $TMP_DIR/$FLAVOR.desc)" \
1425 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
1426 else
1427 separator
1428 cat $TMP_DIR/$FLAVOR.desc
1429 fi
1430 rm -Rf $TMP_DIR
1431 ;;
1432 gen-liveflavor)
1433 # Generate a new flavor from the live system.
1434 FLAVOR=${2%.flavor}
1435 DESC=""
1436 case "$FLAVOR" in
1437 '') echo -n "Flavor name : "
1438 read FLAVOR
1439 [ -z "$FLAVOR" ] && exit 1;;
1440 -?|-h*|--help) echo -e "
1442 SliTaz Live Tool - Version: $VERSION
1443 \033[1mUsage: \033[0m `basename $0` gen-liveflavor flavor-name [flavor-patch-file]
1444 \033[1mflavor-patch-file format: \033[0m
1445 code data
1446 + package to add
1447 - package to remove
1448 ! non-free package to add
1449 ? display message
1450 @ flavor description
1452 \033[1mExample: \033[0m
1453 @ Developer tools for slitaz maintainers
1454 + slitaz-toolchain
1455 + mercurial
1457 exit 1;;
1458 esac
1459 mv /etc/tazlito/distro-packages.list \
1460 /etc/tazlito/distro-packages.list.$$ 2> /dev/null
1461 rm -f distro-packages.list non-free.list 2> /dev/null
1462 tazpkg recharge
1463 [ -n "$3" ] && while read action pkg; do
1464 case "$action" in
1465 +) yes | tazpkg get-install $pkg 2>&1 >> $log || exit 1 ;;
1466 -) yes | tazpkg remove $pkg ;;
1467 !) echo $pkg >> non-free.list ;;
1468 @) DESC="$pkg" ;;
1469 \?) echo -en "$pkg"; read action ;;
1470 esac
1471 done < $3
1472 yes '' | tazlito gen-distro
1473 echo "$DESC" | tazlito gen-flavor "$FLAVOR"
1474 mv /etc/tazlito/distro-packages.list.$$ \
1475 /etc/tazlito/distro-packages.list 2> /dev/null
1476 ;;
1477 gen-flavor)
1478 # Generate a new flavor from the last iso image generated.
1479 FLAVOR=${2%.flavor}
1480 echo ""
1481 echo -e "\033[1mFlavor generation\033[0m"
1482 separator
1483 if [ -z "$FLAVOR" ]; then
1484 echo -n "Flavor name : "
1485 read FLAVOR
1486 [ -z "$FLAVOR" ] && exit 1
1487 fi
1488 check_rootfs
1489 FILES="$FLAVOR.pkglist"
1490 echo -n "Creating file $FLAVOR.flavor..."
1491 for i in rootcd rootfs; do
1492 if [ -d "$ADDFILES/$i" ] ; then
1493 FILES="$FILES\n$FLAVOR.$i"
1494 ( cd "$ADDFILES/$i"; find . | \
1495 cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
1496 fi
1497 done
1498 status
1499 answer=`grep -s ^Description $FLAVOR.desc`
1500 answer=${answer#Description : }
1501 if [ -z "$answer" ]; then
1502 echo -n "Description : "
1503 read answer
1504 fi
1505 echo -n "Compressing flavor $FLAVOR..."
1506 echo "Flavor : $FLAVOR" > $FLAVOR.desc
1507 echo "Description : $answer" >> $FLAVOR.desc
1508 ( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
1509 \rm -f $FLAVOR.pkglist $FLAVOR.nonfree 2> /dev/null
1510 for i in $(ls $ROOTFS$INSTALLED); do
1511 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
1512 EXTRAVERSION=""
1513 eval $(grep ^EXTRAVERSION= $ROOTFS$INSTALLED/$i/receipt)
1514 eval $(grep ^CATEGORY= $ROOTFS$INSTALLED/$i/receipt)
1515 if [ "$CATEGORY" = "non-free" -a "${i%%-*}" != "get" ]
1516 then
1517 echo "$i" >> $FLAVOR.nonfree
1518 else
1519 echo "$i-$VERSION$EXTRAVERSION" >> $FLAVOR.pkglist
1520 fi
1521 done
1522 [ -s $FLAVOR.nonfree ] && $FILES="$FILES\n$FLAVOR.nonfree"
1523 for i in $LOCALSTATE/undigest/*/mirror ; do
1524 [ -s $i ] && cat $i >> $FLAVOR.mirrors
1525 done
1526 [ -s $FLAVOR.mirrors ] && $FILES="$FILES\n$FLAVOR.mirrors"
1527 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
1528 gzip -9 > $FLAVOR.flavor
1529 rm `echo -e $FILES`
1530 status
1531 separator
1532 echo "Flavor size : `du -sh $FLAVOR.flavor`"
1533 echo ""
1534 ;;
1535 upgrade-flavor)
1536 # Update package list to the latest versions available.
1537 FLAVOR=${2%.flavor}
1538 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1539 mkdir $TMP_DIR
1540 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1541 echo -n "Updating $FLAVOR package list..."
1542 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1543 packed_size=0; unpacked_size=0
1544 while read org; do
1545 i=0
1546 pkg=$org
1547 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
1548 pkg=${pkg%-*}
1549 i=$(($i + 1))
1550 [ $i -gt 5 ] && break;
1551 done
1552 set -- $(get_size $pkg)
1553 packed_size=$(( $packed_size + $1 ))
1554 unpacked_size=$(( $unpacked_size + $2 ))
1555 for i in $(grep ^$pkg $LOCALSTATE/packages.list); do
1556 echo $i
1557 break
1558 done
1559 done < $TMP_DIR/$FLAVOR.pkglist \
1560 > $TMP_DIR/$FLAVOR.pkglist.$$
1561 mv -f $TMP_DIR/$FLAVOR.pkglist.$$ $TMP_DIR/$FLAVOR.pkglist
1562 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1563 packed_size=$(($packed_size \
1564 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1565 unpacked_size=$(($unpacked_size \
1566 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1567 fi
1568 # Estimate lzma
1569 packed_size=$(($packed_size * 2 / 3))
1570 iso_size=$(( $packed_size + 26000 ))
1571 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1572 iso_size=$(($iso_size \
1573 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1574 fi
1575 sed -i -e '/Image is ready/d' \
1576 -e "s/Rootfs size\( *:\) \(.*\)/Rootfs size\1 $(cent2human $unpacked_size) (estimated)/" \
1577 -e "s/Initramfs size\( *:\) \(.*\)/Initramfs size\1 $(cent2human $packed_size) (estimated)/" \
1578 -e "s/ISO image size\( *:\) \(.*\)/ISO image size\1 $(cent2human $iso_size) (estimated)/" \
1579 -e "s/date\( *:\) \(.*\)/date\1 $(date +%Y%m%d\ \at\ \%H:%M:%S)/" \
1580 $TMP_DIR/$FLAVOR.desc
1581 ( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
1582 $FLAVOR.flavor
1583 status
1584 rm -Rf $TMP_DIR
1585 fi
1586 ;;
1587 extract-flavor)
1588 # Extract a flavor into $FLAVORS_REPOSITORY.
1589 FLAVOR=${2%.flavor}
1590 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1591 mkdir $TMP_DIR
1592 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1593 echo -n "Extracting $FLAVOR..."
1594 rm -rf $FLAVORS_REPOSITORY/$FLAVOR 2> /dev/null
1595 mkdir -p $FLAVORS_REPOSITORY/$FLAVOR
1596 echo "FLAVOR=\"$FLAVOR\"" > $FLAVORS_REPOSITORY/$FLAVOR/receipt
1597 grep ^Description $TMP_DIR/$FLAVOR.desc | \
1598 sed 's/.*: \(.*\)$/SHORT_DESC="\1"/' >> \
1599 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1600 grep ^Version $TMP_DIR/$FLAVOR.desc | \
1601 sed 's/.*: \(.*\)$/VERSION="\1"/' >> \
1602 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1603 grep ^Maintainer $TMP_DIR/$FLAVOR.desc | \
1604 sed 's/.*: \(.*\)$/MAINTAINER="\1"/' >> \
1605 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1606 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc && \
1607 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1608 sed 's/.*: \(.*\)$/ROOTFS_SELECTION="\1"/' >> \
1609 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1610 grep '^Rootfs size' $TMP_DIR/$FLAVOR.desc | \
1611 sed 's/.*: \(.*\)$/ROOTFS_SIZE="\1"/' >> \
1612 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1613 grep ^Initramfs $TMP_DIR/$FLAVOR.desc | \
1614 sed 's/.*: \(.*\)$/INITRAMFS_SIZE="\1"/' >> \
1615 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1616 grep ^ISO $TMP_DIR/$FLAVOR.desc | \
1617 sed 's/.*: \(.*\)$/ISO_SIZE="\1"/' >> \
1618 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1619 for i in rootcd rootfs; do
1620 [ -f $TMP_DIR/$FLAVOR.$i ] || continue
1621 mkdir $FLAVORS_REPOSITORY/$FLAVOR/$i
1622 zcat $TMP_DIR/$FLAVOR.$i | \
1623 (cd $FLAVORS_REPOSITORY/$FLAVOR/$i; \
1624 cpio -idm > /dev/null)
1625 done
1626 [ -s $TMP_DIR/$FLAVOR.mirrors ] &&
1627 cp $TMP_DIR/$FLAVOR.mirrors \
1628 $FLAVORS_REPOSITORY/$FLAVOR/mirrors
1629 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1630 while read org; do
1631 i=0
1632 pkg=$org
1633 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
1634 pkg=${pkg%-*}
1635 i=$(($i + 1))
1636 [ $i -gt 5 ] && break;
1637 done
1638 echo $pkg
1639 done < $TMP_DIR/$FLAVOR.pkglist \
1640 > $FLAVORS_REPOSITORY/$FLAVOR/packages.list
1641 status
1642 rm -Rf $TMP_DIR
1643 fi
1644 ;;
1645 pack-flavor)
1646 # Create a flavor from $FLAVORS_REPOSITORY.
1647 FLAVOR=${2%.flavor}
1648 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/receipt ]; then
1649 mkdir $TMP_DIR
1650 echo -n "Creating flavor $FLAVOR..."
1651 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1652 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/mirrors ]; then
1653 cp $FLAVORS_REPOSITORY/$FLAVOR/mirrors \
1654 $TMP_DIR/$FLAVOR.mirrors
1655 for i in $(cat $TMP_DIR/$FLAVOR.mirrors); do
1656 wget -O - $i/packages.list >> $TMP_DIR/packages.list
1657 done
1658 fi
1659 #add distro;sh if exist
1660 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/distro.sh ]; then
1661 cp $FLAVORS_REPOSITORY/$FLAVOR/distro.sh $TMP_DIR/$FLAVOR-distro.sh
1662 fi
1663 [ -s $FLAVORS_REPOSITORY/$FLAVOR/packages.list ] &&
1664 get_pkglist $FLAVOR > $TMP_DIR/$FLAVOR.pkglist
1665 if grep -q ^ROOTFS_SELECTION \
1666 $FLAVORS_REPOSITORY/$FLAVOR/receipt; then
1667 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1668 set -- $ROOTFS_SELECTION
1669 [ -n "$FRUGAL_RAM" ] || FRUGAL_RAM=$1
1670 [ -f $FLAVORS_REPOSITORY/$2/packages.list ] ||
1671 tazlito extract-flavor $2
1672 get_pkglist $2 > $TMP_DIR/$FLAVOR.pkglist
1673 for i in rootcd rootfs; do
1674 mkdir $TMP_DIR/$i
1675 # Copy extra files from the first flavor
1676 [ -d $FLAVORS_REPOSITORY/$2/$i ] &&
1677 cp -a $FLAVORS_REPOSITORY/$2/$i $TMP_DIR
1678 # Overload extra files by meta flavor
1679 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] &&
1680 cp -a $FLAVORS_REPOSITORY/$FLAVOR/$i $TMP_DIR
1681 [ -n "$(ls $TMP_DIR/$i)" ] &&
1682 ( cd $TMP_DIR/$i ; find . | cpio -o -H newc 2> /dev/null ) | \
1683 gzip -9 >$TMP_DIR/$FLAVOR.$i
1684 rm -rf $TMP_DIR/$i
1685 done
1686 else
1687 for i in rootcd rootfs; do
1688 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] || \
1689 continue
1690 ( cd $FLAVORS_REPOSITORY/$FLAVOR/$i ; \
1691 find . | cpio -o -H newc 2> /dev/null ) | \
1692 gzip -9 >$TMP_DIR/$FLAVOR.$i
1693 done
1694 fi
1695 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1696 packed_size=$(($packed_size \
1697 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1698 unpacked_size=$(($unpacked_size \
1699 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1700 fi
1701 # Estimate lzma
1702 packed_size=$(($packed_size * 2 / 3))
1703 iso_size=$(( $packed_size + 26000 ))
1704 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1705 iso_size=$(($iso_size \
1706 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1707 fi
1708 VERSION=""
1709 MAINTAINER=""
1710 ROOTFS_SELECTION=""
1711 ROOTFS_SIZE="$(cent2human $unpacked_size) (estimated)"
1712 INITRAMFS_SIZE="$(cent2human $packed_size) (estimated)"
1713 ISO_SIZE="$(cent2human $iso_size) (estimated)"
1714 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1715 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1716 Flavor : $FLAVOR
1717 Description : $SHORT_DESC
1718 EOT
1719 [ -n "$VERSION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1720 Version : $VERSION
1721 EOT
1722 [ -n "$MAINTAINER" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1723 Maintainer : $MAINTAINER
1724 EOT
1725 [ -n "$FRUGAL_RAM" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1726 LiveCD RAM size : $FRUGAL_RAM
1727 EOT
1728 [ -n "$ROOTFS_SELECTION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1729 Rootfs list : $ROOTFS_SELECTION
1730 EOT
1731 cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1732 Build date : $(date +%Y%m%d\ \at\ \%H:%M:%S)
1733 Packages : $(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l)
1734 Rootfs size : $ROOTFS_SIZE
1735 Initramfs size : $INITRAMFS_SIZE
1736 ISO image size : $ISO_SIZE
1737 ================================================================================
1739 EOT
1740 rm -f $TMP_DIR/packages.list
1741 ( cd $TMP_DIR ; ls | cpio -o -H newc 2> /dev/null) | \
1742 gzip -9 > $FLAVOR.flavor
1743 status
1744 rm -Rf $TMP_DIR
1745 else
1746 echo "No $FLAVOR flavor in $FLAVORS_REPOSITORY."
1747 fi
1748 ;;
1749 get-flavor)
1750 # Get a flavor's files and prepare for gen-distro.
1751 FLAVOR=${2%.flavor}
1752 echo -e "\n\033[1mPreparing $FLAVOR distro flavor\033[0m"
1753 separator
1754 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1755 echo -n "Cleaning $DISTRO..."
1756 rm -R $DISTRO 2> /dev/null
1757 mkdir -p $DISTRO
1758 status
1759 mkdir $TMP_DIR
1760 echo -n "Extracting flavor $FLAVOR.flavor... "
1761 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1762 status
1763 echo -n "Creating distro-packages.list..."
1764 mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
1765 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
1766 status
1767 if [ -f "$TMP_DIR/$FLAVOR-distro.sh" ]; then
1768 echo -n "Extracting distro.sh... "
1769 mv $TMP_DIR/$FLAVOR-distro.sh distro.sh 2> /dev/null
1770 status
1771 fi
1772 infos="$FLAVOR.desc"
1773 for i in rootcd rootfs; do
1774 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
1775 echo -n "Adding $i files... "
1776 mkdir -p "$ADDFILES/$i"
1777 zcat $TMP_DIR/$FLAVOR.$i | \
1778 ( cd "$ADDFILES/$i"; cpio -id > /dev/null)
1779 zcat $TMP_DIR/$FLAVOR.$i | cpio -tv 2> /dev/null \
1780 > $TMP_DIR/$FLAVOR.list$i
1781 infos="$infos\n$FLAVOR.list$i"
1782 status
1783 fi
1784 done
1785 if [ -s $TMP_DIR/$FLAVOR.mirrors ]; then
1786 n=""
1787 while read line; do
1788 mkdir -p $LOCALSTATE/undigest/$FLAVOR$n
1789 echo "$line" > $LOCALSTATE/undigest/$FLAVOR$n/mirror
1790 n=$(( $n + 1 ))
1791 done < $TMP_DIR/$FLAVOR.mirrors
1792 infos="$infos\n$FLAVOR.mirrors"
1793 tazpkg recharge
1794 fi
1795 rm -f /etc/tazlito/rootfs.list
1796 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc &&
1797 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1798 sed 's/.*: \(.*\)$/\1/' > /etc/tazlito/rootfs.list
1799 echo -n "Updating tazlito.conf..."
1800 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
1801 cat tazlito.conf | grep -v "^#VOLUM_NAME" | \
1802 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
1803 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
1804 sed -i "s/ISO_NAME=.*/ISO_NAME=\"slitaz-$FLAVOR\"/" tazlito.conf
1805 status
1806 ( cd $TMP_DIR ; echo -e $infos | cpio -o -H newc ) | \
1807 gzip -9 > /etc/tazlito/info
1808 rm -Rf $TMP_DIR
1809 fi
1810 separator
1811 echo -e "Flavor is ready to be generated by: tazlito gen-distro\n"
1812 ;;
1814 iso2flavor)
1815 if [ -z "$3" -o ! -s "$2" ]; then
1816 cat <<EOT
1817 Usage : tazlito iso2flavor image.iso flavor_name
1819 Create a file flavor_name.flavor from the cdrom image file image.iso
1820 EOT
1821 exit 1
1822 fi
1823 FLAVOR=${3%.flavor}
1824 mkdir -p $TMP_DIR/iso $TMP_DIR/rootfs
1825 mount -o loop,ro $2 $TMP_DIR/iso
1826 if [ -s $TMP_DIR/iso/boot/rootfs1.gz ]; then
1827 echo "META flavors are not supported."
1828 umount -d $TMP_DIR/iso
1829 elif [ ! -s $TMP_DIR/iso/boot/rootfs.gz ]; then
1830 echo "No /boot/rootfs.gz in iso image. Needs a SliTaz iso."
1831 umount -d $TMP_DIR/iso
1832 else
1833 ( unlzma -c $TMP_DIR/iso/boot/rootfs.gz || \
1834 zcat $TMP_DIR/iso/boot/rootfs.gz ) | \
1835 ( cd $TMP_DIR/rootfs ; cpio -idmu > /dev/null 2>&1 )
1836 if [ ! -s $TMP_DIR/rootfs/etc/slitaz-release ]; then
1837 echo "No file /etc/slitaz-release in /boot/rootfs.gz of iso image. Needs a non loram SliTaz iso."
1838 umount -d $TMP_DIR/iso
1839 else
1840 ROOTFS_SIZE=$(du -hs $TMP_DIR/rootfs | awk '{ print $1 }')
1841 RAM_SIZE=$(du -s $TMP_DIR/rootfs | awk '{ print 32*int(($1+36000)/32768) "M" }')
1842 cp -a $TMP_DIR/iso $TMP_DIR/rootcd
1843 ISO_SIZE=$(df -h $TMP_DIR/iso | awk 'END { print $2 }')
1844 BUILD_DATE=$(date +%Y%m%d\ \at\ \%H:%M:%S -r $TMP_DIR/iso/md5sum)
1845 umount -d $TMP_DIR/iso
1846 INITRAMFS_SIZE=$(du -chs $TMP_DIR/rootcd/boot/rootfs.gz | awk '{ s=$1 } END { print $1 }')
1847 rm -f $TMP_DIR/rootcd/boot/rootfs.gz $TMP_DIR/rootcd/md5sum
1848 mv $TMP_DIR/rootcd/boot $TMP_DIR/rootfs
1849 sed 's/.* \(.*\).tazpkg*/\1/' > $TMP_DIR/$FLAVOR.pkglist \
1850 < $TMP_DIR/rootfs$INSTALLED.md5
1851 #[ -s $TMP_DIR/rootfs/etc/tazlito/distro-packages.list ] &&
1852 # mv $TMP_DIR/rootfs/etc/tazlito/distro-packages.list $TMP_DIR/$FLAVOR.pkglist
1853 PKGCNT=$(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l | awk '{ print $1 }')
1854 find_flavor_rootfs $TMP_DIR/rootfs
1855 [ -d $TMP_DIR/rootfs/boot ] && mv $TMP_DIR/rootfs/boot $TMP_DIR/rootcd
1856 [ -n "$(ls $TMP_DIR/rootfs)" ] && ( cd $TMP_DIR/rootfs ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootfs
1857 [ -n "$(ls $TMP_DIR/rootcd)" ] && ( cd $TMP_DIR/rootcd ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootcd
1858 rm -rf $TMP_DIR/rootcd $TMP_DIR/rootfs
1859 VERSION=""; MAINTAINER=""
1860 echo -en "Flavor short description \007: "; read -t 30 DESCRIPTION
1861 if [ -n "$DESCRIPTION" ]; then
1862 echo -en "Flavor version : "; read -t 30 VERSION
1863 echo -en "Flavor maintainer (your email) : "; read -t 30 MAINTAINER
1864 fi
1865 [ -n "$DESCRIPTION" ] || DESCRIPTION="Slitaz $FLAVOR flavor"
1866 [ -n "$VERSION" ] || VERSION="1.0"
1867 [ -n "$MAINTAINER" ] || MAINTAINER="nobody@slitaz.org"
1868 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1869 Flavor : $FLAVOR
1870 Description : $DESCRIPTION
1871 Version : $VERSION
1872 Maintainer : $MAINTAINER
1873 LiveCD RAM size : $RAM_SIZE
1874 Build date : $BUILD_DATE
1875 Packages : $PKGCNT
1876 Rootfs size : $ROOTFS_SIZE
1877 Initramfs size : $INITRAMFS_SIZE
1878 ISO image size : $ISO_SIZE
1879 ================================================================================
1881 EOT
1882 ( cd $TMP_DIR ; ls $FLAVOR.* | cpio -o -H newc ) | gzip -9 > $FLAVOR.flavor
1883 cat <<EOT
1884 Tazlito can't detect each file installed during a package post_install.
1885 You should extract this flavor (tazlito extract-flavor $FLAVOR),
1886 check the files in /home/slitaz/flavors/$(cat /etc/slitaz-release)/$FLAVOR/rootfs tree and remove
1887 files generated by post_installs.
1888 Check /home/slitaz/flavors/$(cat /etc/slitaz-release)/$FLAVOR/receipt too and repack the flavor
1889 (tazlito pack-flavor $FLAVOR)
1890 EOT
1891 fi
1892 fi
1893 rm -rf $TMP_DIR
1894 ;;
1896 check-list)
1897 # Use current packages list in $PWD by default.
1898 DISTRO_PKGS_LIST=distro-packages.list
1899 [ -d "$2" ] && DISTRO_PKGS_LIST=$2/distro-packages.list
1900 [ -f "$2" ] && DISTRO_PKGS_LIST=$2
1901 [ ! -f $DISTRO_PKGS_LIST ] && echo "No packages list found." && exit 0
1902 echo ""
1903 echo -e "\033[1mLiveCD packages list check\033[0m"
1904 separator
1905 for pkg in `cat $DISTRO_PKGS_LIST`
1906 do
1907 if ! grep -q "$pkg" $LOCALSTATE/packages.list; then
1908 echo "Updating: $pkg"
1909 up=$(($up + 1))
1910 fi
1911 done
1912 [ -z $up ] && echo -e "List is up-to-date\n" && exit 0
1913 separator
1914 echo -e "Updates: $up\n" ;;
1915 gen-distro)
1916 # Generate a live distro tree with a set of packages.
1918 check_root
1919 time=$(date +%s)
1921 # Check if a package list was specified on cmdline.
1922 LIST_NAME="distro-packages.list"
1923 CDROM=""
1924 while [ -n "$2" ]; do
1925 case "$2" in
1926 --iso=*)
1927 CDROM="-o loop ${2#--iso=}"
1928 ;;
1929 --cdrom)
1930 CDROM="/dev/cdrom"
1931 ;;
1932 --force)
1933 DELETE_ROOTFS="true"
1934 ;;
1935 *) if [ ! -f "$2" ] ; then
1936 echo -e "\nUnable to find the specified packages list."
1937 echo -e "List name : $2\n"
1938 exit 1
1939 fi
1940 LIST_NAME=$2
1941 ;;
1942 esac
1943 shift
1944 done
1946 if [ -d $ROOTFS ] ; then
1947 # Delete $ROOTFS if --force is set on command line
1948 if [ ! -z $DELETE_ROOTFS ]; then
1949 rm -rf $ROOTFS
1950 unset $DELETE_ROOTFS
1951 else
1952 echo -e "\nA rootfs exists in : $DISTRO"
1953 echo -e "Please clean the distro tree or change directory path.\n"
1954 exit 0
1955 fi
1956 fi
1957 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
1958 # Build list with installed packages
1959 for i in $(ls $INSTALLED); do
1960 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
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 /etc/asound.state
2285 rm -f /etc/X11/screen.conf
2286 rm -f /etc/X11/xorg.conf ;;
2287 *)
2288 echo -n "Keeping current sound card and screen configurations..." ;;
2289 esac
2290 status
2292 cd /
2293 # Create list of files including default user files since it is defined in /etc/passwd
2294 # and some new users might have been added.
2295 find bin etc init sbin var dev lib root usr home >/tmp/list
2297 for dir in proc sys tmp mnt media media/cdrom media/flash media/usbdisk
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.
2423 EOT
2424 exit 2
2425 fi
2427 shift # skip merge
2428 append="$1 slitaz1"
2429 shift # skip size1
2430 mkdir -p $TMP_DIR/mnt $TMP_DIR/rootfs1
2432 ISO=$1.merged
2433 # Extract filesystems
2434 echo -n "Mounting $1"
2435 mount -o loop,ro $1 $TMP_DIR/mnt 2> /dev/null
2436 status || cleanup_merge
2437 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2438 rm -f $TMP_DIR/iso/boot/bzImage
2439 ln $TMP_DIR/iso/boot/vmlinuz* $TMP_DIR/iso/boot/bzImage
2440 umount -d $TMP_DIR/mnt
2441 if [ -f $TMP_DIR/iso/boot/rootfs1.gz ]; then
2442 echo "$1 is already a merged iso. Aborting."
2443 cleanup_merge
2444 fi
2445 if [ ! -f $TMP_DIR/iso/boot/isolinux/ifmem.c32 -a
2446 ! -f $TMP_DIR/iso/boot/isolinux/c32box.c32 ]; then
2447 if [ ! -f /boot/isolinux/ifmem.c32 -a
2448 ! -f /boot/isolinux/c32box.c32 ]; then
2449 cat <<EOT
2450 No file /boot/isolinux/ifmem.c32
2451 Please install syslinux package !
2452 EOT
2453 rm -rf $TMP_DIR
2454 exit 1
2455 fi
2456 cp /boot/isolinux/c32box.c32 $TMP_DIR/iso/boot/isolinux 2> /dev/null ||
2457 cp /boot/isolinux/ifmem.c32 $TMP_DIR/iso/boot/isolinux
2458 fi
2460 echo -n "Extracting iso/rootfs.gz"
2461 extract_rootfs $TMP_DIR/iso/boot/rootfs.gz $TMP_DIR/rootfs1 &&
2462 [ -d $TMP_DIR/rootfs1/etc ]
2463 status || cleanup_merge
2464 n=1
2465 while [ -n "$2" ]; do
2466 shift # skip rootfs N-1
2467 p=$n
2468 n=$(($n + 1))
2469 append="$append $1 slitaz$n"
2470 shift # skip size N
2471 mkdir -p $TMP_DIR/rootfs$n
2472 echo -n "Extracting $1"
2473 extract_rootfs $1 $TMP_DIR/rootfs$n &&
2474 [ -d $TMP_DIR/rootfs$n/etc ]
2475 status || cleanup_merge
2476 mergefs $TMP_DIR/rootfs$n $TMP_DIR/rootfs$p
2477 echo "Creating rootfs$p.gz"
2478 pack_rootfs $TMP_DIR/rootfs$p $TMP_DIR/iso/boot/rootfs$p.gz
2479 status
2480 done
2481 echo "Creating rootfs$n.gz"
2482 pack_rootfs $TMP_DIR/rootfs$n $TMP_DIR/iso/boot/rootfs$n.gz
2483 status
2484 rm -f $TMP_DIR/iso/boot/rootfs.gz
2485 update_bootconfig $TMP_DIR/iso/boot/isolinux "$append"
2486 create_iso $ISO $TMP_DIR/iso
2487 rm -rf $TMP_DIR
2488 ;;
2490 repack)
2491 # Repack an iso with maximum lzma compression ratio.
2494 ISO=$2
2496 mkdir -p $TMP_DIR/mnt
2497 # Extract filesystems
2498 echo -n "Mounting $ISO"
2499 mount -o loop,ro $ISO $TMP_DIR/mnt 2> /dev/null
2500 status || cleanup_merge
2501 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2502 umount -d $TMP_DIR/mnt
2504 for i in $TMP_DIR/iso/boot/rootfs* ; do
2505 echo -n "Repacking $(basename $i)"
2506 (zcat $i 2> /dev/null || unlzma -c $i || cat $i) \
2507 2>/dev/null > $TMP_DIR/rootfs
2508 lzma e $TMP_DIR/rootfs $i \
2509 $(lzma_switches $TMP_DIR/rootfs)
2510 status
2511 done
2513 create_iso $ISO $TMP_DIR/iso
2514 rm -rf $TMP_DIR ;;
2516 build-loram)
2517 # Build a Live CD for low ram systems.
2520 ISO=$2
2521 OUTPUT=$3
2522 if [ -z "$3" ]; then
2523 echo "Usage: tazlito $1 input.iso output.iso [cdrom|smallcdrom|http|ram]"
2524 exit 1
2525 fi
2526 mkdir -p $TMP_DIR/iso
2527 mount -o loop,ro -t iso9660 $ISO $TMP_DIR/iso
2528 if ! check_iso_for_loram ; then
2529 echo "$2 is not a valid SliTaz live CD. Abort."
2530 umount -d $TMP_DIR/iso
2531 rm -rf $TMP_DIR
2532 exit 1
2533 fi
2535 case "$4" in
2536 cdrom) build_loram_cdrom ;;
2537 smallcdrom) build_loram_cdrom small ;;
2538 http) build_loram_http ;;
2539 *) build_loram_ram ;;
2540 esac
2541 umount -d $TMP_DIR/iso
2542 rm -rf $TMP_DIR ;;
2545 frugal-install|-fi)
2546 ISO_IMAGE="$2"
2547 echo ""
2548 mkdir -p /boot/frugal
2549 if [ -f "$ISO_IMAGE" ]; then
2550 echo -n "Using ISO image: $ISO_IMAGE"
2551 mkdir -p /tmp/iso && mount -o loop $ISO_IMAGE /tmp/iso
2552 status
2553 echo -n "Installing the Kernel and rootfs..."
2554 cp -a /tmp/iso/boot/bzImage /boot/frugal
2555 if [ -f $DISTRO/rootcd/boot/rootfs1.gz ]; then
2556 cd /tmp/iso/boot
2557 cat $(ls -r rootfs*.gz) > /boot/frugal/rootfs.gz
2558 else
2559 cp -a /tmp/iso/boot/rootfs.gz /boot/frugal
2560 fi
2561 umount /tmp/iso
2562 status
2563 else
2564 echo -n "Using distro: $DISTRO"
2565 cd $DISTRO && status
2566 echo -n "Installing the Kernel and rootfs..."
2567 cp -a $DISTRO/rootcd/boot/bzImage /boot/frugal
2568 if [ -f $DISTRO/rootcd/boot/rootfs1.gz ]; then
2569 cd $DISTRO/rootcd/boot
2570 cat $(ls -r rootfs*.gz) > /boot/frugal/rootfs.gz
2571 else
2572 cp -a $DISTRO/rootcd/boot/rootfs.gz /boot/frugal
2573 fi
2574 status
2575 fi
2576 # Grub entry
2577 if ! grep -q "^kernel /boot/frugal/bzImage" /boot/grub/menu.lst; then
2578 echo -n "Configuring GRUB menu list..."
2579 cat >> /boot/grub/menu.lst << EOT
2580 title SliTaz GNU/Linux (frugal)
2581 root (hd0,0)
2582 kernel /boot/frugal/bzImage root=/dev/null
2583 initrd /boot/frugal/rootfs.gz
2584 EOT
2585 else
2586 echo -n "GRUB menu list is up-to-date..."
2587 fi
2588 status
2589 echo "" ;;
2591 emu-iso)
2592 # Emulate an ISO image with Qemu.
2593 if [ -n "$2" ] ; then
2594 iso=$2
2595 else
2596 iso=$DISTRO/$ISO_NAME.iso
2597 fi
2598 if [ ! -f "$iso" ]; then
2599 echo -e "\nUnable to find ISO : $iso\n"
2600 exit 0
2601 fi
2602 if [ ! -x "/usr/bin/qemu" ]; then
2603 echo -e "\nUnable to find Qemu binary. Please install: qemu\n"
2604 exit 0
2605 fi
2606 echo -e "\nStarting Qemu emulator:\n"
2607 echo -e "qemu $QEMU_OPTS $iso\n"
2608 qemu $QEMU_OPTS $iso ;;
2610 deduplicate)
2611 # Deduplicate files in a tree
2612 shift
2613 deduplicate "$@" ;;
2614 usage|*)
2615 # Clear and print usage also for all unknown commands.
2617 clear
2618 usage ;;
2619 esac
2621 exit 0