tazlito view tazlito @ rev 287

tazlito: do not deduplicate soft links
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Aug 07 18:49:08 2012 +0200 (2012-08-07)
parents f9f9ab92b556
children ff1150bb5001
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=4.5
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 }
262 # Generate a new ISO image using isolinux.
263 gen_livecd_isolinux()
264 {
265 # Some packages may want to alter iso
266 genisohooks iso
267 if [ ! -f "$ROOTCD/boot/isolinux/isolinux.bin" ]; then
268 echo -e "\nUnable to find isolinux binary.\n"
269 cleanup
270 exit 0
271 fi
272 # Set date for boot msg.
273 if grep -q 'XXXXXXXX' $ROOTCD/boot/isolinux/isolinux.*g; then
274 DATE=`date +%Y%m%d`
275 echo -n "Setting build date to: $DATE..."
276 sed -i "s/XXXXXXXX/$DATE/" $ROOTCD/boot/isolinux/isolinux.*g
277 status
278 fi
279 cd $DISTRO
280 create_iso $ISO_NAME.iso $ROOTCD
281 echo -n "Creating the ISO md5sum..."
282 md5sum $ISO_NAME.iso > $ISO_NAME.md5
283 status
284 separator
285 # Some packages may want to alter final iso
286 genisohooks final
287 }
289 lzma_history_bits()
290 {
291 #
292 # This generates an ISO which boots with Qemu but gives
293 # rootfs errors in frugal or liveUSB mode.
294 #
295 #local n
296 #local sz
297 #n=20 # 1Mb
298 #sz=$(du -sk $1 | cut -f1)
299 #while [ $sz -gt 1024 -a $n -lt 28 ]; do
300 #n=$(( $n + 1 ))
301 #sz=$(( $sz / 2 ))
302 #done
303 #echo $n
304 echo 24
305 }
307 lzma_switches()
308 {
309 local proc=$(grep -s '^processor' < /proc/cpuinfo | wc -l)
310 echo "-d$(lzma_history_bits $1) -mt${proc:-1}"
311 }
313 lzma_set_size()
314 {
315 # Update size field for lzma'd file packed using -si switch
316 local n
317 local i
318 return # Need to fix kernel code ?
319 n=$(unlzma -c $1 | wc -c)
320 for i in $(seq 1 8); do
321 printf '\\\\x%02X' $(($n & 255))
322 n=$(($n >> 8))
323 done | xargs echo -en | dd of=$1 conv=notrunc bs=1 seek=5 2> /dev/null
324 }
326 # Pack rootfs
327 pack_rootfs()
328 {
329 ( cd $1 ; find . -print | cpio -o -H newc ) | \
330 if [ "$COMPRESSION" = "none" ]; then
331 echo "Generating uncompressed initramfs... "
332 cat > $2
333 elif [ -x /usr/bin/lzma -a "$COMPRESSION" != "gzip" ]; then
334 echo -n "Generating lzma'ed initramfs... "
335 lzma e -si -so $(lzma_switches $1) > $2
336 lzma_set_size $2
337 else
338 echo "Generating gziped initramfs... "
339 gzip -9 > $2
340 fi
341 echo 1 > /tmp/rootfs
342 }
344 # Compression functions for writeiso.
345 write_initramfs()
346 {
347 if [ "$COMPRESSION" = "lzma" ]; then
348 echo -n "Creating rootfs.gz with lzma compression... "
349 cat /tmp/list | cpio -o -H newc | lzma e -si -so > /rootfs.gz
350 lzma_set_size /rootfs.gz
351 elif [ "$COMPRESSION" = "gzip" ]; then
352 echo "Creating rootfs.gz with gzip compression... "
353 cat /tmp/list | cpio -o -H newc | gzip -9 > /rootfs.gz
354 else
355 echo "Creating rootfs.gz without compression... "
356 cat /tmp/list | cpio -o -H newc > /rootfs.gz
357 fi
358 echo 1 > /tmp/rootfs
359 }
361 # Deduplicate files (MUST be on the same filesystem).
362 deduplicate()
363 {
364 find "$@" -type f -size +0c -exec stat -c '%s-%a-%u-%g %i %h %n' {} \; | \
365 sort | ( save=0; old_attr=""; old_inode=""; old_link=""; old_file=""
366 while read attr inode link file; do
367 [ -L "$file" ] && continue
368 if [ "$attr" = "$old_attr" -a "$inode" != "$old_inode" ]; then
369 if cmp "$file" "$old_file" >/dev/null 2>&1 ; then
370 rm -f "$file"
371 ln "$old_file" "$file"
372 inode="$old_inode"
373 [ "$link" = "1" ] && save="$(expr $save + ${attr%%-*})"
374 fi
375 fi
376 old_attr="$attr" ; old_inode="$inode" ; old_file="$file"
377 done
378 echo "$save bytes saved in duplicate files."
379 )
380 }
382 # Generate a new initramfs from the root filesystem.
383 gen_initramfs()
384 {
385 # Just in case CTRL+c
386 rm -f $DISTRO/gen
388 # Some packages may want to alter rootfs
389 genisohooks rootfs
390 cd $1
392 # Link duplicate files
393 deduplicate .
395 # Use lzma if installed. Display rootfs size in realtime.
396 rm -f /tmp/rootfs
397 pack_rootfs . $DISTRO/$(basename $1).gz &
398 sleep 2
399 echo -en "\nFilesystem size:"
400 while [ ! -f /tmp/rootfs ]
401 do
402 sleep 1
403 echo -en "\\033[18G`du -sh $DISTRO/$(basename $1).gz | awk '{print $1}'` "
404 done
405 echo -e "\n"
406 cd $DISTRO
407 mv $(basename $1).gz $ROOTCD/boot
408 }
410 distro_sizes()
411 {
412 if [ "$time" ]; then
413 time=$(($(date +%s) - $time))
414 sec=$time
415 div=$(( ($time + 30) / 60))
416 [ "$div" != 0 ] && min="~ ${div}m"
417 echo "Build time : ${sec}s $min"
418 fi
419 cat << EOT
420 Build date : $(date +%Y%m%d)
421 Packages : $(ls -1 $ROOTFS*$INSTALLED/*/receipt | wc -l)
422 Rootfs size : $(du -csh $ROOTFS*/ | awk '{ s=$1 } END { print s }')
423 Initramfs size : $(du -csh $ROOTCD/boot/rootfs*.gz | awk '{ s=$1 } END { print s }')
424 ISO image size : $(du -sh $ISO_NAME.iso | awk '{ print $1 }')
425 ================================================================================
426 Image is ready: $ISO_NAME.iso
428 EOT
429 }
431 # Print ISO and rootfs size.
432 distro_stats()
433 {
434 echo ""
435 echo -e "\033[1mDistro statistics\033[0m ($DISTRO)"
436 separator
437 distro_sizes
438 }
440 # Create an empty configuration file.
441 empty_config_file()
442 {
443 cat >> tazlito.conf << "EOF"
444 # tazlito.conf: Tazlito (SliTaz Live Tool)
445 # configuration file.
446 #
448 # Name of the ISO image to generate.
449 ISO_NAME=""
451 # ISO image volume name.
452 VOLUM_NAME="SliTaz"
454 # Name of the preparer.
455 PREPARED="$USER"
457 # Path to the packages repository and the packages.list.
458 PACKAGES_REPOSITORY=""
460 # Path to the distro tree to gen-distro from a
461 # list of packages.
462 DISTRO=""
464 # Path to the directory containing additional files
465 # to copy into the rootfs and rootcd of the LiveCD.
466 ADDFILES="$DISTRO/addfiles"
468 # Default answer for binary question (Y or N)
469 DEFAULT_ANSWER="ASK"
471 # Compression utility (lzma, gzip or none)
472 COMPRESSION="lzma"
473 EOF
474 }
476 # extract rootfs.gz somewhere
477 extract_rootfs()
478 {
479 (zcat $1 || unlzma -c $1 || cat $1) 2>/dev/null | \
480 (cd $2; cpio -idm > /dev/null)
481 }
483 # Remove duplicate files
484 mergefs()
485 {
486 echo -n "Merge $(basename $1) ($(du -hs $1 | awk '{ print $1}')) into "
487 echo -n "$(basename $2) ($(du -hs $2 | awk '{ print $1}'))"
488 # merge symlinks files and devices
489 ( cd $1; find ) | while read file; do
490 if [ -L $1/$file ]; then
491 [ -L $2/$file ] &&
492 [ "$(readlink $1/$file)" == "$(readlink $2/$file)" ] &&
493 rm -f $2/$file
494 elif [ -f $1/$file ]; then
495 [ -f $2/$file ] &&
496 cmp $1/$file $2/$file > /dev/null 2>&1 && rm -f $2/$file
497 [ -f $2/$file ] &&
498 [ "$(basename $file)" == "volatile.cpio.gz" ] &&
499 [ "$(dirname $(dirname $file))" == \
500 ".$INSTALLED" ] && rm -f $2/$file
501 elif [ -b $1/$file ]; then
502 [ -b $2/$file ] &&
503 [ "$(stat -c '%a:%u:%g:%t:%T' $1/$file)" == \
504 "$(stat -c '%a:%u:%g:%t:%T' $2/$file)" ] &&
505 rm -f $2/$file
506 elif [ -c $1/$file ]; then
507 [ -c $2/$file ] &&
508 [ "$(stat -c '%a:%u:%g:%t:%T' $1/$file)" == \
509 "$(stat -c '%a:%u:%g:%t:%T' $2/$file)" ] &&
510 rm -f $2/$file
511 fi
512 done
514 # cleanup directories
515 ( cd $1; find -type d ) | sed '1!G;h;$!d' | while read file; do
516 [ -d $2/$file ] && rmdir $2/$file 2> /dev/null
517 done
518 true
519 status
520 }
522 cleanup_merge()
523 {
524 rm -rf $TMP_DIR
525 exit 1
526 }
528 human2cent()
529 {
530 case "$1" in
531 *k) echo $1 | sed 's/\(.*\).\(.\)k/\1\2/';;
532 *M) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)M/\1\2/') * 1024));;
533 *G) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)G/\1\2/') * 1024 * 1024));;
534 esac
535 }
537 cent2human()
538 {
539 if [ $1 -lt 10000 ]; then
540 echo "$(($1 / 10)).$(($1 % 10))k"
541 elif [ $1 -lt 10000000 ]; then
542 echo "$(($1 / 10240)).$(( ($1/1024) % 10))M"
543 else
544 echo "$(($1 / 10485760)).$(( ($1/1048576) % 10))G"
545 fi
546 }
548 get_size()
549 {
550 cat $LOCALSTATE/packages.list $TMP_DIR/packages.list 2>/dev/null | awk "{ \
551 if (/^$(echo $1 | sed 's/[$+.\]/\\&/g')$/) get=1; \
552 if (/installed/ && get == 1) { print ; get++ } \
553 }
554 END { if (get < 2) print \" 0.0k (0.0k installed)\" }" | \
555 sed 's/ *\(.*\) .\(.*\) installed./\1 \2/' | while read packed unpacked; do
556 echo "$(human2cent $packed) $(human2cent $unpacked)"
557 done
558 }
560 # Display package list with version, set packed_size and unpacked_size
561 get_pkglist()
562 {
563 packed_size=0; unpacked_size=0
564 grep -v ^# $FLAVORS_REPOSITORY/$1/packages.list > $TMP_DIR/flavor.pkg
565 while read pkg; do
566 set -- $(get_size $pkg)
567 packed_size=$(( $packed_size + $1 ))
568 unpacked_size=$(( $unpacked_size + $2 ))
569 for i in $(grep -hs ^$pkg $LOCALSTATE/packages.list \
570 $TMP_DIR/packages.list); do
571 echo $i
572 break
573 done
574 done < $TMP_DIR/flavor.pkg
575 rm -f $TMP_DIR/flavor.pkg
576 }
578 # Update isolinux config files for multiple rootfs
579 update_bootconfig()
580 {
581 local files
582 echo -n "Updating boot config files..."
583 files="$(grep -l 'include common' $1/*.cfg)"
584 for file in $files ; do
585 awk -v n=$(echo $2 | awk '{ print NF/2 }') '{
586 if (/label/) label=$0;
587 else if (/kernel/) kernel=$0;
588 else if (/append/) {
589 i=index($0,"rootfs.gz");
590 append=substr($0,i+9);
591 }
592 else if (/include/) {
593 for (i = 1; i <= n; i++) {
594 print label i
595 print kernel;
596 initrd="initrd=/boot/rootfs" n ".gz"
597 for (j = n - 1; j >= i; j--) {
598 initrd=initrd ",/boot/rootfs" j ".gz";
599 }
600 printf "\tappend %s%s\n",initrd,append;
601 print "";
602 }
603 print;
604 }
605 else print;
606 }' < $file > $file.$$
607 mv -f $file.$$ $file
608 done
609 sel="$(echo $2 | awk '{
610 for (i=1; i<=NF; i++)
611 if (i % 2 == 0) printf " slitaz%d",i/2
612 else printf " %s",$i
613 }')"
614 [ -s $1/common.cfg ] && cat >> $1/common.cfg <<EOT
616 label slitaz
617 kernel /boot/isolinux/ifmem.c32
618 append$sel noram
620 label noram
621 config noram.cfg
623 EOT
624 # Update vesamenu
625 if [ -s $1/isolinux.cfg ]; then
626 files="$files $1/isolinux.cfg"
627 awk -v n=$(echo $2 | awk '{ print NF/2 }') -v "sel=$sel" '
628 BEGIN {
629 kernel=" COM32 c32box.c32"
630 }
631 {
632 if (/ROWS/) print "MENU ROW " n+$3;
633 else if (/TIMEOUTROW/) print "MENU TIMEOUTROW " n+$3;
634 else if (/TABMSGROW/) print "MENU TABMSGROW " n+$3;
635 else if (/CMDLINEROW/) print "MENU CMDLINEROW " n+$3;
636 else if (/VSHIFT/) {
637 x=$3-n;
638 if (x < 0) x=0;
639 print "MENU VSHIFT " x;
640 }
641 else if (/rootfs.gz/) {
642 linux=""
643 if (/bzImage/) {
644 linux="linux /boot/bzImage "
645 }
646 i=index($0,"rootfs.gz");
647 append=substr($0,i+9);
648 print " kernel /boot/isolinux/ifmem.c32"
649 print " append" sel " noram"
650 print ""
651 print "label noram"
652 print " MENU HIDE"
653 print " config noram.cfg"
654 print ""
655 for (i = 1; i <= n; i++) {
656 print "LABEL slitaz" i
657 print " MENU LABEL SliTaz slitaz" i " Live"
658 print kernel;
659 initrd="initrd=/boot/rootfs" n ".gz"
660 for (j = n - 1; j >= i; j--) {
661 initrd=initrd ",/boot/rootfs" j ".gz";
662 }
663 printf "\tappend %s%s%s\n",linux,initrd,append;
664 print "";
665 }
666 }
667 else if (/bzImage/) kernel=$0;
668 else print;
669 }' < $1/isolinux.cfg > $1/isolinux.cfg.$$
670 mv $1/isolinux.cfg.$$ $1/isolinux.cfg
671 fi
672 [ -s $1/c32box.c32 ] && sed -i -e '/kernel.*ifmem/d' \
673 -e 's/append \([0-9]\)/append ifmem \1/' $1/isolinux.cfg
674 cat > $1/noram.cfg <<EOT
675 implicit 0
676 prompt 1
677 timeout 80
678 F1 help.txt
679 F2 options.txt
680 F3 isolinux.msg
681 F4 display.txt
682 F5 enhelp.txt
683 F6 enopts.txt
685 display isolinux.msg
686 say Not enough RAM to boot slitaz. Give http://tiny.slitaz.org/ a try ?
687 default reboot
688 label reboot
689 EOT
690 if [ -s $1/c32box.c32 ]; then
691 cat >> $1/noram.cfg <<EOT
692 COM32 c32box.c32
693 append reboot
695 label poweroff
696 COM32 c32box.c32
697 append poweroff
699 EOT
700 else
701 echo " com32 reboot.c32" >> $1/noram.cfg
702 fi
703 # Restore real label names
704 [ -s $1/common.cfg ] && files="$1/common.cfg $files"
705 echo $2 | awk '{ for (i=NF; i>1; i-=2) printf "%d/%s\n",i/2,$i }' | \
706 while read pat; do
707 sed -i "s/slitaz$pat/" $files
708 done
709 status
710 }
712 # Install a missing package
713 install_package()
714 {
715 echo -n "Install package $1 "
716 [ -n "$2" ] && echo -n "for kernel $2 "
717 echo -n "?"
718 read answer
719 case "$answer" in
720 y*|Y*|o*|O*)
721 # We dont want package on host cache.
722 echo -n "Getting and installing package: $1"
723 yes y | tazpkg get-install $1 2>&1 >> $log || exit 1
724 status ;;
725 *)
726 return 1 ;;
727 esac
728 }
730 # Check iso for loram transformation
731 check_iso_for_loram()
732 {
733 [ -s $TMP_DIR/iso/boot/rootfs.gz ] ||
734 [ -s $TMP_DIR/iso/boot/rootfs1.gz ]
735 }
737 # Build initial rootfs for loram ISO ram/cdrom/http
738 build_initfs()
739 {
740 urliso="mirror.slitaz.org mirror.switch.ch/ftp/mirror/slitaz \
741 download.tuxfamily.org/slitaz slitaz.c3sl.ufpr.br"
742 version=$(ls $TMP_DIR/iso/boot/vmlinuz-* | sed 's/.*vmlinuz-//')
743 if [ -z "$version" ]; then
744 cat <<EOT
745 Can't find the kernel version.
746 No file /boot/vmlinuz-<version> in ISO image.
747 Abort.
748 EOT
749 exit 1
750 fi
751 [ -s /usr/share/boot/busybox-static ] || install_package busybox-static
752 need_lib=false
753 mkdir -p $TMP_DIR/initfs/bin $TMP_DIR/initfs/dev $TMP_DIR/initfs/lib \
754 $TMP_DIR/initfs/mnt $TMP_DIR/initfs/proc $TMP_DIR/initfs/tmp \
755 $TMP_DIR/initfs/sys
756 while [ ! -f /lib/modules/$version/kernel/fs/aufs/aufs.ko.gz ]; do
757 install_package aufs $version || return 1
758 done
759 # bootfloppybox will need floppy.ko.gz, /dev/fd0, /dev/tty0
760 cp /lib/modules/$version/kernel/drivers/block/floppy.ko.gz \
761 $TMP_DIR/initfs/lib 2> /dev/null
762 cp -a /dev/tty0 /dev/fd0 $TMP_DIR/initfs/dev 2> /dev/null
763 cp /lib/modules/$version/kernel/fs/aufs/aufs.ko.gz \
764 $TMP_DIR/initfs/lib
765 if [ -f /bin/cromfs-driver ]; then
766 cp /bin/cromfs-driver $TMP_DIR/initfs/bin
767 ls /bin/unmkcromfs | \
768 cpio -o -H newc > $TMP_DIR/initfs/extractfs.cpio
769 else
770 [ ! -f /usr/sbin/mksquashfs ] && ! install_package squashfs && return 1
771 while [ ! -f /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.gz ]; do
772 install_package linux-squashfs $version || return 1
773 done
774 cp /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.gz \
775 $TMP_DIR/initfs/lib
776 ls /sbin/unsquashfs /usr/lib/liblzma.so* $INSTALLED/squashfs/* | \
777 cpio -o -H newc > $TMP_DIR/initfs/extractfs.cpio
778 fi
779 if [ "$1" == "cdrom" ]; then
780 for i in $(ls /dev/[hs]d[a-f]*); do
781 cp -a $i $TMP_DIR/initfs/dev
782 done
783 fi
784 if [ "$1" == "http" ]; then
785 mkdir $TMP_DIR/initfs/etc
786 ln -s /proc/mounts $TMP_DIR/initfs/etc/mtab
787 cp /usr/share/udhcpc/default.script $TMP_DIR/initfs/lib/udhcpc
788 sed -i 's|/sbin/||' $TMP_DIR/initfs/lib/udhcpc
789 cp -a /dev/fuse $TMP_DIR/initfs/dev
790 if ! $need_lib && [ -x /usr/share/boot/fusermount-static ]; then
791 cp /usr/share/boot/fusermount-static $TMP_DIR/initfs/bin/httpfs
792 else
793 cp /usr/bin/fusermount $TMP_DIR/initfs/bin
794 need_lib=true
795 fi
796 if ! $need_lib && [ -x /usr/share/boot/httpfs-static ]; then
797 cp /usr/share/boot/httpfs-static $TMP_DIR/initfs/bin/httpfs
798 else
799 [ ! -f /usr/bin/httpfs ] && ! install_package httpfs-fuse && return 1
800 cp /usr/bin/httpfs $TMP_DIR/initfs/bin
801 cp -a /lib/librt* $TMP_DIR/initfs/lib
802 cp -a /lib/libdl* $TMP_DIR/initfs/lib
803 cp -a /lib/libpthread* $TMP_DIR/initfs/lib
804 cp -a /usr/lib/libfuse* $TMP_DIR/initfs/lib
805 cp -a /lib/libresolv* $TMP_DIR/initfs/lib
806 cp -a /lib/libnss_dns* $TMP_DIR/initfs/lib
807 need_lib=true
808 fi
809 cd $TMP_DIR/initfs
810 echo "Getting slitaz-release..."
811 for i in $TMP_DIR/iso/boot/rootfs*.gz; do
812 ( zcat $i 2> /dev/null || unlzma -c $i) | \
813 cpio -idmu etc/slitaz-release > /dev/null
814 done
815 cd - > /dev/null
816 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"
817 echo -n "List of urls to insert: "
818 read -t 30 urliso2
819 urliso="$urliso2 $urliso"
820 fi
821 if ! $need_lib && [ -x /usr/share/boot/busybox-static ]; then
822 cp /usr/share/boot/busybox-static $TMP_DIR/initfs/bin/busybox
823 else
824 cp /bin/busybox $TMP_DIR/initfs/bin
825 need_lib=true
826 fi
827 for i in $($TMP_DIR/initfs/bin/busybox | awk \
828 '{ if (s) printf "%s",$0 } /Currently/ { s=1 }' | sed 's/,//g'); do
829 ln $TMP_DIR/initfs/bin/busybox $TMP_DIR/initfs/bin/$i
830 done
831 for i in /dev/console /dev/loop* /dev/null /dev/tty /dev/zero \
832 /dev/kmem /dev/mem /dev/random /dev/urandom; do
833 cp -a $i $TMP_DIR/initfs/dev
834 done
835 $need_lib && for i in /lib/ld-* /lib/lib[cm].so* /lib/lib[cm]-* ; do
836 cp -a $i $TMP_DIR/initfs/lib
837 done
838 cat > $TMP_DIR/initfs/init <<EOTEOT
839 #!/bin/sh
841 getarg()
842 {
843 grep -q " \$1=" /proc/cmdline || return 1
844 eval \$2=\$(sed "s/.* \$1=\\\\([^ ]*\\\\).*/\\\\1/" < /proc/cmdline)
845 return 0
846 }
848 copy_rootfs()
849 {
850 total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g')
851 need=\$(du -c \${path}rootfs* | tail -n 1 | cut -f1)
852 [ \$(( \$total / \$need )) -gt 1 ] || return 1
853 if ! grep -q " keep-loram" /proc/cmdline && cp \${path}rootfs* /mnt; then
854 path=/mnt/
855 return 0
856 else
857 rm -f /mnt/rootfs*
858 return 1
859 fi
860 }
862 echo "Switching / to tmpfs..."
863 mount -t proc proc /proc
864 size="\$(grep rootfssize= < /proc/cmdline | \\
865 sed 's/.*rootfssize=\\([0-9]*[kmg%]\\).*/-o size=\\1/')"
866 [ -n "\$size" ] || size="-o size=90%"
868 if [ -x /bin/httpfs ]; then # loram-http
870 while read var default; do
871 eval \$var=\$default
872 getarg \$var \$var
873 done <<EOT
874 eth eth0
875 dns 208.67.222.222,208.67.220.220
876 netmask 255.255.255.0
877 gw
878 ip
879 EOT
880 if [ -n "\$ip" ]; then
881 ifconfig \$eth \$ip netmask \$netmask up
882 route add default gateway \$gw
883 for i in \$(echo \$dns | sed 's/,/ /g'); do
884 echo "nameserver \$i" >> /etc/resolv.conf
885 done
886 else
887 udhcpc -f -q -s /lib/udhcpc -i \$eth
888 fi
889 for i in $urliso ; do
890 [ -n "\$URLISO" ] && URLISO="\$URLISO,"
891 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"
892 done
893 getarg urliso URLISO
894 DIR=fs
895 if getarg loram DIR; then
896 DEVICE=\${DIR%,*}
897 DIR=/\${DIR#*,}
898 fi
899 mount -t tmpfs \$size tmpfs /mnt
900 path2=/mnt/.httpfs/
901 path=/mnt/.cdrom/
902 mkdir -p /mnt/.rw \$path \$path2
903 while [ ! -d \$path/boot ]; do
904 for i in \$(echo \$URLISO | sed 's/,/ /g'); do
905 httpfs \$i \$path2 && break
906 done
907 mount -o loop,ro -t iso9660 \$path2/*.iso \$path
908 done
909 #copy_rootfs && umount -d \$path && umount -d \$path2
911 elif [ -f \$(echo /rootfs*.gz | cut -f1 -d' ') ]; then # loram-ram
913 total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g')
914 free=\$(grep MemFree /proc/meminfo | sed 's/[^0-9]//g')
915 if [ \$(( \$total/\$free )) -gt 1 ] || ! mount -t tmpfs \$size tmpfs /mnt; then
916 echo "No tmpfs for /mnt"
917 mkdir -p /mnt/.rw
918 mount -t tmpfs tmpfs /mnt/.rw
919 mkdir -p /mnt/.rw/mnt/.rw
920 path=/
921 else
922 mkdir -p /mnt/.rw
923 path=/mnt/.
924 for i in rootfs* ; do
925 mv /\$i \$path\$i
926 done
927 fi
929 else # loram-cdrom
931 getarg cdrom DRIVE_NAME ||
932 DRIVE_NAME=\$(grep "drive name" < /proc/sys/dev/cdrom/info | cut -f 3)
933 DEVICE=/dev/\$DRIVE_NAME
934 DIR=fs
935 if getarg loram DIR; then
936 DEVICE=\${DIR%,*}
937 DIR=/\${DIR#*,}
938 fi
939 mount -t tmpfs \$size tmpfs /mnt
940 mkdir -p /mnt/.rw /mnt/.cdrom /mnt/mnt/.cdrom
941 i=0
942 while [ \$i -lt 5 ] && ! mount -r \$DEVICE /mnt/.cdrom; do
943 case "\$DEVICE" in
944 /dev/sd*|UUID=*|LABEL=*)
945 mount -t sysfs sysfs /sys
946 USBDELAY=\$(cat /sys/module/usb_storage/parameters/delay_use)
947 umount /sys
948 sleep \$((1+\$USBDELAY)) ;;
949 esac
950 i=\$((i+1))
951 done
952 path=/mnt/.cdrom/
953 copy_rootfs && umount -d /mnt/.cdrom
955 fi
957 memfree=\$(grep MemFree /proc/meminfo | sed 's/[^0-9]//g')
958 umount /proc
959 branch=br=/mnt/.rw:/mnt/.cdrom/\$DIR
960 if [ ! -d /mnt/.cdrom/\$DIR/etc ]; then
961 branch=br=/mnt/.rw
962 for i in \${path}rootfs* ; do
963 fs=\${i#*root}
964 branch=\$branch:/mnt/.\$fs
965 mkdir -p /mnt/.rw/mnt/.\$fs /mnt/.\$fs /mnt/.rw/mnt/.cdrom
966 if [ -f /bin/cromfs-driver ]; then
967 cromfs-driver \${path}root\$fs /mnt/.\$fs -o ro,dev,suid,allow_other
968 else
969 insmod /lib/squashfs.ko.gz 2> /dev/null
970 mount -o loop,ro -t squashfs \${path}root\$fs /mnt/.\$fs
971 fi
972 done
973 else
974 mkdir -p /mnt/.rw/mnt/.httpfs
975 fi
976 insmod /lib/aufs.ko.gz
977 mount -t aufs -o \$branch none /mnt
978 [ -x /bin/httpfs ] && sed -i 's/DHCP="yes"/DHCP="no"/' /mnt/etc/network.conf
979 [ \$memfree -lt 30000 ] && sed -i 's/ slim//' /mnt/etc/rcS.conf
980 [ -x /mnt/sbin/init ] && exec /bin/switch_root mnt /sbin/init || sh
981 EOTEOT
982 chmod +x $TMP_DIR/initfs/init
983 ( cd $TMP_DIR/initfs ; find | busybox cpio -o -H newc 2> /dev/null) | \
984 lzma e $TMP_DIR/initfs.gz -si
985 lzma_set_size $TMP_DIR/initfs.gz
986 rm -rf $TMP_DIR/initfs
987 rem=$(( $(stat -c "%s" $TMP_DIR/initfs.gz) % 4 ))
988 [ $rem -ne 0 ] &&
989 dd if=/dev/zero bs=1 count=$(( 4 - $rem )) >> $TMP_DIR/initfs.gz 2> /dev/null
990 return 0
991 }
993 # Move each initramfs to squashfs (or cromfs)
994 build_loram_rootfs()
995 {
996 rootfs_sizes=""
997 for i in $TMP_DIR/iso/boot/rootfs*.gz; do
998 mkdir -p $TMP_DIR/fs
999 cd $TMP_DIR/fs
1000 ( zcat $i 2> /dev/null || unlzma -c $i) | cpio -idm
1001 cd - > /dev/null
1002 rootfs=$TMP_DIR/$(basename $i)
1003 if [ -x /usr/bin/mkcromfs ]; then
1004 /usr/bin/mkcromfs -qq -f 262144 -b 16384 $TMP_DIR/fs $rootfs
1005 else
1006 /usr/sbin/mksquashfs $TMP_DIR/fs $rootfs -comp xz -Xbcj x86
1007 fi
1008 cd $TMP_DIR
1009 rootfs_sizes="$rootfs_sizes $(( $(du -s $TMP_DIR/fs | cut -f1) - $(du -s $rootfs | cut -f1) ))"
1010 ( cd $(dirname $rootfs); echo $(basename $rootfs) | \
1011 cpio -o -H newc ) > $rootfs.cpio
1012 rm -f $rootfs
1013 mv $rootfs.cpio $rootfs
1014 cd - > /dev/null
1015 rm -rf $TMP_DIR/fs
1016 done
1019 # Move each initramfs to squashfs (or cromfs)
1020 build_loram_rootfs_cdrom()
1022 mkdir -p $TMP_DIR/fs
1023 cd $TMP_DIR/fs
1024 for i in $(ls -r $TMP_DIR/iso/boot/rootfs*.gz); do
1025 ( zcat $i 2> /dev/null || unlzma -c $i) | cpio -idmu
1026 done
1027 rootfs=$TMP_DIR/rootfs.gz
1028 if [ -x /usr/bin/mkcromfs ]; then
1029 /usr/bin/mkcromfs -qq -f 262144 -b 16384 $TMP_DIR/fs $rootfs
1030 else
1031 /usr/sbin/mksquashfs $TMP_DIR/fs $rootfs -comp xz -Xbcj x86
1032 fi
1033 rm -rf $TMP_DIR/fs
1034 cd - > /dev/null
1037 # Move meta boot configuration files to basic configuration files
1038 # because meta loram flavor is useless when rootfs is not loaded in ram
1039 unmeta_boot()
1041 local root=${1:-$TMP_DIR/loramiso}
1042 if [ -f $root/boot/isolinux/noram.cfg ]; then
1043 # We keep enough information to do unloram...
1044 [ -s $root/boot/isolinux/common.cfg ] &&
1045 sed -i 's/label slitaz/label orgslitaz/' \
1046 $root/boot/isolinux/common.cfg
1047 set -- $(grep 'append ifmem [0-9]' $root/boot/isolinux/isolinux.cfg)
1048 shift
1049 sed -i '/ifmem/{NNNNNNNNd};/^LABEL/{N;/LABEL SliTaz [^L]/{NNNd}}' \
1050 $root/boot/isolinux/isolinux.cfg
1051 [ -n "$3" ] || set -- $(grep 'append [0-9]' $root/boot/isolinux/common.cfg)
1052 sed -i "s/label $3\$/label slitaz/;s|=/boot/rootfs\(.*\).gz |=/boot/rootfs.gz |" \
1053 $root/boot/isolinux/*.cfg
1054 fi
1057 # Move rootfs to squashfs filesystem(s) to the cdrom writeable with aufs.
1058 # These squashfs may be loaded in ram a boot time.
1059 # Rootfs are also copied to cdrom for tiny ramsize systems.
1060 # Meta flavors are converted to normal flavors.
1061 build_loram_cdrom()
1063 build_initfs cdrom || return 1
1064 build_loram_rootfs_cdrom
1065 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1066 if [ "$1" == "small" ]; then
1067 rm -f $TMP_DIR/loramiso/boot/root*
1068 else
1069 mkdir $TMP_DIR/loramiso/fs
1070 cd $TMP_DIR/loramiso/fs
1071 for i in $( ls ../boot/root* | sort -r ) ; do
1072 ( zcat $i 2> /dev/null || unlzma -c $i ) | cpio -idmu
1073 rm -f $i
1074 done
1075 mkdir -p $TMP_DIR/loramiso/fs/mnt/.cdrom
1076 cd - > /dev/null
1077 fi
1078 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
1079 mv $TMP_DIR/rootfs*.gz $TMP_DIR/loramiso
1080 unmeta_boot
1081 VOLUM_NAME="SliTaz_LoRAM_CDROM"
1082 sed -i "s/root=/loram=LABEL=$VOLUM_NAME,fs &/" \
1083 $TMP_DIR/loramiso/boot/isolinux/*.cfg
1084 create_iso $OUTPUT $TMP_DIR/loramiso
1087 # Create http bootstrap to load and remove loram_cdrom
1088 # Meta flavors are converted to normal flavors.
1089 build_loram_http()
1091 build_initfs http || return 1
1092 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1093 rm -f $TMP_DIR/loramiso/boot/rootfs*
1094 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
1095 unmeta_boot
1096 create_iso $OUTPUT $TMP_DIR/loramiso
1099 # Update meta flavor selection sizes.
1100 # Reduce sizes with rootfs gains.
1101 update_metaiso_sizes()
1103 for cfg in $(grep -El '(append|ifmem) [0-9]' $TMP_DIR/loramiso/boot/isolinux/*.cfg)
1104 do
1105 local append="$(grep -E '(append|ifmem) [0-9]' $cfg)"
1106 local sizes="$rootfs_sizes"
1107 local new
1108 set -- $append
1109 shift
1110 [ "$1" == "ifmem" ] && shift
1111 new=""
1112 while [ -n "$2" ]; do
1113 local s
1114 case "$1" in
1115 *G) s=$(( ${1%G} * 1024 * 1024 ));;
1116 *M) s=$(( ${1%M} * 1024 ));;
1117 *) s=${1%K};;
1118 esac
1119 sizes=${sizes#* }
1120 for i in $sizes ; do
1121 s=$(( $s - $i ))
1122 done
1123 new="$new $s $2"
1124 shift 2
1125 done
1126 sed -i -e "/append [0-9]/s/append .*/append$new $1/" -e \
1127 "/append ifmem [0-9]/s/append .*/append ifmem$new $1/" $cfg
1128 done
1131 # Move rootfs to a squashfs filesystem into the initramfs writeable with aufs.
1132 # Meta flavor selection sizes are updated.
1133 build_loram_ram()
1135 build_initfs ram || return 1
1136 build_loram_rootfs
1137 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1138 rm -f $TMP_DIR/loramiso/boot/bzImage
1139 ln $TMP_DIR/loramiso/boot/vmlinuz* $TMP_DIR/loramiso/boot/bzImage
1140 rootfs=$(ls $TMP_DIR/rootfs* | sort | tail -n 1)
1141 cat $rootfs >> $TMP_DIR/initfs.gz
1142 mv $TMP_DIR/initfs.gz $rootfs
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 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
1962 EXTRAVERSION=""
1963 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
1964 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
1965 done
1966 fi
1967 # Exit if no list name.
1968 if [ ! -f "$LIST_NAME" ]; then
1969 echo -e "\nNo packages list found or specified. Please read the docs.\n"
1970 exit 0
1971 fi
1972 # Start generation.
1973 echo ""
1974 echo -e "\033[1mTazlito generating a distro\033[0m"
1975 separator
1976 # Misc checks
1977 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
1978 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
1979 # Get the list of packages using cat for a file list.
1980 LIST=`cat $LIST_NAME`
1981 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
1982 REPACK=""
1983 DOWNLOAD=""
1984 for pkg in $LIST
1985 do
1986 [ "$pkg" = "" ] && continue
1987 pkg=${pkg%.tazpkg}
1988 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
1989 PACKAGE=$(installed_package_name $pkg)
1990 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
1991 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
1992 echo -e "\nUnable to find $pkg in the repository."
1993 echo -e "Path : $PACKAGES_REPOSITORY\n"
1994 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
1995 yesorno "Repack packages from rootfs (y/N) ? "
1996 REPACK="$answer"
1997 [ "$answer" = "y" ] || REPACK="n"
1998 [ "$DOWNLOAD" = "y" ] && break
1999 fi
2000 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
2001 yesorno "Download packages from mirror (Y/n) ? "
2002 DOWNLOAD="$answer"
2003 if [ "$answer" = "n" ]; then
2004 [ -z "$PACKAGE" ] && exit 1
2005 else
2006 DOWNLOAD="y"
2007 [ -n "$REPACK" ] && break
2008 fi
2009 fi
2010 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
2011 done
2013 # Mount cdrom to be able to repack boot-loader packages
2014 if [ ! -e /boot -a -n "$CDROM" ]; then
2015 mkdir $TMP_MNT
2016 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
2017 ln -s $TMP_MNT/boot /
2018 if [ ! -d "$ADDFILES/rootcd" ] ; then
2019 mkdir -p $ADDFILES/rootcd
2020 for i in $(ls $TMP_MNT); do
2021 [ "$i" = "boot" ] && continue
2022 cp -a $TMP_MNT/$i $ADDFILES/rootcd
2023 done
2024 fi
2025 else
2026 rmdir $TMP_MNT
2027 fi
2028 fi
2030 # Root fs stuff.
2031 echo "Preparing the rootfs directory..."
2032 mkdir -p $ROOTFS
2033 for pkg in $LIST
2034 do
2035 [ "$pkg" = "" ] && continue
2036 # First copy and extract the package in tmp dir.
2037 pkg=${pkg%.tazpkg}
2038 PACKAGE=$(installed_package_name $pkg)
2039 mkdir -p $TMP_DIR
2040 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
2041 # Look for package in cache
2042 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
2043 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
2044 # Look for package in running distribution
2045 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
2046 tazpkg repack $PACKAGE && \
2047 mv $pkg.tazpkg $PACKAGES_REPOSITORY
2048 fi
2049 fi
2050 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
2051 # Get package from mirror
2052 [ "$DOWNLOAD" = "y" ] && \
2053 download $pkg.tazpkg && \
2054 mv $pkg.tazpkg $PACKAGES_REPOSITORY
2055 fi
2056 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
2057 echo "Missing package $pkg."
2058 cleanup
2059 exit 1
2060 fi
2061 done
2062 if [ -f non-free.list ]; then
2063 echo "Preparing non-free packages..."
2064 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
2065 for pkg in $(cat non-free.list); do
2066 if [ ! -d $INSTALLED/$pkg ]; then
2067 if [ ! -d $INSTALLED/get-$pkg ]; then
2068 tazpkg get-install get-$pkg
2069 fi
2070 get-$pkg
2071 fi
2072 tazpkg repack $pkg
2073 pkg=$(ls $pkg*.tazpkg)
2074 grep -q "^$pkg$" $LIST_NAME || \
2075 echo $pkg >>$LIST_NAME
2076 mv $pkg $PACKAGES_REPOSITORY
2077 done
2078 fi
2079 cp $LIST_NAME $DISTRO/distro-packages.list
2080 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/distro-packages.list > $DISTRO/list-packages
2081 cd $PACKAGES_REPOSITORY
2082 for pkg in $(cat $DISTRO/list-packages)
2083 do
2084 echo -n "Installing package: $pkg"
2085 yes y | tazpkg install $pkg --root=$ROOTFS 2>&1 >> $log || exit 1
2086 status
2087 done
2088 rm -f $ROOTFS/var/lib/tazpkg/packages.*
2089 cd $DISTRO
2090 cp distro-packages.list $ROOTFS/etc/tazlito
2091 # Copy all files from $ADDFILES/rootfs to the rootfs.
2092 if [ -d "$ADDFILES/rootfs" ] ; then
2093 echo -n "Copying addfiles content to the rootfs... "
2094 cp -a $ADDFILES/rootfs/* $ROOTFS
2095 status
2096 fi
2097 echo -n "Root filesystem is generated..." && status
2098 # Root CD part.
2099 echo -n "Preparing the rootcd directory..."
2100 mkdir -p $ROOTCD
2101 status
2102 # Move the boot dir with the Linux kernel from rootfs.
2103 # The boot dir goes directly on the CD.
2104 if [ -d "$ROOTFS/boot" ] ; then
2105 echo -n "Moving the boot directory..."
2106 mv $ROOTFS/boot $ROOTCD
2107 cd $ROOTCD/boot
2108 ln vmlinuz-* bzImage
2109 status
2110 fi
2111 cd $DISTRO
2112 # Copy all files from $ADDFILES/rootcd to the rootcd.
2113 if [ -d "$ADDFILES/rootcd" ] ; then
2114 echo -n "Copying addfiles content to the rootcd... "
2115 cp -a $ADDFILES/rootcd/* $ROOTCD
2116 status
2117 fi
2118 # Execute the distro script used to perform tasks in the rootfs
2119 # before compression. Give rootfs path in arg
2120 [ -z $DISTRO_SCRIPT ] && DISTRO_SCRIPT=$TOP_DIR/distro.sh
2121 if [ -x $DISTRO_SCRIPT ]; then
2122 echo "Executing distro script..."
2123 sh $DISTRO_SCRIPT $DISTRO
2124 fi
2125 if [ -s /etc/tazlito/rootfs.list ]; then
2126 FLAVOR_LIST="$(awk '{ for (i = 2; i <= NF; i+=2) \
2127 printf("%s ",$i) }' < /etc/tazlito/rootfs.list)"
2128 sed -i "s/ *//;s/)/), flavors $FLAVOR_LIST/" \
2129 $ROOTCD/boot/isolinux/isolinux.msg 2> /dev/null
2130 [ -f $ROOTCD/boot/isolinux/ifmem.c32 ] ||
2131 cp /boot/isolinux/ifmem.c32 $ROOTCD/boot/isolinux
2132 n=0
2133 last=$ROOTFS
2134 while read flavor; do
2135 n=$(($n+1))
2136 echo "Building $flavor rootfs..."
2137 [ -s $TOP_DIR/$flavor.flavor ] &&
2138 cp $TOP_DIR/$flavor.flavor .
2139 [ -s $flavor.flavor ] || download $flavor.flavor
2140 zcat $flavor.flavor | cpio -i \
2141 $flavor.pkglist $flavor.rootfs
2142 sed 's/.*/&.tazpkg/' < $flavor.pkglist \
2143 > $DISTRO/list-packages0$n
2144 mkdir ${ROOTFS}0$n
2145 cd $PACKAGES_REPOSITORY
2146 yes y | tazpkg install-list \
2147 $DISTRO/list-packages0$n --root=${ROOTFS}0$n
2148 rm -rf ${ROOTFS}0$n/boot ${ROOTFS}0$n/var/lib/tazpkg/packages.*
2149 status
2150 cd $DISTRO
2151 if [ -s $flavor.rootfs ]; then
2152 echo "Adding $flavor rootfs extra files..."
2153 zcat $flavor.rootfs | \
2154 ( cd ${ROOTFS}0$n ; cpio -idmu )
2155 fi
2156 mv $flavor.pkglist ${ROOTFS}0$n/etc/tazlito/distro-packages.list
2157 rm -f $flavor.flavor install-list
2158 mergefs ${ROOTFS}0$n $last
2159 last=${ROOTFS}0$n
2160 done <<EOT
2161 $(awk '{ for (i = 4; i <= NF; i+=2) print $i; }' < /etc/tazlito/rootfs.list)
2162 EOT
2163 i=$(($n+1))
2164 while [ $n -gt 0 ]; do
2165 mv ${ROOTFS}0$n ${ROOTFS}$i
2166 echo "Compression ${ROOTFS}0$n ($(du -hs ${ROOTFS}$i | awk '{ print $1 }')) ..."
2167 gen_initramfs ${ROOTFS}$i
2168 n=$(($n-1))
2169 i=$(($i-1))
2170 done
2171 mv $ROOTFS ${ROOTFS}$i
2172 gen_initramfs ${ROOTFS}$i
2173 update_bootconfig $ROOTCD/boot/isolinux \
2174 "$(cat /etc/tazlito/rootfs.list)"
2175 else
2176 # Initramfs and ISO image stuff.
2177 gen_initramfs $ROOTFS
2178 fi
2179 gen_livecd_isolinux
2180 distro_stats
2181 cleanup
2182 ;;
2183 clean-distro)
2184 # Remove old distro tree.
2186 check_root
2187 echo ""
2188 boldify "Cleaning : $DISTRO"
2189 separator
2190 if [ -d "$DISTRO" ] ; then
2191 if [ -d "$ROOTFS" ] ; then
2192 echo -n "Removing the rootfs..."
2193 rm -f $DISTRO/$INITRAMFS
2194 rm -rf $ROOTFS
2195 status
2196 fi
2197 if [ -d "$ROOTCD" ] ; then
2198 echo -n "Removing the rootcd..."
2199 rm -rf $ROOTCD
2200 status
2201 fi
2202 echo -n "Removing eventual ISO image..."
2203 rm -f $DISTRO/$ISO_NAME.iso
2204 rm -f $DISTRO/$ISO_NAME.md5
2205 status
2206 fi
2207 separator
2208 echo "" ;;
2209 check-distro)
2210 # Check for a few LiveCD needed files not installed by packages.
2212 check_rootfs
2213 echo ""
2214 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
2215 separator
2216 # SliTaz release info.
2217 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
2218 echo "Missing release info : /etc/slitaz-release"
2219 else
2220 release=`cat $ROOTFS/etc/slitaz-release`
2221 echo -n "Release : $release"
2222 status
2223 fi
2224 # Tazpkg mirror.
2225 if [ ! -f "$ROOTFS$LOCALSTATE/mirror" ]; then
2226 echo -n "Mirror URL : Missing $LOCALSTATE/mirror"
2227 todomsg
2228 else
2229 echo -n "Mirror configuration exists..."
2230 status
2231 fi
2232 # Isolinux msg
2233 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.*g; then
2234 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
2235 todomsg
2236 else
2237 echo -n "Isolinux message seems good..."
2238 status
2239 fi
2240 separator
2241 echo ""
2242 ;;
2243 writeiso)
2244 # Writefs to ISO image including /home unlike gen-distro we dont use
2245 # packages to generate a rootfs, we build a compressed rootfs with all
2246 # the current filesystem similar to 'tazusb writefs'.
2248 DISTRO="/home/slitaz/distro"
2249 ROOTCD="$DISTRO/rootcd"
2250 if [ -z $2 ]; then
2251 COMPRESSION=none
2252 else
2253 COMPRESSION=$2
2254 fi
2255 if [ -z $3 ]; then
2256 ISO_NAME="slitaz"
2257 else
2258 ISO_NAME="$3"
2259 fi
2260 check_root
2261 # Start info
2262 echo ""
2263 echo -e "\033[1mWrite filesystem to ISO\033[0m
2264 ===============================================================================
2265 The command writeiso will write the current filesystem into a suitable cpio
2266 archive (rootfs.gz) and generate a bootable ISO image (slitaz.iso).
2268 Archive compression: $COMPRESSION"
2269 echo ""
2271 # Save some space
2272 rm /var/cache/tazpkg/* -r -f
2273 rm -rf /home/slitaz/distro
2275 # Optionally remove sound card selection and screen resolution.
2276 echo "Do you wish to remove the sound card and screen configs ? "
2277 echo -n "Press ENTER to keep or answer (No|yes|exit): "
2278 read anser
2279 case $anser in
2280 e|E|"exit"|Exit)
2281 exit 0 ;;
2282 y|Y|yes|Yes)
2283 echo -n "Removing current sound card and screen configurations..."
2284 rm -f /var/lib/sound-card-driver
2285 rm -f /etc/asound.state
2286 rm -f /etc/X11/screen.conf
2287 rm -f /etc/X11/xorg.conf ;;
2288 *)
2289 echo -n "Keeping current sound card and screen configurations..." ;;
2290 esac
2291 status
2293 cd /
2294 # Create list of files including default user files since it is defined in /etc/passwd
2295 # and some new users might have been added.
2296 find bin etc init sbin var dev lib root usr home >/tmp/list
2298 for dir in proc sys tmp mnt media media/cdrom media/flash media/usbdisk
2299 do
2300 echo $dir >>/tmp/list
2301 done
2303 # Generate initramfs with specified compression and display rootfs
2304 # size in realtime.
2305 rm -f /tmp/rootfs
2306 write_initramfs &
2307 sleep 2
2308 cd - > /dev/null
2309 echo -en "\nFilesystem size:"
2310 while [ ! -f /tmp/rootfs ]
2311 do
2312 sleep 1
2313 echo -en "\\033[18G`du -sh /rootfs.gz | awk '{print $1}'` "
2314 done
2315 echo -e "\n"
2317 # Move freshly generated rootfs to the cdrom.
2318 mkdir -p $ROOTCD/boot
2319 mv -f /rootfs.gz $ROOTCD/boot
2321 # Now we need the kernel and isolinux files.
2322 if mount /dev/cdrom /media/cdrom 2>/dev/null; then
2323 cp /media/cdrom/boot/bzImage $ROOTCD/boot
2324 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
2325 unmeta_boot $ROOTCD
2326 umount /media/cdrom
2327 elif mount |grep /media/cdrom; then
2328 cp /media/cdrom/boot/bzImage $ROOTCD/boot
2329 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
2330 unmeta_boot $ROOTCD
2331 umount /media/cdrom;
2332 else
2333 echo -e "
2334 When SliTaz is running in RAM the kernel and bootloader files are kept
2335 on the cdrom. Please insert a LiveCD or loop mount the slitaz.iso to
2336 /media/cdrom to let Tazlito copy the files.\n"
2337 echo -en "----\nENTER to continue..."; read i
2338 exit 1
2339 fi
2341 # Generate the iso image.
2342 cd $DISTRO
2343 echo "Generating ISO image..."
2344 genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
2345 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
2346 -V "SliTaz" -input-charset iso8859-1 -boot-info-table $ROOTCD
2347 if [ -x /usr/bin/isohybrid ]; then
2348 echo -n "Creating hybrid ISO..."
2349 /usr/bin/isohybrid $ISO_NAME.iso -entry 2 2> /dev/null
2350 status
2351 fi
2352 echo -n "Creating the ISO md5sum..."
2353 md5sum $ISO_NAME.iso > $ISO_NAME.md5
2354 status
2356 echo "==============================================================================="
2357 echo "ISO image: `du -sh /home/slitaz/distro/$ISO_NAME.iso`"
2358 echo ""
2359 echo -n "Exit or burn ISO to cdrom (Exit|burn)? "; read anser
2360 case $anser in
2361 burn)
2362 eject
2363 echo -n "Please insert a blank cdrom and press ENTER..."
2364 read i && sleep 2
2365 tazlito burn-iso /home/slitaz/distro/$ISO_NAME.iso
2366 echo -en "----\nENTER to continue..."; read i ;;
2367 *)
2368 exit 0 ;;
2369 esac ;;
2370 burn-iso)
2371 # Guess cdrom device, ask user and burn the ISO.
2373 check_root
2374 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
2375 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
2376 # We can specify an alternative ISO from the cmdline.
2377 if [ -n "$2" ] ; then
2378 iso=$2
2379 else
2380 iso=$DISTRO/$ISO_NAME.iso
2381 fi
2382 if [ ! -f "$iso" ]; then
2383 echo -e "\nUnable to find ISO : $iso\n"
2384 exit 0
2385 fi
2386 echo ""
2387 echo -e "\033[1mTazlito burn ISO\033[0m "
2388 separator
2389 echo "Cdrom device : /dev/$DRIVE_NAME"
2390 echo "Drive speed : $DRIVE_SPEED"
2391 echo "ISO image : $iso"
2392 separator
2393 echo ""
2394 yesorno "Burn ISO image (y/N) ? "
2395 if [ "$answer" == "y" ]; then
2396 echo ""
2397 echo "Starting Wodim to burn the iso..." && sleep 2
2398 separator
2399 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
2400 separator
2401 echo "ISO image is burned to cdrom."
2402 else
2403 echo -e "\nExiting. No ISO burned."
2404 fi
2405 echo ""
2406 ;;
2407 merge)
2408 # Merge multiple rootfs into one iso.
2410 if [ -z "$2" ]; then
2411 cat << EOT
2412 Usage: tazlito merge size1 iso size2 rootfs2 [sizeN rootfsN]...
2414 Merge multiple rootfs into one iso. Rootfs are like russian dolls
2415 i.e: rootfsN is a subset of rootfsN-1
2416 rootfs1 is found in iso, sizeN is the RAM size need to launch rootfsN.
2417 The boot loader will select the rootfs according to the RAM size detected.
2419 Example:
2420 $ tazlito merge 160M slitaz-core.iso 96M rootfs-justx.gz 32M rootfs-base.gz
2422 Will start slitaz-core with 160M+ RAM, slitaz-justX with 96M-160M RAM,
2423 slitaz-base with 32M-96M RAM and display an error message if RAM < 32M.
2424 EOT
2425 exit 2
2426 fi
2428 shift # skip merge
2429 append="$1 slitaz1"
2430 shift # skip size1
2431 mkdir -p $TMP_DIR/mnt $TMP_DIR/rootfs1
2433 ISO=$1.merged
2434 # Extract filesystems
2435 echo -n "Mounting $1"
2436 mount -o loop,ro $1 $TMP_DIR/mnt 2> /dev/null
2437 status || cleanup_merge
2438 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2439 rm -f $TMP_DIR/iso/boot/bzImage
2440 ln $TMP_DIR/iso/boot/vmlinuz* $TMP_DIR/iso/boot/bzImage
2441 umount -d $TMP_DIR/mnt
2442 if [ -f $TMP_DIR/iso/boot/rootfs1.gz ]; then
2443 echo "$1 is already a merged iso. Aborting."
2444 cleanup_merge
2445 fi
2446 if [ ! -f $TMP_DIR/iso/boot/isolinux/ifmem.c32 -a
2447 ! -f $TMP_DIR/iso/boot/isolinux/c32box.c32 ]; then
2448 if [ ! -f /boot/isolinux/ifmem.c32 -a
2449 ! -f /boot/isolinux/c32box.c32 ]; then
2450 cat <<EOT
2451 No file /boot/isolinux/ifmem.c32
2452 Please install syslinux package !
2453 EOT
2454 rm -rf $TMP_DIR
2455 exit 1
2456 fi
2457 cp /boot/isolinux/c32box.c32 $TMP_DIR/iso/boot/isolinux 2> /dev/null ||
2458 cp /boot/isolinux/ifmem.c32 $TMP_DIR/iso/boot/isolinux
2459 fi
2461 echo -n "Extracting iso/rootfs.gz"
2462 extract_rootfs $TMP_DIR/iso/boot/rootfs.gz $TMP_DIR/rootfs1 &&
2463 [ -d $TMP_DIR/rootfs1/etc ]
2464 status || cleanup_merge
2465 n=1
2466 while [ -n "$2" ]; do
2467 shift # skip rootfs N-1
2468 p=$n
2469 n=$(($n + 1))
2470 append="$append $1 slitaz$n"
2471 shift # skip size N
2472 mkdir -p $TMP_DIR/rootfs$n
2473 echo -n "Extracting $1"
2474 extract_rootfs $1 $TMP_DIR/rootfs$n &&
2475 [ -d $TMP_DIR/rootfs$n/etc ]
2476 status || cleanup_merge
2477 mergefs $TMP_DIR/rootfs$n $TMP_DIR/rootfs$p
2478 echo "Creating rootfs$p.gz"
2479 pack_rootfs $TMP_DIR/rootfs$p $TMP_DIR/iso/boot/rootfs$p.gz
2480 status
2481 done
2482 echo "Creating rootfs$n.gz"
2483 pack_rootfs $TMP_DIR/rootfs$n $TMP_DIR/iso/boot/rootfs$n.gz
2484 status
2485 rm -f $TMP_DIR/iso/boot/rootfs.gz
2486 update_bootconfig $TMP_DIR/iso/boot/isolinux "$append"
2487 create_iso $ISO $TMP_DIR/iso
2488 rm -rf $TMP_DIR
2489 ;;
2491 repack)
2492 # Repack an iso with maximum lzma compression ratio.
2495 ISO=$2
2497 mkdir -p $TMP_DIR/mnt
2498 # Extract filesystems
2499 echo -n "Mounting $ISO"
2500 mount -o loop,ro $ISO $TMP_DIR/mnt 2> /dev/null
2501 status || cleanup_merge
2502 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2503 umount -d $TMP_DIR/mnt
2505 for i in $TMP_DIR/iso/boot/rootfs* ; do
2506 echo -n "Repacking $(basename $i)"
2507 (zcat $i 2> /dev/null || unlzma -c $i || cat $i) \
2508 2>/dev/null > $TMP_DIR/rootfs
2509 lzma e $TMP_DIR/rootfs $i \
2510 $(lzma_switches $TMP_DIR/rootfs)
2511 status
2512 done
2514 create_iso $ISO $TMP_DIR/iso
2515 rm -rf $TMP_DIR ;;
2517 build-loram)
2518 # Build a Live CD for low ram systems.
2521 ISO=$2
2522 OUTPUT=$3
2523 if [ -z "$3" ]; then
2524 echo "Usage: tazlito $1 input.iso output.iso [cdrom|smallcdrom|http|ram]"
2525 exit 1
2526 fi
2527 mkdir -p $TMP_DIR/iso
2528 mount -o loop,ro -t iso9660 $ISO $TMP_DIR/iso
2529 loopdev=$(losetup | grep $ISO | cut -d: -f1)
2530 if ! check_iso_for_loram ; then
2531 echo "$2 is not a valid SliTaz live CD. Abort."
2532 umount -d $TMP_DIR/iso
2533 rm -rf $TMP_DIR
2534 exit 1
2535 fi
2537 case "$4" in
2538 cdrom) build_loram_cdrom ;;
2539 smallcdrom) build_loram_cdrom small ;;
2540 http) build_loram_http ;;
2541 *) build_loram_ram ;;
2542 esac
2543 umount $TMP_DIR/iso # no -d: needs /proc
2544 losetup -d $loopdev
2545 rm -rf $TMP_DIR ;;
2548 frugal-install|-fi)
2549 ISO_IMAGE="$2"
2550 echo ""
2551 mkdir -p /boot/frugal
2552 if [ -f "$ISO_IMAGE" ]; then
2553 echo -n "Using ISO image: $ISO_IMAGE"
2554 mkdir -p /tmp/iso && mount -o loop $ISO_IMAGE /tmp/iso
2555 status
2556 echo -n "Installing the Kernel and rootfs..."
2557 cp -a /tmp/iso/boot/bzImage /boot/frugal
2558 if [ -f $DISTRO/rootcd/boot/rootfs1.gz ]; then
2559 cd /tmp/iso/boot
2560 cat $(ls -r rootfs*.gz) > /boot/frugal/rootfs.gz
2561 else
2562 cp -a /tmp/iso/boot/rootfs.gz /boot/frugal
2563 fi
2564 umount /tmp/iso
2565 status
2566 else
2567 echo -n "Using distro: $DISTRO"
2568 cd $DISTRO && status
2569 echo -n "Installing the Kernel and rootfs..."
2570 cp -a $DISTRO/rootcd/boot/bzImage /boot/frugal
2571 if [ -f $DISTRO/rootcd/boot/rootfs1.gz ]; then
2572 cd $DISTRO/rootcd/boot
2573 cat $(ls -r rootfs*.gz) > /boot/frugal/rootfs.gz
2574 else
2575 cp -a $DISTRO/rootcd/boot/rootfs.gz /boot/frugal
2576 fi
2577 status
2578 fi
2579 # Grub entry
2580 if ! grep -q "^kernel /boot/frugal/bzImage" /boot/grub/menu.lst; then
2581 echo -n "Configuring GRUB menu list..."
2582 cat >> /boot/grub/menu.lst << EOT
2583 title SliTaz GNU/Linux (frugal)
2584 root (hd0,0)
2585 kernel /boot/frugal/bzImage root=/dev/null
2586 initrd /boot/frugal/rootfs.gz
2587 EOT
2588 else
2589 echo -n "GRUB menu list is up-to-date..."
2590 fi
2591 status
2592 echo "" ;;
2594 emu-iso)
2595 # Emulate an ISO image with Qemu.
2596 if [ -n "$2" ] ; then
2597 iso=$2
2598 else
2599 iso=$DISTRO/$ISO_NAME.iso
2600 fi
2601 if [ ! -f "$iso" ]; then
2602 echo -e "\nUnable to find ISO : $iso\n"
2603 exit 0
2604 fi
2605 if [ ! -x "/usr/bin/qemu" ]; then
2606 echo -e "\nUnable to find Qemu binary. Please install: qemu\n"
2607 exit 0
2608 fi
2609 echo -e "\nStarting Qemu emulator:\n"
2610 echo -e "qemu $QEMU_OPTS $iso\n"
2611 qemu $QEMU_OPTS $iso ;;
2613 deduplicate)
2614 # Deduplicate files in a tree
2615 shift
2616 deduplicate "$@" ;;
2617 usage|*)
2618 # Clear and print usage also for all unknown commands.
2620 clear
2621 usage ;;
2622 esac
2624 exit 0