tazlito view tazlito @ rev 342

Move "es_AR" to "es" translations; tiny edits for "ru"
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat Apr 12 15:28:33 2014 +0300 (2014-04-12)
parents 0744badda2ef
children cb1b9eb7c9f8
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) configuration file.
457 #
459 # Name of the ISO image to generate.
460 ISO_NAME=""
462 # ISO image volume name.
463 VOLUM_NAME="SliTaz"
465 # Name of the preparer.
466 PREPARED="$USER"
468 # Path to the packages repository and the packages.list.
469 PACKAGES_REPOSITORY=""
471 # Path to the distro tree to gen-distro from a
472 # list of packages.
473 DISTRO=""
475 # Path to the directory containing additional files
476 # to copy into the rootfs and rootcd of the LiveCD.
477 ADDFILES="$DISTRO/addfiles"
479 # Default answer for binary question (Y or N)
480 DEFAULT_ANSWER="ASK"
482 # Compression utility (lzma, gzip or none)
483 COMPRESSION="lzma"
484 EOF
485 }
487 # extract rootfs.gz somewhere
488 extract_rootfs()
489 {
490 (zcat $1 || unlzma -c $1 || cat $1) 2>/dev/null | \
491 (cd $2; cpio -idm > /dev/null)
492 }
494 # Remove duplicate files
495 mergefs()
496 {
497 echo -n "Merge $(basename $1) ($(du -hs $1 | awk '{ print $1}')) into "
498 echo -n "$(basename $2) ($(du -hs $2 | awk '{ print $1}'))"
499 # merge symlinks files and devices
500 ( cd $1; find ) | while read file; do
501 if [ -L $1/$file ]; then
502 [ -L $2/$file ] &&
503 [ "$(readlink $1/$file)" == "$(readlink $2/$file)" ] &&
504 rm -f $2/$file
505 elif [ -f $1/$file ]; then
506 [ -f $2/$file ] &&
507 cmp $1/$file $2/$file > /dev/null 2>&1 && rm -f $2/$file
508 [ -f $2/$file ] &&
509 [ "$(basename $file)" == "volatile.cpio.gz" ] &&
510 [ "$(dirname $(dirname $file))" == \
511 ".$INSTALLED" ] && rm -f $2/$file
512 elif [ -b $1/$file ]; then
513 [ -b $2/$file ] &&
514 [ "$(stat -c '%a:%u:%g:%t:%T' $1/$file)" == \
515 "$(stat -c '%a:%u:%g:%t:%T' $2/$file)" ] &&
516 rm -f $2/$file
517 elif [ -c $1/$file ]; then
518 [ -c $2/$file ] &&
519 [ "$(stat -c '%a:%u:%g:%t:%T' $1/$file)" == \
520 "$(stat -c '%a:%u:%g:%t:%T' $2/$file)" ] &&
521 rm -f $2/$file
522 fi
523 done
525 # cleanup directories
526 ( cd $1; find . -type d ) | sed '1!G;h;$!d' | while read file; do
527 [ -d $2/$file ] && rmdir $2/$file 2> /dev/null
528 done
529 true
530 status
531 }
533 cleanup_merge()
534 {
535 rm -rf $TMP_DIR
536 exit 1
537 }
539 human2cent()
540 {
541 case "$1" in
542 *k) echo $1 | sed 's/\(.*\).\(.\)k/\1\2/';;
543 *M) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)M/\1\2/') * 1024));;
544 *G) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)G/\1\2/') * 1024 * 1024));;
545 esac
546 }
548 cent2human()
549 {
550 if [ $1 -lt 10000 ]; then
551 echo "$(($1 / 10)).$(($1 % 10))k"
552 elif [ $1 -lt 10000000 ]; then
553 echo "$(($1 / 10240)).$(( ($1/1024) % 10))M"
554 else
555 echo "$(($1 / 10485760)).$(( ($1/1048576) % 10))G"
556 fi
557 }
559 get_size()
560 {
561 cat $LOCALSTATE/packages.list $TMP_DIR/packages.list 2>/dev/null | awk "{ \
562 if (/^$(echo $1 | sed 's/[$+.\]/\\&/g')$/) get=1; \
563 if (/installed/ && get == 1) { print ; get++ } \
564 }
565 END { if (get < 2) print \" 0.0k (0.0k installed)\" }" | \
566 sed 's/ *\(.*\) .\(.*\) installed./\1 \2/' | while read packed unpacked; do
567 echo "$(human2cent $packed) $(human2cent $unpacked)"
568 done
569 }
571 # Display package list with version, set packed_size and unpacked_size
572 get_pkglist()
573 {
574 packed_size=0; unpacked_size=0
575 grep -v ^# $FLAVORS_REPOSITORY/$1/packages.list > $TMP_DIR/flavor.pkg
576 while read pkg; do
577 set -- $(get_size $pkg)
578 packed_size=$(( $packed_size + $1 ))
579 unpacked_size=$(( $unpacked_size + $2 ))
580 for i in $(grep -hs ^$pkg $LOCALSTATE/packages.list \
581 $TMP_DIR/packages.list); do
582 echo $i
583 break
584 done
585 done < $TMP_DIR/flavor.pkg
586 rm -f $TMP_DIR/flavor.pkg
587 }
589 # Update isolinux config files for multiple rootfs
590 update_bootconfig()
591 {
592 local files
593 echo -n "Updating boot config files..."
594 files="$(grep -l 'include common' $1/*.cfg)"
595 for file in $files ; do
596 awk -v n=$(echo $2 | awk '{ print NF/2 }') '{
597 if (/label/) label=$0;
598 else if (/kernel/) kernel=$0;
599 else if (/append/) {
600 i=index($0,"rootfs.gz");
601 append=substr($0,i+9);
602 }
603 else if (/include/) {
604 for (i = 1; i <= n; i++) {
605 print label i
606 print kernel;
607 initrd="initrd=/boot/rootfs" n ".gz"
608 for (j = n - 1; j >= i; j--) {
609 initrd=initrd ",/boot/rootfs" j ".gz";
610 }
611 printf "\tappend %s%s\n",initrd,append;
612 print "";
613 }
614 print;
615 }
616 else print;
617 }' < $file > $file.$$
618 mv -f $file.$$ $file
619 done
620 sel="$(echo $2 | awk '{
621 for (i=1; i<=NF; i++)
622 if (i % 2 == 0) printf " slitaz%d",i/2
623 else printf " %s",$i
624 }')"
625 [ -s $1/common.cfg ] && cat >> $1/common.cfg <<EOT
627 label slitaz
628 kernel /boot/isolinux/ifmem.c32
629 append$sel noram
631 label noram
632 config noram.cfg
634 EOT
635 # Update vesamenu
636 if [ -s $1/isolinux.cfg ]; then
637 files="$files $1/isolinux.cfg"
638 awk -v n=$(echo $2 | awk '{ print NF/2 }') -v "sel=$sel" '
639 BEGIN {
640 kernel=" COM32 c32box.c32"
641 }
642 {
643 if (/ROWS/) print "MENU ROW " n+$3;
644 else if (/TIMEOUTROW/) print "MENU TIMEOUTROW " n+$3;
645 else if (/TABMSGROW/) print "MENU TABMSGROW " n+$3;
646 else if (/CMDLINEROW/) print "MENU CMDLINEROW " n+$3;
647 else if (/VSHIFT/) {
648 x=$3-n;
649 if (x < 0) x=0;
650 print "MENU VSHIFT " x;
651 }
652 else if (/rootfs.gz/) {
653 linux=""
654 if (/bzImage/) {
655 linux="linux /boot/bzImage "
656 }
657 i=index($0,"rootfs.gz");
658 append=substr($0,i+9);
659 print " kernel /boot/isolinux/ifmem.c32"
660 print " append" sel " noram"
661 print ""
662 print "label noram"
663 print " MENU HIDE"
664 print " config noram.cfg"
665 print ""
666 for (i = 1; i <= n; i++) {
667 print "LABEL slitaz" i
668 print " MENU LABEL SliTaz slitaz" i " Live"
669 print kernel;
670 initrd="initrd=/boot/rootfs" n ".gz"
671 for (j = n - 1; j >= i; j--) {
672 initrd=initrd ",/boot/rootfs" j ".gz";
673 }
674 printf "\tappend %s%s%s\n",linux,initrd,append;
675 print "";
676 }
677 }
678 else if (/bzImage/) kernel=$0;
679 else print;
680 }' < $1/isolinux.cfg > $1/isolinux.cfg.$$
681 mv $1/isolinux.cfg.$$ $1/isolinux.cfg
682 fi
683 [ -s $1/c32box.c32 ] && sed -i -e '/kernel.*ifmem/d' \
684 -e 's/append \([0-9]\)/append ifmem \1/' $1/isolinux.cfg
685 cat > $1/noram.cfg <<EOT
686 implicit 0
687 prompt 1
688 timeout 80
689 F1 help.txt
690 F2 options.txt
691 F3 isolinux.msg
692 F4 display.txt
693 F5 enhelp.txt
694 F6 enopts.txt
696 display isolinux.msg
697 say Not enough RAM to boot slitaz. Trying hacker mode...
698 default hacker
699 label hacker
700 KERNEL /boot/bzImage
701 append rw root=/dev/null vga=normal
703 label reboot
704 EOT
705 if [ -s $1/c32box.c32 ]; then
706 cat >> $1/noram.cfg <<EOT
707 COM32 c32box.c32
708 append reboot
710 label poweroff
711 COM32 c32box.c32
712 append poweroff
714 EOT
715 else
716 echo " com32 reboot.c32" >> $1/noram.cfg
717 fi
718 # Restore real label names
719 [ -s $1/common.cfg ] && files="$1/common.cfg $files"
720 echo $2 | awk '{ for (i=NF; i>1; i-=2) printf "%d/%s\n",i/2,$i }' | \
721 while read pat; do
722 sed -i "s/slitaz$pat/" $files
723 done
724 status
725 }
727 # Install a missing package
728 install_package()
729 {
730 echo -n "Install package $1 "
731 [ -n "$2" ] && echo -n "for kernel $2 "
732 echo -n "?"
733 read answer
734 case "$answer" in
735 y*|Y*|o*|O*)
736 # We dont want package on host cache.
737 echo -n "Getting and installing package: $1"
738 yes y | tazpkg get-install $1 2>&1 >> $log || exit 1
739 status ;;
740 *)
741 return 1 ;;
742 esac
743 }
745 # Check iso for loram transformation
746 check_iso_for_loram()
747 {
748 [ -s $TMP_DIR/iso/boot/rootfs.gz ] ||
749 [ -s $TMP_DIR/iso/boot/rootfs1.gz ]
750 }
752 # Build initial rootfs for loram ISO ram/cdrom/http
753 build_initfs()
754 {
755 urliso="mirror.slitaz.org mirror.switch.ch/ftp/mirror/slitaz \
756 download.tuxfamily.org/slitaz slitaz.c3sl.ufpr.br"
757 version=$(ls $TMP_DIR/iso/boot/vmlinuz-* | sed 's/.*vmlinuz-//')
758 if [ -z "$version" ]; then
759 cat <<EOT
760 Can't find the kernel version.
761 No file /boot/vmlinuz-<version> in ISO image.
762 Abort.
763 EOT
764 exit 1
765 fi
766 [ -s /usr/share/boot/busybox-static ] || install_package busybox-static
767 need_lib=false
768 mkdir -p $TMP_DIR/initfs/bin $TMP_DIR/initfs/dev $TMP_DIR/initfs/run \
769 $TMP_DIR/initfs/mnt $TMP_DIR/initfs/proc $TMP_DIR/initfs/tmp \
770 $TMP_DIR/initfs/sys $TMP_DIR/initfs/lib/modules
771 ln -s bin $TMP_DIR/initfs/sbin
772 ln -s . $TMP_DIR/initfs/usr
773 while [ ! -f /lib/modules/$version/kernel/fs/aufs/aufs.ko.?z ]; do
774 install_package aufs $version || return 1
775 done
776 cp /init $TMP_DIR/initfs/
777 # bootfloppybox will need floppy.ko.?z, /dev/fd0, /dev/tty0
778 cp /lib/modules/$version/kernel/drivers/block/floppy.ko.?z \
779 $TMP_DIR/initfs/lib/modules 2> /dev/null
780 cp -a /dev/tty0 /dev/fd0 $TMP_DIR/initfs/dev 2> /dev/null
781 cp /lib/modules/$version/kernel/fs/aufs/aufs.ko.?z \
782 $TMP_DIR/initfs/lib/modules
783 if [ "$1" == "cdrom" ]; then
784 sed -i '/mod squashfs/d' $TMP_DIR/initfs/init
785 else
786 [ ! -f /usr/sbin/mksquashfs ] && ! install_package squashfs && return 1
787 while [ ! -f /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.?z ]; do
788 install_package linux-squashfs $version || return 1
789 done
790 cp /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.?z \
791 $TMP_DIR/initfs/lib/modules
792 ls /sbin/unsquashfs /usr/lib/liblzma.so* $INSTALLED/squashfs/* | \
793 cpio -o -H newc > $TMP_DIR/initfs/extractfs.cpio
794 fi
795 for i in $(ls /dev/[hs]d[a-f]*); do
796 cp -a $i $TMP_DIR/initfs/dev
797 done
798 if [ "$1" == "http" ]; then
799 mkdir $TMP_DIR/initfs/etc
800 ln -s /proc/mounts $TMP_DIR/initfs/etc/mtab
801 cp /usr/share/udhcpc/default.script $TMP_DIR/initfs/lib/udhcpc
802 sed -i 's|/sbin/||' $TMP_DIR/initfs/lib/udhcpc
803 cp -a /dev/fuse $TMP_DIR/initfs/dev
804 if ! $need_lib && [ -x /usr/share/boot/fusermount-static ]; then
805 cp /usr/share/boot/fusermount-static $TMP_DIR/initfs/bin/httpfs
806 else
807 cp /usr/bin/fusermount $TMP_DIR/initfs/bin
808 need_lib=true
809 fi
810 if ! $need_lib && [ -x /usr/share/boot/httpfs-static ]; then
811 cp /usr/share/boot/httpfs-static $TMP_DIR/initfs/bin/httpfs
812 else
813 [ ! -f /usr/bin/httpfs ] && ! install_package httpfs-fuse && return 1
814 cp /usr/bin/httpfs $TMP_DIR/initfs/bin
815 cp -a /lib/librt* $TMP_DIR/initfs/lib
816 cp -a /lib/libdl* $TMP_DIR/initfs/lib
817 cp -a /lib/libpthread* $TMP_DIR/initfs/lib
818 cp -a /usr/lib/libfuse* $TMP_DIR/initfs/lib
819 cp -a /lib/libresolv* $TMP_DIR/initfs/lib
820 cp -a /lib/libnss_dns* $TMP_DIR/initfs/lib
821 need_lib=true
822 fi
823 cd $TMP_DIR/initfs
824 echo "Getting slitaz-release..."
825 for i in $TMP_DIR/iso/boot/rootfs*.gz; do
826 ( zcat $i 2> /dev/null || unlzma -c $i) | \
827 cpio -idmu etc/slitaz-release > /dev/null
828 done
829 cd - > /dev/null
830 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"
831 echo -n "List of urls to insert: "
832 read -t 30 urliso2
833 urliso="$urliso2 $urliso"
834 fi
835 if ! $need_lib && [ -x /usr/share/boot/busybox-static ]; then
836 cp /usr/share/boot/busybox-static $TMP_DIR/initfs/bin/busybox
837 sed -i 's/LD_T.*ot/newline/;s/".*ld-.*) /"/' $TMP_DIR/initfs/init
838 else
839 cp /bin/busybox $TMP_DIR/initfs/bin
840 need_lib=true
841 fi
842 for i in $($TMP_DIR/initfs/bin/busybox | awk \
843 '{ if (s) printf "%s",$0 } /Currently/ { s=1 }' | sed 's/,//g'); do
844 ln $TMP_DIR/initfs/bin/busybox $TMP_DIR/initfs/bin/$i
845 done
846 for i in /dev/console /dev/loop* /dev/null /dev/tty /dev/zero \
847 /dev/kmem /dev/mem /dev/random /dev/urandom; do
848 cp -a $i $TMP_DIR/initfs/dev
849 done
850 $need_lib && for i in /lib/ld-* /lib/lib[cm].so* /lib/lib[cm]-* ; do
851 cp -a $i $TMP_DIR/initfs/lib
852 done
853 [ "$1" == "http" ] && cat > $TMP_DIR/initfs/init <<EOTEOT
854 #!/bin/sh
856 getarg()
857 {
858 grep -q " \$1=" /proc/cmdline || return 1
859 eval \$2=\$(sed "s/.* \$1=\\\\([^ ]*\\\\).*/\\\\1/" < /proc/cmdline)
860 return 0
861 }
863 copy_rootfs()
864 {
865 total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g')
866 need=\$(du -c \${path}rootfs* | tail -n 1 | cut -f1)
867 [ \$(( \$total / \$need )) -gt 1 ] || return 1
868 if ! grep -q " keep-loram" /proc/cmdline && cp \${path}rootfs* /mnt; then
869 path=/mnt/
870 return 0
871 else
872 rm -f /mnt/rootfs*
873 return 1
874 fi
875 }
877 echo "Switching / to tmpfs..."
878 mount -t proc proc /proc
879 size="\$(grep rootfssize= < /proc/cmdline | \\
880 sed 's/.*rootfssize=\\([0-9]*[kmg%]\\).*/-o size=\\1/')"
881 [ -n "\$size" ] || size="-o size=90%"
883 while read var default; do
884 eval \$var=\$default
885 getarg \$var \$var
886 done <<EOT
887 eth eth0
888 dns 208.67.222.222,208.67.220.220
889 netmask 255.255.255.0
890 gw
891 ip
892 EOT
893 if [ -n "\$ip" ]; then
894 ifconfig \$eth \$ip netmask \$netmask up
895 route add default gateway \$gw
896 for i in \$(echo \$dns | sed 's/,/ /g'); do
897 echo "nameserver \$i" >> /etc/resolv.conf
898 done
899 else
900 udhcpc -f -q -s /lib/udhcpc -i \$eth
901 fi
902 for i in $urliso ; do
903 [ -n "\$URLISO" ] && URLISO="\$URLISO,"
904 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"
905 done
906 getarg urliso URLISO
907 DIR=fs
908 if getarg loram DIR; then
909 DEVICE=\${DIR%,*}
910 DIR=/\${DIR#*,}
911 fi
912 mount -t tmpfs \$size tmpfs /mnt
913 path2=/mnt/.httpfs/
914 path=/mnt/.cdrom/
915 mkdir -p /mnt/.rw \$path \$path2
916 while [ ! -d \$path/boot ]; do
917 for i in \$(echo \$URLISO | sed 's/,/ /g'); do
918 httpfs \$i \$path2 && break
919 done
920 mount -o loop,ro -t iso9660 \$path2/*.iso \$path
921 done
923 memfree=\$(grep MemFree /proc/meminfo | sed 's/[^0-9]//g')
924 umount /proc
925 branch=br=/mnt/.rw:/mnt/.cdrom/\$DIR
926 if [ ! -d /mnt/.cdrom/\$DIR/etc ]; then
927 branch=br=/mnt/.rw
928 for i in \${path}rootfs* ; do
929 fs=\${i#*root}
930 branch=\$branch:/mnt/.\$fs
931 mkdir -p /mnt/.rw/mnt/.\$fs /mnt/.\$fs /mnt/.rw/mnt/.cdrom
932 insmod /lib/squashfs.ko.gz 2> /dev/null
933 mount -o loop,ro -t squashfs \${path}root\$fs /mnt/.\$fs
934 done
935 else
936 mkdir -p /mnt/.rw/mnt/.httpfs
937 fi
938 insmod /lib/aufs.ko.gz
939 mount -t aufs -o \$branch none /mnt
940 [ -x /bin/httpfs ] && sed -i 's/DHCP="yes"/DHCP="no"/' /mnt/etc/network.conf
941 [ \$memfree -lt 30000 ] && sed -i 's/ slim//' /mnt/etc/rcS.conf
942 [ -x /mnt/sbin/init ] && exec /bin/switch_root mnt /sbin/init || sh
943 EOTEOT
944 chmod +x $TMP_DIR/initfs/init
945 for i in $TMP_DIR/initfs/lib/modules/*z ; do
946 unxz $i || gunzip $i || lzma d $i ${i%.gz}
947 rm -f $i
948 gzip -9 ${i%.gz}
949 done 2> /dev/null
950 ( cd $TMP_DIR/initfs ; find | busybox cpio -o -H newc 2> /dev/null) | \
951 lzma e $TMP_DIR/initfs.gz -si
952 lzma_set_size $TMP_DIR/initfs.gz
953 rm -rf $TMP_DIR/initfs
954 align_to_32bits $TMP_DIR/initfs.gz
955 return 0
956 }
958 # Move each initramfs to squashfs
959 build_loram_rootfs()
960 {
961 rootfs_sizes=""
962 for i in $TMP_DIR/iso/boot/rootfs*.gz; do
963 mkdir -p $TMP_DIR/fs
964 cd $TMP_DIR/fs
965 ( zcat $i 2> /dev/null || unlzma -c $i) | cpio -idm
966 cd - > /dev/null
967 rootfs=$TMP_DIR/$(basename $i)
968 /usr/sbin/mksquashfs $TMP_DIR/fs $rootfs -comp xz -Xbcj x86
969 cd $TMP_DIR
970 rootfs_sizes="$rootfs_sizes $(( $(du -s $TMP_DIR/fs | cut -f1) - $(du -s $rootfs | cut -f1) ))"
971 ( cd $(dirname $rootfs); echo $(basename $rootfs) | \
972 cpio -o -H newc ) > $rootfs.cpio
973 rm -f $rootfs
974 mv $rootfs.cpio $rootfs
975 cd - > /dev/null
976 rm -rf $TMP_DIR/fs
977 done
978 }
980 # Move meta boot configuration files to basic configuration files
981 # because meta loram flavor is useless when rootfs is not loaded in ram
982 unmeta_boot()
983 {
984 local root=${1:-$TMP_DIR/loramiso}
985 if [ -f $root/boot/isolinux/noram.cfg ]; then
986 # We keep enough information to do unloram...
987 [ -s $root/boot/isolinux/common.cfg ] &&
988 sed -i 's/label slitaz/label orgslitaz/' \
989 $root/boot/isolinux/common.cfg
990 set -- $(grep 'append ifmem [0-9]' $root/boot/isolinux/isolinux.cfg)
991 shift
992 sed -i '/ifmem/{NNNNNNNNd};/^LABEL/{N;/LABEL SliTaz [^L]/{NNNd}}' \
993 $root/boot/isolinux/isolinux.cfg
994 [ -n "$3" ] || set -- $(grep 'append [0-9]' $root/boot/isolinux/common.cfg)
995 sed -i "s/label $3\$/label slitaz/;s|=/boot/rootfs\(.*\).gz |=/boot/rootfs.gz |" \
996 $root/boot/isolinux/*.cfg
997 fi
998 }
1000 # Move rootfs to squashfs filesystem(s) to the cdrom writeable with aufs.
1001 # These squashfs may be loaded in ram at boot time.
1002 # Rootfs are also copied to cdrom for tiny ramsize systems.
1003 # Meta flavors are converted to normal flavors.
1004 build_loram_cdrom()
1006 build_initfs cdrom || return 1
1007 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1008 mkdir $TMP_DIR/loramiso/fs
1009 cd $TMP_DIR/loramiso/fs
1010 for i in $( ls ../boot/root* | sort -r ) ; do
1011 ( zcat $i 2> /dev/null || unlzma -c $i ) | cpio -idmu
1012 rm -f $i
1013 done
1014 mkdir -p $TMP_DIR/loramiso/fs/mnt/.cdrom
1015 cd - > /dev/null
1016 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
1017 unmeta_boot
1018 VOLUM_NAME="SliTaz_LoRAM_CDROM"
1019 sed -i "s|root=|isofs= rodev=/dev/cdrom/fs &|;s/.ive/cdrom/" \
1020 $TMP_DIR/loramiso/boot/isolinux/*.cfg
1021 create_iso $OUTPUT $TMP_DIR/loramiso
1024 # Create http bootstrap to load and remove loram_cdrom
1025 # Meta flavors are converted to normal flavors.
1026 build_loram_http()
1028 build_initfs http || return 1
1029 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1030 rm -f $TMP_DIR/loramiso/boot/rootfs*
1031 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
1032 unmeta_boot
1033 create_iso $OUTPUT $TMP_DIR/loramiso
1036 # Update meta flavor selection sizes.
1037 # Reduce sizes with rootfs gains.
1038 update_metaiso_sizes()
1040 for cfg in $(grep -El '(append|ifmem) [0-9]' $TMP_DIR/loramiso/boot/isolinux/*.cfg)
1041 do
1042 local append="$(grep -E '(append|ifmem) [0-9]' $cfg)"
1043 local sizes="$rootfs_sizes"
1044 local new
1045 set -- $append
1046 shift
1047 [ "$1" == "ifmem" ] && shift
1048 new=""
1049 while [ -n "$2" ]; do
1050 local s
1051 case "$1" in
1052 *G) s=$(( ${1%G} * 1024 * 1024 ));;
1053 *M) s=$(( ${1%M} * 1024 ));;
1054 *) s=${1%K};;
1055 esac
1056 sizes=${sizes#* }
1057 for i in $sizes ; do
1058 s=$(( $s - $i ))
1059 done
1060 new="$new $s $2"
1061 shift 2
1062 done
1063 sed -i -e "/append [0-9]/s/append .*/append$new $1/" -e \
1064 "/append ifmem [0-9]/s/append .*/append ifmem$new $1/" $cfg
1065 sed -i 's|\(initrd=\)\(/boot/rootfs.\.gz\)|\1/boot/rootfs.gz,\2|' $cfg
1066 sed -i '/LABEL base/{NNNNp;s|base .ive|cdrom|;s|base|cdrom|;s|,[^ ]*||}' $cfg
1067 done
1070 # Move rootfs to a squashfs filesystem into the initramfs writeable with aufs.
1071 # Meta flavor selection sizes are updated.
1072 build_loram_ram()
1074 build_initfs ram || return 1
1075 build_loram_rootfs
1076 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1077 rm -f $TMP_DIR/loramiso/boot/bzImage
1078 ln $TMP_DIR/loramiso/boot/vmlinuz* $TMP_DIR/loramiso/boot/bzImage
1079 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
1080 cp $TMP_DIR/rootfs* $TMP_DIR/loramiso/boot
1081 update_metaiso_sizes
1082 create_iso $OUTPUT $TMP_DIR/loramiso
1085 # Remove files installed by packages
1086 find_flavor_rootfs()
1088 for i in $1/etc/tazlito/*.extract; do
1089 [ -e $i ] || continue
1090 chroot $1 /bin/sh ${i#$1}
1091 done
1093 # Clean hardlinks and files patched by genisofs in /boot
1094 for i in isolinux/isolinux.bin isolinux/boot.cat bzImage ; do
1095 rm -f $1/boot/$i
1096 done
1098 # Clean files generated in post_install
1099 rm -f $1/lib/modules/*/modules.* $1/etc/mtab \
1100 $1/dev/core $1/dev/fd $1/dev/std*
1102 # Verify md5
1103 cat $1$INSTALLED/*/md5sum | \
1104 while read md5 file; do
1105 [ -e $1$file ] || continue
1106 [ "$(md5sum < $1$file)" == "$md5 -" ] &&
1107 rm -f $1$file
1108 done
1110 # Check configuration files
1111 for i in $1$INSTALLED/*/volatile.cpio.gz; do
1112 [ -e $i ] || continue
1113 mkdir /tmp/volatile$$
1114 zcat $i | ( cd /tmp/volatile$$ ; cpio -idmu > /dev/null 2>&1 )
1115 ( cd /tmp/volatile$$ ; find * -type f 2> /dev/null) | \
1116 while read file ; do
1117 [ -e $1/$file ] || continue
1118 cmp -s /tmp/volatile$$/$file $1/$file && rm -f $1/$file
1119 done
1120 rm -rf /tmp/volatile$$
1121 done
1123 # Remove other files blindly
1124 for i in $1$INSTALLED/*/files.list; do
1125 for file in $(cat $i); do
1126 [ $1$file -nt $i ] && continue
1127 [ -f $1$file -a ! -L $1$file ] && continue
1128 [ -d $1$file ] || rm -f $1$file
1129 done
1130 done
1132 # Remove tazpkg files and tmp files
1133 rm -rf $1$INSTALLED* $1/tmp $1/var/tmp
1134 rm -f $1$LOCALSTATE/*packages* $1$LOCALSTATE/files.list.lzma \
1135 $1$LOCALSTATE/mirror* $1/var/cache/*/* \
1136 $1/var/lock/* $1/var/log/* $1/var/run/* $1/var/run/*/* \
1137 $1/var/lib/* $1/var/lib/dbus/* 2> /dev/null
1139 # Cleanup directory tree
1140 cd $1
1141 find * -type d | sort -r | while read dir; do
1142 rmdir $dir 2> /dev/null
1143 done
1144 cd - > /dev/null
1147 ####################
1148 # Tazlito commands #
1149 ####################
1151 case "$COMMAND" in
1152 stats)
1153 # Tazlito general statistics from the config file.
1155 newline
1156 boldify "Tazlito statistics"
1157 separator
1158 echo "\
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 && newline ;;
1170 list-addfiles)
1171 # Simple list of additional files in the rootfs
1172 newline
1173 cd $ADDFILES
1174 find rootfs -type f
1175 newline ;;
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 newline
1188 if [ -f "tazlito.conf" ] ; then
1189 echo "Configuration file is ready to edit."
1190 echo "File location : `pwd`/tazlito.conf"
1191 newline
1192 fi ;;
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 newline ;;
1230 gen-iso)
1231 # Simply generate a new iso.
1233 check_root
1234 verify_rootcd
1235 gen_livecd_isolinux
1236 distro_stats ;;
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 ;;
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 newline
1270 echo -e "\033[1mTazlito extracting :\033[0m `basename $ISO_IMAGE`"
1271 separator
1272 # Start to mount the ISO.
1273 newline
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 newline
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 newline ;;
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 newline
1342 boldify "List of flavors"
1343 separator
1344 cat /etc/tazlito/flavors.list
1345 newline ;;
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 ;;
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 ;;
1416 gen-flavor)
1417 # Generate a new flavor from the last iso image generated.
1418 FLAVOR=${2%.flavor}
1419 newline
1420 boldify "Flavor generation"
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 newline ;;
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 ;;
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 ;;
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 exists
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 ;;
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 --quiet >/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 --quiet > /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" ;;
1777 iso2flavor)
1778 if [ -z "$3" -o ! -s "$2" ]; then
1779 cat <<EOT
1780 Usage : tazlito iso2flavor image.iso flavor_name
1782 Create a file flavor_name.flavor from the cdrom image file image.iso
1783 EOT
1784 exit 1
1785 fi
1786 FLAVOR=${3%.flavor}
1787 mkdir -p $TMP_DIR/iso $TMP_DIR/rootfs
1788 mount -o loop,ro $2 $TMP_DIR/iso
1789 if [ -s $TMP_DIR/iso/boot/rootfs1.gz ]; then
1790 echo "META flavors are not supported."
1791 umount -d $TMP_DIR/iso
1792 elif [ ! -s $TMP_DIR/iso/boot/rootfs.gz ]; then
1793 echo "No /boot/rootfs.gz in iso image. Needs a SliTaz iso."
1794 umount -d $TMP_DIR/iso
1795 else
1796 ( unlzma -c $TMP_DIR/iso/boot/rootfs.gz || \
1797 zcat $TMP_DIR/iso/boot/rootfs.gz ) | \
1798 ( cd $TMP_DIR/rootfs ; cpio -idmu > /dev/null 2>&1 )
1799 if [ ! -s $TMP_DIR/rootfs/etc/slitaz-release ]; then
1800 echo "No file /etc/slitaz-release in /boot/rootfs.gz of iso image. Needs a non loram SliTaz iso."
1801 umount -d $TMP_DIR/iso
1802 else
1803 ROOTFS_SIZE=$(du -hs $TMP_DIR/rootfs | awk '{ print $1 }')
1804 RAM_SIZE=$(du -s $TMP_DIR/rootfs | awk '{ print 32*int(($1+36000)/32768) "M" }')
1805 cp -a $TMP_DIR/iso $TMP_DIR/rootcd
1806 ISO_SIZE=$(df -h $TMP_DIR/iso | awk 'END { print $2 }')
1807 BUILD_DATE=$(date +%Y%m%d\ \at\ \%H:%M:%S -r $TMP_DIR/iso/md5sum)
1808 umount -d $TMP_DIR/iso
1809 INITRAMFS_SIZE=$(du -chs $TMP_DIR/rootcd/boot/rootfs.gz | awk '{ s=$1 } END { print $1 }')
1810 rm -f $TMP_DIR/rootcd/boot/rootfs.gz $TMP_DIR/rootcd/md5sum
1811 mv $TMP_DIR/rootcd/boot $TMP_DIR/rootfs
1812 sed 's/.* \(.*\).tazpkg*/\1/' > $TMP_DIR/$FLAVOR.pkglist \
1813 < $TMP_DIR/rootfs$INSTALLED.md5
1814 #[ -s $TMP_DIR/rootfs/etc/tazlito/distro-packages.list ] &&
1815 # mv $TMP_DIR/rootfs/etc/tazlito/distro-packages.list $TMP_DIR/$FLAVOR.pkglist
1816 PKGCNT=$(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l | awk '{ print $1 }')
1817 find_flavor_rootfs $TMP_DIR/rootfs
1818 [ -d $TMP_DIR/rootfs/boot ] && mv $TMP_DIR/rootfs/boot $TMP_DIR/rootcd
1819 [ -n "$(ls $TMP_DIR/rootfs)" ] && ( cd $TMP_DIR/rootfs ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootfs
1820 [ -n "$(ls $TMP_DIR/rootcd)" ] && ( cd $TMP_DIR/rootcd ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootcd
1821 rm -rf $TMP_DIR/rootcd $TMP_DIR/rootfs
1822 VERSION=""; MAINTAINER=""
1823 echo -en "Flavor short description \007: "; read -t 30 DESCRIPTION
1824 if [ -n "$DESCRIPTION" ]; then
1825 echo -en "Flavor version : "; read -t 30 VERSION
1826 echo -en "Flavor maintainer (your email) : "; read -t 30 MAINTAINER
1827 fi
1828 [ -n "$DESCRIPTION" ] || DESCRIPTION="Slitaz $FLAVOR flavor"
1829 [ -n "$VERSION" ] || VERSION="1.0"
1830 [ -n "$MAINTAINER" ] || MAINTAINER="nobody@slitaz.org"
1831 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1832 Flavor : $FLAVOR
1833 Description : $DESCRIPTION
1834 Version : $VERSION
1835 Maintainer : $MAINTAINER
1836 LiveCD RAM size : $RAM_SIZE
1837 Build date : $BUILD_DATE
1838 Packages : $PKGCNT
1839 Rootfs size : $ROOTFS_SIZE
1840 Initramfs size : $INITRAMFS_SIZE
1841 ISO image size : $ISO_SIZE
1842 ================================================================================
1844 EOT
1845 ( cd $TMP_DIR ; ls $FLAVOR.* | cpio -o -H newc ) | gzip -9 > $FLAVOR.flavor
1846 cat <<EOT
1847 Tazlito can't detect each file installed during a package post_install.
1848 You should extract this flavor (tazlito extract-flavor $FLAVOR),
1849 check the files in /home/slitaz/flavors/$(cat /etc/slitaz-release)/$FLAVOR/rootfs tree and remove
1850 files generated by post_installs.
1851 Check /home/slitaz/flavors/$(cat /etc/slitaz-release)/$FLAVOR/receipt too and repack the flavor
1852 (tazlito pack-flavor $FLAVOR)
1853 EOT
1854 fi
1855 fi
1856 rm -rf $TMP_DIR ;;
1858 check-list)
1859 # Use current packages list in $PWD by default.
1860 DISTRO_PKGS_LIST=distro-packages.list
1861 [ -d "$2" ] && DISTRO_PKGS_LIST=$2/distro-packages.list
1862 [ -f "$2" ] && DISTRO_PKGS_LIST=$2
1863 [ ! -f $DISTRO_PKGS_LIST ] && echo "No packages list found." && exit 0
1864 newline
1865 boldify "LiveCD packages list check"
1866 separator
1867 for pkg in $(cat $DISTRO_PKGS_LIST)
1868 do
1869 if ! grep -q "$pkg" $LOCALSTATE/packages.list; then
1870 echo "Updating: $pkg"
1871 up=$(($up + 1))
1872 fi
1873 done
1874 [ -z $up ] && echo -e "List is up-to-date\n" && exit 0
1875 separator
1876 echo -e "Updates: $up\n" ;;
1878 gen-distro)
1879 # Generate a live distro tree with a set of packages.
1881 check_root
1882 time=$(date +%s)
1884 # Libtaz will set $iso or $cdrom
1885 CDROM=""
1886 [ "$iso" ] && CDROM="-o loop $iso"
1887 [ "$cdrom" ] && CDROM="/dev/cdrom"
1888 # Check if a package list was specified on cmdline.
1889 if [ -f "$2" ]; then
1890 LIST_NAME=$2
1891 else
1892 LIST_NAME="distro-packages.list"
1893 fi
1895 if [ -d "$ROOTFS" ] ; then
1896 # Delete $ROOTFS if --force is set on command line
1897 if [ "$forced" ]; then
1898 rm -rf $ROOTFS $ROOTCD
1899 else
1900 echo -e "\nA rootfs exists in : $DISTRO"
1901 echo -e "Please clean the distro tree or change directory path.\n"
1902 exit 0
1903 fi
1904 fi
1906 # Build list with installed packages
1907 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
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 boldify "Tazlito generating a distro"
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 # Rootfs 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 -i $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.
2079 if [ -s $TOP_DIR/receipt ]; then
2080 if grep -q ^custom_rules $TOP_DIR/receipt; then
2081 echo -e "Executing: custom_rules\n"
2082 . $TOP_DIR/receipt
2083 custom_rules || echo -e "\nERROR: custom_rules failed\n"
2084 fi
2085 fi
2087 # Multi-rootfs
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 newline
2102 boldify "Building $flavor rootfs..."
2103 [ -s $TOP_DIR/$flavor.flavor ] &&
2104 cp $TOP_DIR/$flavor.flavor .
2105 if [ ! -s $flavor.flavor ]; then
2106 # We may have it in $FLAVORS_REPOSITORY
2107 if [ -d "$FLAVORS_REPOSITORY/$flavor" ]; then
2108 tazlito pack-flavor $flavor
2109 else
2110 download $flavor.flavor
2111 fi
2112 fi
2113 echo -n "Extracting $flavor.pkglist and $flavor.rootfs..."
2114 zcat < $flavor.flavor | cpio -i --quiet \
2115 $flavor.pkglist $flavor.rootfs
2116 sed 's/.*/&.tazpkg/' < $flavor.pkglist \
2117 > $DISTRO/list-packages0$n
2118 status
2119 mkdir ${ROOTFS}0$n
2120 # Install packages
2121 cd ${PACKAGES_REPOSITORY}
2122 for pkg in $(cat $DISTRO/list-packages0$n)
2123 do
2124 echo -n "Installing package: $pkg"
2125 yes y | tazpkg -i $pkg --root=${ROOTFS}0$n 2>&1 >> $log || exit 1
2126 status
2127 done
2128 rm -rf ${ROOTFS}0$n/boot ${ROOTFS}0$n/var/lib/tazpkg/packages.*
2129 cd $DISTRO
2130 if [ -s $flavor.rootfs ]; then
2131 echo -n "Adding $flavor rootfs extra files..."
2132 zcat < $flavor.rootfs | ( cd ${ROOTFS}0$n ; cpio -idmu )
2133 fi
2134 echo -n "Moving list-packages0$n to rootfs0$n"
2135 mv $DISTRO/list-packages0$n ${ROOTFS}0$n/etc/tazlito/distro-packages.list
2136 status
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 "Compressing ${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 ;;
2163 clean-distro)
2164 # Remove old distro tree.
2166 check_root
2167 newline
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 newline ;;
2190 check-distro)
2191 # Check for a few LiveCD needed files not installed by packages.
2193 check_rootfs
2194 newline
2195 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
2196 separator
2197 # SliTaz release info.
2198 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
2199 echo "Missing release info : /etc/slitaz-release"
2200 else
2201 release=`cat $ROOTFS/etc/slitaz-release`
2202 echo -n "Release : $release"
2203 status
2204 fi
2205 # Tazpkg mirror.
2206 if [ ! -f "$ROOTFS$LOCALSTATE/mirror" ]; then
2207 echo -n "Mirror URL : Missing $LOCALSTATE/mirror"
2208 todomsg
2209 else
2210 echo -n "Mirror configuration exists..."
2211 status
2212 fi
2213 # Isolinux msg
2214 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.*g; then
2215 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
2216 todomsg
2217 else
2218 echo -n "Isolinux message seems good..."
2219 status
2220 fi
2221 separator
2222 newline ;;
2224 writeiso)
2225 # Writefs to ISO image including /home unlike gen-distro we dont use
2226 # packages to generate a rootfs, we build a compressed rootfs with all
2227 # the current filesystem similar to 'tazusb writefs'.
2229 DISTRO="/home/slitaz/distro"
2230 ROOTCD="$DISTRO/rootcd"
2231 if [ -z $2 ]; then
2232 COMPRESSION=none
2233 else
2234 COMPRESSION=$2
2235 fi
2236 if [ -z $3 ]; then
2237 ISO_NAME="slitaz"
2238 else
2239 ISO_NAME="$3"
2240 fi
2241 check_root
2242 # Start info
2243 newline
2244 boldify "Write filesystem to ISO"
2245 separator
2246 cat << EOT
2247 The command writeiso will write the current filesystem into a suitable cpio
2248 archive (rootfs.gz) and generate a bootable ISO image (slitaz.iso).
2250 $(boldify "Archive compression:") $(colorize 36 "$COMPRESSION")
2252 EOT
2253 # Save some space
2254 rm /var/cache/tazpkg/* -r -f
2255 rm -rf /home/slitaz/distro
2257 # Optionally remove sound card selection and screen resolution.
2258 echo "Do you wish to remove the sound card and screen configs ? "
2259 echo -n "Press ENTER to keep or answer (No|yes|exit): "
2260 read anser
2261 case $anser in
2262 e|E|"exit"|Exit)
2263 exit 0 ;;
2264 y|Y|yes|Yes)
2265 echo -n "Removing current sound card and screen configurations..."
2266 rm -f /var/lib/sound-card-driver
2267 rm -f /var/lib/alsa/asound.state
2268 rm -f /etc/X11/xorg.conf ;;
2269 *)
2270 echo -n "Keeping current sound card and screen configurations..." ;;
2271 esac
2272 status && newline
2274 # Optionally remove i18n settings
2275 echo "Do you wish to remove local/keymap settings ? "
2276 echo -n "Press ENTER to keep or answer (No|yes|exit): "
2277 read anser
2278 case $anser in
2279 e|E|"exit"|Exit)
2280 exit 0 ;;
2281 y|Y|yes|Yes)
2282 echo "Removing current locale/keymap settings..."
2283 newline > /etc/locale.conf
2284 newline > /etc/keymap.conf ;;
2285 *)
2286 echo "Keeping current locale/keymap settings..." ;;
2287 esac
2288 status
2290 # Clean-up files by default
2291 newline > /etc/udev/rules.d/70-persistent-net.rules
2292 newline > /etc/udev/rules.d/70-persistant-cd.rules
2294 # Create list of files including default user files since it is defined in /etc/passwd
2295 # and some new users might have been added.
2296 cd /
2297 find bin etc init sbin var dev lib root usr home >/tmp/list
2299 for dir in proc sys tmp mnt media media/cdrom media/flash \
2300 media/usbdisk run run/udev
2301 do
2302 echo $dir >>/tmp/list
2303 done
2305 # Generate initramfs with specified compression and display rootfs
2306 # size in realtime.
2307 rm -f /tmp/rootfs
2308 write_initramfs &
2309 sleep 2
2310 cd - > /dev/null
2311 echo -en "\nFilesystem size:"
2312 while [ ! -f /tmp/rootfs ]
2313 do
2314 sleep 1
2315 echo -en "\\033[18G`du -sh /rootfs.gz | awk '{print $1}'` "
2316 done
2317 echo -e "\n"
2319 # Move freshly generated rootfs to the cdrom.
2320 mkdir -p $ROOTCD/boot
2321 mv -f /rootfs.gz $ROOTCD/boot
2323 # Now we need the kernel and isolinux files.
2324 if mount /dev/cdrom /media/cdrom 2>/dev/null; then
2325 cp /media/cdrom/boot/bzImage $ROOTCD/boot
2326 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
2327 unmeta_boot $ROOTCD
2328 umount /media/cdrom
2329 elif mount |grep /media/cdrom; then
2330 cp /media/cdrom/boot/bzImage $ROOTCD/boot
2331 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
2332 unmeta_boot $ROOTCD
2333 umount /media/cdrom;
2334 else
2335 echo -e "
2336 When SliTaz is running in RAM the kernel and bootloader files are kept
2337 on the cdrom. Please insert a LiveCD or loop mount the slitaz.iso to
2338 /media/cdrom to let Tazlito copy the files.\n"
2339 echo -en "----\nENTER to continue..."; read i
2340 exit 1
2341 fi
2343 # Generate the iso image.
2344 cd $DISTRO
2345 echo "Generating ISO image..."
2346 genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
2347 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
2348 -V "SliTaz" -input-charset iso8859-1 -boot-info-table $ROOTCD
2349 if [ -x /usr/bin/isohybrid ]; then
2350 echo -n "Creating hybrid ISO..."
2351 /usr/bin/isohybrid $ISO_NAME.iso -entry 2 2> /dev/null
2352 status
2353 fi
2354 echo -n "Creating the ISO md5sum..."
2355 md5sum $ISO_NAME.iso > $ISO_NAME.md5
2356 status
2358 separator
2359 echo "ISO image: $(du -sh /home/slitaz/distro/$ISO_NAME.iso)"
2360 newline
2361 echo -n "Exit or burn ISO to cdrom (Exit|burn)? "; read anser
2362 case $anser in
2363 burn)
2364 eject
2365 echo -n "Please insert a blank cdrom and press ENTER..."
2366 read i && sleep 2
2367 tazlito burn-iso /home/slitaz/distro/$ISO_NAME.iso
2368 echo -en "----\nENTER to continue..."; read i ;;
2369 *)
2370 exit 0 ;;
2371 esac ;;
2373 burn-iso)
2374 # Guess cdrom device, ask user and burn the ISO.
2376 check_root
2377 DRIVE_NAME=$(grep "drive name" < /proc/sys/dev/cdrom/info | cut -f 3)
2378 DRIVE_SPEED=$(grep "drive speed" < /proc/sys/dev/cdrom/info | cut -f 3)
2379 # We can specify an alternative ISO from the cmdline.
2380 if [ -n "$2" ] ; then
2381 iso=$2
2382 else
2383 iso=$DISTRO/$ISO_NAME.iso
2384 fi
2385 if [ ! -f "$iso" ]; then
2386 echo -e "\nUnable to find ISO : $iso\n"
2387 exit 0
2388 fi
2389 newline
2390 boldify "Tazlito burn ISO"
2391 separator
2392 echo "Cdrom device : /dev/$DRIVE_NAME"
2393 echo "Drive speed : $DRIVE_SPEED"
2394 echo "ISO image : $iso"
2395 separator
2396 newline
2397 yesorno "Burn ISO image (y/N) ? "
2398 if [ "$answer" == "y" ]; then
2399 newline
2400 echo "Starting Wodim to burn the iso..." && sleep 2
2401 separator
2402 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
2403 separator
2404 echo "ISO image is burned to cdrom."
2405 else
2406 echo -e "\nExiting. No ISO burned."
2407 fi
2408 newline ;;
2410 merge)
2411 # Merge multiple rootfs into one iso.
2413 if [ -z "$2" ]; then
2414 cat << EOT
2415 Usage: tazlito merge size1 iso size2 rootfs2 [sizeN rootfsN]...
2417 Merge multiple rootfs into one iso. Rootfs are like russian dolls
2418 i.e: rootfsN is a subset of rootfsN-1
2419 rootfs1 is found in iso, sizeN is the RAM size needed to launch rootfsN.
2420 The boot loader will select the rootfs according to the RAM size detected.
2422 Example:
2423 $ tazlito merge 160M slitaz-core.iso 96M rootfs-justx.gz 32M rootfs-base.gz
2425 Will start slitaz-core with 160M+ RAM, slitaz-justX with 96M-160M RAM,
2426 slitaz-base with 32M-96M RAM and display an error message if RAM < 32M.
2428 EOT
2429 exit 2
2430 fi
2432 shift # skip merge
2433 append="$1 slitaz1"
2434 shift # skip size1
2435 mkdir -p $TMP_DIR/mnt $TMP_DIR/rootfs1
2437 ISO=$1.merged
2438 # Extract filesystems
2439 echo -n "Mounting $1"
2440 mount -o loop,ro $1 $TMP_DIR/mnt 2> /dev/null
2441 status || cleanup_merge
2442 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2443 rm -f $TMP_DIR/iso/boot/bzImage
2444 ln $TMP_DIR/iso/boot/vmlinuz* $TMP_DIR/iso/boot/bzImage
2445 umount -d $TMP_DIR/mnt
2446 if [ -f $TMP_DIR/iso/boot/rootfs1.gz ]; then
2447 echo "$1 is already a merged iso. Aborting."
2448 cleanup_merge
2449 fi
2450 if [ ! -f $TMP_DIR/iso/boot/isolinux/ifmem.c32 -a
2451 ! -f $TMP_DIR/iso/boot/isolinux/c32box.c32 ]; then
2452 if [ ! -f /boot/isolinux/ifmem.c32 -a
2453 ! -f /boot/isolinux/c32box.c32 ]; then
2454 cat <<EOT
2455 No file /boot/isolinux/ifmem.c32
2456 Please install syslinux package !
2457 EOT
2458 rm -rf $TMP_DIR
2459 exit 1
2460 fi
2461 cp /boot/isolinux/c32box.c32 $TMP_DIR/iso/boot/isolinux 2> /dev/null ||
2462 cp /boot/isolinux/ifmem.c32 $TMP_DIR/iso/boot/isolinux
2463 fi
2465 echo -n "Extracting iso/rootfs.gz"
2466 extract_rootfs $TMP_DIR/iso/boot/rootfs.gz $TMP_DIR/rootfs1 &&
2467 [ -d $TMP_DIR/rootfs1/etc ]
2468 status || cleanup_merge
2469 n=1
2470 while [ -n "$2" ]; do
2471 shift # skip rootfs N-1
2472 p=$n
2473 n=$(($n + 1))
2474 append="$append $1 slitaz$n"
2475 shift # skip size N
2476 mkdir -p $TMP_DIR/rootfs$n
2477 echo -n "Extracting $1"
2478 extract_rootfs $1 $TMP_DIR/rootfs$n &&
2479 [ -d $TMP_DIR/rootfs$n/etc ]
2480 status || cleanup_merge
2481 mergefs $TMP_DIR/rootfs$n $TMP_DIR/rootfs$p
2482 echo "Creating rootfs$p.gz"
2483 pack_rootfs $TMP_DIR/rootfs$p $TMP_DIR/iso/boot/rootfs$p.gz
2484 status
2485 done
2486 echo "Creating rootfs$n.gz"
2487 pack_rootfs $TMP_DIR/rootfs$n $TMP_DIR/iso/boot/rootfs$n.gz
2488 status
2489 rm -f $TMP_DIR/iso/boot/rootfs.gz
2490 update_bootconfig $TMP_DIR/iso/boot/isolinux "$append"
2491 create_iso $ISO $TMP_DIR/iso
2492 rm -rf $TMP_DIR ;;
2494 repack)
2495 # Repack an iso with maximum lzma compression ratio.
2497 ISO=$2
2498 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.
2523 ISO=$2
2524 OUTPUT=$3
2525 if [ -z "$3" ]; then
2526 echo "Usage: tazlito $1 input.iso output.iso [cdrom|smallcdrom|http|ram]"
2527 exit 1
2528 fi
2529 mkdir -p $TMP_DIR/iso
2530 mount -o loop,ro -t iso9660 $ISO $TMP_DIR/iso
2531 loopdev=$( (losetup -a 2>/dev/null || losetup) | grep $ISO | cut -d: -f1)
2532 if ! check_iso_for_loram ; then
2533 echo "$2 is not a valid SliTaz live CD. Abort."
2534 umount -d $TMP_DIR/iso
2535 rm -rf $TMP_DIR
2536 exit 1
2537 fi
2538 case "$4" in
2539 cdrom) build_loram_cdrom ;;
2540 http) build_loram_http ;;
2541 *) build_loram_ram ;;
2542 esac
2543 umount $TMP_DIR/iso # no -d: needs /proc
2544 losetup -d $loopdev
2545 rm -rf $TMP_DIR ;;
2547 emu-iso)
2548 # Emulate an ISO image with Qemu.
2549 if [ -n "$2" ] ; then
2550 iso=$2
2551 else
2552 iso=$DISTRO/$ISO_NAME.iso
2553 fi
2554 if [ ! -f "$iso" ]; then
2555 echo -e "\nUnable to find ISO : $iso\n"
2556 exit 0
2557 fi
2558 if [ ! -x "/usr/bin/qemu" ]; then
2559 echo -e "\nUnable to find Qemu binary. Please install: qemu\n"
2560 exit 0
2561 fi
2562 echo -e "\nStarting Qemu emulator:\n"
2563 echo -e "qemu $QEMU_OPTS $iso\n"
2564 qemu $QEMU_OPTS $iso ;;
2566 deduplicate)
2567 # Deduplicate files in a tree
2568 shift
2569 deduplicate "$@" ;;
2571 usage|*)
2572 # Print usage also for all unknown commands.
2573 usage ;;
2574 esac
2576 exit 0