tazlito view tazlito @ rev 316

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