tazlito view tazlito @ rev 292

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