tazlito view tazlito @ rev 269

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