tazlito view tazlito @ rev 312

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