tazlito view tazlito @ rev 332

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