tazlito view tazlito @ rev 291

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