tazlito view tazlito @ rev 308

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