tazlito view tazlito @ rev 278

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