tazlito view tazlito @ rev 331

tazlito: typo with losetup
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Jan 15 13:15:16 2014 +0000 (2014-01-15)
parents 99005f3c104b
children 29f2100e2208
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 "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 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 cpio -o -H newc | gzip -9 > /rootfs.gz
367 else
368 echo "Creating rootfs.gz without compression... "
369 cpio -o -H newc > /rootfs.gz
370 fi < /tmp/list
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 gzip -9 ${i%.gz}
957 done 2> /dev/null
958 ( cd $TMP_DIR/initfs ; find | busybox cpio -o -H newc 2> /dev/null) | \
959 lzma e $TMP_DIR/initfs.gz -si
960 lzma_set_size $TMP_DIR/initfs.gz
961 rm -rf $TMP_DIR/initfs
962 align_to_32bits $TMP_DIR/initfs.gz
963 return 0
964 }
966 # Move each initramfs to squashfs
967 build_loram_rootfs()
968 {
969 rootfs_sizes=""
970 for i in $TMP_DIR/iso/boot/rootfs*.gz; do
971 mkdir -p $TMP_DIR/fs
972 cd $TMP_DIR/fs
973 ( zcat $i 2> /dev/null || unlzma -c $i) | cpio -idm
974 cd - > /dev/null
975 rootfs=$TMP_DIR/$(basename $i)
976 /usr/sbin/mksquashfs $TMP_DIR/fs $rootfs -comp xz -Xbcj x86
977 cd $TMP_DIR
978 rootfs_sizes="$rootfs_sizes $(( $(du -s $TMP_DIR/fs | cut -f1) - $(du -s $rootfs | cut -f1) ))"
979 ( cd $(dirname $rootfs); echo $(basename $rootfs) | \
980 cpio -o -H newc ) > $rootfs.cpio
981 rm -f $rootfs
982 mv $rootfs.cpio $rootfs
983 cd - > /dev/null
984 rm -rf $TMP_DIR/fs
985 done
986 }
988 # Move meta boot configuration files to basic configuration files
989 # because meta loram flavor is useless when rootfs is not loaded in ram
990 unmeta_boot()
991 {
992 local root=${1:-$TMP_DIR/loramiso}
993 if [ -f $root/boot/isolinux/noram.cfg ]; then
994 # We keep enough information to do unloram...
995 [ -s $root/boot/isolinux/common.cfg ] &&
996 sed -i 's/label slitaz/label orgslitaz/' \
997 $root/boot/isolinux/common.cfg
998 set -- $(grep 'append ifmem [0-9]' $root/boot/isolinux/isolinux.cfg)
999 shift
1000 sed -i '/ifmem/{NNNNNNNNd};/^LABEL/{N;/LABEL SliTaz [^L]/{NNNd}}' \
1001 $root/boot/isolinux/isolinux.cfg
1002 [ -n "$3" ] || set -- $(grep 'append [0-9]' $root/boot/isolinux/common.cfg)
1003 sed -i "s/label $3\$/label slitaz/;s|=/boot/rootfs\(.*\).gz |=/boot/rootfs.gz |" \
1004 $root/boot/isolinux/*.cfg
1005 fi
1008 # Move rootfs to squashfs filesystem(s) to the cdrom writeable with aufs.
1009 # These squashfs may be loaded in ram a boot time.
1010 # Rootfs are also copied to cdrom for tiny ramsize systems.
1011 # Meta flavors are converted to normal flavors.
1012 build_loram_cdrom()
1014 build_initfs cdrom || return 1
1015 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1016 mkdir $TMP_DIR/loramiso/fs
1017 cd $TMP_DIR/loramiso/fs
1018 for i in $( ls ../boot/root* | sort -r ) ; do
1019 ( zcat $i 2> /dev/null || unlzma -c $i ) | cpio -idmu
1020 rm -f $i
1021 done
1022 mkdir -p $TMP_DIR/loramiso/fs/mnt/.cdrom
1023 cd - > /dev/null
1024 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
1025 unmeta_boot
1026 VOLUM_NAME="SliTaz_LoRAM_CDROM"
1027 sed -i "s|root=|isofs= rodev=/dev/cdrom/fs &|;s/.ive/cdrom/" \
1028 $TMP_DIR/loramiso/boot/isolinux/*.cfg
1029 create_iso $OUTPUT $TMP_DIR/loramiso
1032 # Create http bootstrap to load and remove loram_cdrom
1033 # Meta flavors are converted to normal flavors.
1034 build_loram_http()
1036 build_initfs http || return 1
1037 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1038 rm -f $TMP_DIR/loramiso/boot/rootfs*
1039 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
1040 unmeta_boot
1041 create_iso $OUTPUT $TMP_DIR/loramiso
1044 # Update meta flavor selection sizes.
1045 # Reduce sizes with rootfs gains.
1046 update_metaiso_sizes()
1048 for cfg in $(grep -El '(append|ifmem) [0-9]' $TMP_DIR/loramiso/boot/isolinux/*.cfg)
1049 do
1050 local append="$(grep -E '(append|ifmem) [0-9]' $cfg)"
1051 local sizes="$rootfs_sizes"
1052 local new
1053 set -- $append
1054 shift
1055 [ "$1" == "ifmem" ] && shift
1056 new=""
1057 while [ -n "$2" ]; do
1058 local s
1059 case "$1" in
1060 *G) s=$(( ${1%G} * 1024 * 1024 ));;
1061 *M) s=$(( ${1%M} * 1024 ));;
1062 *) s=${1%K};;
1063 esac
1064 sizes=${sizes#* }
1065 for i in $sizes ; do
1066 s=$(( $s - $i ))
1067 done
1068 new="$new $s $2"
1069 shift 2
1070 done
1071 sed -i -e "/append [0-9]/s/append .*/append$new $1/" -e \
1072 "/append ifmem [0-9]/s/append .*/append ifmem$new $1/" $cfg
1073 sed -i 's|\(initrd=\)\(/boot/rootfs.\.gz\)|\1/boot/rootfs.gz,\2|' $cfg
1074 sed -i '/LABEL base/{NNNNp;s|base .ive|cdrom|;s|base|cdrom|;s|,[^ ]*||}' $cfg
1075 done
1078 # Move rootfs to a squashfs filesystem into the initramfs writeable with aufs.
1079 # Meta flavor selection sizes are updated.
1080 build_loram_ram()
1082 build_initfs ram || return 1
1083 build_loram_rootfs
1084 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1085 rm -f $TMP_DIR/loramiso/boot/bzImage
1086 ln $TMP_DIR/loramiso/boot/vmlinuz* $TMP_DIR/loramiso/boot/bzImage
1087 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
1088 cp $TMP_DIR/rootfs* $TMP_DIR/loramiso/boot
1089 update_metaiso_sizes
1090 create_iso $OUTPUT $TMP_DIR/loramiso
1093 # Remove files installed by packages
1094 find_flavor_rootfs()
1096 for i in $1/etc/tazlito/*.extract; do
1097 [ -e $i ] || continue
1098 chroot $1 /bin/sh ${i#$1}
1099 done
1101 # Clean hardlinks and files patched by genisofs in /boot
1102 for i in isolinux/isolinux.bin isolinux/boot.cat bzImage ; do
1103 rm -f $1/boot/$i
1104 done
1106 # Clean files generated in post_install
1107 rm -f $1/lib/modules/*/modules.* $1/etc/mtab \
1108 $1/dev/core $1/dev/fd $1/dev/std*
1110 # Verify md5
1111 cat $1$INSTALLED/*/md5sum | \
1112 while read md5 file; do
1113 [ -e $1$file ] || continue
1114 [ "$(md5sum < $1$file)" == "$md5 -" ] &&
1115 rm -f $1$file
1116 done
1118 # Check configuration files
1119 for i in $1$INSTALLED/*/volatile.cpio.gz; do
1120 [ -e $i ] || continue
1121 mkdir /tmp/volatile$$
1122 zcat $i | ( cd /tmp/volatile$$ ; cpio -idmu > /dev/null 2>&1 )
1123 ( cd /tmp/volatile$$ ; find * -type f 2> /dev/null) | \
1124 while read file ; do
1125 [ -e $1/$file ] || continue
1126 cmp -s /tmp/volatile$$/$file $1/$file && rm -f $1/$file
1127 done
1128 rm -rf /tmp/volatile$$
1129 done
1131 # Remove other files blindly
1132 for i in $1$INSTALLED/*/files.list; do
1133 for file in $(cat $i); do
1134 [ $1$file -nt $i ] && continue
1135 [ -f $1$file -a ! -L $1$file ] && continue
1136 [ -d $1$file ] || rm -f $1$file
1137 done
1138 done
1140 # Remove tazpkg files and tmp files
1141 rm -rf $1$INSTALLED* $1/tmp $1/var/tmp
1142 rm -f $1$LOCALSTATE/*packages* $1$LOCALSTATE/files.list.lzma \
1143 $1$LOCALSTATE/mirror* $1/var/cache/*/* \
1144 $1/var/lock/* $1/var/log/* $1/var/run/* $1/var/run/*/* \
1145 $1/var/lib/* $1/var/lib/dbus/* 2> /dev/null
1147 # Cleanup directory tree
1148 cd $1
1149 find * -type d | sort -r | while read dir; do
1150 rmdir $dir 2> /dev/null
1151 done
1152 cd - > /dev/null
1155 ####################
1156 # Tazlito commands #
1157 ####################
1159 case "$COMMAND" in
1160 stats)
1161 # Tazlito general statistics from the config file.
1163 echo ""
1164 echo -e "\033[1mTazlito statistics\033[0m
1165 ===============================================================================
1166 Config file : $CONFIG_FILE
1167 ISO name : $ISO_NAME.iso
1168 Volume name : $VOLUM_NAME
1169 Prepared : $PREPARED
1170 Packages repository : $PACKAGES_REPOSITORY
1171 Distro directory : $DISTRO"
1172 if [ ! "$ADDFILES" = "" ] ; then
1173 echo -e "Additional files : $ADDFILES"
1174 fi
1175 separator
1176 echo ""
1177 ;;
1178 list-addfiles)
1179 # Simple list of additional files in the rootfs
1180 echo ""
1181 cd $ADDFILES
1182 find rootfs -type f
1183 echo "" ;;
1184 gen-config)
1185 # Generate a new config file in the current dir or the specified
1186 # directory by $2.
1188 if [ -n "$2" ] ; then
1189 mkdir -p $2 && cd $2
1190 fi
1191 echo -n "Generating empty tazlito.conf..."
1192 empty_config_file
1193 status
1194 echo ""
1195 if [ -f "tazlito.conf" ] ; then
1196 echo "Configuration file is ready to edit."
1197 echo "File location : `pwd`/tazlito.conf"
1198 echo ""
1199 fi
1200 ;;
1201 configure)
1202 # Configure a tazlito.conf config file. Start by getting
1203 # a empty config file and sed it.
1205 if [ -f "tazlito.conf" ] ; then
1206 rm tazlito.conf
1207 else
1208 if test $(id -u) = 0 ; then
1209 cd /etc
1210 else
1211 echo "You must be root to configure the main config file or in"
1212 echo "the same directory of the file you want to configure."
1213 exit 0
1214 fi
1215 fi
1216 empty_config_file
1217 echo""
1218 echo -e "\033[1mConfiguring :\033[0m `pwd`/tazlito.conf"
1219 separator
1220 # ISO name.
1221 echo -n "ISO name : " ; read answer
1222 sed -i s#'ISO_NAME=\"\"'#"ISO_NAME=\"$answer\""# tazlito.conf
1223 # Volume name.
1224 echo -n "Volume name : " ; read answer
1225 sed -i s/'VOLUM_NAME=\"SliTaz\"'/"VOLUM_NAME=\"$answer\""/ tazlito.conf
1226 # Packages repository.
1227 echo -n "Packages repository : " ; read answer
1228 sed -i s#'PACKAGES_REPOSITORY=\"\"'#"PACKAGES_REPOSITORY=\"$answer\""# tazlito.conf
1229 # Distro path.
1230 echo -n "Distro path : " ; read answer
1231 sed -i s#'DISTRO=\"\"'#"DISTRO=\"$answer\""# tazlito.conf
1232 separator
1233 echo "Config file is ready to use."
1234 echo "You can now extract an ISO or generate a distro."
1235 echo ""
1236 ;;
1237 gen-iso)
1238 # Simply generate a new iso.
1240 check_root
1241 verify_rootcd
1242 gen_livecd_isolinux
1243 distro_stats
1244 ;;
1245 gen-initiso)
1246 # Simply generate a new initramfs with a new iso.
1248 check_root
1249 verify_rootcd
1250 gen_initramfs $ROOTFS
1251 gen_livecd_isolinux
1252 distro_stats
1253 ;;
1254 extract-distro)
1255 # Extract an ISO image to a directory and rebuild the LiveCD tree.
1257 check_root
1258 ISO_IMAGE=$2
1259 if [ -z "$ISO_IMAGE" ] ; then
1260 echo -e "\nPlease specify the path to the ISO image."
1261 echo -e "Example : `basename $0` image.iso /path/target\n"
1262 exit 0
1263 fi
1264 # Set the distro path by checking for $3 on cmdline.
1265 if [ -n "$3" ] ; then
1266 TARGET=$3
1267 else
1268 TARGET=$DISTRO
1269 fi
1270 # Exit if existing distro is found.
1271 if [ -d "$TARGET/rootfs" ] ; then
1272 echo -e "\nA rootfs exists in : $TARGET"
1273 echo -e "Please clean the distro tree or change directory path.\n"
1274 exit 0
1275 fi
1276 echo ""
1277 echo -e "\033[1mTazlito extracting :\033[0m `basename $ISO_IMAGE`"
1278 separator
1279 # Start to mount the ISO.
1280 echo ""
1281 echo "Mounting ISO image..."
1282 mkdir -p $TMP_DIR
1283 # Get ISO file size.
1284 isosize=`du -sh $ISO_IMAGE | cut -f1`
1285 mount -o loop $ISO_IMAGE $TMP_DIR
1286 sleep 2
1287 # Prepare target dir, copy the kernel and the rootfs.
1288 mkdir -p $TARGET/rootfs
1289 mkdir -p $TARGET/rootcd/boot
1290 echo -n "Copying the Linux kernel..."
1291 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
1292 ln $TARGET/rootcd/boot/vmlinuz* $TARGET/rootcd/boot/bzImage
1293 else
1294 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
1295 fi
1296 status
1297 echo -n "Copying isolinux files..."
1298 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
1299 for i in $(ls $TMP_DIR); do
1300 [ "$i" = "boot" ] && continue
1301 cp -a $TMP_DIR/$i $TARGET/rootcd
1302 done
1303 status
1304 if [ -d $TMP_DIR/boot/syslinux ]; then
1305 echo -n "Copying syslinux files..."
1306 cp -a $TMP_DIR/boot/syslinux $TARGET/rootcd/boot
1307 status
1308 fi
1309 if [ -d $TMP_DIR/boot/extlinux ]; then
1310 echo -n "Copying extlinux files..."
1311 cp -a $TMP_DIR/boot/extlinux $TARGET/rootcd/boot
1312 status
1313 fi
1314 if [ -d $TMP_DIR/boot/grub ]; then
1315 echo -n "Copying GRUB files..."
1316 cp -a $TMP_DIR/boot/grub $TARGET/rootcd/boot
1317 status
1318 fi
1320 echo -n "Copying the rootfs..."
1321 cp $TMP_DIR/boot/rootfs.?z $TARGET/rootcd/boot
1322 status
1323 # Extract initramfs.
1324 cd $TARGET/rootfs
1325 echo -n "Extracting the rootfs... "
1326 extract_rootfs ../rootcd/boot/rootfs.gz $TARGET/rootfs
1327 # unpack /usr
1328 for i in etc/tazlito/*.extract; do
1329 [ -f "$i" ] && . $i ../rootcd
1330 done
1331 # Umount and remove temp directory and cd to $TARGET to get stats.
1332 umount $TMP_DIR && rm -rf $TMP_DIR
1333 cd ..
1334 echo ""
1335 separator
1336 echo "Extracted : `basename $ISO_IMAGE` ($isosize)"
1337 echo "Distro tree : `pwd`"
1338 echo "Rootfs size : `du -sh rootfs`"
1339 echo "Rootcd size : `du -sh rootcd`"
1340 separator
1341 echo ""
1342 ;;
1343 list-flavors)
1344 # Show available flavors.
1345 if [ ! -s /etc/tazlito/flavors.list -o "$2" == "--recharge" ]; then
1346 download flavors.list -O - > /etc/tazlito/flavors.list
1347 fi
1348 echo ""
1349 echo -e "\033[1mList of flavors\033[0m"
1350 separator
1351 cat /etc/tazlito/flavors.list
1352 echo ""
1353 ;;
1354 show-flavor)
1355 # Show flavor description.
1356 FLAVOR=${2%.flavor}
1357 if [ ! -f "$FLAVOR.flavor" ]; then
1358 echo "File $FLAVOR.flavor not found."
1359 exit 1
1360 fi
1361 mkdir $TMP_DIR
1362 zcat < $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i > /dev/null)
1363 if [ "$3" = "--brief" ]; then
1364 if [ "$4" != "--noheader" ]; then
1365 echo "Name ISO Rootfs Description"
1366 separator
1367 fi
1368 printf "%-16.16s %6.6s %6.6s %s\n" "$FLAVOR" \
1369 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
1370 "$(field 'Rootfs size' $TMP_DIR/$FLAVOR.desc)" \
1371 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
1372 else
1373 separator
1374 cat $TMP_DIR/$FLAVOR.desc
1375 fi
1376 rm -Rf $TMP_DIR
1377 ;;
1378 gen-liveflavor)
1379 # Generate a new flavor from the live system.
1380 FLAVOR=${2%.flavor}
1381 DESC=""
1382 case "$FLAVOR" in
1383 '') echo -n "Flavor name : "
1384 read FLAVOR
1385 [ -z "$FLAVOR" ] && exit 1;;
1386 -?|-h*|--help) echo -e "
1388 SliTaz Live Tool - Version: $VERSION
1389 \033[1mUsage: \033[0m `basename $0` gen-liveflavor flavor-name [flavor-patch-file]
1390 \033[1mflavor-patch-file format: \033[0m
1391 code data
1392 + package to add
1393 - package to remove
1394 ! non-free package to add
1395 ? display message
1396 @ flavor description
1398 \033[1mExample: \033[0m
1399 @ Developer tools for slitaz maintainers
1400 + slitaz-toolchain
1401 + mercurial
1403 exit 1;;
1404 esac
1405 mv /etc/tazlito/distro-packages.list \
1406 /etc/tazlito/distro-packages.list.$$ 2> /dev/null
1407 rm -f distro-packages.list non-free.list 2> /dev/null
1408 tazpkg recharge
1409 [ -n "$3" ] && while read action pkg; do
1410 case "$action" in
1411 +) yes | tazpkg get-install $pkg 2>&1 >> $log || exit 1 ;;
1412 -) yes | tazpkg remove $pkg ;;
1413 !) echo $pkg >> non-free.list ;;
1414 @) DESC="$pkg" ;;
1415 \?) echo -en "$pkg"; read action ;;
1416 esac
1417 done < $3
1418 yes '' | tazlito gen-distro
1419 echo "$DESC" | tazlito gen-flavor "$FLAVOR"
1420 mv /etc/tazlito/distro-packages.list.$$ \
1421 /etc/tazlito/distro-packages.list 2> /dev/null
1422 ;;
1423 gen-flavor)
1424 # Generate a new flavor from the last iso image generated.
1425 FLAVOR=${2%.flavor}
1426 echo ""
1427 echo -e "\033[1mFlavor generation\033[0m"
1428 separator
1429 if [ -z "$FLAVOR" ]; then
1430 echo -n "Flavor name : "
1431 read FLAVOR
1432 [ -z "$FLAVOR" ] && exit 1
1433 fi
1434 check_rootfs
1435 FILES="$FLAVOR.pkglist"
1436 echo -n "Creating file $FLAVOR.flavor..."
1437 for i in rootcd rootfs; do
1438 if [ -d "$ADDFILES/$i" ] ; then
1439 FILES="$FILES\n$FLAVOR.$i"
1440 ( cd "$ADDFILES/$i"; find . | \
1441 cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
1442 fi
1443 done
1444 status
1445 answer=`grep -s ^Description $FLAVOR.desc`
1446 answer=${answer#Description : }
1447 if [ -z "$answer" ]; then
1448 echo -n "Description : "
1449 read answer
1450 fi
1451 echo -n "Compressing flavor $FLAVOR..."
1452 echo "Flavor : $FLAVOR" > $FLAVOR.desc
1453 echo "Description : $answer" >> $FLAVOR.desc
1454 ( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
1455 \rm -f $FLAVOR.pkglist $FLAVOR.nonfree 2> /dev/null
1456 for i in $(ls $ROOTFS$INSTALLED); do
1457 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
1458 EXTRAVERSION=""
1459 eval $(grep ^EXTRAVERSION= $ROOTFS$INSTALLED/$i/receipt)
1460 eval $(grep ^CATEGORY= $ROOTFS$INSTALLED/$i/receipt)
1461 if [ "$CATEGORY" = "non-free" -a "${i%%-*}" != "get" ]
1462 then
1463 echo "$i" >> $FLAVOR.nonfree
1464 else
1465 echo "$i-$VERSION$EXTRAVERSION" >> $FLAVOR.pkglist
1466 fi
1467 done
1468 [ -s $FLAVOR.nonfree ] && $FILES="$FILES\n$FLAVOR.nonfree"
1469 for i in $LOCALSTATE/undigest/*/mirror ; do
1470 [ -s $i ] && cat $i >> $FLAVOR.mirrors
1471 done
1472 [ -s $FLAVOR.mirrors ] && $FILES="$FILES\n$FLAVOR.mirrors"
1473 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
1474 gzip -9 > $FLAVOR.flavor
1475 rm `echo -e $FILES`
1476 status
1477 separator
1478 echo "Flavor size : `du -sh $FLAVOR.flavor`"
1479 echo ""
1480 ;;
1481 upgrade-flavor)
1482 # Update package list to the latest versions available.
1483 FLAVOR=${2%.flavor}
1484 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1485 mkdir $TMP_DIR
1486 zcat < $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1487 echo -n "Updating $FLAVOR package list..."
1488 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1489 packed_size=0; unpacked_size=0
1490 while read org; do
1491 i=0
1492 pkg=$org
1493 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
1494 pkg=${pkg%-*}
1495 i=$(($i + 1))
1496 [ $i -gt 5 ] && break;
1497 done
1498 set -- $(get_size $pkg)
1499 packed_size=$(( $packed_size + $1 ))
1500 unpacked_size=$(( $unpacked_size + $2 ))
1501 for i in $(grep ^$pkg $LOCALSTATE/packages.list); do
1502 echo $i
1503 break
1504 done
1505 done < $TMP_DIR/$FLAVOR.pkglist \
1506 > $TMP_DIR/$FLAVOR.pkglist.$$
1507 mv -f $TMP_DIR/$FLAVOR.pkglist.$$ $TMP_DIR/$FLAVOR.pkglist
1508 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1509 packed_size=$(($packed_size \
1510 + $(wc -c < $TMP_DIR/$FLAVOR.rootfs) / 100 ))
1511 unpacked_size=$(($unpacked_size \
1512 + $(zcat < $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1513 fi
1514 # Estimate lzma
1515 packed_size=$(($packed_size * 2 / 3))
1516 iso_size=$(( $packed_size + 26000 ))
1517 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1518 iso_size=$(($iso_size \
1519 + $(zcat < $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1520 fi
1521 sed -i -e '/Image is ready/d' \
1522 -e "s/Rootfs size\( *:\) \(.*\)/Rootfs size\1 $(cent2human $unpacked_size) (estimated)/" \
1523 -e "s/Initramfs size\( *:\) \(.*\)/Initramfs size\1 $(cent2human $packed_size) (estimated)/" \
1524 -e "s/ISO image size\( *:\) \(.*\)/ISO image size\1 $(cent2human $iso_size) (estimated)/" \
1525 -e "s/date\( *:\) \(.*\)/date\1 $(date +%Y%m%d\ \at\ \%H:%M:%S)/" \
1526 $TMP_DIR/$FLAVOR.desc
1527 ( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
1528 $FLAVOR.flavor
1529 status
1530 rm -Rf $TMP_DIR
1531 fi
1532 ;;
1533 extract-flavor)
1534 # Extract a flavor into $FLAVORS_REPOSITORY.
1535 FLAVOR=${2%.flavor}
1536 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1537 mkdir $TMP_DIR
1538 zcat < $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1539 echo -n "Extracting $FLAVOR..."
1540 rm -rf $FLAVORS_REPOSITORY/$FLAVOR 2> /dev/null
1541 mkdir -p $FLAVORS_REPOSITORY/$FLAVOR
1542 cp $TMP_DIR/$FLAVOR.receipt $FLAVORS_REPOSITORY/$FLAVOR/receipt
1543 #~ echo "FLAVOR=\"$FLAVOR\"" > $FLAVORS_REPOSITORY/$FLAVOR/receipt
1544 #~ grep ^Description $TMP_DIR/$FLAVOR.desc | \
1545 #~ sed 's/.*: \(.*\)$/SHORT_DESC="\1"/' >> \
1546 #~ $FLAVORS_REPOSITORY/$FLAVOR/receipt
1547 #~ grep ^Version $TMP_DIR/$FLAVOR.desc | \
1548 #~ sed 's/.*: \(.*\)$/VERSION="\1"/' >> \
1549 #~ $FLAVORS_REPOSITORY/$FLAVOR/receipt
1550 #~ grep ^Maintainer $TMP_DIR/$FLAVOR.desc | \
1551 #~ sed 's/.*: \(.*\)$/MAINTAINER="\1"/' >> \
1552 #~ $FLAVORS_REPOSITORY/$FLAVOR/receipt
1553 #~ grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc && \
1554 #~ grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1555 #~ sed 's/.*: \(.*\)$/ROOTFS_SELECTION="\1"/' >> \
1556 #~ $FLAVORS_REPOSITORY/$FLAVOR/receipt
1557 #~ grep '^Rootfs size' $TMP_DIR/$FLAVOR.desc | \
1558 #~ sed 's/.*: \(.*\)$/ROOTFS_SIZE="\1"/' >> \
1559 #~ $FLAVORS_REPOSITORY/$FLAVOR/receipt
1560 #~ grep ^Initramfs $TMP_DIR/$FLAVOR.desc | \
1561 #~ sed 's/.*: \(.*\)$/INITRAMFS_SIZE="\1"/' >> \
1562 #~ $FLAVORS_REPOSITORY/$FLAVOR/receipt
1563 #~ grep ^ISO $TMP_DIR/$FLAVOR.desc | \
1564 #~ sed 's/.*: \(.*\)$/ISO_SIZE="\1"/' >> \
1565 #~ $FLAVORS_REPOSITORY/$FLAVOR/receipt
1566 for i in rootcd rootfs; do
1567 [ -f $TMP_DIR/$FLAVOR.$i ] || continue
1568 mkdir $FLAVORS_REPOSITORY/$FLAVOR/$i
1569 zcat < $TMP_DIR/$FLAVOR.$i | \
1570 (cd $FLAVORS_REPOSITORY/$FLAVOR/$i; \
1571 cpio -idm > /dev/null)
1572 done
1573 [ -s $TMP_DIR/$FLAVOR.mirrors ] &&
1574 cp $TMP_DIR/$FLAVOR.mirrors \
1575 $FLAVORS_REPOSITORY/$FLAVOR/mirrors
1576 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1577 while read org; do
1578 i=0
1579 pkg=$org
1580 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
1581 pkg=${pkg%-*}
1582 i=$(($i + 1))
1583 [ $i -gt 5 ] && break;
1584 done
1585 echo $pkg
1586 done < $TMP_DIR/$FLAVOR.pkglist \
1587 > $FLAVORS_REPOSITORY/$FLAVOR/packages.list
1588 status
1589 rm -Rf $TMP_DIR
1590 fi
1591 ;;
1592 pack-flavor)
1593 # Create a flavor from $FLAVORS_REPOSITORY.
1594 FLAVOR=${2%.flavor}
1595 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/receipt ]; then
1596 mkdir $TMP_DIR
1597 echo -n "Creating flavor $FLAVOR..."
1598 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1599 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/mirrors ]; then
1600 cp $FLAVORS_REPOSITORY/$FLAVOR/mirrors \
1601 $TMP_DIR/$FLAVOR.mirrors
1602 for i in $(cat $TMP_DIR/$FLAVOR.mirrors); do
1603 wget -O - $i/packages.list >> $TMP_DIR/packages.list
1604 done
1605 fi
1606 #add distro.sh if exist
1607 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/distro.sh ]; then
1608 cp $FLAVORS_REPOSITORY/$FLAVOR/distro.sh $TMP_DIR/$FLAVOR-distro.sh
1609 fi
1611 # Get receipt in .flavor
1612 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/receipt ]; then
1613 cp $FLAVORS_REPOSITORY/$FLAVOR/receipt $TMP_DIR/$FLAVOR.receipt
1614 fi
1616 # Build the package list.
1618 # On peut inclure une liste venant d'une autre saveur avec le mot clé @include
1619 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/packages.list ]; then
1620 INCLUDE=$(grep '^@include' $FLAVORS_REPOSITORY/$FLAVOR/packages.list)
1621 if [ ! -z "$INCLUDE" ]; then
1622 INCLUDE=${INCLUDE#@include }
1623 [ -s "$FLAVORS_REPOSITORY/$INCLUDE/packages.list" ] && \
1624 get_pkglist $INCLUDE > $TMP_DIR/$FLAVOR.pkglist || \
1625 echo -e "\nERROR: Can't find include package list from $INCLUDE\n"
1626 fi
1627 # Generate the final/initial package list
1628 [ -s $FLAVORS_REPOSITORY/$FLAVOR/packages.list ] && \
1629 get_pkglist $FLAVOR >> $TMP_DIR/$FLAVOR.pkglist
1630 fi
1631 if grep -q ^ROOTFS_SELECTION \
1632 $FLAVORS_REPOSITORY/$FLAVOR/receipt; then
1633 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1634 set -- $ROOTFS_SELECTION
1635 [ -n "$FRUGAL_RAM" ] || FRUGAL_RAM=$1
1636 [ -f $FLAVORS_REPOSITORY/$2/packages.list ] ||
1637 tazlito extract-flavor $2
1638 get_pkglist $2 > $TMP_DIR/$FLAVOR.pkglist
1639 for i in rootcd rootfs; do
1640 mkdir $TMP_DIR/$i
1641 # Copy extra files from the first flavor
1642 [ -d $FLAVORS_REPOSITORY/$2/$i ] &&
1643 cp -a $FLAVORS_REPOSITORY/$2/$i $TMP_DIR
1644 # Overload extra files by meta flavor
1645 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] &&
1646 cp -a $FLAVORS_REPOSITORY/$FLAVOR/$i $TMP_DIR
1647 [ -n "$(ls $TMP_DIR/$i)" ] &&
1648 ( cd $TMP_DIR/$i ; find . | cpio -o -H newc 2> /dev/null ) | \
1649 gzip -9 >$TMP_DIR/$FLAVOR.$i
1650 rm -rf $TMP_DIR/$i
1651 done
1652 else
1653 for i in rootcd rootfs; do
1654 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] || \
1655 continue
1656 ( cd $FLAVORS_REPOSITORY/$FLAVOR/$i ; \
1657 find . | cpio -o -H newc 2> /dev/null ) | \
1658 gzip -9 >$TMP_DIR/$FLAVOR.$i
1659 done
1660 fi
1661 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1662 packed_size=$(($packed_size \
1663 + $(wc -c < $TMP_DIR/$FLAVOR.rootfs) / 100 ))
1664 unpacked_size=$(($unpacked_size \
1665 + $(zcat < $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1666 fi
1667 # Estimate lzma
1668 packed_size=$(($packed_size * 2 / 3))
1669 iso_size=$(( $packed_size + 26000 ))
1670 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1671 iso_size=$(($iso_size \
1672 + $(zcat < $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1673 fi
1674 VERSION=""
1675 MAINTAINER=""
1676 ROOTFS_SELECTION=""
1677 ROOTFS_SIZE="$(cent2human $unpacked_size) (estimated)"
1678 INITRAMFS_SIZE="$(cent2human $packed_size) (estimated)"
1679 ISO_SIZE="$(cent2human $iso_size) (estimated)"
1680 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1681 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1682 Flavor : $FLAVOR
1683 Description : $SHORT_DESC
1684 EOT
1685 [ -n "$VERSION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1686 Version : $VERSION
1687 EOT
1688 [ -n "$MAINTAINER" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1689 Maintainer : $MAINTAINER
1690 EOT
1691 [ -n "$FRUGAL_RAM" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1692 LiveCD RAM size : $FRUGAL_RAM
1693 EOT
1694 [ -n "$ROOTFS_SELECTION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1695 Rootfs list : $ROOTFS_SELECTION
1696 EOT
1697 cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1698 Build date : $(date +%Y%m%d\ \at\ \%H:%M:%S)
1699 Packages : $(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l)
1700 Rootfs size : $ROOTFS_SIZE
1701 Initramfs size : $INITRAMFS_SIZE
1702 ISO image size : $ISO_SIZE
1703 ================================================================================
1705 EOT
1706 rm -f $TMP_DIR/packages.list
1707 ( cd $TMP_DIR ; ls | cpio -o -H newc 2> /dev/null) | \
1708 gzip -9 > $FLAVOR.flavor
1709 status
1710 rm -Rf $TMP_DIR
1711 else
1712 echo "No $FLAVOR flavor in $FLAVORS_REPOSITORY."
1713 fi
1714 ;;
1715 get-flavor)
1716 # Get a flavor's files and prepare for gen-distro.
1717 FLAVOR=${2%.flavor}
1718 echo -e "\n\033[1mPreparing $FLAVOR distro flavor\033[0m"
1719 separator
1720 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1721 echo -n "Cleaning $DISTRO..."
1722 rm -R $DISTRO 2> /dev/null
1723 mkdir -p $DISTRO
1724 status
1725 mkdir $TMP_DIR
1726 echo -n "Extracting flavor $FLAVOR.flavor... "
1727 zcat < $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1728 status
1729 echo -n "Creating distro-packages.list..."
1730 mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
1731 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
1732 status
1733 if [ -f "$TMP_DIR/$FLAVOR-distro.sh" ]; then
1734 echo -n "Extracting distro.sh... "
1735 mv $TMP_DIR/$FLAVOR-distro.sh distro.sh 2> /dev/null
1736 status
1737 fi
1738 if [ -f "$TMP_DIR/$FLAVOR.receipt" ]; then
1739 echo -n "Extracting receipt... "
1740 mv $TMP_DIR/$FLAVOR.receipt receipt 2> /dev/null
1741 status
1742 fi
1743 infos="$FLAVOR.desc"
1744 for i in rootcd rootfs; do
1745 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
1746 echo -n "Adding $i files... "
1747 mkdir -p "$ADDFILES/$i"
1748 zcat < $TMP_DIR/$FLAVOR.$i | \
1749 ( cd "$ADDFILES/$i"; cpio -id > /dev/null)
1750 zcat < $TMP_DIR/$FLAVOR.$i | cpio -tv 2> /dev/null \
1751 > $TMP_DIR/$FLAVOR.list$i
1752 infos="$infos\n$FLAVOR.list$i"
1753 status
1754 fi
1755 done
1756 if [ -s $TMP_DIR/$FLAVOR.mirrors ]; then
1757 n=""
1758 while read line; do
1759 mkdir -p $LOCALSTATE/undigest/$FLAVOR$n
1760 echo "$line" > $LOCALSTATE/undigest/$FLAVOR$n/mirror
1761 n=$(( $n + 1 ))
1762 done < $TMP_DIR/$FLAVOR.mirrors
1763 infos="$infos\n$FLAVOR.mirrors"
1764 tazpkg recharge
1765 fi
1766 rm -f /etc/tazlito/rootfs.list
1767 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc &&
1768 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1769 sed 's/.*: \(.*\)$/\1/' > /etc/tazlito/rootfs.list
1770 echo -n "Updating tazlito.conf..."
1771 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
1772 grep -v "^#VOLUM_NAME" < tazlito.conf | \
1773 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
1774 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
1775 sed -i "s/ISO_NAME=.*/ISO_NAME=\"slitaz-$FLAVOR\"/" tazlito.conf
1776 status
1777 ( cd $TMP_DIR ; echo -e $infos | cpio -o -H newc ) | \
1778 gzip -9 > /etc/tazlito/info
1779 rm -Rf $TMP_DIR
1780 fi
1781 separator
1782 echo -e "Flavor is ready to be generated by: tazlito gen-distro\n"
1783 ;;
1785 iso2flavor)
1786 if [ -z "$3" -o ! -s "$2" ]; then
1787 cat <<EOT
1788 Usage : tazlito iso2flavor image.iso flavor_name
1790 Create a file flavor_name.flavor from the cdrom image file image.iso
1791 EOT
1792 exit 1
1793 fi
1794 FLAVOR=${3%.flavor}
1795 mkdir -p $TMP_DIR/iso $TMP_DIR/rootfs
1796 mount -o loop,ro $2 $TMP_DIR/iso
1797 if [ -s $TMP_DIR/iso/boot/rootfs1.gz ]; then
1798 echo "META flavors are not supported."
1799 umount -d $TMP_DIR/iso
1800 elif [ ! -s $TMP_DIR/iso/boot/rootfs.gz ]; then
1801 echo "No /boot/rootfs.gz in iso image. Needs a SliTaz iso."
1802 umount -d $TMP_DIR/iso
1803 else
1804 ( unlzma -c $TMP_DIR/iso/boot/rootfs.gz || \
1805 zcat $TMP_DIR/iso/boot/rootfs.gz ) | \
1806 ( cd $TMP_DIR/rootfs ; cpio -idmu > /dev/null 2>&1 )
1807 if [ ! -s $TMP_DIR/rootfs/etc/slitaz-release ]; then
1808 echo "No file /etc/slitaz-release in /boot/rootfs.gz of iso image. Needs a non loram SliTaz iso."
1809 umount -d $TMP_DIR/iso
1810 else
1811 ROOTFS_SIZE=$(du -hs $TMP_DIR/rootfs | awk '{ print $1 }')
1812 RAM_SIZE=$(du -s $TMP_DIR/rootfs | awk '{ print 32*int(($1+36000)/32768) "M" }')
1813 cp -a $TMP_DIR/iso $TMP_DIR/rootcd
1814 ISO_SIZE=$(df -h $TMP_DIR/iso | awk 'END { print $2 }')
1815 BUILD_DATE=$(date +%Y%m%d\ \at\ \%H:%M:%S -r $TMP_DIR/iso/md5sum)
1816 umount -d $TMP_DIR/iso
1817 INITRAMFS_SIZE=$(du -chs $TMP_DIR/rootcd/boot/rootfs.gz | awk '{ s=$1 } END { print $1 }')
1818 rm -f $TMP_DIR/rootcd/boot/rootfs.gz $TMP_DIR/rootcd/md5sum
1819 mv $TMP_DIR/rootcd/boot $TMP_DIR/rootfs
1820 sed 's/.* \(.*\).tazpkg*/\1/' > $TMP_DIR/$FLAVOR.pkglist \
1821 < $TMP_DIR/rootfs$INSTALLED.md5
1822 #[ -s $TMP_DIR/rootfs/etc/tazlito/distro-packages.list ] &&
1823 # mv $TMP_DIR/rootfs/etc/tazlito/distro-packages.list $TMP_DIR/$FLAVOR.pkglist
1824 PKGCNT=$(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l | awk '{ print $1 }')
1825 find_flavor_rootfs $TMP_DIR/rootfs
1826 [ -d $TMP_DIR/rootfs/boot ] && mv $TMP_DIR/rootfs/boot $TMP_DIR/rootcd
1827 [ -n "$(ls $TMP_DIR/rootfs)" ] && ( cd $TMP_DIR/rootfs ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootfs
1828 [ -n "$(ls $TMP_DIR/rootcd)" ] && ( cd $TMP_DIR/rootcd ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootcd
1829 rm -rf $TMP_DIR/rootcd $TMP_DIR/rootfs
1830 VERSION=""; MAINTAINER=""
1831 echo -en "Flavor short description \007: "; read -t 30 DESCRIPTION
1832 if [ -n "$DESCRIPTION" ]; then
1833 echo -en "Flavor version : "; read -t 30 VERSION
1834 echo -en "Flavor maintainer (your email) : "; read -t 30 MAINTAINER
1835 fi
1836 [ -n "$DESCRIPTION" ] || DESCRIPTION="Slitaz $FLAVOR flavor"
1837 [ -n "$VERSION" ] || VERSION="1.0"
1838 [ -n "$MAINTAINER" ] || MAINTAINER="nobody@slitaz.org"
1839 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1840 Flavor : $FLAVOR
1841 Description : $DESCRIPTION
1842 Version : $VERSION
1843 Maintainer : $MAINTAINER
1844 LiveCD RAM size : $RAM_SIZE
1845 Build date : $BUILD_DATE
1846 Packages : $PKGCNT
1847 Rootfs size : $ROOTFS_SIZE
1848 Initramfs size : $INITRAMFS_SIZE
1849 ISO image size : $ISO_SIZE
1850 ================================================================================
1852 EOT
1853 ( cd $TMP_DIR ; ls $FLAVOR.* | cpio -o -H newc ) | gzip -9 > $FLAVOR.flavor
1854 cat <<EOT
1855 Tazlito can't detect each file installed during a package post_install.
1856 You should extract this flavor (tazlito extract-flavor $FLAVOR),
1857 check the files in /home/slitaz/flavors/$(cat /etc/slitaz-release)/$FLAVOR/rootfs tree and remove
1858 files generated by post_installs.
1859 Check /home/slitaz/flavors/$(cat /etc/slitaz-release)/$FLAVOR/receipt too and repack the flavor
1860 (tazlito pack-flavor $FLAVOR)
1861 EOT
1862 fi
1863 fi
1864 rm -rf $TMP_DIR
1865 ;;
1867 check-list)
1868 # Use current packages list in $PWD by default.
1869 DISTRO_PKGS_LIST=distro-packages.list
1870 [ -d "$2" ] && DISTRO_PKGS_LIST=$2/distro-packages.list
1871 [ -f "$2" ] && DISTRO_PKGS_LIST=$2
1872 [ ! -f $DISTRO_PKGS_LIST ] && echo "No packages list found." && exit 0
1873 echo ""
1874 echo -e "\033[1mLiveCD packages list check\033[0m"
1875 separator
1876 for pkg in `cat $DISTRO_PKGS_LIST`
1877 do
1878 if ! grep -q "$pkg" $LOCALSTATE/packages.list; then
1879 echo "Updating: $pkg"
1880 up=$(($up + 1))
1881 fi
1882 done
1883 [ -z $up ] && echo -e "List is up-to-date\n" && exit 0
1884 separator
1885 echo -e "Updates: $up\n" ;;
1886 gen-distro)
1887 # Generate a live distro tree with a set of packages.
1889 check_root
1890 time=$(date +%s)
1892 # Check if a package list was specified on cmdline.
1893 LIST_NAME="distro-packages.list"
1894 CDROM=""
1895 while [ -n "$2" ]; do
1896 case "$2" in
1897 --iso=*)
1898 CDROM="-o loop ${2#--iso=}"
1899 ;;
1900 --cdrom)
1901 CDROM="/dev/cdrom"
1902 ;;
1903 --force)
1904 DELETE_ROOTFS="true"
1905 ;;
1906 *) if [ ! -f "$2" ] ; then
1907 echo -e "\nUnable to find the specified packages list."
1908 echo -e "List name : $2\n"
1909 exit 1
1910 fi
1911 LIST_NAME=$2
1912 ;;
1913 esac
1914 shift
1915 done
1917 if [ -d $ROOTFS ] ; then
1918 # Delete $ROOTFS if --force is set on command line
1919 if [ ! -z $DELETE_ROOTFS ]; then
1920 rm -rf $ROOTFS
1921 unset $DELETE_ROOTFS
1922 else
1923 echo -e "\nA rootfs exists in : $DISTRO"
1924 echo -e "Please clean the distro tree or change directory path.\n"
1925 exit 0
1926 fi
1927 fi
1928 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
1929 # Build list with installed packages
1930 for i in $(ls $INSTALLED); do
1931 if grep -q ^_realver $INSTALLED/$i/receipt ; then
1932 VERSION=$(. $INSTALLED/$i/receipt 2>/dev/null ; echo $VERSION)
1933 else
1934 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
1935 fi
1936 EXTRAVERSION=""
1937 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
1938 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
1939 done
1940 fi
1941 # Exit if no list name.
1942 if [ ! -f "$LIST_NAME" ]; then
1943 echo -e "\nNo packages list found or specified. Please read the docs.\n"
1944 exit 0
1945 fi
1946 # Start generation.
1947 echo ""
1948 echo -e "\033[1mTazlito generating a distro\033[0m"
1949 separator
1950 # Misc checks
1951 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
1952 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
1953 # Get the list of packages using cat for a file list.
1954 LIST=`cat $LIST_NAME`
1955 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
1956 REPACK=""
1957 DOWNLOAD=""
1958 for pkg in $LIST
1959 do
1960 [ "$pkg" = "" ] && continue
1961 pkg=${pkg%.tazpkg}
1962 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
1963 PACKAGE=$(installed_package_name $pkg)
1964 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
1965 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
1966 echo -e "\nUnable to find $pkg in the repository."
1967 echo -e "Path : $PACKAGES_REPOSITORY\n"
1968 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
1969 yesorno "Repack packages from rootfs (y/N) ? "
1970 REPACK="$answer"
1971 [ "$answer" = "y" ] || REPACK="n"
1972 [ "$DOWNLOAD" = "y" ] && break
1973 fi
1974 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
1975 yesorno "Download packages from mirror (Y/n) ? "
1976 DOWNLOAD="$answer"
1977 if [ "$answer" = "n" ]; then
1978 [ -z "$PACKAGE" ] && exit 1
1979 else
1980 DOWNLOAD="y"
1981 [ -n "$REPACK" ] && break
1982 fi
1983 fi
1984 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
1985 done
1987 # Mount cdrom to be able to repack boot-loader packages
1988 if [ ! -e /boot -a -n "$CDROM" ]; then
1989 mkdir $TMP_MNT
1990 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
1991 ln -s $TMP_MNT/boot /
1992 if [ ! -d "$ADDFILES/rootcd" ] ; then
1993 mkdir -p $ADDFILES/rootcd
1994 for i in $(ls $TMP_MNT); do
1995 [ "$i" = "boot" ] && continue
1996 cp -a $TMP_MNT/$i $ADDFILES/rootcd
1997 done
1998 fi
1999 else
2000 rmdir $TMP_MNT
2001 fi
2002 fi
2004 # Root fs stuff.
2005 echo "Preparing the rootfs directory..."
2006 mkdir -p $ROOTFS
2007 for pkg in $LIST
2008 do
2009 [ "$pkg" = "" ] && continue
2010 # First copy and extract the package in tmp dir.
2011 pkg=${pkg%.tazpkg}
2012 PACKAGE=$(installed_package_name $pkg)
2013 mkdir -p $TMP_DIR
2014 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
2015 # Look for package in cache
2016 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
2017 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
2018 # Look for package in running distribution
2019 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
2020 tazpkg repack $PACKAGE && \
2021 mv $pkg.tazpkg $PACKAGES_REPOSITORY
2022 fi
2023 fi
2024 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
2025 # Get package from mirror
2026 [ "$DOWNLOAD" = "y" ] && \
2027 download $pkg.tazpkg && \
2028 mv $pkg.tazpkg $PACKAGES_REPOSITORY
2029 fi
2030 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
2031 echo "Missing package $pkg."
2032 cleanup
2033 exit 1
2034 fi
2035 done
2036 if [ -f non-free.list ]; then
2037 echo "Preparing non-free packages..."
2038 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
2039 for pkg in $(cat non-free.list); do
2040 if [ ! -d $INSTALLED/$pkg ]; then
2041 if [ ! -d $INSTALLED/get-$pkg ]; then
2042 tazpkg get-install get-$pkg
2043 fi
2044 get-$pkg
2045 fi
2046 tazpkg repack $pkg
2047 pkg=$(ls $pkg*.tazpkg)
2048 grep -q "^$pkg$" $LIST_NAME || \
2049 echo $pkg >>$LIST_NAME
2050 mv $pkg $PACKAGES_REPOSITORY
2051 done
2052 fi
2053 cp $LIST_NAME $DISTRO/distro-packages.list
2054 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/distro-packages.list > $DISTRO/list-packages
2055 cd $PACKAGES_REPOSITORY
2056 for pkg in $(cat $DISTRO/list-packages)
2057 do
2058 echo -n "Installing package: $pkg"
2059 yes y | tazpkg install $pkg --root=$ROOTFS 2>&1 >> $log || exit 1
2060 status
2061 done
2062 rm -f $ROOTFS/var/lib/tazpkg/packages.*
2063 cd $DISTRO
2064 cp distro-packages.list $ROOTFS/etc/tazlito
2065 # Copy all files from $ADDFILES/rootfs to the rootfs.
2066 if [ -d "$ADDFILES/rootfs" ] ; then
2067 echo -n "Copying addfiles content to the rootfs... "
2068 cp -a $ADDFILES/rootfs/* $ROOTFS
2069 status
2070 fi
2071 echo -n "Root filesystem is generated..." && status
2072 # Root CD part.
2073 echo -n "Preparing the rootcd directory..."
2074 mkdir -p $ROOTCD
2075 status
2076 # Move the boot dir with the Linux kernel from rootfs.
2077 # The boot dir goes directly on the CD.
2078 if [ -d "$ROOTFS/boot" ] ; then
2079 echo -n "Moving the boot directory..."
2080 mv $ROOTFS/boot $ROOTCD
2081 cd $ROOTCD/boot
2082 ln vmlinuz-* bzImage
2083 status
2084 fi
2085 cd $DISTRO
2086 # Copy all files from $ADDFILES/rootcd to the rootcd.
2087 if [ -d "$ADDFILES/rootcd" ] ; then
2088 echo -n "Copying addfiles content to the rootcd... "
2089 cp -a $ADDFILES/rootcd/* $ROOTCD
2090 status
2091 fi
2092 # Execute the distro script used to perform tasks in the rootfs
2093 # before compression. Give rootfs path in arg
2094 [ -z $DISTRO_SCRIPT ] && DISTRO_SCRIPT=$TOP_DIR/distro.sh
2095 if [ -x $DISTRO_SCRIPT ]; then
2096 echo "Executing distro script..."
2097 sh $DISTRO_SCRIPT $DISTRO
2098 fi
2100 # Execute the custom_rules found in receipt.
2102 if [ -s $TOP_DIR/receipt ]; then
2103 if grep -q ^custom_rules $TOP_DIR/receipt; then
2104 echo -e "Executing: custom_rules\n"
2105 . $TOP_DIR/receipt
2106 custom_rules || echo -e "\nERROR: custom_rules failed\n"
2107 fi
2108 fi
2110 if [ -s /etc/tazlito/rootfs.list ]; then
2111 FLAVOR_LIST="$(awk '{ for (i = 2; i <= NF; i+=2) \
2112 printf("%s ",$i) }' < /etc/tazlito/rootfs.list)"
2113 sed -i "s/ *//;s/)/), flavors $FLAVOR_LIST/" \
2114 $ROOTCD/boot/isolinux/isolinux.msg 2> /dev/null
2115 [ -f $ROOTCD/boot/isolinux/ifmem.c32 -o \
2116 -f $ROOTCD/boot/isolinux/c32box.c32 ] ||
2117 cp /boot/isolinux/c32box.c32 $ROOTCD/boot/isolinux 2> /dev/null ||
2118 cp /boot/isolinux/ifmem.c32 $ROOTCD/boot/isolinux
2119 n=0
2120 last=$ROOTFS
2121 while read flavor; do
2122 n=$(($n+1))
2123 echo "Building $flavor rootfs..."
2124 [ -s $TOP_DIR/$flavor.flavor ] &&
2125 cp $TOP_DIR/$flavor.flavor .
2126 [ -s $flavor.flavor ] || download $flavor.flavor
2127 zcat < $flavor.flavor | cpio -i \
2128 $flavor.pkglist $flavor.rootfs
2129 sed 's/.*/&.tazpkg/' < $flavor.pkglist \
2130 > $DISTRO/list-packages0$n
2131 mkdir ${ROOTFS}0$n
2132 cd $PACKAGES_REPOSITORY
2133 yes y | tazpkg install-list \
2134 $DISTRO/list-packages0$n --root=${ROOTFS}0$n
2135 rm -rf ${ROOTFS}0$n/boot ${ROOTFS}0$n/var/lib/tazpkg/packages.*
2136 status
2137 cd $DISTRO
2138 if [ -s $flavor.rootfs ]; then
2139 echo "Adding $flavor rootfs extra files..."
2140 zcat < $flavor.rootfs | \
2141 ( cd ${ROOTFS}0$n ; cpio -idmu )
2142 fi
2143 mv $flavor.pkglist ${ROOTFS}0$n/etc/tazlito/distro-packages.list
2144 rm -f $flavor.flavor install-list
2145 mergefs ${ROOTFS}0$n $last
2146 last=${ROOTFS}0$n
2147 done <<EOT
2148 $(awk '{ for (i = 4; i <= NF; i+=2) print $i; }' < /etc/tazlito/rootfs.list)
2149 EOT
2150 i=$(($n+1))
2151 while [ $n -gt 0 ]; do
2152 mv ${ROOTFS}0$n ${ROOTFS}$i
2153 echo "Compression ${ROOTFS}0$n ($(du -hs ${ROOTFS}$i | awk '{ print $1 }')) ..."
2154 gen_initramfs ${ROOTFS}$i
2155 n=$(($n-1))
2156 i=$(($i-1))
2157 done
2158 mv $ROOTFS ${ROOTFS}$i
2159 gen_initramfs ${ROOTFS}$i
2160 update_bootconfig $ROOTCD/boot/isolinux \
2161 "$(cat /etc/tazlito/rootfs.list)"
2162 else
2163 # Initramfs and ISO image stuff.
2164 gen_initramfs $ROOTFS
2165 fi
2166 gen_livecd_isolinux
2167 distro_stats
2168 cleanup
2169 ;;
2170 clean-distro)
2171 # Remove old distro tree.
2173 check_root
2174 echo ""
2175 boldify "Cleaning : $DISTRO"
2176 separator
2177 if [ -d "$DISTRO" ] ; then
2178 if [ -d "$ROOTFS" ] ; then
2179 echo -n "Removing the rootfs..."
2180 rm -f $DISTRO/$INITRAMFS
2181 rm -rf $ROOTFS
2182 status
2183 fi
2184 if [ -d "$ROOTCD" ] ; then
2185 echo -n "Removing the rootcd..."
2186 rm -rf $ROOTCD
2187 status
2188 fi
2189 echo -n "Removing eventual ISO image..."
2190 rm -f $DISTRO/$ISO_NAME.iso
2191 rm -f $DISTRO/$ISO_NAME.md5
2192 status
2193 fi
2194 separator
2195 echo "" ;;
2196 check-distro)
2197 # Check for a few LiveCD needed files not installed by packages.
2199 check_rootfs
2200 echo ""
2201 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
2202 separator
2203 # SliTaz release info.
2204 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
2205 echo "Missing release info : /etc/slitaz-release"
2206 else
2207 release=`cat $ROOTFS/etc/slitaz-release`
2208 echo -n "Release : $release"
2209 status
2210 fi
2211 # Tazpkg mirror.
2212 if [ ! -f "$ROOTFS$LOCALSTATE/mirror" ]; then
2213 echo -n "Mirror URL : Missing $LOCALSTATE/mirror"
2214 todomsg
2215 else
2216 echo -n "Mirror configuration exists..."
2217 status
2218 fi
2219 # Isolinux msg
2220 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.*g; then
2221 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
2222 todomsg
2223 else
2224 echo -n "Isolinux message seems good..."
2225 status
2226 fi
2227 separator
2228 echo ""
2229 ;;
2230 writeiso)
2231 # Writefs to ISO image including /home unlike gen-distro we dont use
2232 # packages to generate a rootfs, we build a compressed rootfs with all
2233 # the current filesystem similar to 'tazusb writefs'.
2235 DISTRO="/home/slitaz/distro"
2236 ROOTCD="$DISTRO/rootcd"
2237 if [ -z $2 ]; then
2238 COMPRESSION=none
2239 else
2240 COMPRESSION=$2
2241 fi
2242 if [ -z $3 ]; then
2243 ISO_NAME="slitaz"
2244 else
2245 ISO_NAME="$3"
2246 fi
2247 check_root
2248 # Start info
2249 newline
2250 boldify "Write filesystem to ISO"
2251 separator
2252 cat << EOT
2253 The command writeiso will write the current filesystem into a suitable cpio
2254 archive (rootfs.gz) and generate a bootable ISO image (slitaz.iso).
2256 $(boldify "Archive compression:") $(colorize 36 "$COMPRESSION")
2258 EOT
2259 # Save some space
2260 rm /var/cache/tazpkg/* -r -f
2261 rm -rf /home/slitaz/distro
2263 # Optionally remove sound card selection and screen resolution.
2264 echo "Do you wish to remove the sound card and screen configs ? "
2265 echo -n "Press ENTER to keep or answer (No|yes|exit): "
2266 read anser
2267 case $anser in
2268 e|E|"exit"|Exit)
2269 exit 0 ;;
2270 y|Y|yes|Yes)
2271 echo -n "Removing current sound card and screen configurations..."
2272 rm -f /var/lib/sound-card-driver
2273 rm -f /var/lib/alsa/asound.state
2274 rm -f /etc/X11/xorg.conf ;;
2275 *)
2276 echo -n "Keeping current sound card and screen configurations..." ;;
2277 esac
2278 status && newline
2280 # Optionally remove i18n settings
2281 echo "Do you wish to remove local/keymap settings ? "
2282 echo -n "Press ENTER to keep or answer (No|yes|exit): "
2283 read anser
2284 case $anser in
2285 e|E|"exit"|Exit)
2286 exit 0 ;;
2287 y|Y|yes|Yes)
2288 echo "Removing current locale/keymap settings..."
2289 echo "" > /etc/locale.conf
2290 echo "" > /etc/keymap.conf ;;
2291 *)
2292 echo "Keeping current locale/keymap settings..." ;;
2293 esac
2294 status
2296 # Clean-up files by default
2297 echo "" > /etc/udev/rules.d/70-persistent-net.rules
2298 echo "" > /etc/udev/rules.d/70-persistant-cd.rules
2300 # Create list of files including default user files since it is defined in /etc/passwd
2301 # and some new users might have been added.
2302 cd /
2303 find bin etc init sbin var dev lib root usr home >/tmp/list
2305 for dir in proc sys tmp mnt media media/cdrom media/flash \
2306 media/usbdisk run run/udev
2307 do
2308 echo $dir >>/tmp/list
2309 done
2311 # Generate initramfs with specified compression and display rootfs
2312 # size in realtime.
2313 rm -f /tmp/rootfs
2314 write_initramfs &
2315 sleep 2
2316 cd - > /dev/null
2317 echo -en "\nFilesystem size:"
2318 while [ ! -f /tmp/rootfs ]
2319 do
2320 sleep 1
2321 echo -en "\\033[18G`du -sh /rootfs.gz | awk '{print $1}'` "
2322 done
2323 echo -e "\n"
2325 # Move freshly generated rootfs to the cdrom.
2326 mkdir -p $ROOTCD/boot
2327 mv -f /rootfs.gz $ROOTCD/boot
2329 # Now we need the kernel and isolinux files.
2330 if mount /dev/cdrom /media/cdrom 2>/dev/null; then
2331 cp /media/cdrom/boot/bzImage $ROOTCD/boot
2332 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
2333 unmeta_boot $ROOTCD
2334 umount /media/cdrom
2335 elif mount |grep /media/cdrom; then
2336 cp /media/cdrom/boot/bzImage $ROOTCD/boot
2337 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
2338 unmeta_boot $ROOTCD
2339 umount /media/cdrom;
2340 else
2341 echo -e "
2342 When SliTaz is running in RAM the kernel and bootloader files are kept
2343 on the cdrom. Please insert a LiveCD or loop mount the slitaz.iso to
2344 /media/cdrom to let Tazlito copy the files.\n"
2345 echo -en "----\nENTER to continue..."; read i
2346 exit 1
2347 fi
2349 # Generate the iso image.
2350 cd $DISTRO
2351 echo "Generating ISO image..."
2352 genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
2353 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
2354 -V "SliTaz" -input-charset iso8859-1 -boot-info-table $ROOTCD
2355 if [ -x /usr/bin/isohybrid ]; then
2356 echo -n "Creating hybrid ISO..."
2357 /usr/bin/isohybrid $ISO_NAME.iso -entry 2 2> /dev/null
2358 status
2359 fi
2360 echo -n "Creating the ISO md5sum..."
2361 md5sum $ISO_NAME.iso > $ISO_NAME.md5
2362 status
2364 echo "==============================================================================="
2365 echo "ISO image: `du -sh /home/slitaz/distro/$ISO_NAME.iso`"
2366 echo ""
2367 echo -n "Exit or burn ISO to cdrom (Exit|burn)? "; read anser
2368 case $anser in
2369 burn)
2370 eject
2371 echo -n "Please insert a blank cdrom and press ENTER..."
2372 read i && sleep 2
2373 tazlito burn-iso /home/slitaz/distro/$ISO_NAME.iso
2374 echo -en "----\nENTER to continue..."; read i ;;
2375 *)
2376 exit 0 ;;
2377 esac ;;
2378 burn-iso)
2379 # Guess cdrom device, ask user and burn the ISO.
2381 check_root
2382 DRIVE_NAME=$(grep "drive name" < /proc/sys/dev/cdrom/info | cut -f 3)
2383 DRIVE_SPEED=$(grep "drive speed" < /proc/sys/dev/cdrom/info | cut -f 3)
2384 # We can specify an alternative ISO from the cmdline.
2385 if [ -n "$2" ] ; then
2386 iso=$2
2387 else
2388 iso=$DISTRO/$ISO_NAME.iso
2389 fi
2390 if [ ! -f "$iso" ]; then
2391 echo -e "\nUnable to find ISO : $iso\n"
2392 exit 0
2393 fi
2394 echo ""
2395 echo -e "\033[1mTazlito burn ISO\033[0m "
2396 separator
2397 echo "Cdrom device : /dev/$DRIVE_NAME"
2398 echo "Drive speed : $DRIVE_SPEED"
2399 echo "ISO image : $iso"
2400 separator
2401 echo ""
2402 yesorno "Burn ISO image (y/N) ? "
2403 if [ "$answer" == "y" ]; then
2404 echo ""
2405 echo "Starting Wodim to burn the iso..." && sleep 2
2406 separator
2407 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
2408 separator
2409 echo "ISO image is burned to cdrom."
2410 else
2411 echo -e "\nExiting. No ISO burned."
2412 fi
2413 echo ""
2414 ;;
2415 merge)
2416 # Merge multiple rootfs into one iso.
2418 if [ -z "$2" ]; then
2419 cat << EOT
2420 Usage: tazlito merge size1 iso size2 rootfs2 [sizeN rootfsN]...
2422 Merge multiple rootfs into one iso. Rootfs are like russian dolls
2423 i.e: rootfsN is a subset of rootfsN-1
2424 rootfs1 is found in iso, sizeN is the RAM size need to launch rootfsN.
2425 The boot loader will select the rootfs according to the RAM size detected.
2427 Example:
2428 $ tazlito merge 160M slitaz-core.iso 96M rootfs-justx.gz 32M rootfs-base.gz
2430 Will start slitaz-core with 160M+ RAM, slitaz-justX with 96M-160M RAM,
2431 slitaz-base with 32M-96M RAM and display an error message if RAM < 32M.
2433 EOT
2434 exit 2
2435 fi
2437 shift # skip merge
2438 append="$1 slitaz1"
2439 shift # skip size1
2440 mkdir -p $TMP_DIR/mnt $TMP_DIR/rootfs1
2442 ISO=$1.merged
2443 # Extract filesystems
2444 echo -n "Mounting $1"
2445 mount -o loop,ro $1 $TMP_DIR/mnt 2> /dev/null
2446 status || cleanup_merge
2447 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2448 rm -f $TMP_DIR/iso/boot/bzImage
2449 ln $TMP_DIR/iso/boot/vmlinuz* $TMP_DIR/iso/boot/bzImage
2450 umount -d $TMP_DIR/mnt
2451 if [ -f $TMP_DIR/iso/boot/rootfs1.gz ]; then
2452 echo "$1 is already a merged iso. Aborting."
2453 cleanup_merge
2454 fi
2455 if [ ! -f $TMP_DIR/iso/boot/isolinux/ifmem.c32 -a
2456 ! -f $TMP_DIR/iso/boot/isolinux/c32box.c32 ]; then
2457 if [ ! -f /boot/isolinux/ifmem.c32 -a
2458 ! -f /boot/isolinux/c32box.c32 ]; then
2459 cat <<EOT
2460 No file /boot/isolinux/ifmem.c32
2461 Please install syslinux package !
2462 EOT
2463 rm -rf $TMP_DIR
2464 exit 1
2465 fi
2466 cp /boot/isolinux/c32box.c32 $TMP_DIR/iso/boot/isolinux 2> /dev/null ||
2467 cp /boot/isolinux/ifmem.c32 $TMP_DIR/iso/boot/isolinux
2468 fi
2470 echo -n "Extracting iso/rootfs.gz"
2471 extract_rootfs $TMP_DIR/iso/boot/rootfs.gz $TMP_DIR/rootfs1 &&
2472 [ -d $TMP_DIR/rootfs1/etc ]
2473 status || cleanup_merge
2474 n=1
2475 while [ -n "$2" ]; do
2476 shift # skip rootfs N-1
2477 p=$n
2478 n=$(($n + 1))
2479 append="$append $1 slitaz$n"
2480 shift # skip size N
2481 mkdir -p $TMP_DIR/rootfs$n
2482 echo -n "Extracting $1"
2483 extract_rootfs $1 $TMP_DIR/rootfs$n &&
2484 [ -d $TMP_DIR/rootfs$n/etc ]
2485 status || cleanup_merge
2486 mergefs $TMP_DIR/rootfs$n $TMP_DIR/rootfs$p
2487 echo "Creating rootfs$p.gz"
2488 pack_rootfs $TMP_DIR/rootfs$p $TMP_DIR/iso/boot/rootfs$p.gz
2489 status
2490 done
2491 echo "Creating rootfs$n.gz"
2492 pack_rootfs $TMP_DIR/rootfs$n $TMP_DIR/iso/boot/rootfs$n.gz
2493 status
2494 rm -f $TMP_DIR/iso/boot/rootfs.gz
2495 update_bootconfig $TMP_DIR/iso/boot/isolinux "$append"
2496 create_iso $ISO $TMP_DIR/iso
2497 rm -rf $TMP_DIR
2498 ;;
2500 repack)
2501 # Repack an iso with maximum lzma compression ratio.
2504 ISO=$2
2506 mkdir -p $TMP_DIR/mnt
2507 # Extract filesystems
2508 echo -n "Mounting $ISO"
2509 mount -o loop,ro $ISO $TMP_DIR/mnt 2> /dev/null
2510 status || cleanup_merge
2511 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2512 umount -d $TMP_DIR/mnt
2514 for i in $TMP_DIR/iso/boot/rootfs* ; do
2515 echo -n "Repacking $(basename $i)"
2516 (zcat $i 2> /dev/null || unlzma -c $i || cat $i) \
2517 2>/dev/null > $TMP_DIR/rootfs
2518 lzma e $TMP_DIR/rootfs $i \
2519 $(lzma_switches $TMP_DIR/rootfs)
2520 align_to_32bits $i
2521 status
2522 done
2524 create_iso $ISO $TMP_DIR/iso
2525 rm -rf $TMP_DIR ;;
2527 build-loram)
2528 # Build a Live CD for low ram systems.
2531 ISO=$2
2532 OUTPUT=$3
2533 if [ -z "$3" ]; then
2534 echo "Usage: tazlito $1 input.iso output.iso [cdrom|smallcdrom|http|ram]"
2535 exit 1
2536 fi
2537 mkdir -p $TMP_DIR/iso
2538 mount -o loop,ro -t iso9660 $ISO $TMP_DIR/iso
2539 loopdev=$( (losetup -a 2>/dev/null || losetup) | grep $ISO | cut -d: -f1)
2540 if ! check_iso_for_loram ; then
2541 echo "$2 is not a valid SliTaz live CD. Abort."
2542 umount -d $TMP_DIR/iso
2543 rm -rf $TMP_DIR
2544 exit 1
2545 fi
2547 case "$4" in
2548 cdrom) build_loram_cdrom ;;
2549 http) build_loram_http ;;
2550 *) build_loram_ram ;;
2551 esac
2552 umount $TMP_DIR/iso # no -d: needs /proc
2553 losetup -d $loopdev
2554 rm -rf $TMP_DIR ;;
2556 emu-iso)
2557 # Emulate an ISO image with Qemu.
2558 if [ -n "$2" ] ; then
2559 iso=$2
2560 else
2561 iso=$DISTRO/$ISO_NAME.iso
2562 fi
2563 if [ ! -f "$iso" ]; then
2564 echo -e "\nUnable to find ISO : $iso\n"
2565 exit 0
2566 fi
2567 if [ ! -x "/usr/bin/qemu" ]; then
2568 echo -e "\nUnable to find Qemu binary. Please install: qemu\n"
2569 exit 0
2570 fi
2571 echo -e "\nStarting Qemu emulator:\n"
2572 echo -e "qemu $QEMU_OPTS $iso\n"
2573 qemu $QEMU_OPTS $iso ;;
2575 deduplicate)
2576 # Deduplicate files in a tree
2577 shift
2578 deduplicate "$@" ;;
2579 usage|*)
2580 # Clear and print usage also for all unknown commands.
2582 clear
2583 usage ;;
2584 esac
2586 exit 0