tazlito view tazlito @ rev 326

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