tazlito view tazlito @ rev 279

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