tazlito view tazlito @ rev 196

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