tazlito view tazlito @ rev 201

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