tazlito view tazlito @ rev 248

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