tazlito view tazlito @ rev 193

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