tazlito view tazlito @ rev 373

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