tazlito view tazlito @ rev 274

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