tazlito view tazlito @ rev 335

Added tag 5.2 for changeset 8c271470b47b
author Christophe Lincoln <pankso@slitaz.org>
date Sun Feb 16 15:31:46 2014 +0100 (2014-02-16)
parents 29f2100e2208
children b095e74f0f66
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 newline > $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 cat << EOT
80 SliTaz Live Tool - Version: $(colorize 34 "$VERSION")
82 $(boldify "Usage:") $(basename $0) [command] [list|iso|flavor|compression] [dir|iso]
84 $(boldify "Commands:")
85 usage Print this short usage.
86 stats View Tazlito and distro configuration statistics.
87 gen-config Generate a new configuration file for a distro.
88 configure Configure the main config file or a specific tazlito.conf.
89 gen-iso Generate a new ISO from a distro tree.
90 gen-initiso Generate a new initramfs and ISO from the distro tree.
91 list-flavors List all available package lists on the mirror.
92 gen-flavor Generate a new live-CD description.
93 gen-liveflavor Generate a live-CD description from current system.
94 show-flavor Show live-CD description.
95 get-flavor Get a flavor's list of packages.
96 upgrade-flavor Update package list to the latest available versions.
97 extract-flavor Extract a (*.flavor) flavor into $FLAVORS_REPOSITORY.
98 pack-flavor Pack (and update) a flavor from $FLAVORS_REPOSITORY.
99 iso2flavor Create a flavor file from a SliTaz iso image.
100 check-list Check a distro-packages.list for updates.
101 extract-distro Extract an ISO to a directory and rebuild LiveCD tree.
102 gen-distro Generate a Live distro and ISO from a list of packages.
103 clean-distro Remove all files generated by gen-distro.
104 check-distro Help to check if distro is ready to release.
105 writeiso Use running system to generate a bootable ISO (with /home).
106 merge Merge multiple rootfs into one iso.
107 deduplicate Deduplicate files in a tree.
108 repack Recompress rootfs into iso with maximum ratio.
109 build-loram Generate a live-CD for low ram systems.
110 emu-iso Emulate an ISO image with Qemu.
111 burn-iso Burn ISO image to a cdrom using Wodim.
113 EOT
114 }
116 yesorno() {
117 echo -n "$1"
118 case "$DEFAULT_ANSWER" in
119 Y|y) answer="y";;
120 N|n) answer="n";;
121 *) read answer;;
122 esac
123 }
125 field() {
126 grep "^$1" "$2" | sed 's/.*: \([0-9KMG\.]*\).*/\1/'
127 }
129 todomsg() {
130 echo -e "\\033[70G[ \\033[1;31mTODO\\033[0;39m ]"
131 }
133 # Download a file from this mirror
134 download_from() {
135 local i
136 local mirrors
137 mirrors="$1"
138 shift
139 for i in $mirrors; do
140 case "$i" in
141 http://*|ftp://*) busybox wget -c $i$@ && break;;
142 *) cp $i/$1 . && break;;
143 esac
144 done
145 }
147 # Download a file trying all mirrors
148 download() {
149 local i
150 for i in $(cat $MIRROR $LOCALSTATE/undigest/*/mirror 2> /dev/null); do
151 download_from "$i" "$@" && break
152 done
153 }
155 # Execute hooks provided by some packages
156 genisohooks() {
157 local here=`pwd`
158 for i in $(ls $ROOTFS/etc/tazlito/*.$1 2> /dev/null); do
159 cd $ROOTFS
160 . $i $ROOTCD
161 done
162 cd $here
163 }
165 cleanup() {
166 if [ -d $TMP_MNT ]; then
167 umount $TMP_MNT
168 rmdir $TMP_MNT
169 rm -f /boot
170 fi
171 }
173 # Echo the package name if the tazpkg is already installed
174 installed_package_name() {
175 local tazpkg
176 local package
177 local VERSION
178 local EXTRAVERSION
179 tazpkg=$1
180 # Try to find package name and version to be able
181 # to repack it from installation
182 # A dash (-) can exist in name *and* in version
183 package=${tazpkg%-*}
184 i=$package
185 while true; do
186 VERSION=""
187 eval $(grep -s ^VERSION= $INSTALLED/$i/receipt)
188 EXTRAVERSION=""
189 eval $(grep -s ^EXTRAVERSION= $INSTALLED/$i/receipt)
190 if [ "$i-$VERSION$EXTRAVERSION" = "$tazpkg" ]; then
191 echo $i
192 break
193 fi
194 case "$i" in
195 *-*);;
196 *) break;;
197 esac
198 i=${i%-*}
199 done
200 }
202 # Check for the rootfs tree.
203 check_rootfs() {
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 newline
229 boldify "Generating ISO image"
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 fi
259 }
261 # Generate a new ISO image using isolinux.
262 gen_livecd_isolinux()
263 {
264 # Some packages may want to alter iso
265 genisohooks iso
266 if [ ! -f "$ROOTCD/boot/isolinux/isolinux.bin" ]; then
267 echo -e "\nUnable to find isolinux binary.\n"
268 cleanup
269 exit 0
270 fi
271 # Set date for boot msg.
272 if grep -q 'XXXXXXXX' $ROOTCD/boot/isolinux/isolinux.*g; then
273 DATE=`date +%Y%m%d`
274 echo -n "Setting build date to: $DATE..."
275 sed -i "s/XXXXXXXX/$DATE/" $ROOTCD/boot/isolinux/isolinux.*g
276 status
277 fi
278 cd $DISTRO
279 create_iso $ISO_NAME.iso $ROOTCD
280 echo -n "Creating the ISO md5sum..."
281 md5sum $ISO_NAME.iso > $ISO_NAME.md5
282 status
283 separator
284 # Some packages may want to alter final iso
285 genisohooks final
286 }
288 lzma_history_bits()
289 {
290 #
291 # This generates an ISO which boots with Qemu but gives
292 # rootfs errors in frugal or liveUSB mode.
293 #
294 #local n
295 #local sz
296 #n=20 # 1Mb
297 #sz=$(du -sk $1 | cut -f1)
298 #while [ $sz -gt 1024 -a $n -lt 28 ]; do
299 #n=$(( $n + 1 ))
300 #sz=$(( $sz / 2 ))
301 #done
302 #echo $n
303 echo 24
304 }
306 lzma_switches()
307 {
308 local proc=$(grep -s '^processor' < /proc/cpuinfo | wc -l)
309 echo "-d$(lzma_history_bits $1) -mt${proc:-1}"
310 }
312 lzma_set_size()
313 {
314 # Update size field for lzma'd file packed using -si switch
315 local n
316 local i
317 return # Need to fix kernel code ?
318 n=$(unlzma -c $1 | wc -c)
319 for i in $(seq 1 8); do
320 printf '\\\\x%02X' $(($n & 255))
321 n=$(($n >> 8))
322 done | xargs echo -en | dd of=$1 conv=notrunc bs=1 seek=5 2> /dev/null
323 }
325 align_to_32bits()
326 {
327 local size
328 size=$(stat -c %s ${1:-/dev/null})
329 [ $((${size:-0} & 3)) -ne 0 ] &&
330 dd if=/dev/zero bs=1 count=$((4 - ($size & 3))) >> $1 2> /dev/null
331 }
333 # Pack rootfs
334 pack_rootfs()
335 {
336 ( cd $1 ; find . -print | cpio -o -H newc ) | \
337 if [ "$COMPRESSION" = "none" ]; then
338 echo "Generating uncompressed initramfs... "
339 cat > $2
340 elif [ -x /usr/bin/lzma -a "$COMPRESSION" != "gzip" ]; then
341 echo -n "Generating lzma'ed initramfs... "
342 lzma e -si -so $(lzma_switches $1) > $2
343 lzma_set_size $2
344 else
345 echo "Generating gziped initramfs... "
346 gzip -9 > $2
347 fi
348 align_to_32bits $2
349 echo 1 > /tmp/rootfs
350 }
352 # Compression functions for writeiso.
353 write_initramfs()
354 {
355 if [ "$COMPRESSION" = "lzma" ]; then
356 echo -n "Creating rootfs.gz with lzma compression... "
357 cpio -o -H newc | lzma e -si -so > /rootfs.gz
358 lzma_set_size /rootfs.gz
359 elif [ "$COMPRESSION" = "gzip" ]; then
360 echo "Creating rootfs.gz with gzip compression... "
361 cpio -o -H newc | gzip -9 > /rootfs.gz
362 else
363 echo "Creating rootfs.gz without compression... "
364 cpio -o -H newc > /rootfs.gz
365 fi < /tmp/list
366 align_to_32bits /rootfs.gz
367 echo 1 > /tmp/rootfs
368 }
370 # Deduplicate files (MUST be on the same filesystem).
371 deduplicate()
372 {
373 find "$@" -type f -size +0c -xdev \
374 -exec stat -c '%s-%a-%u-%g %i %h %n' {} \; | sort | \
375 ( 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 if ln "$old_file" "$file" 2> /dev/null; then
382 inode="$old_inode"
383 [ "$link" = "1" ] &&
384 save="$(($save+(${attr%%-*}+512)/1024))"
385 else
386 cp "$old_file" "$file"
387 fi
388 fi
389 fi
390 old_attr="$attr" ; old_inode="$inode" ; old_file="$file"
391 done
392 echo "$save Kbytes saved in duplicate files."
393 )
394 }
396 # Generate a new initramfs from the root filesystem.
397 gen_initramfs()
398 {
399 # Just in case CTRL+c
400 rm -f $DISTRO/gen
402 # Some packages may want to alter rootfs
403 genisohooks rootfs
404 cd $1
406 # Link duplicate files
407 deduplicate .
409 # Use lzma if installed. Display rootfs size in realtime.
410 rm -f /tmp/rootfs
411 pack_rootfs . $DISTRO/$(basename $1).gz &
412 sleep 2
413 echo -en "\nFilesystem size:"
414 while [ ! -f /tmp/rootfs ]
415 do
416 sleep 1
417 echo -en "\\033[18G`du -sh $DISTRO/$(basename $1).gz | awk '{print $1}'` "
418 done
419 echo -e "\n"
420 cd $DISTRO
421 mv $(basename $1).gz $ROOTCD/boot
422 }
424 distro_sizes() {
425 if [ "$time" ]; then
426 time=$(($(date +%s) - $time))
427 sec=$time
428 div=$(( ($time + 30) / 60))
429 [ "$div" != 0 ] && min="~ ${div}m"
430 echo "Build time : ${sec}s $min"
431 fi
432 cat << EOT
433 Build date : $(date +%Y%m%d)
434 Packages : $(ls -1 $ROOTFS*$INSTALLED/*/receipt | wc -l)
435 Rootfs size : $(du -csh $ROOTFS*/ | awk '{ s=$1 } END { print s }')
436 Initramfs size : $(du -csh $ROOTCD/boot/rootfs*.gz | awk '{ s=$1 } END { print s }')
437 ISO image size : $(du -sh $ISO_NAME.iso | awk '{ print $1 }')
438 EOT
439 separator
440 echo "Image is ready: $ISO_NAME.iso"
441 newline
442 }
444 # Print ISO and rootfs size.
445 distro_stats() {
446 newline
447 echo "$(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/newline/;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 newline
1157 boldify "Tazlito statistics"
1158 separator
1159 echo "\
1160 Config file : $CONFIG_FILE
1161 ISO name : $ISO_NAME.iso
1162 Volume name : $VOLUM_NAME
1163 Prepared : $PREPARED
1164 Packages repository : $PACKAGES_REPOSITORY
1165 Distro directory : $DISTRO"
1166 if [ ! "$ADDFILES" = "" ] ; then
1167 echo -e "Additional files : $ADDFILES"
1168 fi
1169 separator && newline ;;
1171 list-addfiles)
1172 # Simple list of additional files in the rootfs
1173 newline
1174 cd $ADDFILES
1175 find rootfs -type f
1176 newline ;;
1178 gen-config)
1179 # Generate a new config file in the current dir or the specified
1180 # directory by $2.
1182 if [ -n "$2" ] ; then
1183 mkdir -p $2 && cd $2
1184 fi
1185 echo -n "Generating empty tazlito.conf..."
1186 empty_config_file
1187 status
1188 newline
1189 if [ -f "tazlito.conf" ] ; then
1190 echo "Configuration file is ready to edit."
1191 echo "File location : `pwd`/tazlito.conf"
1192 newline
1193 fi ;;
1195 configure)
1196 # Configure a tazlito.conf config file. Start by getting
1197 # a empty config file and sed it.
1199 if [ -f "tazlito.conf" ] ; then
1200 rm tazlito.conf
1201 else
1202 if test $(id -u) = 0 ; then
1203 cd /etc
1204 else
1205 echo "You must be root to configure the main config file or in"
1206 echo "the same directory of the file you want to configure."
1207 exit 0
1208 fi
1209 fi
1210 empty_config_file
1211 echo""
1212 echo -e "\033[1mConfiguring :\033[0m `pwd`/tazlito.conf"
1213 separator
1214 # ISO name.
1215 echo -n "ISO name : " ; read answer
1216 sed -i s#'ISO_NAME=\"\"'#"ISO_NAME=\"$answer\""# tazlito.conf
1217 # Volume name.
1218 echo -n "Volume name : " ; read answer
1219 sed -i s/'VOLUM_NAME=\"SliTaz\"'/"VOLUM_NAME=\"$answer\""/ tazlito.conf
1220 # Packages repository.
1221 echo -n "Packages repository : " ; read answer
1222 sed -i s#'PACKAGES_REPOSITORY=\"\"'#"PACKAGES_REPOSITORY=\"$answer\""# tazlito.conf
1223 # Distro path.
1224 echo -n "Distro path : " ; read answer
1225 sed -i s#'DISTRO=\"\"'#"DISTRO=\"$answer\""# tazlito.conf
1226 separator
1227 echo "Config file is ready to use."
1228 echo "You can now extract an ISO or generate a distro."
1229 newline ;;
1231 gen-iso)
1232 # Simply generate a new iso.
1234 check_root
1235 verify_rootcd
1236 gen_livecd_isolinux
1237 distro_stats ;;
1239 gen-initiso)
1240 # Simply generate a new initramfs with a new iso.
1242 check_root
1243 verify_rootcd
1244 gen_initramfs $ROOTFS
1245 gen_livecd_isolinux
1246 distro_stats ;;
1248 extract-distro)
1249 # Extract an ISO image to a directory and rebuild the LiveCD tree.
1251 check_root
1252 ISO_IMAGE=$2
1253 if [ -z "$ISO_IMAGE" ] ; then
1254 echo -e "\nPlease specify the path to the ISO image."
1255 echo -e "Example : `basename $0` image.iso /path/target\n"
1256 exit 0
1257 fi
1258 # Set the distro path by checking for $3 on cmdline.
1259 if [ -n "$3" ] ; then
1260 TARGET=$3
1261 else
1262 TARGET=$DISTRO
1263 fi
1264 # Exit if existing distro is found.
1265 if [ -d "$TARGET/rootfs" ] ; then
1266 echo -e "\nA rootfs exists in : $TARGET"
1267 echo -e "Please clean the distro tree or change directory path.\n"
1268 exit 0
1269 fi
1270 newline
1271 echo -e "\033[1mTazlito extracting :\033[0m `basename $ISO_IMAGE`"
1272 separator
1273 # Start to mount the ISO.
1274 newline
1275 echo "Mounting ISO image..."
1276 mkdir -p $TMP_DIR
1277 # Get ISO file size.
1278 isosize=`du -sh $ISO_IMAGE | cut -f1`
1279 mount -o loop $ISO_IMAGE $TMP_DIR
1280 sleep 2
1281 # Prepare target dir, copy the kernel and the rootfs.
1282 mkdir -p $TARGET/rootfs
1283 mkdir -p $TARGET/rootcd/boot
1284 echo -n "Copying the Linux kernel..."
1285 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
1286 ln $TARGET/rootcd/boot/vmlinuz* $TARGET/rootcd/boot/bzImage
1287 else
1288 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
1289 fi
1290 status
1291 echo -n "Copying isolinux files..."
1292 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
1293 for i in $(ls $TMP_DIR); do
1294 [ "$i" = "boot" ] && continue
1295 cp -a $TMP_DIR/$i $TARGET/rootcd
1296 done
1297 status
1298 if [ -d $TMP_DIR/boot/syslinux ]; then
1299 echo -n "Copying syslinux files..."
1300 cp -a $TMP_DIR/boot/syslinux $TARGET/rootcd/boot
1301 status
1302 fi
1303 if [ -d $TMP_DIR/boot/extlinux ]; then
1304 echo -n "Copying extlinux files..."
1305 cp -a $TMP_DIR/boot/extlinux $TARGET/rootcd/boot
1306 status
1307 fi
1308 if [ -d $TMP_DIR/boot/grub ]; then
1309 echo -n "Copying GRUB files..."
1310 cp -a $TMP_DIR/boot/grub $TARGET/rootcd/boot
1311 status
1312 fi
1314 echo -n "Copying the rootfs..."
1315 cp $TMP_DIR/boot/rootfs.?z $TARGET/rootcd/boot
1316 status
1317 # Extract initramfs.
1318 cd $TARGET/rootfs
1319 echo -n "Extracting the rootfs... "
1320 extract_rootfs ../rootcd/boot/rootfs.gz $TARGET/rootfs
1321 # unpack /usr
1322 for i in etc/tazlito/*.extract; do
1323 [ -f "$i" ] && . $i ../rootcd
1324 done
1325 # Umount and remove temp directory and cd to $TARGET to get stats.
1326 umount $TMP_DIR && rm -rf $TMP_DIR
1327 cd ..
1328 newline
1329 separator
1330 echo "Extracted : `basename $ISO_IMAGE` ($isosize)"
1331 echo "Distro tree : `pwd`"
1332 echo "Rootfs size : `du -sh rootfs`"
1333 echo "Rootcd size : `du -sh rootcd`"
1334 separator
1335 newline ;;
1337 list-flavors)
1338 # Show available flavors.
1339 if [ ! -s /etc/tazlito/flavors.list -o "$2" == "--recharge" ]; then
1340 download flavors.list -O - > /etc/tazlito/flavors.list
1341 fi
1342 newline
1343 echo -e "\033[1mList of flavors\033[0m"
1344 separator
1345 cat /etc/tazlito/flavors.list
1346 newline ;;
1348 show-flavor)
1349 # Show flavor description.
1350 FLAVOR=${2%.flavor}
1351 if [ ! -f "$FLAVOR.flavor" ]; then
1352 echo "File $FLAVOR.flavor not found."
1353 exit 1
1354 fi
1355 mkdir $TMP_DIR
1356 zcat < $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i > /dev/null)
1357 if [ "$3" = "--brief" ]; then
1358 if [ "$4" != "--noheader" ]; then
1359 echo "Name ISO Rootfs Description"
1360 separator
1361 fi
1362 printf "%-16.16s %6.6s %6.6s %s\n" "$FLAVOR" \
1363 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
1364 "$(field 'Rootfs size' $TMP_DIR/$FLAVOR.desc)" \
1365 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
1366 else
1367 separator
1368 cat $TMP_DIR/$FLAVOR.desc
1369 fi
1370 rm -Rf $TMP_DIR ;;
1372 gen-liveflavor)
1373 # Generate a new flavor from the live system.
1374 FLAVOR=${2%.flavor}
1375 DESC=""
1376 case "$FLAVOR" in
1377 '') echo -n "Flavor name : "
1378 read FLAVOR
1379 [ -z "$FLAVOR" ] && exit 1;;
1380 -?|-h*|--help) echo -e "
1382 SliTaz Live Tool - Version: $VERSION
1383 \033[1mUsage: \033[0m `basename $0` gen-liveflavor flavor-name [flavor-patch-file]
1384 \033[1mflavor-patch-file format: \033[0m
1385 code data
1386 + package to add
1387 - package to remove
1388 ! non-free package to add
1389 ? display message
1390 @ flavor description
1392 \033[1mExample: \033[0m
1393 @ Developer tools for slitaz maintainers
1394 + slitaz-toolchain
1395 + mercurial
1397 exit 1;;
1398 esac
1399 mv /etc/tazlito/distro-packages.list \
1400 /etc/tazlito/distro-packages.list.$$ 2> /dev/null
1401 rm -f distro-packages.list non-free.list 2> /dev/null
1402 tazpkg recharge
1403 [ -n "$3" ] && while read action pkg; do
1404 case "$action" in
1405 +) yes | tazpkg get-install $pkg 2>&1 >> $log || exit 1 ;;
1406 -) yes | tazpkg remove $pkg ;;
1407 !) echo $pkg >> non-free.list ;;
1408 @) DESC="$pkg" ;;
1409 \?) echo -en "$pkg"; read action ;;
1410 esac
1411 done < $3
1412 yes '' | tazlito gen-distro
1413 echo "$DESC" | tazlito gen-flavor "$FLAVOR"
1414 mv /etc/tazlito/distro-packages.list.$$ \
1415 /etc/tazlito/distro-packages.list 2> /dev/null ;;
1417 gen-flavor)
1418 # Generate a new flavor from the last iso image generated.
1419 FLAVOR=${2%.flavor}
1420 newline
1421 echo -e "\033[1mFlavor generation\033[0m"
1422 separator
1423 if [ -z "$FLAVOR" ]; then
1424 echo -n "Flavor name : "
1425 read FLAVOR
1426 [ -z "$FLAVOR" ] && exit 1
1427 fi
1428 check_rootfs
1429 FILES="$FLAVOR.pkglist"
1430 echo -n "Creating file $FLAVOR.flavor..."
1431 for i in rootcd rootfs; do
1432 if [ -d "$ADDFILES/$i" ] ; then
1433 FILES="$FILES\n$FLAVOR.$i"
1434 ( cd "$ADDFILES/$i"; find . | \
1435 cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
1436 fi
1437 done
1438 status
1439 answer=`grep -s ^Description $FLAVOR.desc`
1440 answer=${answer#Description : }
1441 if [ -z "$answer" ]; then
1442 echo -n "Description : "
1443 read answer
1444 fi
1445 echo -n "Compressing flavor $FLAVOR..."
1446 echo "Flavor : $FLAVOR" > $FLAVOR.desc
1447 echo "Description : $answer" >> $FLAVOR.desc
1448 ( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
1449 \rm -f $FLAVOR.pkglist $FLAVOR.nonfree 2> /dev/null
1450 for i in $(ls $ROOTFS$INSTALLED); do
1451 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
1452 EXTRAVERSION=""
1453 eval $(grep ^EXTRAVERSION= $ROOTFS$INSTALLED/$i/receipt)
1454 eval $(grep ^CATEGORY= $ROOTFS$INSTALLED/$i/receipt)
1455 if [ "$CATEGORY" = "non-free" -a "${i%%-*}" != "get" ]
1456 then
1457 echo "$i" >> $FLAVOR.nonfree
1458 else
1459 echo "$i-$VERSION$EXTRAVERSION" >> $FLAVOR.pkglist
1460 fi
1461 done
1462 [ -s $FLAVOR.nonfree ] && $FILES="$FILES\n$FLAVOR.nonfree"
1463 for i in $LOCALSTATE/undigest/*/mirror ; do
1464 [ -s $i ] && cat $i >> $FLAVOR.mirrors
1465 done
1466 [ -s $FLAVOR.mirrors ] && $FILES="$FILES\n$FLAVOR.mirrors"
1467 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
1468 gzip -9 > $FLAVOR.flavor
1469 rm `echo -e $FILES`
1470 status
1471 separator
1472 echo "Flavor size : `du -sh $FLAVOR.flavor`"
1473 newline ;;
1475 upgrade-flavor)
1476 # Update package list to the latest versions available.
1477 FLAVOR=${2%.flavor}
1478 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1479 mkdir $TMP_DIR
1480 zcat < $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1481 echo -n "Updating $FLAVOR package list..."
1482 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1483 packed_size=0; unpacked_size=0
1484 while read org; do
1485 i=0
1486 pkg=$org
1487 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
1488 pkg=${pkg%-*}
1489 i=$(($i + 1))
1490 [ $i -gt 5 ] && break;
1491 done
1492 set -- $(get_size $pkg)
1493 packed_size=$(( $packed_size + $1 ))
1494 unpacked_size=$(( $unpacked_size + $2 ))
1495 for i in $(grep ^$pkg $LOCALSTATE/packages.list); do
1496 echo $i
1497 break
1498 done
1499 done < $TMP_DIR/$FLAVOR.pkglist \
1500 > $TMP_DIR/$FLAVOR.pkglist.$$
1501 mv -f $TMP_DIR/$FLAVOR.pkglist.$$ $TMP_DIR/$FLAVOR.pkglist
1502 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1503 packed_size=$(($packed_size \
1504 + $(wc -c < $TMP_DIR/$FLAVOR.rootfs) / 100 ))
1505 unpacked_size=$(($unpacked_size \
1506 + $(zcat < $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1507 fi
1508 # Estimate lzma
1509 packed_size=$(($packed_size * 2 / 3))
1510 iso_size=$(( $packed_size + 26000 ))
1511 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1512 iso_size=$(($iso_size \
1513 + $(zcat < $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1514 fi
1515 sed -i -e '/Image is ready/d' \
1516 -e "s/Rootfs size\( *:\) \(.*\)/Rootfs size\1 $(cent2human $unpacked_size) (estimated)/" \
1517 -e "s/Initramfs size\( *:\) \(.*\)/Initramfs size\1 $(cent2human $packed_size) (estimated)/" \
1518 -e "s/ISO image size\( *:\) \(.*\)/ISO image size\1 $(cent2human $iso_size) (estimated)/" \
1519 -e "s/date\( *:\) \(.*\)/date\1 $(date +%Y%m%d\ \at\ \%H:%M:%S)/" \
1520 $TMP_DIR/$FLAVOR.desc
1521 ( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
1522 $FLAVOR.flavor
1523 status
1524 rm -Rf $TMP_DIR
1525 fi ;;
1527 extract-flavor)
1528 # Extract a flavor into $FLAVORS_REPOSITORY.
1529 FLAVOR=${2%.flavor}
1530 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1531 mkdir $TMP_DIR
1532 zcat < $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1533 echo -n "Extracting $FLAVOR..."
1534 rm -rf $FLAVORS_REPOSITORY/$FLAVOR 2> /dev/null
1535 mkdir -p $FLAVORS_REPOSITORY/$FLAVOR
1536 cp $TMP_DIR/$FLAVOR.receipt $FLAVORS_REPOSITORY/$FLAVOR/receipt
1537 #~ echo "FLAVOR=\"$FLAVOR\"" > $FLAVORS_REPOSITORY/$FLAVOR/receipt
1538 #~ grep ^Description $TMP_DIR/$FLAVOR.desc | \
1539 #~ sed 's/.*: \(.*\)$/SHORT_DESC="\1"/' >> \
1540 #~ $FLAVORS_REPOSITORY/$FLAVOR/receipt
1541 #~ grep ^Version $TMP_DIR/$FLAVOR.desc | \
1542 #~ sed 's/.*: \(.*\)$/VERSION="\1"/' >> \
1543 #~ $FLAVORS_REPOSITORY/$FLAVOR/receipt
1544 #~ grep ^Maintainer $TMP_DIR/$FLAVOR.desc | \
1545 #~ sed 's/.*: \(.*\)$/MAINTAINER="\1"/' >> \
1546 #~ $FLAVORS_REPOSITORY/$FLAVOR/receipt
1547 #~ grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc && \
1548 #~ grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1549 #~ sed 's/.*: \(.*\)$/ROOTFS_SELECTION="\1"/' >> \
1550 #~ $FLAVORS_REPOSITORY/$FLAVOR/receipt
1551 #~ grep '^Rootfs size' $TMP_DIR/$FLAVOR.desc | \
1552 #~ sed 's/.*: \(.*\)$/ROOTFS_SIZE="\1"/' >> \
1553 #~ $FLAVORS_REPOSITORY/$FLAVOR/receipt
1554 #~ grep ^Initramfs $TMP_DIR/$FLAVOR.desc | \
1555 #~ sed 's/.*: \(.*\)$/INITRAMFS_SIZE="\1"/' >> \
1556 #~ $FLAVORS_REPOSITORY/$FLAVOR/receipt
1557 #~ grep ^ISO $TMP_DIR/$FLAVOR.desc | \
1558 #~ sed 's/.*: \(.*\)$/ISO_SIZE="\1"/' >> \
1559 #~ $FLAVORS_REPOSITORY/$FLAVOR/receipt
1560 for i in rootcd rootfs; do
1561 [ -f $TMP_DIR/$FLAVOR.$i ] || continue
1562 mkdir $FLAVORS_REPOSITORY/$FLAVOR/$i
1563 zcat < $TMP_DIR/$FLAVOR.$i | \
1564 (cd $FLAVORS_REPOSITORY/$FLAVOR/$i; \
1565 cpio -idm > /dev/null)
1566 done
1567 [ -s $TMP_DIR/$FLAVOR.mirrors ] &&
1568 cp $TMP_DIR/$FLAVOR.mirrors \
1569 $FLAVORS_REPOSITORY/$FLAVOR/mirrors
1570 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1571 while read org; do
1572 i=0
1573 pkg=$org
1574 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
1575 pkg=${pkg%-*}
1576 i=$(($i + 1))
1577 [ $i -gt 5 ] && break;
1578 done
1579 echo $pkg
1580 done < $TMP_DIR/$FLAVOR.pkglist \
1581 > $FLAVORS_REPOSITORY/$FLAVOR/packages.list
1582 status
1583 rm -Rf $TMP_DIR
1584 fi ;;
1586 pack-flavor)
1587 # Create a flavor from $FLAVORS_REPOSITORY.
1588 FLAVOR=${2%.flavor}
1589 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/receipt ]; then
1590 mkdir $TMP_DIR
1591 echo -n "Creating flavor $FLAVOR..."
1592 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1593 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/mirrors ]; then
1594 cp $FLAVORS_REPOSITORY/$FLAVOR/mirrors \
1595 $TMP_DIR/$FLAVOR.mirrors
1596 for i in $(cat $TMP_DIR/$FLAVOR.mirrors); do
1597 wget -O - $i/packages.list >> $TMP_DIR/packages.list
1598 done
1599 fi
1600 #add distro.sh if exist
1601 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/distro.sh ]; then
1602 cp $FLAVORS_REPOSITORY/$FLAVOR/distro.sh $TMP_DIR/$FLAVOR-distro.sh
1603 fi
1605 # Get receipt in .flavor
1606 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/receipt ]; then
1607 cp $FLAVORS_REPOSITORY/$FLAVOR/receipt $TMP_DIR/$FLAVOR.receipt
1608 fi
1610 # Build the package list.
1612 # On peut inclure une liste venant d'une autre saveur avec le mot clé @include
1613 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/packages.list ]; then
1614 INCLUDE=$(grep '^@include' $FLAVORS_REPOSITORY/$FLAVOR/packages.list)
1615 if [ ! -z "$INCLUDE" ]; then
1616 INCLUDE=${INCLUDE#@include }
1617 [ -s "$FLAVORS_REPOSITORY/$INCLUDE/packages.list" ] && \
1618 get_pkglist $INCLUDE > $TMP_DIR/$FLAVOR.pkglist || \
1619 echo -e "\nERROR: Can't find include package list from $INCLUDE\n"
1620 fi
1621 # Generate the final/initial package list
1622 [ -s $FLAVORS_REPOSITORY/$FLAVOR/packages.list ] && \
1623 get_pkglist $FLAVOR >> $TMP_DIR/$FLAVOR.pkglist
1624 fi
1625 if grep -q ^ROOTFS_SELECTION \
1626 $FLAVORS_REPOSITORY/$FLAVOR/receipt; then
1627 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1628 set -- $ROOTFS_SELECTION
1629 [ -n "$FRUGAL_RAM" ] || FRUGAL_RAM=$1
1630 [ -f $FLAVORS_REPOSITORY/$2/packages.list ] ||
1631 tazlito extract-flavor $2
1632 get_pkglist $2 > $TMP_DIR/$FLAVOR.pkglist
1633 for i in rootcd rootfs; do
1634 mkdir $TMP_DIR/$i
1635 # Copy extra files from the first flavor
1636 [ -d $FLAVORS_REPOSITORY/$2/$i ] &&
1637 cp -a $FLAVORS_REPOSITORY/$2/$i $TMP_DIR
1638 # Overload extra files by meta flavor
1639 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] &&
1640 cp -a $FLAVORS_REPOSITORY/$FLAVOR/$i $TMP_DIR
1641 [ -n "$(ls $TMP_DIR/$i)" ] &&
1642 ( cd $TMP_DIR/$i ; find . | cpio -o -H newc 2> /dev/null ) | \
1643 gzip -9 >$TMP_DIR/$FLAVOR.$i
1644 rm -rf $TMP_DIR/$i
1645 done
1646 else
1647 for i in rootcd rootfs; do
1648 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] || \
1649 continue
1650 ( cd $FLAVORS_REPOSITORY/$FLAVOR/$i ; \
1651 find . | cpio -o -H newc 2> /dev/null ) | \
1652 gzip -9 >$TMP_DIR/$FLAVOR.$i
1653 done
1654 fi
1655 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1656 packed_size=$(($packed_size \
1657 + $(wc -c < $TMP_DIR/$FLAVOR.rootfs) / 100 ))
1658 unpacked_size=$(($unpacked_size \
1659 + $(zcat < $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1660 fi
1661 # Estimate lzma
1662 packed_size=$(($packed_size * 2 / 3))
1663 iso_size=$(( $packed_size + 26000 ))
1664 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1665 iso_size=$(($iso_size \
1666 + $(zcat < $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1667 fi
1668 VERSION=""
1669 MAINTAINER=""
1670 ROOTFS_SELECTION=""
1671 ROOTFS_SIZE="$(cent2human $unpacked_size) (estimated)"
1672 INITRAMFS_SIZE="$(cent2human $packed_size) (estimated)"
1673 ISO_SIZE="$(cent2human $iso_size) (estimated)"
1674 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1675 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1676 Flavor : $FLAVOR
1677 Description : $SHORT_DESC
1678 EOT
1679 [ -n "$VERSION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1680 Version : $VERSION
1681 EOT
1682 [ -n "$MAINTAINER" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1683 Maintainer : $MAINTAINER
1684 EOT
1685 [ -n "$FRUGAL_RAM" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1686 LiveCD RAM size : $FRUGAL_RAM
1687 EOT
1688 [ -n "$ROOTFS_SELECTION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1689 Rootfs list : $ROOTFS_SELECTION
1690 EOT
1691 cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1692 Build date : $(date +%Y%m%d\ \at\ \%H:%M:%S)
1693 Packages : $(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l)
1694 Rootfs size : $ROOTFS_SIZE
1695 Initramfs size : $INITRAMFS_SIZE
1696 ISO image size : $ISO_SIZE
1697 ================================================================================
1699 EOT
1700 rm -f $TMP_DIR/packages.list
1701 ( cd $TMP_DIR ; ls | cpio -o -H newc 2> /dev/null) | \
1702 gzip -9 > $FLAVOR.flavor
1703 status
1704 rm -Rf $TMP_DIR
1705 else
1706 echo "No $FLAVOR flavor in $FLAVORS_REPOSITORY."
1707 fi ;;
1709 get-flavor)
1710 # Get a flavor's files and prepare for gen-distro.
1711 FLAVOR=${2%.flavor}
1712 echo -e "\n\033[1mPreparing $FLAVOR distro flavor\033[0m"
1713 separator
1714 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1715 echo -n "Cleaning $DISTRO..."
1716 rm -R $DISTRO 2> /dev/null
1717 mkdir -p $DISTRO
1718 status
1719 mkdir $TMP_DIR
1720 echo -n "Extracting flavor $FLAVOR.flavor... "
1721 zcat < $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i --quiet >/dev/null )
1722 status
1723 echo -n "Creating distro-packages.list..."
1724 mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
1725 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
1726 status
1727 if [ -f "$TMP_DIR/$FLAVOR-distro.sh" ]; then
1728 echo -n "Extracting distro.sh... "
1729 mv $TMP_DIR/$FLAVOR-distro.sh distro.sh 2> /dev/null
1730 status
1731 fi
1732 if [ -f "$TMP_DIR/$FLAVOR.receipt" ]; then
1733 echo -n "Extracting receipt... "
1734 mv $TMP_DIR/$FLAVOR.receipt receipt 2> /dev/null
1735 status
1736 fi
1737 infos="$FLAVOR.desc"
1738 for i in rootcd rootfs; do
1739 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
1740 echo -n "Adding $i files... "
1741 mkdir -p "$ADDFILES/$i"
1742 zcat < $TMP_DIR/$FLAVOR.$i | \
1743 ( cd "$ADDFILES/$i"; cpio -id --quiet > /dev/null)
1744 zcat < $TMP_DIR/$FLAVOR.$i | cpio -tv 2> /dev/null \
1745 > $TMP_DIR/$FLAVOR.list$i
1746 infos="$infos\n$FLAVOR.list$i"
1747 status
1748 fi
1749 done
1750 if [ -s $TMP_DIR/$FLAVOR.mirrors ]; then
1751 n=""
1752 while read line; do
1753 mkdir -p $LOCALSTATE/undigest/$FLAVOR$n
1754 echo "$line" > $LOCALSTATE/undigest/$FLAVOR$n/mirror
1755 n=$(( $n + 1 ))
1756 done < $TMP_DIR/$FLAVOR.mirrors
1757 infos="$infos\n$FLAVOR.mirrors"
1758 tazpkg recharge
1759 fi
1760 rm -f /etc/tazlito/rootfs.list
1761 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc &&
1762 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1763 sed 's/.*: \(.*\)$/\1/' > /etc/tazlito/rootfs.list
1764 echo -n "Updating tazlito.conf..."
1765 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
1766 grep -v "^#VOLUM_NAME" < tazlito.conf | \
1767 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
1768 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
1769 sed -i "s/ISO_NAME=.*/ISO_NAME=\"slitaz-$FLAVOR\"/" tazlito.conf
1770 status
1771 ( cd $TMP_DIR ; echo -e $infos | cpio -o -H newc ) | \
1772 gzip -9 > /etc/tazlito/info
1773 rm -Rf $TMP_DIR
1774 fi
1775 separator
1776 echo -e "Flavor is ready to be generated by: tazlito gen-distro\n" ;;
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 ;;
1859 check-list)
1860 # Use current packages list in $PWD by default.
1861 DISTRO_PKGS_LIST=distro-packages.list
1862 [ -d "$2" ] && DISTRO_PKGS_LIST=$2/distro-packages.list
1863 [ -f "$2" ] && DISTRO_PKGS_LIST=$2
1864 [ ! -f $DISTRO_PKGS_LIST ] && echo "No packages list found." && exit 0
1865 newline
1866 echo -e "\033[1mLiveCD packages list check\033[0m"
1867 separator
1868 for pkg in `cat $DISTRO_PKGS_LIST`
1869 do
1870 if ! grep -q "$pkg" $LOCALSTATE/packages.list; then
1871 echo "Updating: $pkg"
1872 up=$(($up + 1))
1873 fi
1874 done
1875 [ -z $up ] && echo -e "List is up-to-date\n" && exit 0
1876 separator
1877 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 # Libtaz will set $iso or $cdrom
1886 CDROM=""
1887 [ "$iso" ] && CDROM="-o loop $iso"
1888 [ "$cdrom" ] && CDROM="/dev/cdrom"
1889 # Check if a package list was specified on cmdline.
1890 if [ -f "$2" ]; then
1891 LIST_NAME=$2
1892 else
1893 LIST_NAME="distro-packages.list"
1894 fi
1896 if [ -d "$ROOTFS" ] ; then
1897 # Delete $ROOTFS if --force is set on command line
1898 if [ "$forced" ]; then
1899 rm -rf $ROOTFS $ROOTCD
1900 else
1901 echo -e "\nA rootfs exists in : $DISTRO"
1902 echo -e "Please clean the distro tree or change directory path.\n"
1903 exit 0
1904 fi
1905 fi
1906 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
1907 # Build list with installed packages
1908 for i in $(ls $INSTALLED); do
1909 if grep -q ^_realver $INSTALLED/$i/receipt ; then
1910 VERSION=$(. $INSTALLED/$i/receipt 2>/dev/null ; echo $VERSION)
1911 else
1912 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
1913 fi
1914 EXTRAVERSION=""
1915 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
1916 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
1917 done
1918 fi
1919 # Exit if no list name.
1920 if [ ! -f "$LIST_NAME" ]; then
1921 echo -e "\nNo packages list found or specified. Please read the docs.\n"
1922 exit 0
1923 fi
1924 # Start generation.
1925 newline
1926 echo -e "\033[1mTazlito generating a distro\033[0m"
1927 separator
1928 # Misc checks
1929 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
1930 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
1931 # Get the list of packages using cat for a file list.
1932 LIST=`cat $LIST_NAME`
1933 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
1934 REPACK=""
1935 DOWNLOAD=""
1936 for pkg in $LIST
1937 do
1938 [ "$pkg" = "" ] && continue
1939 pkg=${pkg%.tazpkg}
1940 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
1941 PACKAGE=$(installed_package_name $pkg)
1942 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
1943 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
1944 echo -e "\nUnable to find $pkg in the repository."
1945 echo -e "Path : $PACKAGES_REPOSITORY\n"
1946 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
1947 yesorno "Repack packages from rootfs (y/N) ? "
1948 REPACK="$answer"
1949 [ "$answer" = "y" ] || REPACK="n"
1950 [ "$DOWNLOAD" = "y" ] && break
1951 fi
1952 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
1953 yesorno "Download packages from mirror (Y/n) ? "
1954 DOWNLOAD="$answer"
1955 if [ "$answer" = "n" ]; then
1956 [ -z "$PACKAGE" ] && exit 1
1957 else
1958 DOWNLOAD="y"
1959 [ -n "$REPACK" ] && break
1960 fi
1961 fi
1962 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
1963 done
1965 # Mount cdrom to be able to repack boot-loader packages
1966 if [ ! -e /boot -a -n "$CDROM" ]; then
1967 mkdir $TMP_MNT
1968 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
1969 ln -s $TMP_MNT/boot /
1970 if [ ! -d "$ADDFILES/rootcd" ] ; then
1971 mkdir -p $ADDFILES/rootcd
1972 for i in $(ls $TMP_MNT); do
1973 [ "$i" = "boot" ] && continue
1974 cp -a $TMP_MNT/$i $ADDFILES/rootcd
1975 done
1976 fi
1977 else
1978 rmdir $TMP_MNT
1979 fi
1980 fi
1982 # Root fs stuff.
1983 echo "Preparing the rootfs directory..."
1984 mkdir -p $ROOTFS
1985 for pkg in $LIST
1986 do
1987 [ "$pkg" = "" ] && continue
1988 # First copy and extract the package in tmp dir.
1989 pkg=${pkg%.tazpkg}
1990 PACKAGE=$(installed_package_name $pkg)
1991 mkdir -p $TMP_DIR
1992 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1993 # Look for package in cache
1994 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
1995 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
1996 # Look for package in running distribution
1997 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
1998 tazpkg repack $PACKAGE && \
1999 mv $pkg.tazpkg $PACKAGES_REPOSITORY
2000 fi
2001 fi
2002 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
2003 # Get package from mirror
2004 [ "$DOWNLOAD" = "y" ] && \
2005 download $pkg.tazpkg && \
2006 mv $pkg.tazpkg $PACKAGES_REPOSITORY
2007 fi
2008 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
2009 echo "Missing package $pkg."
2010 cleanup
2011 exit 1
2012 fi
2013 done
2014 if [ -f non-free.list ]; then
2015 echo "Preparing non-free packages..."
2016 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
2017 for pkg in $(cat non-free.list); do
2018 if [ ! -d $INSTALLED/$pkg ]; then
2019 if [ ! -d $INSTALLED/get-$pkg ]; then
2020 tazpkg get-install get-$pkg
2021 fi
2022 get-$pkg
2023 fi
2024 tazpkg repack $pkg
2025 pkg=$(ls $pkg*.tazpkg)
2026 grep -q "^$pkg$" $LIST_NAME || \
2027 echo $pkg >>$LIST_NAME
2028 mv $pkg $PACKAGES_REPOSITORY
2029 done
2030 fi
2031 cp $LIST_NAME $DISTRO/distro-packages.list
2032 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/distro-packages.list > $DISTRO/list-packages
2033 cd $PACKAGES_REPOSITORY
2034 for pkg in $(cat $DISTRO/list-packages)
2035 do
2036 echo -n "Installing package: $pkg"
2037 yes y | tazpkg install $pkg --root=$ROOTFS 2>&1 >> $log || exit 1
2038 status
2039 done
2040 rm -f $ROOTFS/var/lib/tazpkg/packages.*
2041 cd $DISTRO
2042 cp distro-packages.list $ROOTFS/etc/tazlito
2043 # Copy all files from $ADDFILES/rootfs to the rootfs.
2044 if [ -d "$ADDFILES/rootfs" ] ; then
2045 echo -n "Copying addfiles content to the rootfs... "
2046 cp -a $ADDFILES/rootfs/* $ROOTFS
2047 status
2048 fi
2049 echo -n "Root filesystem is generated..." && status
2050 # Root CD part.
2051 echo -n "Preparing the rootcd directory..."
2052 mkdir -p $ROOTCD
2053 status
2054 # Move the boot dir with the Linux kernel from rootfs.
2055 # The boot dir goes directly on the CD.
2056 if [ -d "$ROOTFS/boot" ] ; then
2057 echo -n "Moving the boot directory..."
2058 mv $ROOTFS/boot $ROOTCD
2059 cd $ROOTCD/boot
2060 ln vmlinuz-* bzImage
2061 status
2062 fi
2063 cd $DISTRO
2064 # Copy all files from $ADDFILES/rootcd to the rootcd.
2065 if [ -d "$ADDFILES/rootcd" ] ; then
2066 echo -n "Copying addfiles content to the rootcd... "
2067 cp -a $ADDFILES/rootcd/* $ROOTCD
2068 status
2069 fi
2070 # Execute the distro script used to perform tasks in the rootfs
2071 # before compression. Give rootfs path in arg
2072 [ -z $DISTRO_SCRIPT ] && DISTRO_SCRIPT=$TOP_DIR/distro.sh
2073 if [ -x $DISTRO_SCRIPT ]; then
2074 echo "Executing distro script..."
2075 sh $DISTRO_SCRIPT $DISTRO
2076 fi
2078 # Execute the custom_rules found in receipt.
2080 if [ -s $TOP_DIR/receipt ]; then
2081 if grep -q ^custom_rules $TOP_DIR/receipt; then
2082 echo -e "Executing: custom_rules\n"
2083 . $TOP_DIR/receipt
2084 custom_rules || echo -e "\nERROR: custom_rules failed\n"
2085 fi
2086 fi
2088 if [ -s /etc/tazlito/rootfs.list ]; then
2089 FLAVOR_LIST="$(awk '{ for (i = 2; i <= NF; i+=2) \
2090 printf("%s ",$i) }' < /etc/tazlito/rootfs.list)"
2091 sed -i "s/ *//;s/)/), flavors $FLAVOR_LIST/" \
2092 $ROOTCD/boot/isolinux/isolinux.msg 2> /dev/null
2093 [ -f $ROOTCD/boot/isolinux/ifmem.c32 -o \
2094 -f $ROOTCD/boot/isolinux/c32box.c32 ] ||
2095 cp /boot/isolinux/c32box.c32 $ROOTCD/boot/isolinux 2> /dev/null ||
2096 cp /boot/isolinux/ifmem.c32 $ROOTCD/boot/isolinux
2097 n=0
2098 last=$ROOTFS
2099 while read flavor; do
2100 n=$(($n+1))
2101 echo "Building $flavor rootfs..."
2102 [ -s $TOP_DIR/$flavor.flavor ] &&
2103 cp $TOP_DIR/$flavor.flavor .
2104 [ -s $flavor.flavor ] || download $flavor.flavor
2105 zcat < $flavor.flavor | cpio -i \
2106 $flavor.pkglist $flavor.rootfs
2107 sed 's/.*/&.tazpkg/' < $flavor.pkglist \
2108 > $DISTRO/list-packages0$n
2109 mkdir ${ROOTFS}0$n
2110 cd $PACKAGES_REPOSITORY
2111 yes y | tazpkg install-list \
2112 $DISTRO/list-packages0$n --root=${ROOTFS}0$n
2113 rm -rf ${ROOTFS}0$n/boot ${ROOTFS}0$n/var/lib/tazpkg/packages.*
2114 status
2115 cd $DISTRO
2116 if [ -s $flavor.rootfs ]; then
2117 echo "Adding $flavor rootfs extra files..."
2118 zcat < $flavor.rootfs | \
2119 ( cd ${ROOTFS}0$n ; cpio -idmu )
2120 fi
2121 mv $flavor.pkglist ${ROOTFS}0$n/etc/tazlito/distro-packages.list
2122 rm -f $flavor.flavor install-list
2123 mergefs ${ROOTFS}0$n $last
2124 last=${ROOTFS}0$n
2125 done <<EOT
2126 $(awk '{ for (i = 4; i <= NF; i+=2) print $i; }' < /etc/tazlito/rootfs.list)
2127 EOT
2128 i=$(($n+1))
2129 while [ $n -gt 0 ]; do
2130 mv ${ROOTFS}0$n ${ROOTFS}$i
2131 echo "Compression ${ROOTFS}0$n ($(du -hs ${ROOTFS}$i | awk '{ print $1 }')) ..."
2132 gen_initramfs ${ROOTFS}$i
2133 n=$(($n-1))
2134 i=$(($i-1))
2135 done
2136 mv $ROOTFS ${ROOTFS}$i
2137 gen_initramfs ${ROOTFS}$i
2138 update_bootconfig $ROOTCD/boot/isolinux \
2139 "$(cat /etc/tazlito/rootfs.list)"
2140 else
2141 # Initramfs and ISO image stuff.
2142 gen_initramfs $ROOTFS
2143 fi
2144 gen_livecd_isolinux
2145 distro_stats
2146 cleanup ;;
2148 clean-distro)
2149 # Remove old distro tree.
2151 check_root
2152 newline
2153 boldify "Cleaning : $DISTRO"
2154 separator
2155 if [ -d "$DISTRO" ] ; then
2156 if [ -d "$ROOTFS" ] ; then
2157 echo -n "Removing the rootfs..."
2158 rm -f $DISTRO/$INITRAMFS
2159 rm -rf $ROOTFS
2160 status
2161 fi
2162 if [ -d "$ROOTCD" ] ; then
2163 echo -n "Removing the rootcd..."
2164 rm -rf $ROOTCD
2165 status
2166 fi
2167 echo -n "Removing eventual ISO image..."
2168 rm -f $DISTRO/$ISO_NAME.iso
2169 rm -f $DISTRO/$ISO_NAME.md5
2170 status
2171 fi
2172 separator
2173 newline ;;
2175 check-distro)
2176 # Check for a few LiveCD needed files not installed by packages.
2178 check_rootfs
2179 newline
2180 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
2181 separator
2182 # SliTaz release info.
2183 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
2184 echo "Missing release info : /etc/slitaz-release"
2185 else
2186 release=`cat $ROOTFS/etc/slitaz-release`
2187 echo -n "Release : $release"
2188 status
2189 fi
2190 # Tazpkg mirror.
2191 if [ ! -f "$ROOTFS$LOCALSTATE/mirror" ]; then
2192 echo -n "Mirror URL : Missing $LOCALSTATE/mirror"
2193 todomsg
2194 else
2195 echo -n "Mirror configuration exists..."
2196 status
2197 fi
2198 # Isolinux msg
2199 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.*g; then
2200 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
2201 todomsg
2202 else
2203 echo -n "Isolinux message seems good..."
2204 status
2205 fi
2206 separator
2207 newline ;;
2209 writeiso)
2210 # Writefs to ISO image including /home unlike gen-distro we dont use
2211 # packages to generate a rootfs, we build a compressed rootfs with all
2212 # the current filesystem similar to 'tazusb writefs'.
2214 DISTRO="/home/slitaz/distro"
2215 ROOTCD="$DISTRO/rootcd"
2216 if [ -z $2 ]; then
2217 COMPRESSION=none
2218 else
2219 COMPRESSION=$2
2220 fi
2221 if [ -z $3 ]; then
2222 ISO_NAME="slitaz"
2223 else
2224 ISO_NAME="$3"
2225 fi
2226 check_root
2227 # Start info
2228 newline
2229 boldify "Write filesystem to ISO"
2230 separator
2231 cat << EOT
2232 The command writeiso will write the current filesystem into a suitable cpio
2233 archive (rootfs.gz) and generate a bootable ISO image (slitaz.iso).
2235 $(boldify "Archive compression:") $(colorize 36 "$COMPRESSION")
2237 EOT
2238 # Save some space
2239 rm /var/cache/tazpkg/* -r -f
2240 rm -rf /home/slitaz/distro
2242 # Optionally remove sound card selection and screen resolution.
2243 echo "Do you wish to remove the sound card and screen configs ? "
2244 echo -n "Press ENTER to keep or answer (No|yes|exit): "
2245 read anser
2246 case $anser in
2247 e|E|"exit"|Exit)
2248 exit 0 ;;
2249 y|Y|yes|Yes)
2250 echo -n "Removing current sound card and screen configurations..."
2251 rm -f /var/lib/sound-card-driver
2252 rm -f /var/lib/alsa/asound.state
2253 rm -f /etc/X11/xorg.conf ;;
2254 *)
2255 echo -n "Keeping current sound card and screen configurations..." ;;
2256 esac
2257 status && newline
2259 # Optionally remove i18n settings
2260 echo "Do you wish to remove local/keymap settings ? "
2261 echo -n "Press ENTER to keep or answer (No|yes|exit): "
2262 read anser
2263 case $anser in
2264 e|E|"exit"|Exit)
2265 exit 0 ;;
2266 y|Y|yes|Yes)
2267 echo "Removing current locale/keymap settings..."
2268 newline > /etc/locale.conf
2269 newline > /etc/keymap.conf ;;
2270 *)
2271 echo "Keeping current locale/keymap settings..." ;;
2272 esac
2273 status
2275 # Clean-up files by default
2276 newline > /etc/udev/rules.d/70-persistent-net.rules
2277 newline > /etc/udev/rules.d/70-persistant-cd.rules
2279 # Create list of files including default user files since it is defined in /etc/passwd
2280 # and some new users might have been added.
2281 cd /
2282 find bin etc init sbin var dev lib root usr home >/tmp/list
2284 for dir in proc sys tmp mnt media media/cdrom media/flash \
2285 media/usbdisk run run/udev
2286 do
2287 echo $dir >>/tmp/list
2288 done
2290 # Generate initramfs with specified compression and display rootfs
2291 # size in realtime.
2292 rm -f /tmp/rootfs
2293 write_initramfs &
2294 sleep 2
2295 cd - > /dev/null
2296 echo -en "\nFilesystem size:"
2297 while [ ! -f /tmp/rootfs ]
2298 do
2299 sleep 1
2300 echo -en "\\033[18G`du -sh /rootfs.gz | awk '{print $1}'` "
2301 done
2302 echo -e "\n"
2304 # Move freshly generated rootfs to the cdrom.
2305 mkdir -p $ROOTCD/boot
2306 mv -f /rootfs.gz $ROOTCD/boot
2308 # Now we need the kernel and isolinux files.
2309 if mount /dev/cdrom /media/cdrom 2>/dev/null; then
2310 cp /media/cdrom/boot/bzImage $ROOTCD/boot
2311 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
2312 unmeta_boot $ROOTCD
2313 umount /media/cdrom
2314 elif mount |grep /media/cdrom; then
2315 cp /media/cdrom/boot/bzImage $ROOTCD/boot
2316 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
2317 unmeta_boot $ROOTCD
2318 umount /media/cdrom;
2319 else
2320 echo -e "
2321 When SliTaz is running in RAM the kernel and bootloader files are kept
2322 on the cdrom. Please insert a LiveCD or loop mount the slitaz.iso to
2323 /media/cdrom to let Tazlito copy the files.\n"
2324 echo -en "----\nENTER to continue..."; read i
2325 exit 1
2326 fi
2328 # Generate the iso image.
2329 cd $DISTRO
2330 echo "Generating ISO image..."
2331 genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
2332 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
2333 -V "SliTaz" -input-charset iso8859-1 -boot-info-table $ROOTCD
2334 if [ -x /usr/bin/isohybrid ]; then
2335 echo -n "Creating hybrid ISO..."
2336 /usr/bin/isohybrid $ISO_NAME.iso -entry 2 2> /dev/null
2337 status
2338 fi
2339 echo -n "Creating the ISO md5sum..."
2340 md5sum $ISO_NAME.iso > $ISO_NAME.md5
2341 status
2343 echo "==============================================================================="
2344 echo "ISO image: `du -sh /home/slitaz/distro/$ISO_NAME.iso`"
2345 newline
2346 echo -n "Exit or burn ISO to cdrom (Exit|burn)? "; read anser
2347 case $anser in
2348 burn)
2349 eject
2350 echo -n "Please insert a blank cdrom and press ENTER..."
2351 read i && sleep 2
2352 tazlito burn-iso /home/slitaz/distro/$ISO_NAME.iso
2353 echo -en "----\nENTER to continue..."; read i ;;
2354 *)
2355 exit 0 ;;
2356 esac ;;
2358 burn-iso)
2359 # Guess cdrom device, ask user and burn the ISO.
2361 check_root
2362 DRIVE_NAME=$(grep "drive name" < /proc/sys/dev/cdrom/info | cut -f 3)
2363 DRIVE_SPEED=$(grep "drive speed" < /proc/sys/dev/cdrom/info | cut -f 3)
2364 # We can specify an alternative ISO from the cmdline.
2365 if [ -n "$2" ] ; then
2366 iso=$2
2367 else
2368 iso=$DISTRO/$ISO_NAME.iso
2369 fi
2370 if [ ! -f "$iso" ]; then
2371 echo -e "\nUnable to find ISO : $iso\n"
2372 exit 0
2373 fi
2374 newline
2375 echo -e "\033[1mTazlito burn ISO\033[0m "
2376 separator
2377 echo "Cdrom device : /dev/$DRIVE_NAME"
2378 echo "Drive speed : $DRIVE_SPEED"
2379 echo "ISO image : $iso"
2380 separator
2381 newline
2382 yesorno "Burn ISO image (y/N) ? "
2383 if [ "$answer" == "y" ]; then
2384 newline
2385 echo "Starting Wodim to burn the iso..." && sleep 2
2386 separator
2387 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
2388 separator
2389 echo "ISO image is burned to cdrom."
2390 else
2391 echo -e "\nExiting. No ISO burned."
2392 fi
2393 newline ;;
2395 merge)
2396 # Merge multiple rootfs into one iso.
2398 if [ -z "$2" ]; then
2399 cat << EOT
2400 Usage: tazlito merge size1 iso size2 rootfs2 [sizeN rootfsN]...
2402 Merge multiple rootfs into one iso. Rootfs are like russian dolls
2403 i.e: rootfsN is a subset of rootfsN-1
2404 rootfs1 is found in iso, sizeN is the RAM size need to launch rootfsN.
2405 The boot loader will select the rootfs according to the RAM size detected.
2407 Example:
2408 $ tazlito merge 160M slitaz-core.iso 96M rootfs-justx.gz 32M rootfs-base.gz
2410 Will start slitaz-core with 160M+ RAM, slitaz-justX with 96M-160M RAM,
2411 slitaz-base with 32M-96M RAM and display an error message if RAM < 32M.
2413 EOT
2414 exit 2
2415 fi
2417 shift # skip merge
2418 append="$1 slitaz1"
2419 shift # skip size1
2420 mkdir -p $TMP_DIR/mnt $TMP_DIR/rootfs1
2422 ISO=$1.merged
2423 # Extract filesystems
2424 echo -n "Mounting $1"
2425 mount -o loop,ro $1 $TMP_DIR/mnt 2> /dev/null
2426 status || cleanup_merge
2427 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2428 rm -f $TMP_DIR/iso/boot/bzImage
2429 ln $TMP_DIR/iso/boot/vmlinuz* $TMP_DIR/iso/boot/bzImage
2430 umount -d $TMP_DIR/mnt
2431 if [ -f $TMP_DIR/iso/boot/rootfs1.gz ]; then
2432 echo "$1 is already a merged iso. Aborting."
2433 cleanup_merge
2434 fi
2435 if [ ! -f $TMP_DIR/iso/boot/isolinux/ifmem.c32 -a
2436 ! -f $TMP_DIR/iso/boot/isolinux/c32box.c32 ]; then
2437 if [ ! -f /boot/isolinux/ifmem.c32 -a
2438 ! -f /boot/isolinux/c32box.c32 ]; then
2439 cat <<EOT
2440 No file /boot/isolinux/ifmem.c32
2441 Please install syslinux package !
2442 EOT
2443 rm -rf $TMP_DIR
2444 exit 1
2445 fi
2446 cp /boot/isolinux/c32box.c32 $TMP_DIR/iso/boot/isolinux 2> /dev/null ||
2447 cp /boot/isolinux/ifmem.c32 $TMP_DIR/iso/boot/isolinux
2448 fi
2450 echo -n "Extracting iso/rootfs.gz"
2451 extract_rootfs $TMP_DIR/iso/boot/rootfs.gz $TMP_DIR/rootfs1 &&
2452 [ -d $TMP_DIR/rootfs1/etc ]
2453 status || cleanup_merge
2454 n=1
2455 while [ -n "$2" ]; do
2456 shift # skip rootfs N-1
2457 p=$n
2458 n=$(($n + 1))
2459 append="$append $1 slitaz$n"
2460 shift # skip size N
2461 mkdir -p $TMP_DIR/rootfs$n
2462 echo -n "Extracting $1"
2463 extract_rootfs $1 $TMP_DIR/rootfs$n &&
2464 [ -d $TMP_DIR/rootfs$n/etc ]
2465 status || cleanup_merge
2466 mergefs $TMP_DIR/rootfs$n $TMP_DIR/rootfs$p
2467 echo "Creating rootfs$p.gz"
2468 pack_rootfs $TMP_DIR/rootfs$p $TMP_DIR/iso/boot/rootfs$p.gz
2469 status
2470 done
2471 echo "Creating rootfs$n.gz"
2472 pack_rootfs $TMP_DIR/rootfs$n $TMP_DIR/iso/boot/rootfs$n.gz
2473 status
2474 rm -f $TMP_DIR/iso/boot/rootfs.gz
2475 update_bootconfig $TMP_DIR/iso/boot/isolinux "$append"
2476 create_iso $ISO $TMP_DIR/iso
2477 rm -rf $TMP_DIR ;;
2479 repack)
2480 # Repack an iso with maximum lzma compression ratio.
2482 ISO=$2
2483 mkdir -p $TMP_DIR/mnt
2485 # Extract filesystems
2486 echo -n "Mounting $ISO"
2487 mount -o loop,ro $ISO $TMP_DIR/mnt 2> /dev/null
2488 status || cleanup_merge
2489 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2490 umount -d $TMP_DIR/mnt
2492 for i in $TMP_DIR/iso/boot/rootfs* ; do
2493 echo -n "Repacking $(basename $i)"
2494 (zcat $i 2> /dev/null || unlzma -c $i || cat $i) \
2495 2>/dev/null > $TMP_DIR/rootfs
2496 lzma e $TMP_DIR/rootfs $i \
2497 $(lzma_switches $TMP_DIR/rootfs)
2498 align_to_32bits $i
2499 status
2500 done
2502 create_iso $ISO $TMP_DIR/iso
2503 rm -rf $TMP_DIR ;;
2505 build-loram)
2506 # Build a Live CD for low ram systems.
2508 ISO=$2
2509 OUTPUT=$3
2510 if [ -z "$3" ]; then
2511 echo "Usage: tazlito $1 input.iso output.iso [cdrom|smallcdrom|http|ram]"
2512 exit 1
2513 fi
2514 mkdir -p $TMP_DIR/iso
2515 mount -o loop,ro -t iso9660 $ISO $TMP_DIR/iso
2516 loopdev=$( (losetup -a 2>/dev/null || losetup) | grep $ISO | cut -d: -f1)
2517 if ! check_iso_for_loram ; then
2518 echo "$2 is not a valid SliTaz live CD. Abort."
2519 umount -d $TMP_DIR/iso
2520 rm -rf $TMP_DIR
2521 exit 1
2522 fi
2523 case "$4" in
2524 cdrom) build_loram_cdrom ;;
2525 http) build_loram_http ;;
2526 *) build_loram_ram ;;
2527 esac
2528 umount $TMP_DIR/iso # no -d: needs /proc
2529 losetup -d $loopdev
2530 rm -rf $TMP_DIR ;;
2532 emu-iso)
2533 # Emulate an ISO image with Qemu.
2534 if [ -n "$2" ] ; then
2535 iso=$2
2536 else
2537 iso=$DISTRO/$ISO_NAME.iso
2538 fi
2539 if [ ! -f "$iso" ]; then
2540 echo -e "\nUnable to find ISO : $iso\n"
2541 exit 0
2542 fi
2543 if [ ! -x "/usr/bin/qemu" ]; then
2544 echo -e "\nUnable to find Qemu binary. Please install: qemu\n"
2545 exit 0
2546 fi
2547 echo -e "\nStarting Qemu emulator:\n"
2548 echo -e "qemu $QEMU_OPTS $iso\n"
2549 qemu $QEMU_OPTS $iso ;;
2551 deduplicate)
2552 # Deduplicate files in a tree
2553 shift
2554 deduplicate "$@" ;;
2556 usage|*)
2557 # Print usage also for all unknown commands.
2558 usage ;;
2559 esac
2561 exit 0