tazlito view tazlito @ rev 192

tazlito: update aufs package name
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Dec 18 17:04:50 2010 +0100 (2010-12-18)
parents 21ba70c9bd53
children eafe7213ce8e
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 date
1043 rm -rf $1/var/lib/tazpkg/installed*
1045 # Cleanup directory tree
1046 cd $1
1047 find * -type d | sort -r | while read dir; do
1048 rmdir $dir 2> /dev/null
1049 done
1050 cd - > /dev/null
1053 ####################
1054 # Tazlito commands #
1055 ####################
1057 case "$COMMAND" in
1058 stats)
1059 # Tazlito general statistics from the config file.
1061 echo ""
1062 echo -e "\033[1mTazlito statistics\033[0m
1063 ===============================================================================
1064 Config file : $CONFIG_FILE
1065 ISO name : $ISO_NAME.iso
1066 Volume name : $VOLUM_NAME
1067 Prepared : $PREPARED
1068 Packages repository : $PACKAGES_REPOSITORY
1069 Distro directory : $DISTRO"
1070 if [ ! "$ADDFILES" = "" ] ; then
1071 echo -e "Additional files : $ADDFILES"
1072 fi
1073 echo "================================================================================"
1074 echo ""
1075 ;;
1076 list-addfiles)
1077 # Simple list of additional files in the rootfs
1078 echo ""
1079 cd $ADDFILES
1080 find rootfs -type f
1081 echo "" ;;
1082 gen-config)
1083 # Generate a new config file in the current dir or the specified
1084 # directory by $2.
1086 if [ -n "$2" ] ; then
1087 mkdir -p $2 && cd $2
1088 fi
1089 echo -n "Generating empty tazlito.conf..."
1090 empty_config_file
1091 status
1092 echo ""
1093 if [ -f "tazlito.conf" ] ; then
1094 echo "Configuration file is ready to edit."
1095 echo "File location : `pwd`/tazlito.conf"
1096 echo ""
1097 fi
1098 ;;
1099 configure)
1100 # Configure a tazlito.conf config file. Start by getting
1101 # a empty config file and sed it.
1103 if [ -f "tazlito.conf" ] ; then
1104 rm tazlito.conf
1105 else
1106 if test $(id -u) = 0 ; then
1107 cd /etc
1108 else
1109 echo "You must be root to configure the main config file or in"
1110 echo "the same directory of the file you want to configure."
1111 exit 0
1112 fi
1113 fi
1114 empty_config_file
1115 echo""
1116 echo -e "\033[1mConfiguring :\033[0m `pwd`/tazlito.conf"
1117 echo "================================================================================"
1118 # ISO name.
1119 echo -n "ISO name : " ; read answer
1120 sed -i s#'ISO_NAME=\"\"'#"ISO_NAME=\"$answer\""# tazlito.conf
1121 # Volume name.
1122 echo -n "Volume name : " ; read answer
1123 sed -i s/'VOLUM_NAME=\"SliTaz\"'/"VOLUM_NAME=\"$answer\""/ tazlito.conf
1124 # Packages repository.
1125 echo -n "Packages repository : " ; read answer
1126 sed -i s#'PACKAGES_REPOSITORY=\"\"'#"PACKAGES_REPOSITORY=\"$answer\""# tazlito.conf
1127 # Distro path.
1128 echo -n "Distro path : " ; read answer
1129 sed -i s#'DISTRO=\"\"'#"DISTRO=\"$answer\""# tazlito.conf
1130 echo "================================================================================"
1131 echo "Config file is ready to use."
1132 echo "You can now extract an ISO or generate a distro."
1133 echo ""
1134 ;;
1135 gen-iso)
1136 # Simply generate a new iso.
1138 check_root
1139 verify_rootcd
1140 gen_livecd_isolinux
1141 distro_stats
1142 ;;
1143 gen-initiso)
1144 # Simply generate a new initramfs with a new iso.
1146 check_root
1147 verify_rootcd
1148 gen_initramfs $ROOTFS
1149 gen_livecd_isolinux
1150 distro_stats
1151 ;;
1152 extract-distro)
1153 # Extract an ISO image to a directory and rebuild the LiveCD tree.
1155 check_root
1156 ISO_IMAGE=$2
1157 if [ -z "$ISO_IMAGE" ] ; then
1158 echo -e "\nPlease specify the path to the ISO image."
1159 echo -e "Example : `basename $0` image.iso /path/target\n"
1160 exit 0
1161 fi
1162 # Set the distro path by checking for $3 on cmdline.
1163 if [ -n "$3" ] ; then
1164 TARGET=$3
1165 else
1166 TARGET=$DISTRO
1167 fi
1168 # Exit if existing distro is found.
1169 if [ -d "$TARGET/rootfs" ] ; then
1170 echo -e "\nA rootfs exists in : $TARGET"
1171 echo -e "Please clean the distro tree or change directory path.\n"
1172 exit 0
1173 fi
1174 echo ""
1175 echo -e "\033[1mTazlito extracting :\033[0m `basename $ISO_IMAGE`"
1176 echo "================================================================================"
1177 # Start to mount the ISO.
1178 echo ""
1179 echo "Mounting ISO image..."
1180 mkdir -p $TMP_DIR
1181 # Get ISO file size.
1182 isosize=`du -sh $ISO_IMAGE | cut -f1`
1183 mount -o loop $ISO_IMAGE $TMP_DIR
1184 sleep 2
1185 # Prepare target dir, copy the kernel and the rootfs.
1186 mkdir -p $TARGET/rootfs
1187 mkdir -p $TARGET/rootcd/boot
1188 echo -n "Copying the Linux kernel..."
1189 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
1190 ln $TARGET/rootcd/boot/vmlinuz* $TARGET/rootcd/boot/bzImage
1191 else
1192 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
1193 fi
1194 status
1195 echo -n "Copying isolinux files..."
1196 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
1197 for i in $(ls $TMP_DIR); do
1198 [ "$i" = "boot" ] && continue
1199 cp -a $TMP_DIR/$i $TARGET/rootcd
1200 done
1201 status
1202 if [ -d $TMP_DIR/boot/syslinux ]; then
1203 echo -n "Copying syslinux files..."
1204 cp -a $TMP_DIR/boot/syslinux $TARGET/rootcd/boot
1205 status
1206 fi
1207 if [ -d $TMP_DIR/boot/extlinux ]; then
1208 echo -n "Copying extlinux files..."
1209 cp -a $TMP_DIR/boot/extlinux $TARGET/rootcd/boot
1210 status
1211 fi
1212 if [ -d $TMP_DIR/boot/grub ]; then
1213 echo -n "Copying GRUB files..."
1214 cp -a $TMP_DIR/boot/grub $TARGET/rootcd/boot
1215 status
1216 fi
1218 echo -n "Copying the rootfs..."
1219 cp $TMP_DIR/boot/rootfs.?z $TARGET/rootcd/boot
1220 status
1221 # Extract initramfs.
1222 cd $TARGET/rootfs
1223 echo -n "Extracting the rootfs... "
1224 extract_rootfs ../rootcd/boot/rootfs.gz $TARGET/rootfs
1225 # unpack /usr
1226 for i in etc/tazlito/*.extract; do
1227 [ -f "$i" ] && . $i ../rootcd
1228 done
1229 # Umount and remove temp directory and cd to $TARGET to get stats.
1230 umount $TMP_DIR && rm -rf $TMP_DIR
1231 cd ..
1232 echo ""
1233 echo "================================================================================"
1234 echo "Extracted : `basename $ISO_IMAGE` ($isosize)"
1235 echo "Distro tree : `pwd`"
1236 echo "Rootfs size : `du -sh rootfs`"
1237 echo "Rootcd size : `du -sh rootcd`"
1238 echo "================================================================================"
1239 echo ""
1240 ;;
1241 list-flavors)
1242 # Show available flavors.
1243 if [ ! -s /etc/tazlito/flavors.list -o "$2" == "--recharge" ]; then
1244 download flavors.list -O - > /etc/tazlito/flavors.list
1245 fi
1246 echo ""
1247 echo -e "\033[1mList of flavors\033[0m"
1248 echo "================================================================================"
1249 cat /etc/tazlito/flavors.list
1250 echo ""
1251 ;;
1252 show-flavor)
1253 # Show flavor description.
1254 FLAVOR=${2%.flavor}
1255 if [ ! -f "$FLAVOR.flavor" ]; then
1256 echo "File $FLAVOR.flavor not found."
1257 exit 1
1258 fi
1259 mkdir $TMP_DIR
1260 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i > /dev/null)
1261 if [ "$3" = "--brief" ]; then
1262 if [ "$4" != "--noheader" ]; then
1263 echo "Name ISO Rootfs Description"
1264 echo "================================================================================"
1265 fi
1266 printf "%-16.16s %6.6s %6.6s %s\n" "$FLAVOR" \
1267 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
1268 "$(field 'Rootfs size' $TMP_DIR/$FLAVOR.desc)" \
1269 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
1270 else
1271 echo "================================================================================"
1272 cat $TMP_DIR/$FLAVOR.desc
1273 fi
1274 rm -Rf $TMP_DIR
1275 ;;
1276 gen-liveflavor)
1277 # Generate a new flavor from the live system.
1278 FLAVOR=${2%.flavor}
1279 DESC=""
1280 case "$FLAVOR" in
1281 '') echo -n "Flavor name : "
1282 read FLAVOR
1283 [ -z "$FLAVOR" ] && exit 1;;
1284 -?|-h*|--help) echo -e "
1286 SliTaz Live Tool - Version: $VERSION
1287 \033[1mUsage: \033[0m `basename $0` gen-liveflavor flavor-name [flavor-patch-file]
1288 \033[1mflavor-patch-file format: \033[0m
1289 code data
1290 + package to add
1291 - package to remove
1292 ! non-free package to add
1293 ? display message
1294 @ flavor description
1296 \033[1mExample: \033[0m
1297 @ Developer tools for slitaz maintainers
1298 + slitaz-toolchain
1299 + mercurial
1301 exit 1;;
1302 esac
1303 mv /etc/tazlito/distro-packages.list \
1304 /etc/tazlito/distro-packages.list.$$ 2> /dev/null
1305 rm -f distro-packages.list non-free.list 2> /dev/null
1306 tazpkg recharge
1307 [ -n "$3" ] && while read action pkg; do
1308 case "$action" in
1309 +) yes | tazpkg get-install $pkg;;
1310 -) yes | tazpkg remove $pkg;;
1311 !) echo $pkg >> non-free.list;;
1312 @) DESC="$pkg";;
1313 \?) echo -en "$pkg"; read action;;
1314 esac
1315 done < $3
1316 yes '' | tazlito gen-distro
1317 echo "$DESC" | tazlito gen-flavor "$FLAVOR"
1318 mv /etc/tazlito/distro-packages.list.$$ \
1319 /etc/tazlito/distro-packages.list 2> /dev/null
1320 ;;
1321 gen-flavor)
1322 # Generate a new flavor from the last iso image generated.
1323 FLAVOR=${2%.flavor}
1324 echo ""
1325 echo -e "\033[1mFlavor generation\033[0m"
1326 echo "================================================================================"
1327 if [ -z "$FLAVOR" ]; then
1328 echo -n "Flavor name : "
1329 read FLAVOR
1330 [ -z "$FLAVOR" ] && exit 1
1331 fi
1332 check_rootfs
1333 FILES="$FLAVOR.pkglist"
1334 echo -n "Creating file $FLAVOR.flavor..."
1335 for i in rootcd rootfs; do
1336 if [ -d "$ADDFILES/$i" ] ; then
1337 FILES="$FILES\n$FLAVOR.$i"
1338 ( cd "$ADDFILES/$i"; find . | \
1339 cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
1340 fi
1341 done
1342 status
1343 answer=`grep -s ^Description $FLAVOR.desc`
1344 answer=${answer#Description : }
1345 if [ -z "$answer" ]; then
1346 echo -n "Description : "
1347 read answer
1348 fi
1349 echo -n "Compressing flavor $FLAVOR..."
1350 echo "Flavor : $FLAVOR" > $FLAVOR.desc
1351 echo "Description : $answer" >> $FLAVOR.desc
1352 ( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
1353 \rm -f $FLAVOR.pkglist $FLAVOR.nonfree 2> /dev/null
1354 for i in $(ls $ROOTFS$INSTALLED); do
1355 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
1356 EXTRAVERSION=""
1357 eval $(grep ^EXTRAVERSION= $ROOTFS$INSTALLED/$i/receipt)
1358 eval $(grep ^CATEGORY= $ROOTFS$INSTALLED/$i/receipt)
1359 if [ "$CATEGORY" = "non-free" -a "${i%%-*}" != "get" ]
1360 then
1361 echo "$i" >> $FLAVOR.nonfree
1362 else
1363 echo "$i-$VERSION$EXTRAVERSION" >> $FLAVOR.pkglist
1364 fi
1365 done
1366 [ -s $FLAVOR.nonfree ] && $FILES="$FILES\n$FLAVOR.nonfree"
1367 for i in $LOCALSTATE/undigest/*/mirror ; do
1368 [ -s $i ] && cat $i >> $FLAVOR.mirrors
1369 done
1370 [ -s $FLAVOR.mirrors ] && $FILES="$FILES\n$FLAVOR.mirrors"
1371 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
1372 gzip -9 > $FLAVOR.flavor
1373 rm `echo -e $FILES`
1374 status
1375 echo "================================================================================"
1376 echo "Flavor size : `du -sh $FLAVOR.flavor`"
1377 echo ""
1378 ;;
1379 upgrade-flavor)
1380 # Update package list to the latest versions available.
1381 FLAVOR=${2%.flavor}
1382 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1383 mkdir $TMP_DIR
1384 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1385 echo -n "Updating $FLAVOR package list..."
1386 [ -s /var/lib/tazpkg/packages.list ] || tazpkg recharge
1387 packed_size=0; unpacked_size=0
1388 while read org; do
1389 i=0
1390 pkg=$org
1391 while ! grep -q ^$pkg$ /var/lib/tazpkg/packages.txt; do
1392 pkg=${pkg%-*}
1393 i=$(($i + 1))
1394 [ $i -gt 5 ] && break;
1395 done
1396 set -- $(get_size $pkg)
1397 packed_size=$(( $packed_size + $1 ))
1398 unpacked_size=$(( $unpacked_size + $2 ))
1399 for i in $(grep ^$pkg /var/lib/tazpkg/packages.list); do
1400 echo $i
1401 break
1402 done
1403 done < $TMP_DIR/$FLAVOR.pkglist \
1404 > $TMP_DIR/$FLAVOR.pkglist.$$
1405 mv -f $TMP_DIR/$FLAVOR.pkglist.$$ $TMP_DIR/$FLAVOR.pkglist
1406 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1407 packed_size=$(($packed_size \
1408 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1409 unpacked_size=$(($unpacked_size \
1410 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1411 fi
1412 # Estimate lzma
1413 packed_size=$(($packed_size * 2 / 3))
1414 iso_size=$(( $packed_size + 26000 ))
1415 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1416 iso_size=$(($iso_size \
1417 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1418 fi
1419 sed -i -e '/Image is ready/d' \
1420 -e "s/Rootfs size\( *:\) \(.*\)/Rootfs size\1 $(cent2human $unpacked_size) (estimated)/" \
1421 -e "s/Initramfs size\( *:\) \(.*\)/Initramfs size\1 $(cent2human $packed_size) (estimated)/" \
1422 -e "s/ISO image size\( *:\) \(.*\)/ISO image size\1 $(cent2human $iso_size) (estimated)/" \
1423 -e "s/date\( *:\) \(.*\)/date\1 $(date +%Y%m%d\ \at\ \%H:%M:%S)/" \
1424 $TMP_DIR/$FLAVOR.desc
1425 ( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
1426 $FLAVOR.flavor
1427 status
1428 rm -Rf $TMP_DIR
1429 fi
1430 ;;
1431 extract-flavor)
1432 # Extract a flavor into $FLAVORS_REPOSITORY.
1433 FLAVOR=${2%.flavor}
1434 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1435 mkdir $TMP_DIR
1436 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1437 echo -n "Extracting $FLAVOR..."
1438 rm -rf $FLAVORS_REPOSITORY/$FLAVOR 2> /dev/null
1439 mkdir -p $FLAVORS_REPOSITORY/$FLAVOR
1440 echo "FLAVOR=\"$FLAVOR\"" > $FLAVORS_REPOSITORY/$FLAVOR/receipt
1441 grep ^Description $TMP_DIR/$FLAVOR.desc | \
1442 sed 's/.*: \(.*\)$/SHORT_DESC="\1"/' >> \
1443 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1444 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc && \
1445 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1446 sed 's/.*: \(.*\)$/ROOTFS_SELECTION="\1"/' >> \
1447 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1448 grep '^Rootfs size' $TMP_DIR/$FLAVOR.desc | \
1449 sed 's/.*: \(.*\)$/ROOTFS_SIZE="\1"/' >> \
1450 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1451 grep ^Initramfs $TMP_DIR/$FLAVOR.desc | \
1452 sed 's/.*: \(.*\)$/INITRAMFS_SIZE="\1"/' >> \
1453 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1454 grep ^ISO $TMP_DIR/$FLAVOR.desc | \
1455 sed 's/.*: \(.*\)$/ISO_SIZE="\1"/' >> \
1456 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1457 for i in rootcd rootfs; do
1458 [ -f $TMP_DIR/$FLAVOR.$i ] || continue
1459 mkdir $FLAVORS_REPOSITORY/$FLAVOR/$i
1460 zcat $TMP_DIR/$FLAVOR.$i | \
1461 (cd $FLAVORS_REPOSITORY/$FLAVOR/$i; \
1462 cpio -idm > /dev/null)
1463 done
1464 [ -s $TMP_DIR/$FLAVOR.mirrors ] &&
1465 cp $TMP_DIR/$FLAVOR.mirrors \
1466 $FLAVORS_REPOSITORY/$FLAVOR/mirrors
1467 [ -s /var/lib/tazpkg/packages.list ] || tazpkg recharge
1468 while read org; do
1469 i=0
1470 pkg=$org
1471 while ! grep -q ^$pkg$ /var/lib/tazpkg/packages.txt; do
1472 pkg=${pkg%-*}
1473 i=$(($i + 1))
1474 [ $i -gt 5 ] && break;
1475 done
1476 echo $pkg
1477 done < $TMP_DIR/$FLAVOR.pkglist \
1478 > $FLAVORS_REPOSITORY/$FLAVOR/packages.list
1479 status
1480 rm -Rf $TMP_DIR
1481 fi
1482 ;;
1483 pack-flavor)
1484 # Create a flavor from $FLAVORS_REPOSITORY.
1485 FLAVOR=${2%.flavor}
1486 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/receipt ]; then
1487 mkdir $TMP_DIR
1488 echo -n "Creating flavor $FLAVOR..."
1489 [ -s /var/lib/tazpkg/packages.list ] || tazpkg recharge
1490 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/mirrors ]; then
1491 cp $FLAVORS_REPOSITORY/$FLAVOR/mirrors \
1492 $TMP_DIR/$FLAVOR.mirrors
1493 for i in $(cat $TMP_DIR/$FLAVOR.mirrors); do
1494 wget -O - $i/packages.list >> $TMP_DIR/packages.list
1495 done
1496 fi
1497 [ -s $FLAVORS_REPOSITORY/$FLAVOR/packages.list ] &&
1498 get_pkglist $FLAVOR > $TMP_DIR/$FLAVOR.pkglist
1499 if grep -q ^ROOTFS_SELECTION \
1500 $FLAVORS_REPOSITORY/$FLAVOR/receipt; then
1501 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1502 set -- $ROOTFS_SELECTION
1503 [ -n "$FRUGAL_RAM" ] || FRUGAL_RAM=$1
1504 [ -f $FLAVORS_REPOSITORY/$2/packages.list ] ||
1505 tazlito extract-flavor $2
1506 get_pkglist $2 > $TMP_DIR/$FLAVOR.pkglist
1507 for i in rootcd rootfs; do
1508 mkdir $TMP_DIR/$i
1509 # Copy extra files from the first flavor
1510 [ -d $FLAVORS_REPOSITORY/$2/$i ] &&
1511 cp -a $FLAVORS_REPOSITORY/$2/$i $TMP_DIR
1512 # Overload extra files by meta flavor
1513 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] &&
1514 cp -a $FLAVORS_REPOSITORY/$FLAVOR/$i $TMP_DIR
1515 [ -n "$(ls $TMP_DIR/$i)" ] &&
1516 ( cd $TMP_DIR/$i ; find . | cpio -o -H newc 2> /dev/null ) | \
1517 gzip -9 >$TMP_DIR/$FLAVOR.$i
1518 rm -rf $TMP_DIR/$i
1519 done
1520 else
1521 for i in rootcd rootfs; do
1522 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] || \
1523 continue
1524 ( cd $FLAVORS_REPOSITORY/$FLAVOR/$i ; \
1525 find . | cpio -o -H newc 2> /dev/null ) | \
1526 gzip -9 >$TMP_DIR/$FLAVOR.$i
1527 done
1528 fi
1529 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1530 packed_size=$(($packed_size \
1531 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1532 unpacked_size=$(($unpacked_size \
1533 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1534 fi
1535 # Estimate lzma
1536 packed_size=$(($packed_size * 2 / 3))
1537 iso_size=$(( $packed_size + 26000 ))
1538 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1539 iso_size=$(($iso_size \
1540 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1541 fi
1542 VERSION=""
1543 MAINTAINER=""
1544 ROOTFS_SELECTION=""
1545 ROOTFS_SIZE="$(cent2human $unpacked_size) (estimated)"
1546 INITRAMFS_SIZE="$(cent2human $packed_size) (estimated)"
1547 ISO_SIZE="$(cent2human $iso_size) (estimated)"
1548 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1549 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1550 Flavor : $FLAVOR
1551 Description : $SHORT_DESC
1552 EOT
1553 [ -n "$VERSION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1554 Version : $VERSION
1555 EOT
1556 [ -n "$MAINTAINER" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1557 Maintainer : $MAINTAINER
1558 EOT
1559 [ -n "$FRUGAL_RAM" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1560 LiveCD RAM size : $FRUGAL_RAM
1561 EOT
1562 [ -n "$ROOTFS_SELECTION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1563 Rootfs list : $ROOTFS_SELECTION
1564 EOT
1565 cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1566 Build date : $(date +%Y%m%d\ \at\ \%H:%M:%S)
1567 Packages : $(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l)
1568 Rootfs size : $ROOTFS_SIZE
1569 Initramfs size : $INITRAMFS_SIZE
1570 ISO image size : $ISO_SIZE
1571 ================================================================================
1573 EOT
1574 rm -f $TMP_DIR/packages.list
1575 ( cd $TMP_DIR ; ls | cpio -o -H newc 2> /dev/null) | \
1576 gzip -9 > $FLAVOR.flavor
1577 status
1578 rm -Rf $TMP_DIR
1579 else
1580 echo "No $FLAVOR flavor in $FLAVORS_REPOSITORY."
1581 fi
1582 ;;
1583 get-flavor)
1584 # Get a flavor's files and prepare for gen-distro.
1585 FLAVOR=${2%.flavor}
1586 echo ""
1587 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1588 echo -n "Cleaning $DISTRO..."
1589 rm -R $DISTRO 2> /dev/null
1590 mkdir -p $DISTRO
1591 status
1592 mkdir $TMP_DIR
1593 echo -n "Extracting flavor $FLAVOR.flavor... "
1594 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1595 echo -n "Creating distro-packages.list..."
1596 mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
1597 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
1598 status
1599 for i in rootcd rootfs; do
1600 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
1601 echo -n "Adding $i... "
1602 mkdir -p "$ADDFILES/$i"
1603 zcat $TMP_DIR/$FLAVOR.$i | \
1604 ( cd "$ADDFILES/$i"; cpio -id > /dev/null)
1605 fi
1606 done
1607 if [ -s $TMP_DIR/$FLAVOR.mirrors ]; then
1608 n=""
1609 while read line; do
1610 mkdir -p $LOCALSTATE/undigest/$FLAVOR$n
1611 echo "$line" > $LOCALSTATE/undigest/$FLAVOR$n/mirror
1612 n=$(( $n + 1 ))
1613 done < $TMP_DIR/$FLAVOR.mirrors
1614 tazpkg recharge
1615 fi
1616 rm -f /etc/tazlito/rootfs.list
1617 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc &&
1618 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1619 sed 's/.*: \(.*\)$/\1/' > /etc/tazlito/rootfs.list
1620 echo -n "Updating tazlito.conf..."
1621 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
1622 cat tazlito.conf | grep -v "^#VOLUM_NAME" | \
1623 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
1624 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
1625 sed -i "s/ISO_NAME=.*/ISO_NAME=\"slitaz-$FLAVOR\"/" tazlito.conf
1626 status
1627 rm -Rf $TMP_DIR
1628 fi
1629 echo ""
1630 ;;
1632 iso2flavor)
1633 if [ -z "$3" -o ! -s "$2" ]; then
1634 cat <<EOT
1635 Usage : tazlito iso2flavor image.iso flavor_name
1637 Create a file flavor_name.flavor from the cdrom image file image.iso
1638 EOT
1639 exit 1
1640 fi
1641 FLAVOR=${3%.flavor}
1642 mkdir -p $TMP_DIR/iso $TMP_DIR/rootfs
1643 mount -o loop,ro $2 $TMP_DIR/iso
1644 if [ -s $TMP_DIR/iso/boot/rootfs1.gz ]; then
1645 echo "META flavors are not supported."
1646 umount -d $TMP_DIR/iso
1647 elif [ ! -s $TMP_DIR/iso/boot/rootfs.gz ]; then
1648 echo "No /boot/rootfs.gz in iso image. Need a SliTaz iso."
1649 umount -d $TMP_DIR/iso
1650 else
1651 ( unlzma -c $TMP_DIR/iso/boot/rootfs.gz || \
1652 zcat $TMP_DIR/iso/boot/rootfs.gz ) | \
1653 ( cd $TMP_DIR/rootfs ; cpio -idmu > /dev/null )
1654 if [ ! -s $TMP_DIR/rootfs/etc/slitaz-release ]; then
1655 echo "No file /etc/slitaz-release in /boot/rootfs.gz of iso image. Need a non loram SliTaz iso."
1656 umount -d $TMP_DIR/iso
1657 else
1658 ROOTFS_SIZE=$(du -hs $TMP_DIR/rootfs | awk '{ print $1 }')
1659 RAM_SIZE=$(du -s $TMP_DIR/rootfs | awk '{ print 32*int(($1+36000)/32768) "M" }')
1660 cp -a $TMP_DIR/iso $TMP_DIR/rootcd
1661 ISO_SIZE=$(df -h $TMP_DIR/iso | awk 'END { print $2 }')
1662 BUILD_DATE=$(date +%Y%m%d\ \at\ \%H:%M:%S -r $TMP_DIR/iso/md5sum)
1663 umount -d $TMP_DIR/iso
1664 INITRAMFS_SIZE=$(du -chs $TMP_DIR/rootcd/boot/rootfs.gz | awk '{ s=$1 } END { print $1 }')
1665 rm -f $TMP_DIR/rootcd/boot/rootfs.gz $TMP_DIR/rootcd/md5sum
1666 mv $TMP_DIR/rootcd/boot $TMP_DIR/rootfs
1667 sed 's/.* \(.*\).tazpkg*/\1/' > $TMP_DIR/$FLAVOR.pkglist \
1668 < $TMP_DIR/rootfs/var/lib/tazpkg/installed.md5
1669 #[ -s $TMP_DIR/rootfs/etc/tazlito/distro-packages.list ] &&
1670 # mv $TMP_DIR/rootfs/etc/tazlito/distro-packages.list $TMP_DIR/$FLAVOR.pkglist
1671 PKGCNT=$(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l | awk '{ print $1 }')
1672 find_flavor_rootfs $TMP_DIR/rootfs
1673 [ -d $TMP_DIR/rootfs/boot ] && mv $TMP_DIR/rootfs/boot $TMP_DIR/rootcd
1674 [ -n "$(ls $TMP_DIR/rootfs)" ] && ( cd $TMP_DIR/rootfs ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootfs
1675 [ -n "$(ls $TMP_DIR/rootcd)" ] && ( cd $TMP_DIR/rootcd ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootcd
1676 rm -rf $TMP_DIR/rootcd $TMP_DIR/rootfs
1677 VERSION=""; MAINTAINER=""
1678 echo -en "Flavor short description \007: "; read -t 30 DESCRIPTION
1679 if [ -n "$DESCRIPTION" ]; then
1680 echo -en "Flavor version : "; read -t 30 VERSION
1681 echo -en "Flavor maintainer (your email) : "; read -t 30 MAINTAINER
1682 fi
1683 [ -n "$DESCRIPTION" ] || DESCRIPTION="Slitaz $FLAVOR flavor"
1684 [ -n "$VERSION" ] || VERSION="1.0"
1685 [ -n "$MAINTAINER" ] || MAINTAINER="nobody@slitaz.org"
1686 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1687 Flavor : $FLAVOR
1688 Description : $DESCRIPTION
1689 Version : $VERSION
1690 Maintainer : $MAINTAINER
1691 LiveCD RAM size : $RAM_SIZE
1692 Build date : $BUILD_DATE
1693 Packages : $PKGCNT
1694 Rootfs size : $ROOTFS_SIZE
1695 Initramfs size : $INITRAMFS_SIZE
1696 ISO image size : $ISO_SIZE
1697 ================================================================================
1699 EOT
1700 ( cd $TMP_DIR ; ls $FLAVOR.* | cpio -o -H newc ) | gzip -9 > $FLAVOR.flavor
1701 cat <<EOT
1702 Tazlito can't detect each file installed during a package post_install.
1703 You should extract this flavor (tazlito extract-flavor $FLAVOR),
1704 check the files in /home/slitaz/flavors/$FLAVOR/rootfs tree and remove
1705 files generated by post_installs.
1706 Check /home/slitaz/flavors/$FLAVOR/receipt too and repack the flavor
1707 (tazlito pack-flavor $FLAVOR)
1708 EOT
1709 fi
1710 fi
1711 rm -rf $TMP_DIR
1712 ;;
1714 check-list)
1715 # Use current packages list in $PWD by default.
1716 DISTRO_PKGS_LIST=distro-packages.list
1717 [ -d "$2" ] && DISTRO_PKGS_LIST=$2/distro-packages.list
1718 [ -f "$2" ] && DISTRO_PKGS_LIST=$2
1719 [ ! -f $DISTRO_PKGS_LIST ] && echo "No packages list found." && exit 0
1720 echo ""
1721 echo -e "\033[1mLiveCD packages list check\033[0m"
1722 echo "================================================================================"
1723 for pkg in `cat $DISTRO_PKGS_LIST`
1724 do
1725 if ! grep -q "$pkg" /var/lib/tazpkg/packages.list; then
1726 echo "Update: $pkg"
1727 up=$(($up + 1))
1728 fi
1729 done
1730 [ -z $up ] && echo -e "List is up-to-date\n" && exit 0
1731 echo "================================================================================"
1732 echo -e "Updates: $up\n" ;;
1733 gen-distro)
1734 # Generate a live distro tree with a set of packages.
1736 check_root
1738 # Check if a package list was specified on cmdline.
1739 LIST_NAME="distro-packages.list"
1740 CDROM=""
1741 while [ -n "$2" ]; do
1742 case "$2" in
1743 --iso=*)
1744 CDROM="-o loop ${2#--iso=}"
1745 ;;
1746 --cdrom)
1747 CDROM="/dev/cdrom"
1748 ;;
1749 --force)
1750 DELETE_ROOTFS="true"
1751 ;;
1752 *) if [ ! -f "$2" ] ; then
1753 echo -e "\nUnable to find the specified packages list."
1754 echo -e "List name : $2\n"
1755 exit 1
1756 fi
1757 LIST_NAME=$2
1758 ;;
1759 esac
1760 shift
1761 done
1763 if [ -d $ROOTFS ] ; then
1764 # Delete $ROOTFS if --force is set on command line
1765 if [ ! -z $DELETE_ROOTFS ]; then
1766 rm -rf $ROOTFS
1767 unset $DELETE_ROOTFS
1768 else
1769 echo -e "\nA rootfs exists in : $DISTRO"
1770 echo -e "Please clean the distro tree or change directory path.\n"
1771 exit 0
1772 fi
1773 fi
1774 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
1775 # Build list with installed packages
1776 for i in $(ls $INSTALLED); do
1777 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
1778 EXTRAVERSION=""
1779 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
1780 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
1781 done
1782 fi
1783 # Exit if no list name.
1784 if [ ! -f "$LIST_NAME" ]; then
1785 echo -e "\nNo packages list found or specified. Please read the docs.\n"
1786 exit 0
1787 fi
1788 # Start generation.
1789 echo ""
1790 echo -e "\033[1mTazlito generating a distro\033[0m"
1791 echo "================================================================================"
1792 # Misc checks
1793 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
1794 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
1795 # Get the list of packages using cat for a file list.
1796 LIST=`cat $LIST_NAME`
1797 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
1798 REPACK=""
1799 DOWNLOAD=""
1800 for pkg in $LIST
1801 do
1802 [ "$pkg" = "" ] && continue
1803 pkg=${pkg%.tazpkg}
1804 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
1805 PACKAGE=$(installed_package_name $pkg)
1806 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
1807 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
1808 echo -e "\nUnable to find $pkg in the repository."
1809 echo -e "Path : $PACKAGES_REPOSITORY\n"
1810 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
1811 yesorno "Repack packages from rootfs (y/N) ? "
1812 REPACK="$answer"
1813 [ "$answer" = "y" ] || REPACK="n"
1814 [ "$DOWNLOAD" = "y" ] && break
1815 fi
1816 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
1817 yesorno "Download packages from mirror (Y/n) ? "
1818 DOWNLOAD="$answer"
1819 if [ "$answer" = "n" ]; then
1820 [ -z "$PACKAGE" ] && exit 1
1821 else
1822 DOWNLOAD="y"
1823 [ -n "$REPACK" ] && break
1824 fi
1825 fi
1826 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
1827 done
1829 # Mount cdrom to be able to repack boot-loader packages
1830 if [ ! -e /boot -a -n "$CDROM" ]; then
1831 mkdir $TMP_MNT
1832 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
1833 ln -s $TMP_MNT/boot /
1834 if [ ! -d "$ADDFILES/rootcd" ] ; then
1835 mkdir -p $ADDFILES/rootcd
1836 for i in $(ls $TMP_MNT); do
1837 [ "$i" = "boot" ] && continue
1838 cp -a $TMP_MNT/$i $ADDFILES/rootcd
1839 done
1840 fi
1841 else
1842 rmdir $TMP_MNT
1843 fi
1844 fi
1846 # Root fs stuff.
1847 echo "Preparing the rootfs directory..."
1848 mkdir -p $ROOTFS
1849 sleep 2
1850 for pkg in $LIST
1851 do
1852 [ "$pkg" = "" ] && continue
1853 # First copy and extract the package in tmp dir.
1854 pkg=${pkg%.tazpkg}
1855 PACKAGE=$(installed_package_name $pkg)
1856 mkdir -p $TMP_DIR
1857 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1858 # Look for package in cache
1859 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
1860 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
1861 # Look for package in running distribution
1862 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
1863 tazpkg repack $PACKAGE && \
1864 mv $pkg.tazpkg $PACKAGES_REPOSITORY
1865 fi
1866 fi
1867 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1868 # Get package from mirror
1869 [ "$DOWNLOAD" = "y" ] && \
1870 download $pkg.tazpkg && \
1871 mv $pkg.tazpkg $PACKAGES_REPOSITORY
1872 fi
1873 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1874 echo "Missing package $pkg."
1875 cleanup
1876 exit 1
1877 fi
1878 done
1879 if [ -f non-free.list ]; then
1880 echo "Preparing non-free packages..."
1881 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
1882 for pkg in $(cat non-free.list); do
1883 if [ ! -d $INSTALLED/$pkg ]; then
1884 if [ ! -d $INSTALLED/get-$pkg ]; then
1885 tazpkg get-install get-$pkg
1886 fi
1887 get-$pkg
1888 fi
1889 tazpkg repack $pkg
1890 pkg=$(ls $pkg*.tazpkg)
1891 grep -q "^$pkg$" $LIST_NAME || \
1892 echo $pkg >>$LIST_NAME
1893 mv $pkg $PACKAGES_REPOSITORY
1894 done
1895 fi
1896 echo ""
1897 cp $LIST_NAME $DISTRO/distro-packages.list
1898 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/distro-packages.list > $DISTRO/list-packages
1899 cd $PACKAGES_REPOSITORY
1900 yes y | tazpkg install-list \
1901 $DISTRO/list-packages --root=$ROOTFS
1902 cd $DISTRO
1903 cp distro-packages.list $ROOTFS/etc/tazlito
1904 # Copy all files from $ADDFILES/rootfs to the rootfs.
1905 if [ -d "$ADDFILES/rootfs" ] ; then
1906 echo -n "Copying addfiles content to the rootfs... "
1907 cp -a $ADDFILES/rootfs/* $ROOTFS
1908 status
1909 fi
1910 echo "Root file system is generated..."
1911 # Root CD part.
1912 echo -n "Preparing the rootcd directory..."
1913 mkdir -p $ROOTCD
1914 status
1915 # Move the boot dir with the Linux kernel from rootfs.
1916 # The boot dir goes directly on the CD.
1917 if [ -d "$ROOTFS/boot" ] ; then
1918 echo -n "Moving the boot directory..."
1919 mv $ROOTFS/boot $ROOTCD
1920 cd $ROOTCD/boot
1921 ln vmlinuz-* bzImage
1922 status
1923 fi
1924 cd $DISTRO
1925 # Copy all files from $ADDFILES/rootcd to the rootcd.
1926 if [ -d "$ADDFILES/rootcd" ] ; then
1927 echo -n "Copying addfiles content to the rootcd... "
1928 cp -a $ADDFILES/rootcd/* $ROOTCD
1929 status
1930 fi
1931 # Execute the distro script used to perform tasks in the rootfs
1932 # before compression. Give rootfs path in arg
1933 [ -z $DISTRO_SCRIPT ] && DISTRO_SCRIPT=$TOP_DIR/distro.sh
1934 if [ -x $DISTRO_SCRIPT ]; then
1935 echo "Executing distro script..."
1936 sh $DISTRO_SCRIPT $DISTRO
1937 fi
1938 if [ -s /etc/tazlito/rootfs.list ]; then
1939 [ -f $ROOTCD/boot/isolinux/ifmem.c32 ] ||
1940 cp /boot/isolinux/ifmem.c32 $ROOTCD/boot/isolinux
1941 n=0
1942 last=$ROOTFS
1943 while read flavor; do
1944 n=$(($n+1))
1945 echo "Building $flavor rootfs..."
1946 download $flavor.flavor
1947 zcat $flavor.flavor | cpio -i \
1948 $flavor.pkglist $flavor.rootfs
1949 sed 's/.*/&.tazpkg/' < $flavor.pkglist \
1950 > $DISTRO/list-packages0$n
1951 mkdir ${ROOTFS}0$n
1952 cd $PACKAGES_REPOSITORY
1953 yes y | tazpkg install-list \
1954 $DISTRO/list-packages0$n --root=${ROOTFS}0$n
1955 rm -rf ${ROOTFS}0$n/boot
1956 status
1957 cd $DISTRO
1958 if [ -s $flavor.rootfs ]; then
1959 echo "Add $flavor rootfs extra files..."
1960 zcat $flavor.rootfs | \
1961 ( cd ${ROOTFS}0$n ; cpio -idmu )
1962 fi
1963 mv $flavor.pkglist ${ROOTFS}0$n/etc/tazlito/distro-packages.list
1964 rm -f $flavor.flavor install-list
1965 mergefs ${ROOTFS}0$n $last
1966 last=${ROOTFS}0$n
1967 done <<EOT
1968 $(awk '{ for (i = 4; i <= NF; i+=2) print $i; }' < /etc/tazlito/rootfs.list)
1969 EOT
1970 i=$(($n+1))
1971 while [ $n -gt 0 ]; do
1972 mv ${ROOTFS}0$n ${ROOTFS}$i
1973 echo "Compression ${ROOTFS}0$n ($(du -hs ${ROOTFS}$i | awk '{ print $1 }')) ..."
1974 gen_initramfs ${ROOTFS}$i
1975 n=$(($n-1))
1976 i=$(($i-1))
1977 done
1978 mv $ROOTFS ${ROOTFS}$i
1979 gen_initramfs ${ROOTFS}$i
1980 update_bootconfig $ROOTCD/boot/isolinux \
1981 "$(cat /etc/tazlito/rootfs.list)"
1982 else
1983 # Initramfs and ISO image stuff.
1984 gen_initramfs $ROOTFS
1985 fi
1986 gen_livecd_isolinux
1987 distro_stats
1988 cleanup
1989 ;;
1990 clean-distro)
1991 # Remove old distro tree.
1993 check_root
1994 echo ""
1995 echo -e "\033[1mCleaning :\033[0m $DISTRO"
1996 echo "================================================================================"
1997 if [ -d "$DISTRO" ] ; then
1998 if [ -d "$ROOTFS" ] ; then
1999 echo -n "Removing the rootfs..."
2000 rm -f $DISTRO/$INITRAMFS
2001 rm -rf $ROOTFS
2002 status
2003 fi
2004 if [ -d "$ROOTCD" ] ; then
2005 echo -n "Removing the rootcd..."
2006 rm -rf $ROOTCD
2007 status
2008 fi
2009 echo -n "Removing eventual ISO image..."
2010 rm -f $DISTRO/$ISO_NAME.iso
2011 rm -f $DISTRO/$ISO_NAME.md5
2012 status
2013 fi
2014 echo "================================================================================"
2015 echo ""
2016 ;;
2017 check-distro)
2018 # Check for a few LiveCD needed files not installed by packages.
2020 check_rootfs
2021 echo ""
2022 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
2023 echo "================================================================================"
2024 # SliTaz release info.
2025 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
2026 echo "Missing release info : /etc/slitaz-release"
2027 else
2028 release=`cat $ROOTFS/etc/slitaz-release`
2029 echo -n "Release : $release"
2030 status
2031 fi
2032 # Tazpkg mirror.
2033 if [ ! -f "$ROOTFS/var/lib/tazpkg/mirror" ]; then
2034 echo -n "Mirror URL : Missing /var/lib/tazpkg/mirror"
2035 todomsg
2036 else
2037 echo -n "Mirror configuration exists..."
2038 status
2039 fi
2040 # Isolinux msg
2041 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.msg; then
2042 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
2043 todomsg
2044 else
2045 echo -n "Isolinux message seems good..."
2046 status
2047 fi
2048 echo "================================================================================"
2049 echo ""
2050 ;;
2051 writeiso)
2052 # Writefs to ISO image including /home unlike gen-distro we dont use
2053 # packages to generate a rootfs, we build a compressed rootfs with all
2054 # the current filesystem similar to 'tazusb writefs'.
2056 DISTRO="/home/slitaz/distro"
2057 ROOTCD="$DISTRO/rootcd"
2058 if [ -z $2 ]; then
2059 COMPRESSION=none
2060 else
2061 COMPRESSION=$2
2062 fi
2063 if [ -z $3 ]; then
2064 ISO_NAME="slitaz"
2065 else
2066 ISO_NAME="$3"
2067 fi
2068 check_root
2069 # Start info
2070 echo ""
2071 echo -e "\033[1mWrite filesystem to ISO\033[0m
2072 ===============================================================================
2073 The command writeiso will write the current filesystem into a suitable cpio
2074 archive (rootfs.gz) and generate a bootable ISO image (slitaz.iso).
2076 Archive compression: $COMPRESSION"
2077 echo ""
2079 # Save some space
2080 rm /var/cache/tazpkg/* -r -f
2081 rm -rf /home/slitaz/distro
2083 # Optionally remove sound card selection and screen resolution.
2084 echo "Do you wish to remove the sound card and screen configs ? "
2085 echo -n "Press ENTER to keep or answer (No|yes|exit): "
2086 read anser
2087 case $anser in
2088 e|E|"exit"|Exit)
2089 exit 0 ;;
2090 y|Y|yes|Yes)
2091 echo -n "Removing current sound card and screen configurations..."
2092 rm -f /var/lib/sound-card-driver
2093 rm -f /etc/asound.state
2094 rm -f /etc/X11/screen.conf
2095 rm -f /etc/X11/xorg.conf ;;
2096 *)
2097 echo -n "Keeping current sound card and screen configurations..." ;;
2098 esac
2099 status
2101 # Create list of files including default user files since it is defined in /etc/passwd
2102 # and some new users might have been added.
2103 find /bin /etc /init /sbin /var /dev /lib /root /usr /home >/tmp/list
2105 for dir in /proc /sys /tmp /mnt /media /media/cdrom /media/flash /media/usbdisk
2106 do
2107 echo $dir >>/tmp/list
2108 done
2110 # Generate initramfs with specified compression and display rootfs
2111 # size in realtime.
2112 rm -f /tmp/rootfs
2113 write_initramfs &
2114 sleep 2
2115 echo -en "\nFilesystem size:"
2116 while [ ! -f /tmp/rootfs ]
2117 do
2118 sleep 1
2119 echo -en "\\033[18G`du -sh /rootfs.gz | awk '{print $1}'` "
2120 done
2121 echo -e "\n"
2123 # Move freshly generated rootfs to the cdrom.
2124 mkdir -p $ROOTCD/boot
2125 mv -f /rootfs.gz $ROOTCD/boot
2127 # Now we need the kernel and isolinux files.
2128 if mount /dev/cdrom /media/cdrom 2>/dev/null; then
2129 cp /media/cdrom/boot/bzImage $ROOTCD/boot
2130 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
2131 umount /media/cdrom
2132 else
2133 echo -e "
2134 Unable to mount the cdrom to copy the Kernel and needed files. When SliTaz
2135 is running in RAM the kernel and bootloader files are kept on the cdrom.
2136 Please insert a LiveCD or unmount the current cdrom to let Tazlito handle
2137 the media.\n"
2138 echo -en "----\nENTER to continue..."; read i
2139 exit 1
2140 fi
2142 # Generate the iso image.
2143 cd $DISTRO
2144 echo "Generating ISO image..."
2145 genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
2146 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
2147 -V "SliTaz" -input-charset iso8859-1 -boot-info-table $ROOTCD
2148 if [ -x /usr/bin/isohybrid ]; then
2149 echo -n "Creating hybrid ISO..."
2150 /usr/bin/isohybrid $ISO_NAME.iso 2> /dev/null
2151 status
2152 fi
2153 echo -n "Creating the ISO md5sum..."
2154 md5sum $ISO_NAME.iso > $ISO_NAME.md5
2155 status
2157 echo "==============================================================================="
2158 echo "ISO image: `du -sh /home/slitaz/distro/$ISO_NAME.iso`"
2159 echo ""
2160 echo -n "Exit or burn ISO to cdrom (Exit|burn)? "; read anser
2161 case $anser in
2162 burn)
2163 eject
2164 echo -n "Please insert a blank cdrom and press ENTER..."
2165 read i && sleep 2
2166 tazlito burn-iso /home/slitaz/distro/$ISO_NAME.iso
2167 echo -en "----\nENTER to continue..."; read i ;;
2168 *)
2169 exit 0 ;;
2170 esac ;;
2171 burn-iso)
2172 # Guess cdrom device, ask user and burn the ISO.
2174 check_root
2175 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
2176 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
2177 # We can specify an alternative ISO from the cmdline.
2178 if [ -n "$2" ] ; then
2179 iso=$2
2180 else
2181 iso=$DISTRO/$ISO_NAME.iso
2182 fi
2183 if [ ! -f "$iso" ]; then
2184 echo -e "\nUnable to find ISO : $iso\n"
2185 exit 0
2186 fi
2187 echo ""
2188 echo -e "\033[1mTazlito burn ISO\033[0m "
2189 echo "================================================================================"
2190 echo "Cdrom device : /dev/$DRIVE_NAME"
2191 echo "Drive speed : $DRIVE_SPEED"
2192 echo "ISO image : $iso"
2193 echo "================================================================================"
2194 echo ""
2195 yesorno "Burn ISO image (y/N) ? "
2196 if [ "$answer" == "y" ]; then
2197 echo ""
2198 echo "Starting Wodim to burn the iso..." && sleep 2
2199 echo "================================================================================"
2200 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
2201 echo "================================================================================"
2202 echo "ISO image is burned to cdrom."
2203 else
2204 echo -e "\nExiting. No ISO burned."
2205 fi
2206 echo ""
2207 ;;
2208 merge)
2209 # Merge multiple rootfs into one iso.
2211 if [ -z "$2" ]; then
2212 cat << EOT
2213 Usage: tazlito merge size1 iso size2 rootfs2 [sizeN rootfsN]...
2215 Merge multiple rootfs into one iso. Rootfs are like russian dolls
2216 i.e: rootfsN is a subset of rootfsN-1
2217 rootfs1 is found in iso, sizeN is the RAM size need to launch rootfsN.
2218 The boot loader will select the rootfs according to the RAM size detected.
2220 Example:
2221 $ tazlito merge 160M slitaz-core.iso 96M rootfs-justx.gz 32M rootfs-base.gz
2223 Will start slitaz-core with 160M+ RAM, slitaz-justX with 96M-160M RAM,
2224 slitaz-base with 32M-96M RAM and display an error message if RAM < 32M.
2225 EOT
2226 exit 2
2227 fi
2229 shift # skip merge
2230 append="$1 slitaz1"
2231 shift # skip size1
2232 mkdir -p $TMP_DIR/mnt $TMP_DIR/rootfs1
2234 ISO=$1.merged
2235 # Extract filesystems
2236 echo -n "Mounting $1"
2237 mount -o loop,ro $1 $TMP_DIR/mnt 2> /dev/null
2238 status || cleanup_merge
2239 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2240 rm -f $TMP_DIR/iso/boot/bzImage
2241 ln $TMP_DIR/iso/boot/vmlinuz* $TMP_DIR/iso/boot/bzImage
2242 umount -d $TMP_DIR/mnt
2243 if [ -f $TMP_DIR/iso/boot/rootfs1.gz ]; then
2244 echo "$1 is already a merged iso. Aborting."
2245 cleanup_merge
2246 fi
2247 if [ ! -f $TMP_DIR/iso/boot/isolinux/ifmem.c32 ]; then
2248 if [ ! -f /boot/isolinux/ifmem.c32 ]; then
2249 cat <<EOT
2250 No file /boot/isolinux/ifmem.c32
2251 Please install syslinux package !
2252 EOT
2253 rm -rf $TMP_DIR
2254 exit 1
2255 fi
2256 cp /boot/isolinux/ifmem.c32 $TMP_DIR/iso/boot/isolinux
2257 fi
2259 echo -n "Extracting iso/rootfs.gz"
2260 extract_rootfs $TMP_DIR/iso/boot/rootfs.gz $TMP_DIR/rootfs1 &&
2261 [ -d $TMP_DIR/rootfs1/etc ]
2262 status || cleanup_merge
2263 n=1
2264 while [ -n "$2" ]; do
2265 shift # skip rootfs N-1
2266 p=$n
2267 n=$(($n + 1))
2268 append="$append $1 slitaz$n"
2269 shift # skip size N
2270 mkdir -p $TMP_DIR/rootfs$n
2271 echo -n "Extracting $1"
2272 extract_rootfs $1 $TMP_DIR/rootfs$n &&
2273 [ -d $TMP_DIR/rootfs$n/etc ]
2274 status || cleanup_merge
2275 mergefs $TMP_DIR/rootfs$n $TMP_DIR/rootfs$p
2276 echo "Creating rootfs$p.gz"
2277 pack_rootfs $TMP_DIR/rootfs$p $TMP_DIR/iso/boot/rootfs$p.gz
2278 status
2279 done
2280 echo "Creating rootfs$n.gz"
2281 pack_rootfs $TMP_DIR/rootfs$n $TMP_DIR/iso/boot/rootfs$n.gz
2282 status
2283 rm -f $TMP_DIR/iso/boot/rootfs.gz
2284 update_bootconfig $TMP_DIR/iso/boot/isolinux "$append"
2285 create_iso $ISO $TMP_DIR/iso
2286 rm -rf $TMP_DIR
2287 ;;
2289 repack)
2290 # Repack an iso with maximum lzma compression ratio.
2293 ISO=$2
2295 mkdir -p $TMP_DIR/mnt
2296 # Extract filesystems
2297 echo -n "Mounting $ISO"
2298 mount -o loop,ro $ISO $TMP_DIR/mnt 2> /dev/null
2299 status || cleanup_merge
2300 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2301 umount -d $TMP_DIR/mnt
2303 for i in $TMP_DIR/iso/boot/rootfs* ; do
2304 echo -n "Repacking $(basename $i)"
2305 (zcat $i 2> /dev/null || unlzma -c $i || cat $i) \
2306 2>/dev/null > $TMP_DIR/rootfs
2307 lzma e $TMP_DIR/rootfs $i \
2308 $(lzma_switches $TMP_DIR/rootfs)
2309 status
2310 done
2312 create_iso $ISO $TMP_DIR/iso
2313 rm -rf $TMP_DIR ;;
2315 build-loram)
2316 # Build a Live CD for low ram systems.
2319 ISO=$2
2320 OUTPUT=$3
2321 mkdir -p $TMP_DIR/iso
2322 mount -o loop,ro -t iso9660 $ISO $TMP_DIR/iso
2323 if ! check_iso_for_loram ; then
2324 echo "$2 is not a valid SliTaz live CD. Abort."
2325 umount -d $TMP_DIR/iso
2326 rm -rf $TMP_DIR
2327 exit 1
2328 fi
2330 case "$4" in
2331 cdrom) build_loram_cdrom ;;
2332 http) build_loram_http ;;
2333 *) build_loram_ram ;;
2334 esac
2335 umount -d $TMP_DIR/iso
2336 rm -rf $TMP_DIR ;;
2339 frugal-install|-fi)
2340 ISO_IMAGE="$2"
2341 echo ""
2342 mkdir -p /boot/frugal
2343 if [ -f "$ISO_IMAGE" ]; then
2344 echo -n "Using ISO image: $ISO_IMAGE"
2345 mkdir -p /tmp/iso && mount -o loop $ISO_IMAGE /tmp/iso
2346 status
2347 echo -n "Installing the Kernel and rootfs..."
2348 cp -a /tmp/iso/boot/bzImage /boot/frugal
2349 cp -a /tmp/iso/boot/rootfs.gz /boot/frugal
2350 umount /tmp/iso
2351 status
2352 else
2353 echo -n "Using distro: $DISTRO"
2354 cd $DISTRO && status
2355 echo -n "Installing the Kernel and rootfs..."
2356 cp -a $DISTRO/rootcd/boot/bzImage /boot/frugal
2357 cp -a $DISTRO/rootcd/boot/rootfs.gz /boot/frugal
2358 status
2359 fi
2360 # Grub entry
2361 if ! grep -q "^kernel /boot/frugal/bzImage" /boot/grub/menu.lst; then
2362 echo -n "Configuring GRUB menu list..."
2363 cat >> /boot/grub/menu.lst << EOT
2364 title SliTaz GNU/Linux (frugal)
2365 root (hd0,0)
2366 kernel /boot/frugal/bzImage root=/dev/null
2367 initrd /boot/frugal/rootfs.gz
2368 EOT
2369 else
2370 echo -n "GRUB menu list is up-to-date..."
2371 fi
2372 status
2373 echo "" ;;
2375 emu-iso)
2376 # Emulate an ISO image with Qemu.
2377 if [ -n "$2" ] ; then
2378 iso=$2
2379 else
2380 iso=$DISTRO/$ISO_NAME.iso
2381 fi
2382 if [ ! -f "$iso" ]; then
2383 echo -e "\nUnable to find ISO : $iso\n"
2384 exit 0
2385 fi
2386 if [ ! -x "/usr/bin/qemu" ]; then
2387 echo -e "\nUnable to find Qemu binary. Please install: qemu\n"
2388 exit 0
2389 fi
2390 echo -e "\nStarting Qemu emulator:\n"
2391 echo -e "qemu $QEMU_OPTS $iso\n"
2392 qemu $QEMU_OPTS $iso ;;
2394 usage|*)
2395 # Clear and print usage also for all unknown commands.
2397 clear
2398 usage ;;
2399 esac
2401 exit 0