tazlito view tazlito @ rev 237

http://tiny.slitaz.org/ advertising
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Feb 18 15:13:15 2012 +0100 (2012-02-18)
parents 962315889ccd
children 1f3fbf7a46c0
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.2
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 if [ -f $TMP_DIR/loramiso/boot/isolinux/noram.cfg ]; then
1008 # We keep enough information to do unloram...
1009 sed -i 's/label slitaz/label orgslitaz/' \
1010 $TMP_DIR/loramiso/boot/isolinux/common.cfg
1011 sed -i -e 's|=/boot/rootfs\(.*\).gz |=/boot/rootfs.gz |' \
1012 -e 's|label slitaz1|label slitaz|' \
1013 -e '/label slitaz[1-9]/{NNNd}' \
1014 $TMP_DIR/loramiso/boot/isolinux/*.cfg
1015 fi
1018 # Move rootfs to squashfs filesystem(s) to the cdrom writeable with aufs.
1019 # These squashfs may be loaded in ram a boot time.
1020 # Rootfs are also copied to cdrom for tiny ramsize systems.
1021 # Meta flavors are converted to normal flavors.
1022 build_loram_cdrom()
1024 build_initfs cdrom || return 1
1025 build_loram_rootfs_cdrom
1026 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1027 if [ "$1" == "small" ]; then
1028 rm -f $TMP_DIR/loramiso/boot/root*
1029 else
1030 mkdir $TMP_DIR/loramiso/fs
1031 cd $TMP_DIR/loramiso/fs
1032 for i in $( ls ../boot/root* | sort -r ) ; do
1033 ( zcat $i 2> /dev/null || unlzma -c $i ) | cpio -idmu
1034 rm -f $i
1035 done
1036 mkdir -p $TMP_DIR/loramiso/fs/mnt/.cdrom
1037 cd - > /dev/null
1038 fi
1039 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
1040 mv $TMP_DIR/rootfs*.gz $TMP_DIR/loramiso
1041 unmeta_boot
1042 VOLUM_NAME="SliTaz_LoRAM_CDROM"
1043 sed -i "s/root=/loram=LABEL=$VOLUM_NAME,fs &/" \
1044 $TMP_DIR/loramiso/boot/isolinux/*.cfg
1045 create_iso $OUTPUT $TMP_DIR/loramiso
1048 # Create http bootstrap to load and remove loram_cdrom
1049 # Meta flavors are converted to normal flavors.
1050 build_loram_http()
1052 build_initfs http || return 1
1053 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1054 rm -f $TMP_DIR/loramiso/boot/rootfs*
1055 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
1056 unmeta_boot
1057 create_iso $OUTPUT $TMP_DIR/loramiso
1060 # Update meta flavor selection sizes.
1061 # Reduce sizes with rootfs gains.
1062 update_metaiso_sizes()
1064 local append="$(grep append $TMP_DIR/loramiso/boot/isolinux/common.cfg)"
1065 local new
1066 [ -n "$append" ] || return
1067 set -- $append
1068 shift
1069 new=""
1070 while [ -n "$2" ]; do
1071 local s
1072 case "$1" in
1073 *G) s=$(( ${1%G} * 1024 * 1024 ));;
1074 *M) s=$(( ${1%M} * 1024 ));;
1075 *) s=${1%K};;
1076 esac
1077 rootfs_sizes=${rootfs_sizes#* }
1078 for i in $rootfs_sizes ; do
1079 s=$(( $s - $i ))
1080 done
1081 new="$new $s $2"
1082 shift 2
1083 done
1084 sed -i "s/append .*/append$new $1/" $TMP_DIR/loramiso/boot/isolinux/common.cfg
1087 # Move rootfs to a squashfs filesystem into the initramfs writeable with aufs.
1088 # Meta flavor selection sizes are updated.
1089 build_loram_ram()
1091 build_initfs ram || return 1
1092 build_loram_rootfs
1093 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1094 rm -f $TMP_DIR/loramiso/boot/bzImage
1095 ln $TMP_DIR/loramiso/boot/vmlinuz* $TMP_DIR/loramiso/boot/bzImage
1096 rootfs=$(ls $TMP_DIR/rootfs* | sort | tail -n 1)
1097 cat $rootfs >> $TMP_DIR/initfs.gz
1098 mv $TMP_DIR/initfs.gz $rootfs
1099 cp $TMP_DIR/rootfs* $TMP_DIR/loramiso/boot
1100 update_metaiso_sizes
1101 create_iso $OUTPUT $TMP_DIR/loramiso
1104 # Remove files installed by packages
1105 find_flavor_rootfs()
1107 for i in $1/etc/tazlito/*.extract; do
1108 [ -e $i ] || continue
1109 chroot $1 /bin/sh ${i#$1}
1110 done
1112 # Clean hardlinks and files patched by genisofs in /boot
1113 for i in isolinux/isolinux.bin isolinux/boot.cat bzImage ; do
1114 rm -f $1/boot/$i
1115 done
1117 # Clean files generated in post_install
1118 rm -f $1/lib/modules/*/modules.* $1/etc/mtab \
1119 $1/dev/core $1/dev/fd $1/dev/std*
1121 # Verify md5
1122 cat $1$INSTALLED/*/md5sum | \
1123 while read md5 file; do
1124 [ -e $1$file ] || continue
1125 [ "$(cat $1$file | md5sum)" == "$md5 -" ] &&
1126 rm -f $1$file
1127 done
1129 # Check configuration files
1130 for i in $1$INSTALLED/*/volatile.cpio.gz; do
1131 [ -e $i ] || continue
1132 mkdir /tmp/volatile$$
1133 zcat $i | ( cd /tmp/volatile$$ ; cpio -idmu > /dev/null 2>&1 )
1134 ( cd /tmp/volatile$$ ; find * -type f 2> /dev/null) | \
1135 while read file ; do
1136 [ -e $1/$file ] || continue
1137 cmp -s /tmp/volatile$$/$file $1/$file && rm -f $1/$file
1138 done
1139 rm -rf /tmp/volatile$$
1140 done
1142 # Remove other files blindly
1143 for i in $1$INSTALLED/*/files.list; do
1144 for file in $(cat $i); do
1145 [ $1$file -nt $i ] && continue
1146 [ -f $1$file -a ! -L $1$file ] && continue
1147 [ -d $1$file ] || rm -f $1$file
1148 done
1149 done
1151 # Remove tazpkg files and tmp files
1152 rm -rf $1$INSTALLED* $1/tmp $1/var/tmp
1153 rm -f $1$LOCALSTATE/*packages* $1$LOCALSTATE/files.list.lzma \
1154 $1$LOCALSTATE/mirror* $1/var/cache/*/* \
1155 $1/var/lock/* $1/var/log/* $1/var/run/* $1/var/run/*/* \
1156 $1/var/lib/* $1/var/lib/dbus/* 2> /dev/null
1158 # Cleanup directory tree
1159 cd $1
1160 find * -type d | sort -r | while read dir; do
1161 rmdir $dir 2> /dev/null
1162 done
1163 cd - > /dev/null
1166 ####################
1167 # Tazlito commands #
1168 ####################
1170 case "$COMMAND" in
1171 stats)
1172 # Tazlito general statistics from the config file.
1174 echo ""
1175 echo -e "\033[1mTazlito statistics\033[0m
1176 ===============================================================================
1177 Config file : $CONFIG_FILE
1178 ISO name : $ISO_NAME.iso
1179 Volume name : $VOLUM_NAME
1180 Prepared : $PREPARED
1181 Packages repository : $PACKAGES_REPOSITORY
1182 Distro directory : $DISTRO"
1183 if [ ! "$ADDFILES" = "" ] ; then
1184 echo -e "Additional files : $ADDFILES"
1185 fi
1186 echo "================================================================================"
1187 echo ""
1188 ;;
1189 list-addfiles)
1190 # Simple list of additional files in the rootfs
1191 echo ""
1192 cd $ADDFILES
1193 find rootfs -type f
1194 echo "" ;;
1195 gen-config)
1196 # Generate a new config file in the current dir or the specified
1197 # directory by $2.
1199 if [ -n "$2" ] ; then
1200 mkdir -p $2 && cd $2
1201 fi
1202 echo -n "Generating empty tazlito.conf..."
1203 empty_config_file
1204 status
1205 echo ""
1206 if [ -f "tazlito.conf" ] ; then
1207 echo "Configuration file is ready to edit."
1208 echo "File location : `pwd`/tazlito.conf"
1209 echo ""
1210 fi
1211 ;;
1212 configure)
1213 # Configure a tazlito.conf config file. Start by getting
1214 # a empty config file and sed it.
1216 if [ -f "tazlito.conf" ] ; then
1217 rm tazlito.conf
1218 else
1219 if test $(id -u) = 0 ; then
1220 cd /etc
1221 else
1222 echo "You must be root to configure the main config file or in"
1223 echo "the same directory of the file you want to configure."
1224 exit 0
1225 fi
1226 fi
1227 empty_config_file
1228 echo""
1229 echo -e "\033[1mConfiguring :\033[0m `pwd`/tazlito.conf"
1230 echo "================================================================================"
1231 # ISO name.
1232 echo -n "ISO name : " ; read answer
1233 sed -i s#'ISO_NAME=\"\"'#"ISO_NAME=\"$answer\""# tazlito.conf
1234 # Volume name.
1235 echo -n "Volume name : " ; read answer
1236 sed -i s/'VOLUM_NAME=\"SliTaz\"'/"VOLUM_NAME=\"$answer\""/ tazlito.conf
1237 # Packages repository.
1238 echo -n "Packages repository : " ; read answer
1239 sed -i s#'PACKAGES_REPOSITORY=\"\"'#"PACKAGES_REPOSITORY=\"$answer\""# tazlito.conf
1240 # Distro path.
1241 echo -n "Distro path : " ; read answer
1242 sed -i s#'DISTRO=\"\"'#"DISTRO=\"$answer\""# tazlito.conf
1243 echo "================================================================================"
1244 echo "Config file is ready to use."
1245 echo "You can now extract an ISO or generate a distro."
1246 echo ""
1247 ;;
1248 gen-iso)
1249 # Simply generate a new iso.
1251 check_root
1252 verify_rootcd
1253 gen_livecd_isolinux
1254 distro_stats
1255 ;;
1256 gen-initiso)
1257 # Simply generate a new initramfs with a new iso.
1259 check_root
1260 verify_rootcd
1261 gen_initramfs $ROOTFS
1262 gen_livecd_isolinux
1263 distro_stats
1264 ;;
1265 extract-distro)
1266 # Extract an ISO image to a directory and rebuild the LiveCD tree.
1268 check_root
1269 ISO_IMAGE=$2
1270 if [ -z "$ISO_IMAGE" ] ; then
1271 echo -e "\nPlease specify the path to the ISO image."
1272 echo -e "Example : `basename $0` image.iso /path/target\n"
1273 exit 0
1274 fi
1275 # Set the distro path by checking for $3 on cmdline.
1276 if [ -n "$3" ] ; then
1277 TARGET=$3
1278 else
1279 TARGET=$DISTRO
1280 fi
1281 # Exit if existing distro is found.
1282 if [ -d "$TARGET/rootfs" ] ; then
1283 echo -e "\nA rootfs exists in : $TARGET"
1284 echo -e "Please clean the distro tree or change directory path.\n"
1285 exit 0
1286 fi
1287 echo ""
1288 echo -e "\033[1mTazlito extracting :\033[0m `basename $ISO_IMAGE`"
1289 echo "================================================================================"
1290 # Start to mount the ISO.
1291 echo ""
1292 echo "Mounting ISO image..."
1293 mkdir -p $TMP_DIR
1294 # Get ISO file size.
1295 isosize=`du -sh $ISO_IMAGE | cut -f1`
1296 mount -o loop $ISO_IMAGE $TMP_DIR
1297 sleep 2
1298 # Prepare target dir, copy the kernel and the rootfs.
1299 mkdir -p $TARGET/rootfs
1300 mkdir -p $TARGET/rootcd/boot
1301 echo -n "Copying the Linux kernel..."
1302 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
1303 ln $TARGET/rootcd/boot/vmlinuz* $TARGET/rootcd/boot/bzImage
1304 else
1305 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
1306 fi
1307 status
1308 echo -n "Copying isolinux files..."
1309 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
1310 for i in $(ls $TMP_DIR); do
1311 [ "$i" = "boot" ] && continue
1312 cp -a $TMP_DIR/$i $TARGET/rootcd
1313 done
1314 status
1315 if [ -d $TMP_DIR/boot/syslinux ]; then
1316 echo -n "Copying syslinux files..."
1317 cp -a $TMP_DIR/boot/syslinux $TARGET/rootcd/boot
1318 status
1319 fi
1320 if [ -d $TMP_DIR/boot/extlinux ]; then
1321 echo -n "Copying extlinux files..."
1322 cp -a $TMP_DIR/boot/extlinux $TARGET/rootcd/boot
1323 status
1324 fi
1325 if [ -d $TMP_DIR/boot/grub ]; then
1326 echo -n "Copying GRUB files..."
1327 cp -a $TMP_DIR/boot/grub $TARGET/rootcd/boot
1328 status
1329 fi
1331 echo -n "Copying the rootfs..."
1332 cp $TMP_DIR/boot/rootfs.?z $TARGET/rootcd/boot
1333 status
1334 # Extract initramfs.
1335 cd $TARGET/rootfs
1336 echo -n "Extracting the rootfs... "
1337 extract_rootfs ../rootcd/boot/rootfs.gz $TARGET/rootfs
1338 # unpack /usr
1339 for i in etc/tazlito/*.extract; do
1340 [ -f "$i" ] && . $i ../rootcd
1341 done
1342 # Umount and remove temp directory and cd to $TARGET to get stats.
1343 umount $TMP_DIR && rm -rf $TMP_DIR
1344 cd ..
1345 echo ""
1346 echo "================================================================================"
1347 echo "Extracted : `basename $ISO_IMAGE` ($isosize)"
1348 echo "Distro tree : `pwd`"
1349 echo "Rootfs size : `du -sh rootfs`"
1350 echo "Rootcd size : `du -sh rootcd`"
1351 echo "================================================================================"
1352 echo ""
1353 ;;
1354 list-flavors)
1355 # Show available flavors.
1356 if [ ! -s /etc/tazlito/flavors.list -o "$2" == "--recharge" ]; then
1357 download flavors.list -O - > /etc/tazlito/flavors.list
1358 fi
1359 echo ""
1360 echo -e "\033[1mList of flavors\033[0m"
1361 echo "================================================================================"
1362 cat /etc/tazlito/flavors.list
1363 echo ""
1364 ;;
1365 show-flavor)
1366 # Show flavor description.
1367 FLAVOR=${2%.flavor}
1368 if [ ! -f "$FLAVOR.flavor" ]; then
1369 echo "File $FLAVOR.flavor not found."
1370 exit 1
1371 fi
1372 mkdir $TMP_DIR
1373 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i > /dev/null)
1374 if [ "$3" = "--brief" ]; then
1375 if [ "$4" != "--noheader" ]; then
1376 echo "Name ISO Rootfs Description"
1377 echo "================================================================================"
1378 fi
1379 printf "%-16.16s %6.6s %6.6s %s\n" "$FLAVOR" \
1380 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
1381 "$(field 'Rootfs size' $TMP_DIR/$FLAVOR.desc)" \
1382 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
1383 else
1384 echo "================================================================================"
1385 cat $TMP_DIR/$FLAVOR.desc
1386 fi
1387 rm -Rf $TMP_DIR
1388 ;;
1389 gen-liveflavor)
1390 # Generate a new flavor from the live system.
1391 FLAVOR=${2%.flavor}
1392 DESC=""
1393 case "$FLAVOR" in
1394 '') echo -n "Flavor name : "
1395 read FLAVOR
1396 [ -z "$FLAVOR" ] && exit 1;;
1397 -?|-h*|--help) echo -e "
1399 SliTaz Live Tool - Version: $VERSION
1400 \033[1mUsage: \033[0m `basename $0` gen-liveflavor flavor-name [flavor-patch-file]
1401 \033[1mflavor-patch-file format: \033[0m
1402 code data
1403 + package to add
1404 - package to remove
1405 ! non-free package to add
1406 ? display message
1407 @ flavor description
1409 \033[1mExample: \033[0m
1410 @ Developer tools for slitaz maintainers
1411 + slitaz-toolchain
1412 + mercurial
1414 exit 1;;
1415 esac
1416 mv /etc/tazlito/distro-packages.list \
1417 /etc/tazlito/distro-packages.list.$$ 2> /dev/null
1418 rm -f distro-packages.list non-free.list 2> /dev/null
1419 tazpkg recharge
1420 [ -n "$3" ] && while read action pkg; do
1421 case "$action" in
1422 +) yes | tazpkg get-install $pkg 2>&1 >> $log || exit 1 ;;
1423 -) yes | tazpkg remove $pkg ;;
1424 !) echo $pkg >> non-free.list ;;
1425 @) DESC="$pkg" ;;
1426 \?) echo -en "$pkg"; read action ;;
1427 esac
1428 done < $3
1429 yes '' | tazlito gen-distro
1430 echo "$DESC" | tazlito gen-flavor "$FLAVOR"
1431 mv /etc/tazlito/distro-packages.list.$$ \
1432 /etc/tazlito/distro-packages.list 2> /dev/null
1433 ;;
1434 gen-flavor)
1435 # Generate a new flavor from the last iso image generated.
1436 FLAVOR=${2%.flavor}
1437 echo ""
1438 echo -e "\033[1mFlavor generation\033[0m"
1439 echo "================================================================================"
1440 if [ -z "$FLAVOR" ]; then
1441 echo -n "Flavor name : "
1442 read FLAVOR
1443 [ -z "$FLAVOR" ] && exit 1
1444 fi
1445 check_rootfs
1446 FILES="$FLAVOR.pkglist"
1447 echo -n "Creating file $FLAVOR.flavor..."
1448 for i in rootcd rootfs; do
1449 if [ -d "$ADDFILES/$i" ] ; then
1450 FILES="$FILES\n$FLAVOR.$i"
1451 ( cd "$ADDFILES/$i"; find . | \
1452 cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
1453 fi
1454 done
1455 status
1456 answer=`grep -s ^Description $FLAVOR.desc`
1457 answer=${answer#Description : }
1458 if [ -z "$answer" ]; then
1459 echo -n "Description : "
1460 read answer
1461 fi
1462 echo -n "Compressing flavor $FLAVOR..."
1463 echo "Flavor : $FLAVOR" > $FLAVOR.desc
1464 echo "Description : $answer" >> $FLAVOR.desc
1465 ( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
1466 \rm -f $FLAVOR.pkglist $FLAVOR.nonfree 2> /dev/null
1467 for i in $(ls $ROOTFS$INSTALLED); do
1468 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
1469 EXTRAVERSION=""
1470 eval $(grep ^EXTRAVERSION= $ROOTFS$INSTALLED/$i/receipt)
1471 eval $(grep ^CATEGORY= $ROOTFS$INSTALLED/$i/receipt)
1472 if [ "$CATEGORY" = "non-free" -a "${i%%-*}" != "get" ]
1473 then
1474 echo "$i" >> $FLAVOR.nonfree
1475 else
1476 echo "$i-$VERSION$EXTRAVERSION" >> $FLAVOR.pkglist
1477 fi
1478 done
1479 [ -s $FLAVOR.nonfree ] && $FILES="$FILES\n$FLAVOR.nonfree"
1480 for i in $LOCALSTATE/undigest/*/mirror ; do
1481 [ -s $i ] && cat $i >> $FLAVOR.mirrors
1482 done
1483 [ -s $FLAVOR.mirrors ] && $FILES="$FILES\n$FLAVOR.mirrors"
1484 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
1485 gzip -9 > $FLAVOR.flavor
1486 rm `echo -e $FILES`
1487 status
1488 echo "================================================================================"
1489 echo "Flavor size : `du -sh $FLAVOR.flavor`"
1490 echo ""
1491 ;;
1492 upgrade-flavor)
1493 # Update package list to the latest versions available.
1494 FLAVOR=${2%.flavor}
1495 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1496 mkdir $TMP_DIR
1497 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1498 echo -n "Updating $FLAVOR package list..."
1499 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1500 packed_size=0; unpacked_size=0
1501 while read org; do
1502 i=0
1503 pkg=$org
1504 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
1505 pkg=${pkg%-*}
1506 i=$(($i + 1))
1507 [ $i -gt 5 ] && break;
1508 done
1509 set -- $(get_size $pkg)
1510 packed_size=$(( $packed_size + $1 ))
1511 unpacked_size=$(( $unpacked_size + $2 ))
1512 for i in $(grep ^$pkg $LOCALSTATE/packages.list); do
1513 echo $i
1514 break
1515 done
1516 done < $TMP_DIR/$FLAVOR.pkglist \
1517 > $TMP_DIR/$FLAVOR.pkglist.$$
1518 mv -f $TMP_DIR/$FLAVOR.pkglist.$$ $TMP_DIR/$FLAVOR.pkglist
1519 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1520 packed_size=$(($packed_size \
1521 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1522 unpacked_size=$(($unpacked_size \
1523 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1524 fi
1525 # Estimate lzma
1526 packed_size=$(($packed_size * 2 / 3))
1527 iso_size=$(( $packed_size + 26000 ))
1528 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1529 iso_size=$(($iso_size \
1530 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1531 fi
1532 sed -i -e '/Image is ready/d' \
1533 -e "s/Rootfs size\( *:\) \(.*\)/Rootfs size\1 $(cent2human $unpacked_size) (estimated)/" \
1534 -e "s/Initramfs size\( *:\) \(.*\)/Initramfs size\1 $(cent2human $packed_size) (estimated)/" \
1535 -e "s/ISO image size\( *:\) \(.*\)/ISO image size\1 $(cent2human $iso_size) (estimated)/" \
1536 -e "s/date\( *:\) \(.*\)/date\1 $(date +%Y%m%d\ \at\ \%H:%M:%S)/" \
1537 $TMP_DIR/$FLAVOR.desc
1538 ( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
1539 $FLAVOR.flavor
1540 status
1541 rm -Rf $TMP_DIR
1542 fi
1543 ;;
1544 extract-flavor)
1545 # Extract a flavor into $FLAVORS_REPOSITORY.
1546 FLAVOR=${2%.flavor}
1547 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1548 mkdir $TMP_DIR
1549 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1550 echo -n "Extracting $FLAVOR..."
1551 rm -rf $FLAVORS_REPOSITORY/$FLAVOR 2> /dev/null
1552 mkdir -p $FLAVORS_REPOSITORY/$FLAVOR
1553 echo "FLAVOR=\"$FLAVOR\"" > $FLAVORS_REPOSITORY/$FLAVOR/receipt
1554 grep ^Description $TMP_DIR/$FLAVOR.desc | \
1555 sed 's/.*: \(.*\)$/SHORT_DESC="\1"/' >> \
1556 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1557 grep ^Version $TMP_DIR/$FLAVOR.desc | \
1558 sed 's/.*: \(.*\)$/VERSION="\1"/' >> \
1559 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1560 grep ^Maintainer $TMP_DIR/$FLAVOR.desc | \
1561 sed 's/.*: \(.*\)$/MAINTAINER="\1"/' >> \
1562 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1563 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc && \
1564 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1565 sed 's/.*: \(.*\)$/ROOTFS_SELECTION="\1"/' >> \
1566 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1567 grep '^Rootfs size' $TMP_DIR/$FLAVOR.desc | \
1568 sed 's/.*: \(.*\)$/ROOTFS_SIZE="\1"/' >> \
1569 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1570 grep ^Initramfs $TMP_DIR/$FLAVOR.desc | \
1571 sed 's/.*: \(.*\)$/INITRAMFS_SIZE="\1"/' >> \
1572 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1573 grep ^ISO $TMP_DIR/$FLAVOR.desc | \
1574 sed 's/.*: \(.*\)$/ISO_SIZE="\1"/' >> \
1575 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1576 for i in rootcd rootfs; do
1577 [ -f $TMP_DIR/$FLAVOR.$i ] || continue
1578 mkdir $FLAVORS_REPOSITORY/$FLAVOR/$i
1579 zcat $TMP_DIR/$FLAVOR.$i | \
1580 (cd $FLAVORS_REPOSITORY/$FLAVOR/$i; \
1581 cpio -idm > /dev/null)
1582 done
1583 [ -s $TMP_DIR/$FLAVOR.mirrors ] &&
1584 cp $TMP_DIR/$FLAVOR.mirrors \
1585 $FLAVORS_REPOSITORY/$FLAVOR/mirrors
1586 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1587 while read org; do
1588 i=0
1589 pkg=$org
1590 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
1591 pkg=${pkg%-*}
1592 i=$(($i + 1))
1593 [ $i -gt 5 ] && break;
1594 done
1595 echo $pkg
1596 done < $TMP_DIR/$FLAVOR.pkglist \
1597 > $FLAVORS_REPOSITORY/$FLAVOR/packages.list
1598 status
1599 rm -Rf $TMP_DIR
1600 fi
1601 ;;
1602 pack-flavor)
1603 # Create a flavor from $FLAVORS_REPOSITORY.
1604 FLAVOR=${2%.flavor}
1605 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/receipt ]; then
1606 mkdir $TMP_DIR
1607 echo -n "Creating flavor $FLAVOR..."
1608 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1609 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/mirrors ]; then
1610 cp $FLAVORS_REPOSITORY/$FLAVOR/mirrors \
1611 $TMP_DIR/$FLAVOR.mirrors
1612 for i in $(cat $TMP_DIR/$FLAVOR.mirrors); do
1613 wget -O - $i/packages.list >> $TMP_DIR/packages.list
1614 done
1615 fi
1616 [ -s $FLAVORS_REPOSITORY/$FLAVOR/packages.list ] &&
1617 get_pkglist $FLAVOR > $TMP_DIR/$FLAVOR.pkglist
1618 if grep -q ^ROOTFS_SELECTION \
1619 $FLAVORS_REPOSITORY/$FLAVOR/receipt; then
1620 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1621 set -- $ROOTFS_SELECTION
1622 [ -n "$FRUGAL_RAM" ] || FRUGAL_RAM=$1
1623 [ -f $FLAVORS_REPOSITORY/$2/packages.list ] ||
1624 tazlito extract-flavor $2
1625 get_pkglist $2 > $TMP_DIR/$FLAVOR.pkglist
1626 for i in rootcd rootfs; do
1627 mkdir $TMP_DIR/$i
1628 # Copy extra files from the first flavor
1629 [ -d $FLAVORS_REPOSITORY/$2/$i ] &&
1630 cp -a $FLAVORS_REPOSITORY/$2/$i $TMP_DIR
1631 # Overload extra files by meta flavor
1632 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] &&
1633 cp -a $FLAVORS_REPOSITORY/$FLAVOR/$i $TMP_DIR
1634 [ -n "$(ls $TMP_DIR/$i)" ] &&
1635 ( cd $TMP_DIR/$i ; find . | cpio -o -H newc 2> /dev/null ) | \
1636 gzip -9 >$TMP_DIR/$FLAVOR.$i
1637 rm -rf $TMP_DIR/$i
1638 done
1639 else
1640 for i in rootcd rootfs; do
1641 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] || \
1642 continue
1643 ( cd $FLAVORS_REPOSITORY/$FLAVOR/$i ; \
1644 find . | cpio -o -H newc 2> /dev/null ) | \
1645 gzip -9 >$TMP_DIR/$FLAVOR.$i
1646 done
1647 fi
1648 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1649 packed_size=$(($packed_size \
1650 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1651 unpacked_size=$(($unpacked_size \
1652 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1653 fi
1654 # Estimate lzma
1655 packed_size=$(($packed_size * 2 / 3))
1656 iso_size=$(( $packed_size + 26000 ))
1657 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1658 iso_size=$(($iso_size \
1659 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1660 fi
1661 VERSION=""
1662 MAINTAINER=""
1663 ROOTFS_SELECTION=""
1664 ROOTFS_SIZE="$(cent2human $unpacked_size) (estimated)"
1665 INITRAMFS_SIZE="$(cent2human $packed_size) (estimated)"
1666 ISO_SIZE="$(cent2human $iso_size) (estimated)"
1667 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1668 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1669 Flavor : $FLAVOR
1670 Description : $SHORT_DESC
1671 EOT
1672 [ -n "$VERSION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1673 Version : $VERSION
1674 EOT
1675 [ -n "$MAINTAINER" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1676 Maintainer : $MAINTAINER
1677 EOT
1678 [ -n "$FRUGAL_RAM" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1679 LiveCD RAM size : $FRUGAL_RAM
1680 EOT
1681 [ -n "$ROOTFS_SELECTION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1682 Rootfs list : $ROOTFS_SELECTION
1683 EOT
1684 cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1685 Build date : $(date +%Y%m%d\ \at\ \%H:%M:%S)
1686 Packages : $(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l)
1687 Rootfs size : $ROOTFS_SIZE
1688 Initramfs size : $INITRAMFS_SIZE
1689 ISO image size : $ISO_SIZE
1690 ================================================================================
1692 EOT
1693 rm -f $TMP_DIR/packages.list
1694 ( cd $TMP_DIR ; ls | cpio -o -H newc 2> /dev/null) | \
1695 gzip -9 > $FLAVOR.flavor
1696 status
1697 rm -Rf $TMP_DIR
1698 else
1699 echo "No $FLAVOR flavor in $FLAVORS_REPOSITORY."
1700 fi
1701 ;;
1702 get-flavor)
1703 # Get a flavor's files and prepare for gen-distro.
1704 FLAVOR=${2%.flavor}
1705 echo -e "\n\033[1mPreparing $FLAVOR distro flavor\033[0m"
1706 echo "================================================================================"
1707 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1708 echo -n "Cleaning $DISTRO..."
1709 rm -R $DISTRO 2> /dev/null
1710 mkdir -p $DISTRO
1711 status
1712 mkdir $TMP_DIR
1713 echo -n "Extracting flavor $FLAVOR.flavor... "
1714 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1715 echo -n "Creating distro-packages.list..."
1716 mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
1717 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
1718 status
1719 infos="$FLAVOR.desc"
1720 for i in rootcd rootfs; do
1721 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
1722 echo -n "Adding $i files... "
1723 mkdir -p "$ADDFILES/$i"
1724 zcat $TMP_DIR/$FLAVOR.$i | \
1725 ( cd "$ADDFILES/$i"; cpio -id > /dev/null)
1726 zcat $TMP_DIR/$FLAVOR.$i | cpio -tv \
1727 > $TMP_DIR/$FLAVOR.list$i
1728 infos="$infos\n$FLAVOR.list$i"
1729 fi
1730 done
1731 if [ -s $TMP_DIR/$FLAVOR.mirrors ]; then
1732 n=""
1733 while read line; do
1734 mkdir -p $LOCALSTATE/undigest/$FLAVOR$n
1735 echo "$line" > $LOCALSTATE/undigest/$FLAVOR$n/mirror
1736 n=$(( $n + 1 ))
1737 done < $TMP_DIR/$FLAVOR.mirrors
1738 infos="$infos\n$FLAVOR.mirrors"
1739 tazpkg recharge
1740 fi
1741 rm -f /etc/tazlito/rootfs.list
1742 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc &&
1743 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1744 sed 's/.*: \(.*\)$/\1/' > /etc/tazlito/rootfs.list
1745 echo -n "Updating tazlito.conf..."
1746 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
1747 cat tazlito.conf | grep -v "^#VOLUM_NAME" | \
1748 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
1749 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
1750 sed -i "s/ISO_NAME=.*/ISO_NAME=\"slitaz-$FLAVOR\"/" tazlito.conf
1751 status
1752 ( cd $TMP_DIR ; echo -e $infos | cpio -o -H newc ) | \
1753 gzip -9 > /etc/tazlito/info
1754 rm -Rf $TMP_DIR
1755 fi
1756 echo "================================================================================"
1757 echo -e "Flavor is ready to be generated by: tazlito gen-distro\n"
1758 ;;
1760 iso2flavor)
1761 if [ -z "$3" -o ! -s "$2" ]; then
1762 cat <<EOT
1763 Usage : tazlito iso2flavor image.iso flavor_name
1765 Create a file flavor_name.flavor from the cdrom image file image.iso
1766 EOT
1767 exit 1
1768 fi
1769 FLAVOR=${3%.flavor}
1770 mkdir -p $TMP_DIR/iso $TMP_DIR/rootfs
1771 mount -o loop,ro $2 $TMP_DIR/iso
1772 if [ -s $TMP_DIR/iso/boot/rootfs1.gz ]; then
1773 echo "META flavors are not supported."
1774 umount -d $TMP_DIR/iso
1775 elif [ ! -s $TMP_DIR/iso/boot/rootfs.gz ]; then
1776 echo "No /boot/rootfs.gz in iso image. Needs a SliTaz iso."
1777 umount -d $TMP_DIR/iso
1778 else
1779 ( unlzma -c $TMP_DIR/iso/boot/rootfs.gz || \
1780 zcat $TMP_DIR/iso/boot/rootfs.gz ) | \
1781 ( cd $TMP_DIR/rootfs ; cpio -idmu > /dev/null 2>&1 )
1782 if [ ! -s $TMP_DIR/rootfs/etc/slitaz-release ]; then
1783 echo "No file /etc/slitaz-release in /boot/rootfs.gz of iso image. Needs a non loram SliTaz iso."
1784 umount -d $TMP_DIR/iso
1785 else
1786 ROOTFS_SIZE=$(du -hs $TMP_DIR/rootfs | awk '{ print $1 }')
1787 RAM_SIZE=$(du -s $TMP_DIR/rootfs | awk '{ print 32*int(($1+36000)/32768) "M" }')
1788 cp -a $TMP_DIR/iso $TMP_DIR/rootcd
1789 ISO_SIZE=$(df -h $TMP_DIR/iso | awk 'END { print $2 }')
1790 BUILD_DATE=$(date +%Y%m%d\ \at\ \%H:%M:%S -r $TMP_DIR/iso/md5sum)
1791 umount -d $TMP_DIR/iso
1792 INITRAMFS_SIZE=$(du -chs $TMP_DIR/rootcd/boot/rootfs.gz | awk '{ s=$1 } END { print $1 }')
1793 rm -f $TMP_DIR/rootcd/boot/rootfs.gz $TMP_DIR/rootcd/md5sum
1794 mv $TMP_DIR/rootcd/boot $TMP_DIR/rootfs
1795 sed 's/.* \(.*\).tazpkg*/\1/' > $TMP_DIR/$FLAVOR.pkglist \
1796 < $TMP_DIR/rootfs$INSTALLED.md5
1797 #[ -s $TMP_DIR/rootfs/etc/tazlito/distro-packages.list ] &&
1798 # mv $TMP_DIR/rootfs/etc/tazlito/distro-packages.list $TMP_DIR/$FLAVOR.pkglist
1799 PKGCNT=$(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l | awk '{ print $1 }')
1800 find_flavor_rootfs $TMP_DIR/rootfs
1801 [ -d $TMP_DIR/rootfs/boot ] && mv $TMP_DIR/rootfs/boot $TMP_DIR/rootcd
1802 [ -n "$(ls $TMP_DIR/rootfs)" ] && ( cd $TMP_DIR/rootfs ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootfs
1803 [ -n "$(ls $TMP_DIR/rootcd)" ] && ( cd $TMP_DIR/rootcd ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootcd
1804 rm -rf $TMP_DIR/rootcd $TMP_DIR/rootfs
1805 VERSION=""; MAINTAINER=""
1806 echo -en "Flavor short description \007: "; read -t 30 DESCRIPTION
1807 if [ -n "$DESCRIPTION" ]; then
1808 echo -en "Flavor version : "; read -t 30 VERSION
1809 echo -en "Flavor maintainer (your email) : "; read -t 30 MAINTAINER
1810 fi
1811 [ -n "$DESCRIPTION" ] || DESCRIPTION="Slitaz $FLAVOR flavor"
1812 [ -n "$VERSION" ] || VERSION="1.0"
1813 [ -n "$MAINTAINER" ] || MAINTAINER="nobody@slitaz.org"
1814 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1815 Flavor : $FLAVOR
1816 Description : $DESCRIPTION
1817 Version : $VERSION
1818 Maintainer : $MAINTAINER
1819 LiveCD RAM size : $RAM_SIZE
1820 Build date : $BUILD_DATE
1821 Packages : $PKGCNT
1822 Rootfs size : $ROOTFS_SIZE
1823 Initramfs size : $INITRAMFS_SIZE
1824 ISO image size : $ISO_SIZE
1825 ================================================================================
1827 EOT
1828 ( cd $TMP_DIR ; ls $FLAVOR.* | cpio -o -H newc ) | gzip -9 > $FLAVOR.flavor
1829 cat <<EOT
1830 Tazlito can't detect each file installed during a package post_install.
1831 You should extract this flavor (tazlito extract-flavor $FLAVOR),
1832 check the files in /home/slitaz/flavors/$(cat /etc/slitaz-release)/$FLAVOR/rootfs tree and remove
1833 files generated by post_installs.
1834 Check /home/slitaz/flavors/$(cat /etc/slitaz-release)/$FLAVOR/receipt too and repack the flavor
1835 (tazlito pack-flavor $FLAVOR)
1836 EOT
1837 fi
1838 fi
1839 rm -rf $TMP_DIR
1840 ;;
1842 check-list)
1843 # Use current packages list in $PWD by default.
1844 DISTRO_PKGS_LIST=distro-packages.list
1845 [ -d "$2" ] && DISTRO_PKGS_LIST=$2/distro-packages.list
1846 [ -f "$2" ] && DISTRO_PKGS_LIST=$2
1847 [ ! -f $DISTRO_PKGS_LIST ] && echo "No packages list found." && exit 0
1848 echo ""
1849 echo -e "\033[1mLiveCD packages list check\033[0m"
1850 echo "================================================================================"
1851 for pkg in `cat $DISTRO_PKGS_LIST`
1852 do
1853 if ! grep -q "$pkg" $LOCALSTATE/packages.list; then
1854 echo "Updating: $pkg"
1855 up=$(($up + 1))
1856 fi
1857 done
1858 [ -z $up ] && echo -e "List is up-to-date\n" && exit 0
1859 echo "================================================================================"
1860 echo -e "Updates: $up\n" ;;
1861 gen-distro)
1862 # Generate a live distro tree with a set of packages.
1864 check_root
1866 # Check if a package list was specified on cmdline.
1867 LIST_NAME="distro-packages.list"
1868 CDROM=""
1869 while [ -n "$2" ]; do
1870 case "$2" in
1871 --iso=*)
1872 CDROM="-o loop ${2#--iso=}"
1873 ;;
1874 --cdrom)
1875 CDROM="/dev/cdrom"
1876 ;;
1877 --force)
1878 DELETE_ROOTFS="true"
1879 ;;
1880 *) if [ ! -f "$2" ] ; then
1881 echo -e "\nUnable to find the specified packages list."
1882 echo -e "List name : $2\n"
1883 exit 1
1884 fi
1885 LIST_NAME=$2
1886 ;;
1887 esac
1888 shift
1889 done
1891 if [ -d $ROOTFS ] ; then
1892 # Delete $ROOTFS if --force is set on command line
1893 if [ ! -z $DELETE_ROOTFS ]; then
1894 rm -rf $ROOTFS
1895 unset $DELETE_ROOTFS
1896 else
1897 echo -e "\nA rootfs exists in : $DISTRO"
1898 echo -e "Please clean the distro tree or change directory path.\n"
1899 exit 0
1900 fi
1901 fi
1902 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
1903 # Build list with installed packages
1904 for i in $(ls $INSTALLED); do
1905 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
1906 EXTRAVERSION=""
1907 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
1908 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
1909 done
1910 fi
1911 # Exit if no list name.
1912 if [ ! -f "$LIST_NAME" ]; then
1913 echo -e "\nNo packages list found or specified. Please read the docs.\n"
1914 exit 0
1915 fi
1916 # Start generation.
1917 echo ""
1918 echo -e "\033[1mTazlito generating a distro\033[0m"
1919 echo "================================================================================"
1920 # Misc checks
1921 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
1922 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
1923 # Get the list of packages using cat for a file list.
1924 LIST=`cat $LIST_NAME`
1925 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
1926 REPACK=""
1927 DOWNLOAD=""
1928 for pkg in $LIST
1929 do
1930 [ "$pkg" = "" ] && continue
1931 pkg=${pkg%.tazpkg}
1932 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
1933 PACKAGE=$(installed_package_name $pkg)
1934 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
1935 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
1936 echo -e "\nUnable to find $pkg in the repository."
1937 echo -e "Path : $PACKAGES_REPOSITORY\n"
1938 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
1939 yesorno "Repack packages from rootfs (y/N) ? "
1940 REPACK="$answer"
1941 [ "$answer" = "y" ] || REPACK="n"
1942 [ "$DOWNLOAD" = "y" ] && break
1943 fi
1944 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
1945 yesorno "Download packages from mirror (Y/n) ? "
1946 DOWNLOAD="$answer"
1947 if [ "$answer" = "n" ]; then
1948 [ -z "$PACKAGE" ] && exit 1
1949 else
1950 DOWNLOAD="y"
1951 [ -n "$REPACK" ] && break
1952 fi
1953 fi
1954 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
1955 done
1957 # Mount cdrom to be able to repack boot-loader packages
1958 if [ ! -e /boot -a -n "$CDROM" ]; then
1959 mkdir $TMP_MNT
1960 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
1961 ln -s $TMP_MNT/boot /
1962 if [ ! -d "$ADDFILES/rootcd" ] ; then
1963 mkdir -p $ADDFILES/rootcd
1964 for i in $(ls $TMP_MNT); do
1965 [ "$i" = "boot" ] && continue
1966 cp -a $TMP_MNT/$i $ADDFILES/rootcd
1967 done
1968 fi
1969 else
1970 rmdir $TMP_MNT
1971 fi
1972 fi
1974 # Root fs stuff.
1975 echo "Preparing the rootfs directory..."
1976 mkdir -p $ROOTFS
1977 for pkg in $LIST
1978 do
1979 [ "$pkg" = "" ] && continue
1980 # First copy and extract the package in tmp dir.
1981 pkg=${pkg%.tazpkg}
1982 PACKAGE=$(installed_package_name $pkg)
1983 mkdir -p $TMP_DIR
1984 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1985 # Look for package in cache
1986 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
1987 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
1988 # Look for package in running distribution
1989 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
1990 tazpkg repack $PACKAGE && \
1991 mv $pkg.tazpkg $PACKAGES_REPOSITORY
1992 fi
1993 fi
1994 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1995 # Get package from mirror
1996 [ "$DOWNLOAD" = "y" ] && \
1997 download $pkg.tazpkg && \
1998 mv $pkg.tazpkg $PACKAGES_REPOSITORY
1999 fi
2000 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
2001 echo "Missing package $pkg."
2002 cleanup
2003 exit 1
2004 fi
2005 done
2006 if [ -f non-free.list ]; then
2007 echo "Preparing non-free packages..."
2008 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
2009 for pkg in $(cat non-free.list); do
2010 if [ ! -d $INSTALLED/$pkg ]; then
2011 if [ ! -d $INSTALLED/get-$pkg ]; then
2012 tazpkg get-install get-$pkg
2013 fi
2014 get-$pkg
2015 fi
2016 tazpkg repack $pkg
2017 pkg=$(ls $pkg*.tazpkg)
2018 grep -q "^$pkg$" $LIST_NAME || \
2019 echo $pkg >>$LIST_NAME
2020 mv $pkg $PACKAGES_REPOSITORY
2021 done
2022 fi
2023 cp $LIST_NAME $DISTRO/distro-packages.list
2024 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/distro-packages.list > $DISTRO/list-packages
2025 cd $PACKAGES_REPOSITORY
2026 for pkg in $(cat $DISTRO/list-packages)
2027 do
2028 echo -n "Installing package: $pkg"
2029 yes y | tazpkg install $pkg --root=$ROOTFS 2>&1 >> $log || exit 1
2030 status
2031 done
2032 cd $DISTRO
2033 cp distro-packages.list $ROOTFS/etc/tazlito
2034 # Copy all files from $ADDFILES/rootfs to the rootfs.
2035 if [ -d "$ADDFILES/rootfs" ] ; then
2036 echo -n "Copying addfiles content to the rootfs... "
2037 cp -a $ADDFILES/rootfs/* $ROOTFS
2038 status
2039 fi
2040 echo -n "Root filesystem is generated..." && status
2041 # Root CD part.
2042 echo -n "Preparing the rootcd directory..."
2043 mkdir -p $ROOTCD
2044 status
2045 # Move the boot dir with the Linux kernel from rootfs.
2046 # The boot dir goes directly on the CD.
2047 if [ -d "$ROOTFS/boot" ] ; then
2048 echo -n "Moving the boot directory..."
2049 mv $ROOTFS/boot $ROOTCD
2050 cd $ROOTCD/boot
2051 ln vmlinuz-* bzImage
2052 status
2053 fi
2054 cd $DISTRO
2055 # Copy all files from $ADDFILES/rootcd to the rootcd.
2056 if [ -d "$ADDFILES/rootcd" ] ; then
2057 echo -n "Copying addfiles content to the rootcd... "
2058 cp -a $ADDFILES/rootcd/* $ROOTCD
2059 status
2060 fi
2061 # Execute the distro script used to perform tasks in the rootfs
2062 # before compression. Give rootfs path in arg
2063 [ -z $DISTRO_SCRIPT ] && DISTRO_SCRIPT=$TOP_DIR/distro.sh
2064 if [ -x $DISTRO_SCRIPT ]; then
2065 echo "Executing distro script..."
2066 sh $DISTRO_SCRIPT $DISTRO
2067 fi
2068 if [ -s /etc/tazlito/rootfs.list ]; then
2069 FLAVOR_LIST="$(awk '{ for (i = 2; i <= NF; i+=2) \
2070 printf("%s ",$i) }' < /etc/tazlito/rootfs.list)"
2071 sed -i "s/ *//;s/)/), flavors $FLAVOR_LIST/" \
2072 $ROOTCD/boot/isolinux/isolinux.msg
2073 [ -f $ROOTCD/boot/isolinux/ifmem.c32 ] ||
2074 cp /boot/isolinux/ifmem.c32 $ROOTCD/boot/isolinux
2075 n=0
2076 last=$ROOTFS
2077 while read flavor; do
2078 n=$(($n+1))
2079 echo "Building $flavor rootfs..."
2080 download $flavor.flavor
2081 zcat $flavor.flavor | cpio -i \
2082 $flavor.pkglist $flavor.rootfs
2083 sed 's/.*/&.tazpkg/' < $flavor.pkglist \
2084 > $DISTRO/list-packages0$n
2085 mkdir ${ROOTFS}0$n
2086 cd $PACKAGES_REPOSITORY
2087 yes y | tazpkg install-list \
2088 $DISTRO/list-packages0$n --root=${ROOTFS}0$n
2089 rm -rf ${ROOTFS}0$n/boot
2090 status
2091 cd $DISTRO
2092 if [ -s $flavor.rootfs ]; then
2093 echo "Adding $flavor rootfs extra files..."
2094 zcat $flavor.rootfs | \
2095 ( cd ${ROOTFS}0$n ; cpio -idmu )
2096 fi
2097 mv $flavor.pkglist ${ROOTFS}0$n/etc/tazlito/distro-packages.list
2098 rm -f $flavor.flavor install-list
2099 mergefs ${ROOTFS}0$n $last
2100 last=${ROOTFS}0$n
2101 done <<EOT
2102 $(awk '{ for (i = 4; i <= NF; i+=2) print $i; }' < /etc/tazlito/rootfs.list)
2103 EOT
2104 i=$(($n+1))
2105 while [ $n -gt 0 ]; do
2106 mv ${ROOTFS}0$n ${ROOTFS}$i
2107 echo "Compression ${ROOTFS}0$n ($(du -hs ${ROOTFS}$i | awk '{ print $1 }')) ..."
2108 gen_initramfs ${ROOTFS}$i
2109 n=$(($n-1))
2110 i=$(($i-1))
2111 done
2112 mv $ROOTFS ${ROOTFS}$i
2113 gen_initramfs ${ROOTFS}$i
2114 update_bootconfig $ROOTCD/boot/isolinux \
2115 "$(cat /etc/tazlito/rootfs.list)"
2116 else
2117 # Initramfs and ISO image stuff.
2118 gen_initramfs $ROOTFS
2119 fi
2120 gen_livecd_isolinux
2121 distro_stats
2122 cleanup
2123 ;;
2124 clean-distro)
2125 # Remove old distro tree.
2127 check_root
2128 echo ""
2129 echo -e "\033[1mCleaning :\033[0m $DISTRO"
2130 echo "================================================================================"
2131 if [ -d "$DISTRO" ] ; then
2132 if [ -d "$ROOTFS" ] ; then
2133 echo -n "Removing the rootfs..."
2134 rm -f $DISTRO/$INITRAMFS
2135 rm -rf $ROOTFS
2136 status
2137 fi
2138 if [ -d "$ROOTCD" ] ; then
2139 echo -n "Removing the rootcd..."
2140 rm -rf $ROOTCD
2141 status
2142 fi
2143 echo -n "Removing eventual ISO image..."
2144 rm -f $DISTRO/$ISO_NAME.iso
2145 rm -f $DISTRO/$ISO_NAME.md5
2146 status
2147 fi
2148 echo "================================================================================"
2149 echo ""
2150 ;;
2151 check-distro)
2152 # Check for a few LiveCD needed files not installed by packages.
2154 check_rootfs
2155 echo ""
2156 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
2157 echo "================================================================================"
2158 # SliTaz release info.
2159 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
2160 echo "Missing release info : /etc/slitaz-release"
2161 else
2162 release=`cat $ROOTFS/etc/slitaz-release`
2163 echo -n "Release : $release"
2164 status
2165 fi
2166 # Tazpkg mirror.
2167 if [ ! -f "$ROOTFS$LOCALSTATE/mirror" ]; then
2168 echo -n "Mirror URL : Missing $LOCALSTATE/mirror"
2169 todomsg
2170 else
2171 echo -n "Mirror configuration exists..."
2172 status
2173 fi
2174 # Isolinux msg
2175 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.*g; then
2176 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
2177 todomsg
2178 else
2179 echo -n "Isolinux message seems good..."
2180 status
2181 fi
2182 echo "================================================================================"
2183 echo ""
2184 ;;
2185 writeiso)
2186 # Writefs to ISO image including /home unlike gen-distro we dont use
2187 # packages to generate a rootfs, we build a compressed rootfs with all
2188 # the current filesystem similar to 'tazusb writefs'.
2190 DISTRO="/home/slitaz/distro"
2191 ROOTCD="$DISTRO/rootcd"
2192 if [ -z $2 ]; then
2193 COMPRESSION=none
2194 else
2195 COMPRESSION=$2
2196 fi
2197 if [ -z $3 ]; then
2198 ISO_NAME="slitaz"
2199 else
2200 ISO_NAME="$3"
2201 fi
2202 check_root
2203 # Start info
2204 echo ""
2205 echo -e "\033[1mWrite filesystem to ISO\033[0m
2206 ===============================================================================
2207 The command writeiso will write the current filesystem into a suitable cpio
2208 archive (rootfs.gz) and generate a bootable ISO image (slitaz.iso).
2210 Archive compression: $COMPRESSION"
2211 echo ""
2213 # Save some space
2214 rm /var/cache/tazpkg/* -r -f
2215 rm -rf /home/slitaz/distro
2217 # Optionally remove sound card selection and screen resolution.
2218 echo "Do you wish to remove the sound card and screen configs ? "
2219 echo -n "Press ENTER to keep or answer (No|yes|exit): "
2220 read anser
2221 case $anser in
2222 e|E|"exit"|Exit)
2223 exit 0 ;;
2224 y|Y|yes|Yes)
2225 echo -n "Removing current sound card and screen configurations..."
2226 rm -f /var/lib/sound-card-driver
2227 rm -f /etc/asound.state
2228 rm -f /etc/X11/screen.conf
2229 rm -f /etc/X11/xorg.conf ;;
2230 *)
2231 echo -n "Keeping current sound card and screen configurations..." ;;
2232 esac
2233 status
2235 cd /
2236 # Create list of files including default user files since it is defined in /etc/passwd
2237 # and some new users might have been added.
2238 find bin etc init sbin var dev lib root usr home >/tmp/list
2240 for dir in proc sys tmp mnt media media/cdrom media/flash media/usbdisk
2241 do
2242 echo $dir >>/tmp/list
2243 done
2245 # Generate initramfs with specified compression and display rootfs
2246 # size in realtime.
2247 rm -f /tmp/rootfs
2248 write_initramfs &
2249 sleep 2
2250 cd - > /dev/null
2251 echo -en "\nFilesystem size:"
2252 while [ ! -f /tmp/rootfs ]
2253 do
2254 sleep 1
2255 echo -en "\\033[18G`du -sh /rootfs.gz | awk '{print $1}'` "
2256 done
2257 echo -e "\n"
2259 # Move freshly generated rootfs to the cdrom.
2260 mkdir -p $ROOTCD/boot
2261 mv -f /rootfs.gz $ROOTCD/boot
2263 # Now we need the kernel and isolinux files.
2264 if mount /dev/cdrom /media/cdrom 2>/dev/null; then
2265 cp /media/cdrom/boot/bzImage $ROOTCD/boot
2266 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
2267 umount /media/cdrom
2268 else
2269 echo -e "
2270 Unable to mount the cdrom to copy the Kernel and needed files. When SliTaz
2271 is running in RAM the kernel and bootloader files are kept on the cdrom.
2272 Please insert a LiveCD or unmount the current cdrom to let Tazlito handle
2273 the media.\n"
2274 echo -en "----\nENTER to continue..."; read i
2275 exit 1
2276 fi
2278 # Generate the iso image.
2279 cd $DISTRO
2280 echo "Generating ISO image..."
2281 genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
2282 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
2283 -V "SliTaz" -input-charset iso8859-1 -boot-info-table $ROOTCD
2284 if [ -x /usr/bin/isohybrid ]; then
2285 echo -n "Creating hybrid ISO..."
2286 /usr/bin/isohybrid $ISO_NAME.iso 2> /dev/null
2287 status
2288 fi
2289 echo -n "Creating the ISO md5sum..."
2290 md5sum $ISO_NAME.iso > $ISO_NAME.md5
2291 status
2293 echo "==============================================================================="
2294 echo "ISO image: `du -sh /home/slitaz/distro/$ISO_NAME.iso`"
2295 echo ""
2296 echo -n "Exit or burn ISO to cdrom (Exit|burn)? "; read anser
2297 case $anser in
2298 burn)
2299 eject
2300 echo -n "Please insert a blank cdrom and press ENTER..."
2301 read i && sleep 2
2302 tazlito burn-iso /home/slitaz/distro/$ISO_NAME.iso
2303 echo -en "----\nENTER to continue..."; read i ;;
2304 *)
2305 exit 0 ;;
2306 esac ;;
2307 burn-iso)
2308 # Guess cdrom device, ask user and burn the ISO.
2310 check_root
2311 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
2312 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
2313 # We can specify an alternative ISO from the cmdline.
2314 if [ -n "$2" ] ; then
2315 iso=$2
2316 else
2317 iso=$DISTRO/$ISO_NAME.iso
2318 fi
2319 if [ ! -f "$iso" ]; then
2320 echo -e "\nUnable to find ISO : $iso\n"
2321 exit 0
2322 fi
2323 echo ""
2324 echo -e "\033[1mTazlito burn ISO\033[0m "
2325 echo "================================================================================"
2326 echo "Cdrom device : /dev/$DRIVE_NAME"
2327 echo "Drive speed : $DRIVE_SPEED"
2328 echo "ISO image : $iso"
2329 echo "================================================================================"
2330 echo ""
2331 yesorno "Burn ISO image (y/N) ? "
2332 if [ "$answer" == "y" ]; then
2333 echo ""
2334 echo "Starting Wodim to burn the iso..." && sleep 2
2335 echo "================================================================================"
2336 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
2337 echo "================================================================================"
2338 echo "ISO image is burned to cdrom."
2339 else
2340 echo -e "\nExiting. No ISO burned."
2341 fi
2342 echo ""
2343 ;;
2344 merge)
2345 # Merge multiple rootfs into one iso.
2347 if [ -z "$2" ]; then
2348 cat << EOT
2349 Usage: tazlito merge size1 iso size2 rootfs2 [sizeN rootfsN]...
2351 Merge multiple rootfs into one iso. Rootfs are like russian dolls
2352 i.e: rootfsN is a subset of rootfsN-1
2353 rootfs1 is found in iso, sizeN is the RAM size need to launch rootfsN.
2354 The boot loader will select the rootfs according to the RAM size detected.
2356 Example:
2357 $ tazlito merge 160M slitaz-core.iso 96M rootfs-justx.gz 32M rootfs-base.gz
2359 Will start slitaz-core with 160M+ RAM, slitaz-justX with 96M-160M RAM,
2360 slitaz-base with 32M-96M RAM and display an error message if RAM < 32M.
2361 EOT
2362 exit 2
2363 fi
2365 shift # skip merge
2366 append="$1 slitaz1"
2367 shift # skip size1
2368 mkdir -p $TMP_DIR/mnt $TMP_DIR/rootfs1
2370 ISO=$1.merged
2371 # Extract filesystems
2372 echo -n "Mounting $1"
2373 mount -o loop,ro $1 $TMP_DIR/mnt 2> /dev/null
2374 status || cleanup_merge
2375 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2376 rm -f $TMP_DIR/iso/boot/bzImage
2377 ln $TMP_DIR/iso/boot/vmlinuz* $TMP_DIR/iso/boot/bzImage
2378 umount -d $TMP_DIR/mnt
2379 if [ -f $TMP_DIR/iso/boot/rootfs1.gz ]; then
2380 echo "$1 is already a merged iso. Aborting."
2381 cleanup_merge
2382 fi
2383 if [ ! -f $TMP_DIR/iso/boot/isolinux/ifmem.c32 ]; then
2384 if [ ! -f /boot/isolinux/ifmem.c32 ]; then
2385 cat <<EOT
2386 No file /boot/isolinux/ifmem.c32
2387 Please install syslinux package !
2388 EOT
2389 rm -rf $TMP_DIR
2390 exit 1
2391 fi
2392 cp /boot/isolinux/ifmem.c32 $TMP_DIR/iso/boot/isolinux
2393 fi
2395 echo -n "Extracting iso/rootfs.gz"
2396 extract_rootfs $TMP_DIR/iso/boot/rootfs.gz $TMP_DIR/rootfs1 &&
2397 [ -d $TMP_DIR/rootfs1/etc ]
2398 status || cleanup_merge
2399 n=1
2400 while [ -n "$2" ]; do
2401 shift # skip rootfs N-1
2402 p=$n
2403 n=$(($n + 1))
2404 append="$append $1 slitaz$n"
2405 shift # skip size N
2406 mkdir -p $TMP_DIR/rootfs$n
2407 echo -n "Extracting $1"
2408 extract_rootfs $1 $TMP_DIR/rootfs$n &&
2409 [ -d $TMP_DIR/rootfs$n/etc ]
2410 status || cleanup_merge
2411 mergefs $TMP_DIR/rootfs$n $TMP_DIR/rootfs$p
2412 echo "Creating rootfs$p.gz"
2413 pack_rootfs $TMP_DIR/rootfs$p $TMP_DIR/iso/boot/rootfs$p.gz
2414 status
2415 done
2416 echo "Creating rootfs$n.gz"
2417 pack_rootfs $TMP_DIR/rootfs$n $TMP_DIR/iso/boot/rootfs$n.gz
2418 status
2419 rm -f $TMP_DIR/iso/boot/rootfs.gz
2420 update_bootconfig $TMP_DIR/iso/boot/isolinux "$append"
2421 create_iso $ISO $TMP_DIR/iso
2422 rm -rf $TMP_DIR
2423 ;;
2425 repack)
2426 # Repack an iso with maximum lzma compression ratio.
2429 ISO=$2
2431 mkdir -p $TMP_DIR/mnt
2432 # Extract filesystems
2433 echo -n "Mounting $ISO"
2434 mount -o loop,ro $ISO $TMP_DIR/mnt 2> /dev/null
2435 status || cleanup_merge
2436 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2437 umount -d $TMP_DIR/mnt
2439 for i in $TMP_DIR/iso/boot/rootfs* ; do
2440 echo -n "Repacking $(basename $i)"
2441 (zcat $i 2> /dev/null || unlzma -c $i || cat $i) \
2442 2>/dev/null > $TMP_DIR/rootfs
2443 lzma e $TMP_DIR/rootfs $i \
2444 $(lzma_switches $TMP_DIR/rootfs)
2445 status
2446 done
2448 create_iso $ISO $TMP_DIR/iso
2449 rm -rf $TMP_DIR ;;
2451 build-loram)
2452 # Build a Live CD for low ram systems.
2455 ISO=$2
2456 OUTPUT=$3
2457 mkdir -p $TMP_DIR/iso
2458 mount -o loop,ro -t iso9660 $ISO $TMP_DIR/iso
2459 if ! check_iso_for_loram ; then
2460 echo "$2 is not a valid SliTaz live CD. Abort."
2461 umount -d $TMP_DIR/iso
2462 rm -rf $TMP_DIR
2463 exit 1
2464 fi
2466 case "$4" in
2467 cdrom) build_loram_cdrom ;;
2468 smallcdrom) build_loram_cdrom small ;;
2469 http) build_loram_http ;;
2470 *) build_loram_ram ;;
2471 esac
2472 umount -d $TMP_DIR/iso
2473 rm -rf $TMP_DIR ;;
2476 frugal-install|-fi)
2477 ISO_IMAGE="$2"
2478 echo ""
2479 mkdir -p /boot/frugal
2480 if [ -f "$ISO_IMAGE" ]; then
2481 echo -n "Using ISO image: $ISO_IMAGE"
2482 mkdir -p /tmp/iso && mount -o loop $ISO_IMAGE /tmp/iso
2483 status
2484 echo -n "Installing the Kernel and rootfs..."
2485 cp -a /tmp/iso/boot/bzImage /boot/frugal
2486 cp -a /tmp/iso/boot/rootfs.gz /boot/frugal
2487 umount /tmp/iso
2488 status
2489 else
2490 echo -n "Using distro: $DISTRO"
2491 cd $DISTRO && status
2492 echo -n "Installing the Kernel and rootfs..."
2493 cp -a $DISTRO/rootcd/boot/bzImage /boot/frugal
2494 cp -a $DISTRO/rootcd/boot/rootfs.gz /boot/frugal
2495 status
2496 fi
2497 # Grub entry
2498 if ! grep -q "^kernel /boot/frugal/bzImage" /boot/grub/menu.lst; then
2499 echo -n "Configuring GRUB menu list..."
2500 cat >> /boot/grub/menu.lst << EOT
2501 title SliTaz GNU/Linux (frugal)
2502 root (hd0,0)
2503 kernel /boot/frugal/bzImage root=/dev/null
2504 initrd /boot/frugal/rootfs.gz
2505 EOT
2506 else
2507 echo -n "GRUB menu list is up-to-date..."
2508 fi
2509 status
2510 echo "" ;;
2512 emu-iso)
2513 # Emulate an ISO image with Qemu.
2514 if [ -n "$2" ] ; then
2515 iso=$2
2516 else
2517 iso=$DISTRO/$ISO_NAME.iso
2518 fi
2519 if [ ! -f "$iso" ]; then
2520 echo -e "\nUnable to find ISO : $iso\n"
2521 exit 0
2522 fi
2523 if [ ! -x "/usr/bin/qemu" ]; then
2524 echo -e "\nUnable to find Qemu binary. Please install: qemu\n"
2525 exit 0
2526 fi
2527 echo -e "\nStarting Qemu emulator:\n"
2528 echo -e "qemu $QEMU_OPTS $iso\n"
2529 qemu $QEMU_OPTS $iso ;;
2531 usage|*)
2532 # Clear and print usage also for all unknown commands.
2534 clear
2535 usage ;;
2536 esac
2538 exit 0