tazlito view tazlito @ rev 275

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