tazlito view tazlito @ rev 234

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