tazlito view tazlito @ rev 206

tazlito/loram-cdrom: fix unpacked fs path
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Dec 25 22:52:13 2010 +0100 (2010-12-25)
parents 18f3e47601dc
children 159353604bbe
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 $TMP_DIR/initfs/sys
657 while [ ! -f /lib/modules/$version/kernel/fs/aufs/aufs.ko.gz ]; do
658 install_package aufs $version || return 1
659 done
660 # bootfloppybox will need floppy.ko.gz, /dev/fd0, /dev/tty0
661 cp /lib/modules/$version/kernel/drivers/block/floppy.ko.gz \
662 $TMP_DIR/initfs/lib 2> /dev/null
663 cp -a /dev/tty0 /dev/fd0 $TMP_DIR/initfs/dev 2> /dev/null
664 cp /lib/modules/$version/kernel/fs/aufs/aufs.ko.gz \
665 $TMP_DIR/initfs/lib
666 if [ -f /bin/cromfs-driver ]; then
667 cp /bin/cromfs-driver $TMP_DIR/initfs/bin
668 else
669 [ ! -f /usr/sbin/mksquashfs ] && ! install_package squashfs && return 1
670 while [ ! -f /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.gz ]; do
671 install_package linux-squashfs $version || return 1
672 done
673 cp /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.gz \
674 $TMP_DIR/initfs/lib
675 fi
676 if [ "$1" == "cdrom" ]; then
677 for i in $(ls /dev/[hs]d[a-f]); do
678 cp -a $i $TMP_DIR/initfs/dev
679 done
680 fi
681 if [ "$1" == "http" ]; then
682 mkdir $TMP_DIR/initfs/etc
683 ln -s /proc/mounts $TMP_DIR/initfs/etc/mtab
684 cp /usr/share/udhcpc/default.script $TMP_DIR/initfs/lib/udhcpc
685 sed -i 's|/sbin/||' $TMP_DIR/initfs/lib/udhcpc
686 cp -a /dev/fuse $TMP_DIR/initfs/dev
687 if ! $need_lib && [ -x /usr/share/boot/fusermount-static ]; then
688 cp /usr/share/boot/fusermount-static $TMP_DIR/initfs/bin/httpfs
689 else
690 cp /usr/bin/fusermount $TMP_DIR/initfs/bin
691 need_lib=true
692 fi
693 if ! $need_lib && [ -x /usr/share/boot/httpfs-static ]; then
694 cp /usr/share/boot/httpfs-static $TMP_DIR/initfs/bin/httpfs
695 else
696 [ ! -f /usr/bin/httpfs ] && ! install_package httpfs-fuse && return 1
697 cp /usr/bin/httpfs $TMP_DIR/initfs/bin
698 cp -a /lib/librt* $TMP_DIR/initfs/lib
699 cp -a /lib/libdl* $TMP_DIR/initfs/lib
700 cp -a /lib/libpthread* $TMP_DIR/initfs/lib
701 cp -a /usr/lib/libfuse* $TMP_DIR/initfs/lib
702 cp -a /lib/libresolv* $TMP_DIR/initfs/lib
703 cp -a /lib/libnss_dns* $TMP_DIR/initfs/lib
704 need_lib=true
705 fi
706 cd $TMP_DIR/initfs
707 echo "Get slitaz-release..."
708 for i in $TMP_DIR/iso/boot/rootfs*.gz; do
709 ( zcat $i 2> /dev/null || unlzma -c $i) | \
710 cpio -idmu etc/slitaz-release > /dev/null
711 done
712 cd - > /dev/null
713 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"
714 echo -n "List of urls to insert: "
715 read -t 30 urliso2
716 urliso="$urliso2 $urliso"
717 fi
718 if ! $need_lib && [ -x /usr/share/boot/busybox-static ]; then
719 cp /usr/share/boot/busybox-static $TMP_DIR/initfs/bin/busybox
720 else
721 cp /bin/busybox $TMP_DIR/initfs/bin
722 need_lib=true
723 fi
724 for i in $($TMP_DIR/initfs/bin/busybox | awk \
725 '{ if (s) printf "%s",$0 } /Currently/ { s=1 }' | sed 's/,//g'); do
726 ln $TMP_DIR/initfs/bin/busybox $TMP_DIR/initfs/bin/$i
727 done
728 for i in /dev/console /dev/loop* /dev/null /dev/tty /dev/zero \
729 /dev/kmem /dev/mem /dev/random /dev/urandom; do
730 cp -a $i $TMP_DIR/initfs/dev
731 done
732 $need_lib && for i in /lib/ld-* /lib/lib[cm].so* /lib/lib[cm]-* ; do
733 cp -a $i $TMP_DIR/initfs/lib
734 done
735 cat > $TMP_DIR/initfs/init <<EOTEOT
736 #!/bin/sh
738 getarg()
739 {
740 grep -q " \$1=" /proc/cmdline || return 1
741 eval \$2=\$(sed "s/.* \$1=\\\\([^ ]*\\\\).*/\\\\1/" < /proc/cmdline)
742 return 0
743 }
745 copy_rootfs()
746 {
747 total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g')
748 need=\$(du -c \${path}rootfs* | tail -n 1 | cut -f1)
749 [ \$(( \$total / \$need )) -gt 1 ] || return 1
750 if ! grep -q " keep-loram" /proc/cmdline && cp \${path}rootfs* /mnt; then
751 path=/mnt/
752 return 0
753 else
754 rm -f /mnt/rootfs*
755 return 1
756 fi
757 }
759 echo "Switching / to tmpfs..."
760 mount -t proc proc /proc
761 size="\$(grep rootfssize= < /proc/cmdline | \\
762 sed 's/.*rootfssize=\\([0-9]*[kmg%]\\).*/-o size=\\1/')"
763 [ -n "\$size" ] || size="-o size=90%"
765 if [ -x /bin/httpfs ]; then # loram-http
767 while read var default; do
768 eval \$var=\$default
769 getarg \$var \$var
770 done <<EOT
771 eth eth0
772 dns 208.67.222.222,208.67.220.220
773 netmask 255.255.255.0
774 gw
775 ip
776 EOT
777 if [ -n "\$ip" ]; then
778 ifconfig \$eth \$ip netmask \$netmask up
779 route add default gateway \$gw
780 for i in \$(echo \$dns | sed 's/,/ /g'); do
781 echo "nameserver \$i" >> /etc/resolv.conf
782 done
783 else
784 udhcpc -f -q -s /lib/udhcpc -i \$eth
785 fi
786 for i in $urliso ; do
787 [ -n "\$URLISO" ] && URLISO="\$URLISO,"
788 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"
789 done
790 getarg urliso URLISO
791 DIR=fs
792 if getarg loram DIR; then
793 DEVICE=\${DIR%,*}
794 DIR=/\${DIR#*,}
795 fi
796 mount -t tmpfs \$size tmpfs /mnt
797 path2=/mnt/.httpfs/
798 path=/mnt/.cdrom/
799 mkdir -p /mnt/.rw \$path \$path2
800 while [ ! -d \$path/boot ]; do
801 for i in \$(echo \$URLISO | sed 's/,/ /g'); do
802 httpfs \$i \$path2 && break
803 done
804 mount -o loop,ro -t iso9660 \$path2/*.iso \$path
805 done
806 #copy_rootfs && umount -d \$path && umount -d \$path2
808 elif [ -f \$(echo /rootfs*.gz | cut -f1 -d' ') ]; then # loram-ram
810 total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g')
811 free=\$(grep MemFree /proc/meminfo | sed 's/[^0-9]//g')
812 if [ \$(( \$total/\$free )) -gt 1 ] || ! mount -t tmpfs \$size tmpfs /mnt; then
813 echo "No tmpfs for /mnt"
814 mkdir -p /mnt/.rw
815 mount -t tmpfs tmpfs /mnt/.rw
816 mkdir -p /mnt/.rw/mnt/.rw
817 path=/
818 else
819 mkdir -p /mnt/.rw
820 path=/mnt/.
821 for i in rootfs* ; do
822 mv /\$i \$path\$i
823 done
824 fi
826 else # loram-cdrom
828 getarg cdrom DRIVE_NAME ||
829 DRIVE_NAME=\$(grep "drive name" < /proc/sys/dev/cdrom/info | cut -f 3)
830 DEVICE=/dev/\$DRIVE_NAME
831 DIR=fs
832 if getarg loram DIR; then
833 DEVICE=\${DIR%,*}
834 DIR=/\${DIR#*,}
835 fi
836 mount -t tmpfs \$size tmpfs /mnt
837 mkdir -p /mnt/.rw /mnt/.cdrom /mnt/mnt/.cdrom
838 i=0
839 while [ \$i -lt 5 ] && ! mount -r \$DEVICE /mnt/.cdrom; do
840 case "\$DEVICE" in
841 /dev/sd*|UUID=*|LABEL=*)
842 mount -t sysfs sysfs /sys
843 USBDELAY=\$(cat /sys/module/usb_storage/parameters/delay_use)
844 umount /sys
845 sleep \$((1+\$USBDELAY)) ;;
846 esac
847 i=\$((i+1))
848 done
849 path=/mnt/.cdrom/
850 copy_rootfs && umount -d /mnt/.cdrom
852 fi
854 memfree=\$(grep MemFree /proc/meminfo | sed 's/[^0-9]//g')
855 umount /proc
856 branch=br=/mnt/.rw:/mnt/.cdrom/\$DIR
857 if [ ! -d /mnt/.cdrom/\$DIR/etc ]; then
858 branch=br=/mnt/.rw
859 for i in \${path}rootfs* ; do
860 fs=\${i#*root}
861 branch=\$branch:/mnt/.\$fs
862 mkdir -p /mnt/.rw/mnt/.\$fs /mnt/.\$fs /mnt/.rw/mnt/.cdrom
863 if [ -f /bin/cromfs-driver ]; then
864 cromfs-driver \${path}root\$fs /mnt/.\$fs -o ro,dev,suid,allow_other
865 else
866 insmod /lib/squashfs.ko.gz 2> /dev/null
867 mount -o loop,ro -t squashfs \${path}root\$fs /mnt/.\$fs
868 fi
869 done
870 else
871 mkdir -p /mnt/.rw/mnt/.httpfs
872 fi
873 insmod /lib/aufs.ko.gz
874 mount -t aufs -o \$branch none /mnt
875 [ -x /bin/httpfs ] && sed -i 's/DHCP="yes"/DHCP="no"/' /mnt/etc/network.conf
876 [ \$memfree -lt 30000 ] && sed -i 's/ slim//' /mnt/etc/rcS.conf
877 [ -x /mnt/sbin/init ] && exec /bin/switch_root mnt /sbin/init || sh
878 EOTEOT
879 chmod +x $TMP_DIR/initfs/init
880 ( cd $TMP_DIR/initfs ; find | busybox cpio -o -H newc 2> /dev/null) | \
881 lzma e $TMP_DIR/initfs.gz -si
882 rm -rf $TMP_DIR/initfs
883 rem=$(( $(stat -c "%s" $TMP_DIR/initfs.gz) % 4 ))
884 [ $rem -ne 0 ] &&
885 dd if=/dev/zero bs=1 count=$(( 4 - $rem )) >> $TMP_DIR/initfs.gz 2> /dev/null
886 return 0
887 }
889 # Move each initramfs to squashfs (or cromfs)
890 build_loram_rootfs()
891 {
892 rootfs_sizes=""
893 for i in $TMP_DIR/iso/boot/rootfs*.gz; do
894 mkdir -p $TMP_DIR/fs
895 cd $TMP_DIR/fs
896 ( zcat $i 2> /dev/null || unlzma -c $i) | cpio -idm
897 cd - > /dev/null
898 rootfs=$TMP_DIR/$(basename $i)
899 if [ -x /usr/bin/mkcromfs ]; then
900 /usr/bin/mkcromfs -qq -f 262144 -b 16384 $TMP_DIR/fs $rootfs
901 else
902 /usr/sbin/mksquashfs $TMP_DIR/fs $rootfs -comp xz -Xbcj x86
903 fi
904 cd $TMP_DIR
905 rootfs_sizes="$rootfs_sizes $(( $(du -s $TMP_DIR/fs | cut -f1) - $(du -s $rootfs | cut -f1) ))"
906 ( cd $(dirname $rootfs); echo $(basename $rootfs) | \
907 cpio -o -H newc ) > $rootfs.cpio
908 rm -f $rootfs
909 mv $rootfs.cpio $rootfs
910 cd - > /dev/null
911 rm -rf $TMP_DIR/fs
912 done
913 }
915 # Move each initramfs to squashfs (or cromfs)
916 build_loram_rootfs_cdrom()
917 {
918 mkdir -p $TMP_DIR/fs
919 cd $TMP_DIR/fs
920 for i in $TMP_DIR/iso/boot/rootfs*.gz; do
921 ( zcat $i 2> /dev/null || unlzma -c $i) | cpio -idm
922 done
923 rootfs=$TMP_DIR/rootfs.gz
924 if [ -x /usr/bin/mkcromfs ]; then
925 /usr/bin/mkcromfs -qq -f 262144 -b 16384 $TMP_DIR/fs $rootfs
926 else
927 /usr/sbin/mksquashfs $TMP_DIR/fs $rootfs -comp xz -Xbcj x86
928 fi
929 rm -rf $TMP_DIR/fs
930 cd $TMP_DIR
931 }
933 # Move meta boot configuration files to basic configuration files
934 # because meta loram flavor is useless when rootfs is not loaded in ram
935 unmeta_boot()
936 {
937 if [ -f $TMP_DIR/loramiso/boot/isolinux/noram.cfg ]; then
938 # We keep enough information to do unloram...
939 sed -i 's/label slitaz/label orgslitaz/' \
940 $TMP_DIR/loramiso/boot/isolinux/common.cfg
941 sed -i -e 's|=/boot/rootfs\(.*\).gz |=/boot/rootfs.gz |' \
942 -e 's|label slitaz1|label slitaz|' \
943 -e '/label slitaz[1-9]/{NNNd}' \
944 $TMP_DIR/loramiso/boot/isolinux/*.cfg
945 fi
946 }
948 # Move rootfs to squashfs filesystem(s) to the cdrom writeable with aufs.
949 # These squashfs may be loaded in ram a boot time.
950 # Rootfs are also copied to cdrom for tiny ramsize systems.
951 # Meta flavors are converted to normal flavors.
952 build_loram_cdrom()
953 {
954 build_initfs cdrom || return 1
955 build_loram_rootfs_cdrom
956 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
957 if [ "$1" == "small" ]; then
958 rm -f $TMP_DIR/loramiso/boot/root*
959 else
960 mkdir $TMP_DIR/loramiso/fs
961 cd $TMP_DIR/loramiso/fs
962 for i in $( ls ../boot/root* | sort -r ) ; do
963 ( zcat $i 2> /dev/null || unlzma -c $i ) | cpio -idmu
964 rm -f $i
965 done
966 mkdir -p $TMP_DIR/loramiso/fs/mnt/.cdrom
967 cd - > /dev/null
968 fi
969 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
970 mv $TMP_DIR/rootfs*.gz $TMP_DIR/loramiso
971 unmeta_boot
972 VOLUM_NAME="SliTaz_LoRAM_CDROM"
973 sed -i "s/root=/loram=LABEL=$VOLUM_NAME,fs &/" \
974 $TMP_DIR/loramiso/boot/isolinux/*.cfg
975 create_iso $OUTPUT $TMP_DIR/loramiso
976 }
978 # Create http bootstrap to load and remove loram_cdrom
979 # Meta flavors are converted to normal flavors.
980 build_loram_http()
981 {
982 build_initfs http || return 1
983 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
984 rm -f $TMP_DIR/loramiso/boot/rootfs*
985 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
986 unmeta_boot
987 create_iso $OUTPUT $TMP_DIR/loramiso
988 }
990 # Update meta flavor selection sizes.
991 # Reduce sizes with rootfs gains.
992 update_metaiso_sizes()
993 {
994 local append="$(grep append $TMP_DIR/loramiso/boot/isolinux/common.cfg)"
995 local new
996 [ -n "$append" ] || return
997 set -- $append
998 shift
999 new=""
1000 while [ -n "$2" ]; do
1001 local s
1002 case "$1" in
1003 *G) s=$(( ${1%G} * 1024 * 1024 ));;
1004 *M) s=$(( ${1%M} * 1024 ));;
1005 *) s=${1%K};;
1006 esac
1007 rootfs_sizes=${rootfs_sizes#* }
1008 for i in $rootfs_sizes ; do
1009 s=$(( $s - $i ))
1010 done
1011 new="$new $s $2"
1012 shift 2
1013 done
1014 sed -i "s/append .*/append$new $1/" $TMP_DIR/loramiso/boot/isolinux/common.cfg
1017 # Move rootfs to a squashfs filesystem into the initramfs writeable with aufs.
1018 # Meta flavor selection sizes are updated.
1019 build_loram_ram()
1021 build_initfs ram || return 1
1022 build_loram_rootfs
1023 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1024 rm -f $TMP_DIR/loramiso/boot/bzImage
1025 ln $TMP_DIR/loramiso/boot/vmlinuz* $TMP_DIR/loramiso/boot/bzImage
1026 rootfs=$(ls $TMP_DIR/rootfs* | sort | tail -n 1)
1027 cat $rootfs >> $TMP_DIR/initfs.gz
1028 mv $TMP_DIR/initfs.gz $rootfs
1029 cp $TMP_DIR/rootfs* $TMP_DIR/loramiso/boot
1030 update_metaiso_sizes
1031 create_iso $OUTPUT $TMP_DIR/loramiso
1034 # Remove files installed by packages
1035 find_flavor_rootfs()
1037 for i in $1/etc/tazlito/*.extract; do
1038 [ -e $i ] || continue
1039 chroot $1 /bin/sh ${i#$1}
1040 done
1042 # Clean hardlinks and files patched by genisofs in /boot
1043 for i in isolinux/isolinux.bin isolinux/boot.cat bzImage ; do
1044 rm -f $1/boot/$i
1045 done
1047 # Clean files generated in post_install
1048 rm -f $1/lib/modules/*/modules.* $1/etc/mtab \
1049 $1/dev/core $1/dev/fd $1/dev/std*
1051 # Verify md5
1052 cat $1/var/lib/tazpkg/installed/*/md5sum | \
1053 while read md5 file; do
1054 [ -e $1$file ] || continue
1055 [ "$(cat $1$file | md5sum)" == "$md5 -" ] &&
1056 rm -f $1$file
1057 done
1059 # Check configuration files
1060 for i in $1/var/lib/tazpkg/installed/*/volatile.cpio.gz; do
1061 [ -e $i ] || continue
1062 mkdir /tmp/volatile$$
1063 zcat $i | ( cd /tmp/volatile$$ ; cpio -idmu > /dev/null )
1064 ( cd /tmp/volatile$$ ; find * -type f ) | while read file ; do
1065 [ -e $1/$file ] || continue
1066 cmp -s /tmp/volatile$$/$file $1/$file && rm -f $1/$file
1067 done
1068 rm -rf /tmp/volatile$$
1069 done
1071 # Remove other files blindly
1072 for i in $1/var/lib/tazpkg/installed/*/files.list; do
1073 for file in $(cat $i); do
1074 [ $1$file -nt $i ] && continue
1075 [ -f $1$file -a ! -L $1$file ] && continue
1076 [ -d $1$file ] || rm -f $1$file
1077 done
1078 done
1080 # Remove tazpkg files and tmp files
1081 rm -rf $1/var/lib/tazpkg/installed* $1/tmp $1/var/tmp
1082 rm -f $1/var/lib/tazpkg/*packages* $1/var/lib/tazpkg/files.list.lzma \
1083 $1/var/lib/tazpkg/mirror* $1/var/cache/*/* \
1084 $1/var/lock/* $1/var/log/* $1/var/run/* $1/var/run/*/* \
1085 $1/var/lib/* $1/var/lib/dbus/* 2> /dev/null
1087 # Cleanup directory tree
1088 cd $1
1089 find * -type d | sort -r | while read dir; do
1090 rmdir $dir 2> /dev/null
1091 done
1092 cd - > /dev/null
1095 ####################
1096 # Tazlito commands #
1097 ####################
1099 case "$COMMAND" in
1100 stats)
1101 # Tazlito general statistics from the config file.
1103 echo ""
1104 echo -e "\033[1mTazlito statistics\033[0m
1105 ===============================================================================
1106 Config file : $CONFIG_FILE
1107 ISO name : $ISO_NAME.iso
1108 Volume name : $VOLUM_NAME
1109 Prepared : $PREPARED
1110 Packages repository : $PACKAGES_REPOSITORY
1111 Distro directory : $DISTRO"
1112 if [ ! "$ADDFILES" = "" ] ; then
1113 echo -e "Additional files : $ADDFILES"
1114 fi
1115 echo "================================================================================"
1116 echo ""
1117 ;;
1118 list-addfiles)
1119 # Simple list of additional files in the rootfs
1120 echo ""
1121 cd $ADDFILES
1122 find rootfs -type f
1123 echo "" ;;
1124 gen-config)
1125 # Generate a new config file in the current dir or the specified
1126 # directory by $2.
1128 if [ -n "$2" ] ; then
1129 mkdir -p $2 && cd $2
1130 fi
1131 echo -n "Generating empty tazlito.conf..."
1132 empty_config_file
1133 status
1134 echo ""
1135 if [ -f "tazlito.conf" ] ; then
1136 echo "Configuration file is ready to edit."
1137 echo "File location : `pwd`/tazlito.conf"
1138 echo ""
1139 fi
1140 ;;
1141 configure)
1142 # Configure a tazlito.conf config file. Start by getting
1143 # a empty config file and sed it.
1145 if [ -f "tazlito.conf" ] ; then
1146 rm tazlito.conf
1147 else
1148 if test $(id -u) = 0 ; then
1149 cd /etc
1150 else
1151 echo "You must be root to configure the main config file or in"
1152 echo "the same directory of the file you want to configure."
1153 exit 0
1154 fi
1155 fi
1156 empty_config_file
1157 echo""
1158 echo -e "\033[1mConfiguring :\033[0m `pwd`/tazlito.conf"
1159 echo "================================================================================"
1160 # ISO name.
1161 echo -n "ISO name : " ; read answer
1162 sed -i s#'ISO_NAME=\"\"'#"ISO_NAME=\"$answer\""# tazlito.conf
1163 # Volume name.
1164 echo -n "Volume name : " ; read answer
1165 sed -i s/'VOLUM_NAME=\"SliTaz\"'/"VOLUM_NAME=\"$answer\""/ tazlito.conf
1166 # Packages repository.
1167 echo -n "Packages repository : " ; read answer
1168 sed -i s#'PACKAGES_REPOSITORY=\"\"'#"PACKAGES_REPOSITORY=\"$answer\""# tazlito.conf
1169 # Distro path.
1170 echo -n "Distro path : " ; read answer
1171 sed -i s#'DISTRO=\"\"'#"DISTRO=\"$answer\""# tazlito.conf
1172 echo "================================================================================"
1173 echo "Config file is ready to use."
1174 echo "You can now extract an ISO or generate a distro."
1175 echo ""
1176 ;;
1177 gen-iso)
1178 # Simply generate a new iso.
1180 check_root
1181 verify_rootcd
1182 gen_livecd_isolinux
1183 distro_stats
1184 ;;
1185 gen-initiso)
1186 # Simply generate a new initramfs with a new iso.
1188 check_root
1189 verify_rootcd
1190 gen_initramfs $ROOTFS
1191 gen_livecd_isolinux
1192 distro_stats
1193 ;;
1194 extract-distro)
1195 # Extract an ISO image to a directory and rebuild the LiveCD tree.
1197 check_root
1198 ISO_IMAGE=$2
1199 if [ -z "$ISO_IMAGE" ] ; then
1200 echo -e "\nPlease specify the path to the ISO image."
1201 echo -e "Example : `basename $0` image.iso /path/target\n"
1202 exit 0
1203 fi
1204 # Set the distro path by checking for $3 on cmdline.
1205 if [ -n "$3" ] ; then
1206 TARGET=$3
1207 else
1208 TARGET=$DISTRO
1209 fi
1210 # Exit if existing distro is found.
1211 if [ -d "$TARGET/rootfs" ] ; then
1212 echo -e "\nA rootfs exists in : $TARGET"
1213 echo -e "Please clean the distro tree or change directory path.\n"
1214 exit 0
1215 fi
1216 echo ""
1217 echo -e "\033[1mTazlito extracting :\033[0m `basename $ISO_IMAGE`"
1218 echo "================================================================================"
1219 # Start to mount the ISO.
1220 echo ""
1221 echo "Mounting ISO image..."
1222 mkdir -p $TMP_DIR
1223 # Get ISO file size.
1224 isosize=`du -sh $ISO_IMAGE | cut -f1`
1225 mount -o loop $ISO_IMAGE $TMP_DIR
1226 sleep 2
1227 # Prepare target dir, copy the kernel and the rootfs.
1228 mkdir -p $TARGET/rootfs
1229 mkdir -p $TARGET/rootcd/boot
1230 echo -n "Copying the Linux kernel..."
1231 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
1232 ln $TARGET/rootcd/boot/vmlinuz* $TARGET/rootcd/boot/bzImage
1233 else
1234 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
1235 fi
1236 status
1237 echo -n "Copying isolinux files..."
1238 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
1239 for i in $(ls $TMP_DIR); do
1240 [ "$i" = "boot" ] && continue
1241 cp -a $TMP_DIR/$i $TARGET/rootcd
1242 done
1243 status
1244 if [ -d $TMP_DIR/boot/syslinux ]; then
1245 echo -n "Copying syslinux files..."
1246 cp -a $TMP_DIR/boot/syslinux $TARGET/rootcd/boot
1247 status
1248 fi
1249 if [ -d $TMP_DIR/boot/extlinux ]; then
1250 echo -n "Copying extlinux files..."
1251 cp -a $TMP_DIR/boot/extlinux $TARGET/rootcd/boot
1252 status
1253 fi
1254 if [ -d $TMP_DIR/boot/grub ]; then
1255 echo -n "Copying GRUB files..."
1256 cp -a $TMP_DIR/boot/grub $TARGET/rootcd/boot
1257 status
1258 fi
1260 echo -n "Copying the rootfs..."
1261 cp $TMP_DIR/boot/rootfs.?z $TARGET/rootcd/boot
1262 status
1263 # Extract initramfs.
1264 cd $TARGET/rootfs
1265 echo -n "Extracting the rootfs... "
1266 extract_rootfs ../rootcd/boot/rootfs.gz $TARGET/rootfs
1267 # unpack /usr
1268 for i in etc/tazlito/*.extract; do
1269 [ -f "$i" ] && . $i ../rootcd
1270 done
1271 # Umount and remove temp directory and cd to $TARGET to get stats.
1272 umount $TMP_DIR && rm -rf $TMP_DIR
1273 cd ..
1274 echo ""
1275 echo "================================================================================"
1276 echo "Extracted : `basename $ISO_IMAGE` ($isosize)"
1277 echo "Distro tree : `pwd`"
1278 echo "Rootfs size : `du -sh rootfs`"
1279 echo "Rootcd size : `du -sh rootcd`"
1280 echo "================================================================================"
1281 echo ""
1282 ;;
1283 list-flavors)
1284 # Show available flavors.
1285 if [ ! -s /etc/tazlito/flavors.list -o "$2" == "--recharge" ]; then
1286 download flavors.list -O - > /etc/tazlito/flavors.list
1287 fi
1288 echo ""
1289 echo -e "\033[1mList of flavors\033[0m"
1290 echo "================================================================================"
1291 cat /etc/tazlito/flavors.list
1292 echo ""
1293 ;;
1294 show-flavor)
1295 # Show flavor description.
1296 FLAVOR=${2%.flavor}
1297 if [ ! -f "$FLAVOR.flavor" ]; then
1298 echo "File $FLAVOR.flavor not found."
1299 exit 1
1300 fi
1301 mkdir $TMP_DIR
1302 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i > /dev/null)
1303 if [ "$3" = "--brief" ]; then
1304 if [ "$4" != "--noheader" ]; then
1305 echo "Name ISO Rootfs Description"
1306 echo "================================================================================"
1307 fi
1308 printf "%-16.16s %6.6s %6.6s %s\n" "$FLAVOR" \
1309 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
1310 "$(field 'Rootfs size' $TMP_DIR/$FLAVOR.desc)" \
1311 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
1312 else
1313 echo "================================================================================"
1314 cat $TMP_DIR/$FLAVOR.desc
1315 fi
1316 rm -Rf $TMP_DIR
1317 ;;
1318 gen-liveflavor)
1319 # Generate a new flavor from the live system.
1320 FLAVOR=${2%.flavor}
1321 DESC=""
1322 case "$FLAVOR" in
1323 '') echo -n "Flavor name : "
1324 read FLAVOR
1325 [ -z "$FLAVOR" ] && exit 1;;
1326 -?|-h*|--help) echo -e "
1328 SliTaz Live Tool - Version: $VERSION
1329 \033[1mUsage: \033[0m `basename $0` gen-liveflavor flavor-name [flavor-patch-file]
1330 \033[1mflavor-patch-file format: \033[0m
1331 code data
1332 + package to add
1333 - package to remove
1334 ! non-free package to add
1335 ? display message
1336 @ flavor description
1338 \033[1mExample: \033[0m
1339 @ Developer tools for slitaz maintainers
1340 + slitaz-toolchain
1341 + mercurial
1343 exit 1;;
1344 esac
1345 mv /etc/tazlito/distro-packages.list \
1346 /etc/tazlito/distro-packages.list.$$ 2> /dev/null
1347 rm -f distro-packages.list non-free.list 2> /dev/null
1348 tazpkg recharge
1349 [ -n "$3" ] && while read action pkg; do
1350 case "$action" in
1351 +) yes | tazpkg get-install $pkg;;
1352 -) yes | tazpkg remove $pkg;;
1353 !) echo $pkg >> non-free.list;;
1354 @) DESC="$pkg";;
1355 \?) echo -en "$pkg"; read action;;
1356 esac
1357 done < $3
1358 yes '' | tazlito gen-distro
1359 echo "$DESC" | tazlito gen-flavor "$FLAVOR"
1360 mv /etc/tazlito/distro-packages.list.$$ \
1361 /etc/tazlito/distro-packages.list 2> /dev/null
1362 ;;
1363 gen-flavor)
1364 # Generate a new flavor from the last iso image generated.
1365 FLAVOR=${2%.flavor}
1366 echo ""
1367 echo -e "\033[1mFlavor generation\033[0m"
1368 echo "================================================================================"
1369 if [ -z "$FLAVOR" ]; then
1370 echo -n "Flavor name : "
1371 read FLAVOR
1372 [ -z "$FLAVOR" ] && exit 1
1373 fi
1374 check_rootfs
1375 FILES="$FLAVOR.pkglist"
1376 echo -n "Creating file $FLAVOR.flavor..."
1377 for i in rootcd rootfs; do
1378 if [ -d "$ADDFILES/$i" ] ; then
1379 FILES="$FILES\n$FLAVOR.$i"
1380 ( cd "$ADDFILES/$i"; find . | \
1381 cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
1382 fi
1383 done
1384 status
1385 answer=`grep -s ^Description $FLAVOR.desc`
1386 answer=${answer#Description : }
1387 if [ -z "$answer" ]; then
1388 echo -n "Description : "
1389 read answer
1390 fi
1391 echo -n "Compressing flavor $FLAVOR..."
1392 echo "Flavor : $FLAVOR" > $FLAVOR.desc
1393 echo "Description : $answer" >> $FLAVOR.desc
1394 ( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
1395 \rm -f $FLAVOR.pkglist $FLAVOR.nonfree 2> /dev/null
1396 for i in $(ls $ROOTFS$INSTALLED); do
1397 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
1398 EXTRAVERSION=""
1399 eval $(grep ^EXTRAVERSION= $ROOTFS$INSTALLED/$i/receipt)
1400 eval $(grep ^CATEGORY= $ROOTFS$INSTALLED/$i/receipt)
1401 if [ "$CATEGORY" = "non-free" -a "${i%%-*}" != "get" ]
1402 then
1403 echo "$i" >> $FLAVOR.nonfree
1404 else
1405 echo "$i-$VERSION$EXTRAVERSION" >> $FLAVOR.pkglist
1406 fi
1407 done
1408 [ -s $FLAVOR.nonfree ] && $FILES="$FILES\n$FLAVOR.nonfree"
1409 for i in $LOCALSTATE/undigest/*/mirror ; do
1410 [ -s $i ] && cat $i >> $FLAVOR.mirrors
1411 done
1412 [ -s $FLAVOR.mirrors ] && $FILES="$FILES\n$FLAVOR.mirrors"
1413 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
1414 gzip -9 > $FLAVOR.flavor
1415 rm `echo -e $FILES`
1416 status
1417 echo "================================================================================"
1418 echo "Flavor size : `du -sh $FLAVOR.flavor`"
1419 echo ""
1420 ;;
1421 upgrade-flavor)
1422 # Update package list to the latest versions available.
1423 FLAVOR=${2%.flavor}
1424 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1425 mkdir $TMP_DIR
1426 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1427 echo -n "Updating $FLAVOR package list..."
1428 [ -s /var/lib/tazpkg/packages.list ] || tazpkg recharge
1429 packed_size=0; unpacked_size=0
1430 while read org; do
1431 i=0
1432 pkg=$org
1433 while ! grep -q ^$pkg$ /var/lib/tazpkg/packages.txt; do
1434 pkg=${pkg%-*}
1435 i=$(($i + 1))
1436 [ $i -gt 5 ] && break;
1437 done
1438 set -- $(get_size $pkg)
1439 packed_size=$(( $packed_size + $1 ))
1440 unpacked_size=$(( $unpacked_size + $2 ))
1441 for i in $(grep ^$pkg /var/lib/tazpkg/packages.list); do
1442 echo $i
1443 break
1444 done
1445 done < $TMP_DIR/$FLAVOR.pkglist \
1446 > $TMP_DIR/$FLAVOR.pkglist.$$
1447 mv -f $TMP_DIR/$FLAVOR.pkglist.$$ $TMP_DIR/$FLAVOR.pkglist
1448 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1449 packed_size=$(($packed_size \
1450 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1451 unpacked_size=$(($unpacked_size \
1452 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1453 fi
1454 # Estimate lzma
1455 packed_size=$(($packed_size * 2 / 3))
1456 iso_size=$(( $packed_size + 26000 ))
1457 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1458 iso_size=$(($iso_size \
1459 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1460 fi
1461 sed -i -e '/Image is ready/d' \
1462 -e "s/Rootfs size\( *:\) \(.*\)/Rootfs size\1 $(cent2human $unpacked_size) (estimated)/" \
1463 -e "s/Initramfs size\( *:\) \(.*\)/Initramfs size\1 $(cent2human $packed_size) (estimated)/" \
1464 -e "s/ISO image size\( *:\) \(.*\)/ISO image size\1 $(cent2human $iso_size) (estimated)/" \
1465 -e "s/date\( *:\) \(.*\)/date\1 $(date +%Y%m%d\ \at\ \%H:%M:%S)/" \
1466 $TMP_DIR/$FLAVOR.desc
1467 ( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
1468 $FLAVOR.flavor
1469 status
1470 rm -Rf $TMP_DIR
1471 fi
1472 ;;
1473 extract-flavor)
1474 # Extract a flavor into $FLAVORS_REPOSITORY.
1475 FLAVOR=${2%.flavor}
1476 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1477 mkdir $TMP_DIR
1478 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1479 echo -n "Extracting $FLAVOR..."
1480 rm -rf $FLAVORS_REPOSITORY/$FLAVOR 2> /dev/null
1481 mkdir -p $FLAVORS_REPOSITORY/$FLAVOR
1482 echo "FLAVOR=\"$FLAVOR\"" > $FLAVORS_REPOSITORY/$FLAVOR/receipt
1483 grep ^Description $TMP_DIR/$FLAVOR.desc | \
1484 sed 's/.*: \(.*\)$/SHORT_DESC="\1"/' >> \
1485 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1486 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc && \
1487 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1488 sed 's/.*: \(.*\)$/ROOTFS_SELECTION="\1"/' >> \
1489 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1490 grep '^Rootfs size' $TMP_DIR/$FLAVOR.desc | \
1491 sed 's/.*: \(.*\)$/ROOTFS_SIZE="\1"/' >> \
1492 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1493 grep ^Initramfs $TMP_DIR/$FLAVOR.desc | \
1494 sed 's/.*: \(.*\)$/INITRAMFS_SIZE="\1"/' >> \
1495 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1496 grep ^ISO $TMP_DIR/$FLAVOR.desc | \
1497 sed 's/.*: \(.*\)$/ISO_SIZE="\1"/' >> \
1498 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1499 for i in rootcd rootfs; do
1500 [ -f $TMP_DIR/$FLAVOR.$i ] || continue
1501 mkdir $FLAVORS_REPOSITORY/$FLAVOR/$i
1502 zcat $TMP_DIR/$FLAVOR.$i | \
1503 (cd $FLAVORS_REPOSITORY/$FLAVOR/$i; \
1504 cpio -idm > /dev/null)
1505 done
1506 [ -s $TMP_DIR/$FLAVOR.mirrors ] &&
1507 cp $TMP_DIR/$FLAVOR.mirrors \
1508 $FLAVORS_REPOSITORY/$FLAVOR/mirrors
1509 [ -s /var/lib/tazpkg/packages.list ] || tazpkg recharge
1510 while read org; do
1511 i=0
1512 pkg=$org
1513 while ! grep -q ^$pkg$ /var/lib/tazpkg/packages.txt; do
1514 pkg=${pkg%-*}
1515 i=$(($i + 1))
1516 [ $i -gt 5 ] && break;
1517 done
1518 echo $pkg
1519 done < $TMP_DIR/$FLAVOR.pkglist \
1520 > $FLAVORS_REPOSITORY/$FLAVOR/packages.list
1521 status
1522 rm -Rf $TMP_DIR
1523 fi
1524 ;;
1525 pack-flavor)
1526 # Create a flavor from $FLAVORS_REPOSITORY.
1527 FLAVOR=${2%.flavor}
1528 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/receipt ]; then
1529 mkdir $TMP_DIR
1530 echo -n "Creating flavor $FLAVOR..."
1531 [ -s /var/lib/tazpkg/packages.list ] || tazpkg recharge
1532 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/mirrors ]; then
1533 cp $FLAVORS_REPOSITORY/$FLAVOR/mirrors \
1534 $TMP_DIR/$FLAVOR.mirrors
1535 for i in $(cat $TMP_DIR/$FLAVOR.mirrors); do
1536 wget -O - $i/packages.list >> $TMP_DIR/packages.list
1537 done
1538 fi
1539 [ -s $FLAVORS_REPOSITORY/$FLAVOR/packages.list ] &&
1540 get_pkglist $FLAVOR > $TMP_DIR/$FLAVOR.pkglist
1541 if grep -q ^ROOTFS_SELECTION \
1542 $FLAVORS_REPOSITORY/$FLAVOR/receipt; then
1543 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1544 set -- $ROOTFS_SELECTION
1545 [ -n "$FRUGAL_RAM" ] || FRUGAL_RAM=$1
1546 [ -f $FLAVORS_REPOSITORY/$2/packages.list ] ||
1547 tazlito extract-flavor $2
1548 get_pkglist $2 > $TMP_DIR/$FLAVOR.pkglist
1549 for i in rootcd rootfs; do
1550 mkdir $TMP_DIR/$i
1551 # Copy extra files from the first flavor
1552 [ -d $FLAVORS_REPOSITORY/$2/$i ] &&
1553 cp -a $FLAVORS_REPOSITORY/$2/$i $TMP_DIR
1554 # Overload extra files by meta flavor
1555 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] &&
1556 cp -a $FLAVORS_REPOSITORY/$FLAVOR/$i $TMP_DIR
1557 [ -n "$(ls $TMP_DIR/$i)" ] &&
1558 ( cd $TMP_DIR/$i ; find . | cpio -o -H newc 2> /dev/null ) | \
1559 gzip -9 >$TMP_DIR/$FLAVOR.$i
1560 rm -rf $TMP_DIR/$i
1561 done
1562 else
1563 for i in rootcd rootfs; do
1564 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] || \
1565 continue
1566 ( cd $FLAVORS_REPOSITORY/$FLAVOR/$i ; \
1567 find . | cpio -o -H newc 2> /dev/null ) | \
1568 gzip -9 >$TMP_DIR/$FLAVOR.$i
1569 done
1570 fi
1571 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1572 packed_size=$(($packed_size \
1573 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1574 unpacked_size=$(($unpacked_size \
1575 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1576 fi
1577 # Estimate lzma
1578 packed_size=$(($packed_size * 2 / 3))
1579 iso_size=$(( $packed_size + 26000 ))
1580 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1581 iso_size=$(($iso_size \
1582 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1583 fi
1584 VERSION=""
1585 MAINTAINER=""
1586 ROOTFS_SELECTION=""
1587 ROOTFS_SIZE="$(cent2human $unpacked_size) (estimated)"
1588 INITRAMFS_SIZE="$(cent2human $packed_size) (estimated)"
1589 ISO_SIZE="$(cent2human $iso_size) (estimated)"
1590 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1591 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1592 Flavor : $FLAVOR
1593 Description : $SHORT_DESC
1594 EOT
1595 [ -n "$VERSION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1596 Version : $VERSION
1597 EOT
1598 [ -n "$MAINTAINER" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1599 Maintainer : $MAINTAINER
1600 EOT
1601 [ -n "$FRUGAL_RAM" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1602 LiveCD RAM size : $FRUGAL_RAM
1603 EOT
1604 [ -n "$ROOTFS_SELECTION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1605 Rootfs list : $ROOTFS_SELECTION
1606 EOT
1607 cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1608 Build date : $(date +%Y%m%d\ \at\ \%H:%M:%S)
1609 Packages : $(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l)
1610 Rootfs size : $ROOTFS_SIZE
1611 Initramfs size : $INITRAMFS_SIZE
1612 ISO image size : $ISO_SIZE
1613 ================================================================================
1615 EOT
1616 rm -f $TMP_DIR/packages.list
1617 ( cd $TMP_DIR ; ls | cpio -o -H newc 2> /dev/null) | \
1618 gzip -9 > $FLAVOR.flavor
1619 status
1620 rm -Rf $TMP_DIR
1621 else
1622 echo "No $FLAVOR flavor in $FLAVORS_REPOSITORY."
1623 fi
1624 ;;
1625 get-flavor)
1626 # Get a flavor's files and prepare for gen-distro.
1627 FLAVOR=${2%.flavor}
1628 echo ""
1629 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1630 echo -n "Cleaning $DISTRO..."
1631 rm -R $DISTRO 2> /dev/null
1632 mkdir -p $DISTRO
1633 status
1634 mkdir $TMP_DIR
1635 echo -n "Extracting flavor $FLAVOR.flavor... "
1636 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1637 echo -n "Creating distro-packages.list..."
1638 mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
1639 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
1640 status
1641 infos="$FLAVOR.desc"
1642 for i in rootcd rootfs; do
1643 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
1644 echo -n "Adding $i... "
1645 mkdir -p "$ADDFILES/$i"
1646 zcat $TMP_DIR/$FLAVOR.$i | \
1647 ( cd "$ADDFILES/$i"; cpio -id > /dev/null)
1648 zcat $TMP_DIR/$FLAVOR.$i | cpio -tv \
1649 > $TMP_DIR/$FLAVOR.list$i
1650 infos="$infos\n$FLAVOR.list$i"
1651 fi
1652 done
1653 if [ -s $TMP_DIR/$FLAVOR.mirrors ]; then
1654 n=""
1655 while read line; do
1656 mkdir -p $LOCALSTATE/undigest/$FLAVOR$n
1657 echo "$line" > $LOCALSTATE/undigest/$FLAVOR$n/mirror
1658 n=$(( $n + 1 ))
1659 done < $TMP_DIR/$FLAVOR.mirrors
1660 infos="$infos\n$FLAVOR.mirrors"
1661 tazpkg recharge
1662 fi
1663 rm -f /etc/tazlito/rootfs.list
1664 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc &&
1665 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1666 sed 's/.*: \(.*\)$/\1/' > /etc/tazlito/rootfs.list
1667 echo -n "Updating tazlito.conf..."
1668 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
1669 cat tazlito.conf | grep -v "^#VOLUM_NAME" | \
1670 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
1671 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
1672 sed -i "s/ISO_NAME=.*/ISO_NAME=\"slitaz-$FLAVOR\"/" tazlito.conf
1673 status
1674 ( cd $TMP_DIR ; echo -e $infos | cpio -o -H newc ) | \
1675 gzip -9 > /etc/tazlito/info
1676 rm -Rf $TMP_DIR
1677 fi
1678 echo ""
1679 ;;
1681 iso2flavor)
1682 if [ -z "$3" -o ! -s "$2" ]; then
1683 cat <<EOT
1684 Usage : tazlito iso2flavor image.iso flavor_name
1686 Create a file flavor_name.flavor from the cdrom image file image.iso
1687 EOT
1688 exit 1
1689 fi
1690 FLAVOR=${3%.flavor}
1691 mkdir -p $TMP_DIR/iso $TMP_DIR/rootfs
1692 mount -o loop,ro $2 $TMP_DIR/iso
1693 if [ -s $TMP_DIR/iso/boot/rootfs1.gz ]; then
1694 echo "META flavors are not supported."
1695 umount -d $TMP_DIR/iso
1696 elif [ ! -s $TMP_DIR/iso/boot/rootfs.gz ]; then
1697 echo "No /boot/rootfs.gz in iso image. Need a SliTaz iso."
1698 umount -d $TMP_DIR/iso
1699 else
1700 ( unlzma -c $TMP_DIR/iso/boot/rootfs.gz || \
1701 zcat $TMP_DIR/iso/boot/rootfs.gz ) | \
1702 ( cd $TMP_DIR/rootfs ; cpio -idmu > /dev/null )
1703 if [ ! -s $TMP_DIR/rootfs/etc/slitaz-release ]; then
1704 echo "No file /etc/slitaz-release in /boot/rootfs.gz of iso image. Need a non loram SliTaz iso."
1705 umount -d $TMP_DIR/iso
1706 else
1707 ROOTFS_SIZE=$(du -hs $TMP_DIR/rootfs | awk '{ print $1 }')
1708 RAM_SIZE=$(du -s $TMP_DIR/rootfs | awk '{ print 32*int(($1+36000)/32768) "M" }')
1709 cp -a $TMP_DIR/iso $TMP_DIR/rootcd
1710 ISO_SIZE=$(df -h $TMP_DIR/iso | awk 'END { print $2 }')
1711 BUILD_DATE=$(date +%Y%m%d\ \at\ \%H:%M:%S -r $TMP_DIR/iso/md5sum)
1712 umount -d $TMP_DIR/iso
1713 INITRAMFS_SIZE=$(du -chs $TMP_DIR/rootcd/boot/rootfs.gz | awk '{ s=$1 } END { print $1 }')
1714 rm -f $TMP_DIR/rootcd/boot/rootfs.gz $TMP_DIR/rootcd/md5sum
1715 mv $TMP_DIR/rootcd/boot $TMP_DIR/rootfs
1716 sed 's/.* \(.*\).tazpkg*/\1/' > $TMP_DIR/$FLAVOR.pkglist \
1717 < $TMP_DIR/rootfs/var/lib/tazpkg/installed.md5
1718 #[ -s $TMP_DIR/rootfs/etc/tazlito/distro-packages.list ] &&
1719 # mv $TMP_DIR/rootfs/etc/tazlito/distro-packages.list $TMP_DIR/$FLAVOR.pkglist
1720 PKGCNT=$(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l | awk '{ print $1 }')
1721 find_flavor_rootfs $TMP_DIR/rootfs
1722 [ -d $TMP_DIR/rootfs/boot ] && mv $TMP_DIR/rootfs/boot $TMP_DIR/rootcd
1723 [ -n "$(ls $TMP_DIR/rootfs)" ] && ( cd $TMP_DIR/rootfs ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootfs
1724 [ -n "$(ls $TMP_DIR/rootcd)" ] && ( cd $TMP_DIR/rootcd ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootcd
1725 rm -rf $TMP_DIR/rootcd $TMP_DIR/rootfs
1726 VERSION=""; MAINTAINER=""
1727 echo -en "Flavor short description \007: "; read -t 30 DESCRIPTION
1728 if [ -n "$DESCRIPTION" ]; then
1729 echo -en "Flavor version : "; read -t 30 VERSION
1730 echo -en "Flavor maintainer (your email) : "; read -t 30 MAINTAINER
1731 fi
1732 [ -n "$DESCRIPTION" ] || DESCRIPTION="Slitaz $FLAVOR flavor"
1733 [ -n "$VERSION" ] || VERSION="1.0"
1734 [ -n "$MAINTAINER" ] || MAINTAINER="nobody@slitaz.org"
1735 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1736 Flavor : $FLAVOR
1737 Description : $DESCRIPTION
1738 Version : $VERSION
1739 Maintainer : $MAINTAINER
1740 LiveCD RAM size : $RAM_SIZE
1741 Build date : $BUILD_DATE
1742 Packages : $PKGCNT
1743 Rootfs size : $ROOTFS_SIZE
1744 Initramfs size : $INITRAMFS_SIZE
1745 ISO image size : $ISO_SIZE
1746 ================================================================================
1748 EOT
1749 ( cd $TMP_DIR ; ls $FLAVOR.* | cpio -o -H newc ) | gzip -9 > $FLAVOR.flavor
1750 cat <<EOT
1751 Tazlito can't detect each file installed during a package post_install.
1752 You should extract this flavor (tazlito extract-flavor $FLAVOR),
1753 check the files in /home/slitaz/flavors/$FLAVOR/rootfs tree and remove
1754 files generated by post_installs.
1755 Check /home/slitaz/flavors/$FLAVOR/receipt too and repack the flavor
1756 (tazlito pack-flavor $FLAVOR)
1757 EOT
1758 fi
1759 fi
1760 rm -rf $TMP_DIR
1761 ;;
1763 check-list)
1764 # Use current packages list in $PWD by default.
1765 DISTRO_PKGS_LIST=distro-packages.list
1766 [ -d "$2" ] && DISTRO_PKGS_LIST=$2/distro-packages.list
1767 [ -f "$2" ] && DISTRO_PKGS_LIST=$2
1768 [ ! -f $DISTRO_PKGS_LIST ] && echo "No packages list found." && exit 0
1769 echo ""
1770 echo -e "\033[1mLiveCD packages list check\033[0m"
1771 echo "================================================================================"
1772 for pkg in `cat $DISTRO_PKGS_LIST`
1773 do
1774 if ! grep -q "$pkg" /var/lib/tazpkg/packages.list; then
1775 echo "Update: $pkg"
1776 up=$(($up + 1))
1777 fi
1778 done
1779 [ -z $up ] && echo -e "List is up-to-date\n" && exit 0
1780 echo "================================================================================"
1781 echo -e "Updates: $up\n" ;;
1782 gen-distro)
1783 # Generate a live distro tree with a set of packages.
1785 check_root
1787 # Check if a package list was specified on cmdline.
1788 LIST_NAME="distro-packages.list"
1789 CDROM=""
1790 while [ -n "$2" ]; do
1791 case "$2" in
1792 --iso=*)
1793 CDROM="-o loop ${2#--iso=}"
1794 ;;
1795 --cdrom)
1796 CDROM="/dev/cdrom"
1797 ;;
1798 --force)
1799 DELETE_ROOTFS="true"
1800 ;;
1801 *) if [ ! -f "$2" ] ; then
1802 echo -e "\nUnable to find the specified packages list."
1803 echo -e "List name : $2\n"
1804 exit 1
1805 fi
1806 LIST_NAME=$2
1807 ;;
1808 esac
1809 shift
1810 done
1812 if [ -d $ROOTFS ] ; then
1813 # Delete $ROOTFS if --force is set on command line
1814 if [ ! -z $DELETE_ROOTFS ]; then
1815 rm -rf $ROOTFS
1816 unset $DELETE_ROOTFS
1817 else
1818 echo -e "\nA rootfs exists in : $DISTRO"
1819 echo -e "Please clean the distro tree or change directory path.\n"
1820 exit 0
1821 fi
1822 fi
1823 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
1824 # Build list with installed packages
1825 for i in $(ls $INSTALLED); do
1826 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
1827 EXTRAVERSION=""
1828 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
1829 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
1830 done
1831 fi
1832 # Exit if no list name.
1833 if [ ! -f "$LIST_NAME" ]; then
1834 echo -e "\nNo packages list found or specified. Please read the docs.\n"
1835 exit 0
1836 fi
1837 # Start generation.
1838 echo ""
1839 echo -e "\033[1mTazlito generating a distro\033[0m"
1840 echo "================================================================================"
1841 # Misc checks
1842 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
1843 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
1844 # Get the list of packages using cat for a file list.
1845 LIST=`cat $LIST_NAME`
1846 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
1847 REPACK=""
1848 DOWNLOAD=""
1849 for pkg in $LIST
1850 do
1851 [ "$pkg" = "" ] && continue
1852 pkg=${pkg%.tazpkg}
1853 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
1854 PACKAGE=$(installed_package_name $pkg)
1855 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
1856 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
1857 echo -e "\nUnable to find $pkg in the repository."
1858 echo -e "Path : $PACKAGES_REPOSITORY\n"
1859 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
1860 yesorno "Repack packages from rootfs (y/N) ? "
1861 REPACK="$answer"
1862 [ "$answer" = "y" ] || REPACK="n"
1863 [ "$DOWNLOAD" = "y" ] && break
1864 fi
1865 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
1866 yesorno "Download packages from mirror (Y/n) ? "
1867 DOWNLOAD="$answer"
1868 if [ "$answer" = "n" ]; then
1869 [ -z "$PACKAGE" ] && exit 1
1870 else
1871 DOWNLOAD="y"
1872 [ -n "$REPACK" ] && break
1873 fi
1874 fi
1875 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
1876 done
1878 # Mount cdrom to be able to repack boot-loader packages
1879 if [ ! -e /boot -a -n "$CDROM" ]; then
1880 mkdir $TMP_MNT
1881 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
1882 ln -s $TMP_MNT/boot /
1883 if [ ! -d "$ADDFILES/rootcd" ] ; then
1884 mkdir -p $ADDFILES/rootcd
1885 for i in $(ls $TMP_MNT); do
1886 [ "$i" = "boot" ] && continue
1887 cp -a $TMP_MNT/$i $ADDFILES/rootcd
1888 done
1889 fi
1890 else
1891 rmdir $TMP_MNT
1892 fi
1893 fi
1895 # Root fs stuff.
1896 echo "Preparing the rootfs directory..."
1897 mkdir -p $ROOTFS
1898 sleep 2
1899 for pkg in $LIST
1900 do
1901 [ "$pkg" = "" ] && continue
1902 # First copy and extract the package in tmp dir.
1903 pkg=${pkg%.tazpkg}
1904 PACKAGE=$(installed_package_name $pkg)
1905 mkdir -p $TMP_DIR
1906 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1907 # Look for package in cache
1908 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
1909 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
1910 # Look for package in running distribution
1911 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
1912 tazpkg repack $PACKAGE && \
1913 mv $pkg.tazpkg $PACKAGES_REPOSITORY
1914 fi
1915 fi
1916 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1917 # Get package from mirror
1918 [ "$DOWNLOAD" = "y" ] && \
1919 download $pkg.tazpkg && \
1920 mv $pkg.tazpkg $PACKAGES_REPOSITORY
1921 fi
1922 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1923 echo "Missing package $pkg."
1924 cleanup
1925 exit 1
1926 fi
1927 done
1928 if [ -f non-free.list ]; then
1929 echo "Preparing non-free packages..."
1930 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
1931 for pkg in $(cat non-free.list); do
1932 if [ ! -d $INSTALLED/$pkg ]; then
1933 if [ ! -d $INSTALLED/get-$pkg ]; then
1934 tazpkg get-install get-$pkg
1935 fi
1936 get-$pkg
1937 fi
1938 tazpkg repack $pkg
1939 pkg=$(ls $pkg*.tazpkg)
1940 grep -q "^$pkg$" $LIST_NAME || \
1941 echo $pkg >>$LIST_NAME
1942 mv $pkg $PACKAGES_REPOSITORY
1943 done
1944 fi
1945 echo ""
1946 cp $LIST_NAME $DISTRO/distro-packages.list
1947 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/distro-packages.list > $DISTRO/list-packages
1948 cd $PACKAGES_REPOSITORY
1949 yes y | tazpkg install-list \
1950 $DISTRO/list-packages --root=$ROOTFS
1951 cd $DISTRO
1952 cp distro-packages.list $ROOTFS/etc/tazlito
1953 # Copy all files from $ADDFILES/rootfs to the rootfs.
1954 if [ -d "$ADDFILES/rootfs" ] ; then
1955 echo -n "Copying addfiles content to the rootfs... "
1956 cp -a $ADDFILES/rootfs/* $ROOTFS
1957 status
1958 fi
1959 echo "Root file system is generated..."
1960 # Root CD part.
1961 echo -n "Preparing the rootcd directory..."
1962 mkdir -p $ROOTCD
1963 status
1964 # Move the boot dir with the Linux kernel from rootfs.
1965 # The boot dir goes directly on the CD.
1966 if [ -d "$ROOTFS/boot" ] ; then
1967 echo -n "Moving the boot directory..."
1968 mv $ROOTFS/boot $ROOTCD
1969 cd $ROOTCD/boot
1970 ln vmlinuz-* bzImage
1971 status
1972 fi
1973 cd $DISTRO
1974 # Copy all files from $ADDFILES/rootcd to the rootcd.
1975 if [ -d "$ADDFILES/rootcd" ] ; then
1976 echo -n "Copying addfiles content to the rootcd... "
1977 cp -a $ADDFILES/rootcd/* $ROOTCD
1978 status
1979 fi
1980 # Execute the distro script used to perform tasks in the rootfs
1981 # before compression. Give rootfs path in arg
1982 [ -z $DISTRO_SCRIPT ] && DISTRO_SCRIPT=$TOP_DIR/distro.sh
1983 if [ -x $DISTRO_SCRIPT ]; then
1984 echo "Executing distro script..."
1985 sh $DISTRO_SCRIPT $DISTRO
1986 fi
1987 if [ -s /etc/tazlito/rootfs.list ]; then
1988 FLAVOR_LIST="$(awk '{ for (i = 2; i <= NF; i+=2) \
1989 printf("%s ",$i) }' < /etc/tazlito/rootfs.list)"
1990 sed -i "s/ *//;s/)/), flavors $FLAVOR_LIST/" \
1991 $ROOTCD/boot/isolinux/isolinux.msg
1992 [ -f $ROOTCD/boot/isolinux/ifmem.c32 ] ||
1993 cp /boot/isolinux/ifmem.c32 $ROOTCD/boot/isolinux
1994 n=0
1995 last=$ROOTFS
1996 while read flavor; do
1997 n=$(($n+1))
1998 echo "Building $flavor rootfs..."
1999 download $flavor.flavor
2000 zcat $flavor.flavor | cpio -i \
2001 $flavor.pkglist $flavor.rootfs
2002 sed 's/.*/&.tazpkg/' < $flavor.pkglist \
2003 > $DISTRO/list-packages0$n
2004 mkdir ${ROOTFS}0$n
2005 cd $PACKAGES_REPOSITORY
2006 yes y | tazpkg install-list \
2007 $DISTRO/list-packages0$n --root=${ROOTFS}0$n
2008 rm -rf ${ROOTFS}0$n/boot
2009 status
2010 cd $DISTRO
2011 if [ -s $flavor.rootfs ]; then
2012 echo "Add $flavor rootfs extra files..."
2013 zcat $flavor.rootfs | \
2014 ( cd ${ROOTFS}0$n ; cpio -idmu )
2015 fi
2016 mv $flavor.pkglist ${ROOTFS}0$n/etc/tazlito/distro-packages.list
2017 rm -f $flavor.flavor install-list
2018 mergefs ${ROOTFS}0$n $last
2019 last=${ROOTFS}0$n
2020 done <<EOT
2021 $(awk '{ for (i = 4; i <= NF; i+=2) print $i; }' < /etc/tazlito/rootfs.list)
2022 EOT
2023 i=$(($n+1))
2024 while [ $n -gt 0 ]; do
2025 mv ${ROOTFS}0$n ${ROOTFS}$i
2026 echo "Compression ${ROOTFS}0$n ($(du -hs ${ROOTFS}$i | awk '{ print $1 }')) ..."
2027 gen_initramfs ${ROOTFS}$i
2028 n=$(($n-1))
2029 i=$(($i-1))
2030 done
2031 mv $ROOTFS ${ROOTFS}$i
2032 gen_initramfs ${ROOTFS}$i
2033 update_bootconfig $ROOTCD/boot/isolinux \
2034 "$(cat /etc/tazlito/rootfs.list)"
2035 else
2036 # Initramfs and ISO image stuff.
2037 gen_initramfs $ROOTFS
2038 fi
2039 gen_livecd_isolinux
2040 distro_stats
2041 cleanup
2042 ;;
2043 clean-distro)
2044 # Remove old distro tree.
2046 check_root
2047 echo ""
2048 echo -e "\033[1mCleaning :\033[0m $DISTRO"
2049 echo "================================================================================"
2050 if [ -d "$DISTRO" ] ; then
2051 if [ -d "$ROOTFS" ] ; then
2052 echo -n "Removing the rootfs..."
2053 rm -f $DISTRO/$INITRAMFS
2054 rm -rf $ROOTFS
2055 status
2056 fi
2057 if [ -d "$ROOTCD" ] ; then
2058 echo -n "Removing the rootcd..."
2059 rm -rf $ROOTCD
2060 status
2061 fi
2062 echo -n "Removing eventual ISO image..."
2063 rm -f $DISTRO/$ISO_NAME.iso
2064 rm -f $DISTRO/$ISO_NAME.md5
2065 status
2066 fi
2067 echo "================================================================================"
2068 echo ""
2069 ;;
2070 check-distro)
2071 # Check for a few LiveCD needed files not installed by packages.
2073 check_rootfs
2074 echo ""
2075 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
2076 echo "================================================================================"
2077 # SliTaz release info.
2078 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
2079 echo "Missing release info : /etc/slitaz-release"
2080 else
2081 release=`cat $ROOTFS/etc/slitaz-release`
2082 echo -n "Release : $release"
2083 status
2084 fi
2085 # Tazpkg mirror.
2086 if [ ! -f "$ROOTFS/var/lib/tazpkg/mirror" ]; then
2087 echo -n "Mirror URL : Missing /var/lib/tazpkg/mirror"
2088 todomsg
2089 else
2090 echo -n "Mirror configuration exists..."
2091 status
2092 fi
2093 # Isolinux msg
2094 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.msg; then
2095 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
2096 todomsg
2097 else
2098 echo -n "Isolinux message seems good..."
2099 status
2100 fi
2101 echo "================================================================================"
2102 echo ""
2103 ;;
2104 writeiso)
2105 # Writefs to ISO image including /home unlike gen-distro we dont use
2106 # packages to generate a rootfs, we build a compressed rootfs with all
2107 # the current filesystem similar to 'tazusb writefs'.
2109 DISTRO="/home/slitaz/distro"
2110 ROOTCD="$DISTRO/rootcd"
2111 if [ -z $2 ]; then
2112 COMPRESSION=none
2113 else
2114 COMPRESSION=$2
2115 fi
2116 if [ -z $3 ]; then
2117 ISO_NAME="slitaz"
2118 else
2119 ISO_NAME="$3"
2120 fi
2121 check_root
2122 # Start info
2123 echo ""
2124 echo -e "\033[1mWrite filesystem to ISO\033[0m
2125 ===============================================================================
2126 The command writeiso will write the current filesystem into a suitable cpio
2127 archive (rootfs.gz) and generate a bootable ISO image (slitaz.iso).
2129 Archive compression: $COMPRESSION"
2130 echo ""
2132 # Save some space
2133 rm /var/cache/tazpkg/* -r -f
2134 rm -rf /home/slitaz/distro
2136 # Optionally remove sound card selection and screen resolution.
2137 echo "Do you wish to remove the sound card and screen configs ? "
2138 echo -n "Press ENTER to keep or answer (No|yes|exit): "
2139 read anser
2140 case $anser in
2141 e|E|"exit"|Exit)
2142 exit 0 ;;
2143 y|Y|yes|Yes)
2144 echo -n "Removing current sound card and screen configurations..."
2145 rm -f /var/lib/sound-card-driver
2146 rm -f /etc/asound.state
2147 rm -f /etc/X11/screen.conf
2148 rm -f /etc/X11/xorg.conf ;;
2149 *)
2150 echo -n "Keeping current sound card and screen configurations..." ;;
2151 esac
2152 status
2154 cd /
2155 # Create list of files including default user files since it is defined in /etc/passwd
2156 # and some new users might have been added.
2157 find bin etc init sbin var dev lib root usr home >/tmp/list
2159 for dir in proc sys tmp mnt media media/cdrom media/flash media/usbdisk
2160 do
2161 echo $dir >>/tmp/list
2162 done
2164 # Generate initramfs with specified compression and display rootfs
2165 # size in realtime.
2166 rm -f /tmp/rootfs
2167 write_initramfs &
2168 sleep 2
2169 cd - > /dev/null
2170 echo -en "\nFilesystem size:"
2171 while [ ! -f /tmp/rootfs ]
2172 do
2173 sleep 1
2174 echo -en "\\033[18G`du -sh /rootfs.gz | awk '{print $1}'` "
2175 done
2176 echo -e "\n"
2178 # Move freshly generated rootfs to the cdrom.
2179 mkdir -p $ROOTCD/boot
2180 mv -f /rootfs.gz $ROOTCD/boot
2182 # Now we need the kernel and isolinux files.
2183 if mount /dev/cdrom /media/cdrom 2>/dev/null; then
2184 cp /media/cdrom/boot/bzImage $ROOTCD/boot
2185 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
2186 umount /media/cdrom
2187 else
2188 echo -e "
2189 Unable to mount the cdrom to copy the Kernel and needed files. When SliTaz
2190 is running in RAM the kernel and bootloader files are kept on the cdrom.
2191 Please insert a LiveCD or unmount the current cdrom to let Tazlito handle
2192 the media.\n"
2193 echo -en "----\nENTER to continue..."; read i
2194 exit 1
2195 fi
2197 # Generate the iso image.
2198 cd $DISTRO
2199 echo "Generating ISO image..."
2200 genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
2201 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
2202 -V "SliTaz" -input-charset iso8859-1 -boot-info-table $ROOTCD
2203 if [ -x /usr/bin/isohybrid ]; then
2204 echo -n "Creating hybrid ISO..."
2205 /usr/bin/isohybrid $ISO_NAME.iso 2> /dev/null
2206 status
2207 fi
2208 echo -n "Creating the ISO md5sum..."
2209 md5sum $ISO_NAME.iso > $ISO_NAME.md5
2210 status
2212 echo "==============================================================================="
2213 echo "ISO image: `du -sh /home/slitaz/distro/$ISO_NAME.iso`"
2214 echo ""
2215 echo -n "Exit or burn ISO to cdrom (Exit|burn)? "; read anser
2216 case $anser in
2217 burn)
2218 eject
2219 echo -n "Please insert a blank cdrom and press ENTER..."
2220 read i && sleep 2
2221 tazlito burn-iso /home/slitaz/distro/$ISO_NAME.iso
2222 echo -en "----\nENTER to continue..."; read i ;;
2223 *)
2224 exit 0 ;;
2225 esac ;;
2226 burn-iso)
2227 # Guess cdrom device, ask user and burn the ISO.
2229 check_root
2230 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
2231 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
2232 # We can specify an alternative ISO from the cmdline.
2233 if [ -n "$2" ] ; then
2234 iso=$2
2235 else
2236 iso=$DISTRO/$ISO_NAME.iso
2237 fi
2238 if [ ! -f "$iso" ]; then
2239 echo -e "\nUnable to find ISO : $iso\n"
2240 exit 0
2241 fi
2242 echo ""
2243 echo -e "\033[1mTazlito burn ISO\033[0m "
2244 echo "================================================================================"
2245 echo "Cdrom device : /dev/$DRIVE_NAME"
2246 echo "Drive speed : $DRIVE_SPEED"
2247 echo "ISO image : $iso"
2248 echo "================================================================================"
2249 echo ""
2250 yesorno "Burn ISO image (y/N) ? "
2251 if [ "$answer" == "y" ]; then
2252 echo ""
2253 echo "Starting Wodim to burn the iso..." && sleep 2
2254 echo "================================================================================"
2255 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
2256 echo "================================================================================"
2257 echo "ISO image is burned to cdrom."
2258 else
2259 echo -e "\nExiting. No ISO burned."
2260 fi
2261 echo ""
2262 ;;
2263 merge)
2264 # Merge multiple rootfs into one iso.
2266 if [ -z "$2" ]; then
2267 cat << EOT
2268 Usage: tazlito merge size1 iso size2 rootfs2 [sizeN rootfsN]...
2270 Merge multiple rootfs into one iso. Rootfs are like russian dolls
2271 i.e: rootfsN is a subset of rootfsN-1
2272 rootfs1 is found in iso, sizeN is the RAM size need to launch rootfsN.
2273 The boot loader will select the rootfs according to the RAM size detected.
2275 Example:
2276 $ tazlito merge 160M slitaz-core.iso 96M rootfs-justx.gz 32M rootfs-base.gz
2278 Will start slitaz-core with 160M+ RAM, slitaz-justX with 96M-160M RAM,
2279 slitaz-base with 32M-96M RAM and display an error message if RAM < 32M.
2280 EOT
2281 exit 2
2282 fi
2284 shift # skip merge
2285 append="$1 slitaz1"
2286 shift # skip size1
2287 mkdir -p $TMP_DIR/mnt $TMP_DIR/rootfs1
2289 ISO=$1.merged
2290 # Extract filesystems
2291 echo -n "Mounting $1"
2292 mount -o loop,ro $1 $TMP_DIR/mnt 2> /dev/null
2293 status || cleanup_merge
2294 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2295 rm -f $TMP_DIR/iso/boot/bzImage
2296 ln $TMP_DIR/iso/boot/vmlinuz* $TMP_DIR/iso/boot/bzImage
2297 umount -d $TMP_DIR/mnt
2298 if [ -f $TMP_DIR/iso/boot/rootfs1.gz ]; then
2299 echo "$1 is already a merged iso. Aborting."
2300 cleanup_merge
2301 fi
2302 if [ ! -f $TMP_DIR/iso/boot/isolinux/ifmem.c32 ]; then
2303 if [ ! -f /boot/isolinux/ifmem.c32 ]; then
2304 cat <<EOT
2305 No file /boot/isolinux/ifmem.c32
2306 Please install syslinux package !
2307 EOT
2308 rm -rf $TMP_DIR
2309 exit 1
2310 fi
2311 cp /boot/isolinux/ifmem.c32 $TMP_DIR/iso/boot/isolinux
2312 fi
2314 echo -n "Extracting iso/rootfs.gz"
2315 extract_rootfs $TMP_DIR/iso/boot/rootfs.gz $TMP_DIR/rootfs1 &&
2316 [ -d $TMP_DIR/rootfs1/etc ]
2317 status || cleanup_merge
2318 n=1
2319 while [ -n "$2" ]; do
2320 shift # skip rootfs N-1
2321 p=$n
2322 n=$(($n + 1))
2323 append="$append $1 slitaz$n"
2324 shift # skip size N
2325 mkdir -p $TMP_DIR/rootfs$n
2326 echo -n "Extracting $1"
2327 extract_rootfs $1 $TMP_DIR/rootfs$n &&
2328 [ -d $TMP_DIR/rootfs$n/etc ]
2329 status || cleanup_merge
2330 mergefs $TMP_DIR/rootfs$n $TMP_DIR/rootfs$p
2331 echo "Creating rootfs$p.gz"
2332 pack_rootfs $TMP_DIR/rootfs$p $TMP_DIR/iso/boot/rootfs$p.gz
2333 status
2334 done
2335 echo "Creating rootfs$n.gz"
2336 pack_rootfs $TMP_DIR/rootfs$n $TMP_DIR/iso/boot/rootfs$n.gz
2337 status
2338 rm -f $TMP_DIR/iso/boot/rootfs.gz
2339 update_bootconfig $TMP_DIR/iso/boot/isolinux "$append"
2340 create_iso $ISO $TMP_DIR/iso
2341 rm -rf $TMP_DIR
2342 ;;
2344 repack)
2345 # Repack an iso with maximum lzma compression ratio.
2348 ISO=$2
2350 mkdir -p $TMP_DIR/mnt
2351 # Extract filesystems
2352 echo -n "Mounting $ISO"
2353 mount -o loop,ro $ISO $TMP_DIR/mnt 2> /dev/null
2354 status || cleanup_merge
2355 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2356 umount -d $TMP_DIR/mnt
2358 for i in $TMP_DIR/iso/boot/rootfs* ; do
2359 echo -n "Repacking $(basename $i)"
2360 (zcat $i 2> /dev/null || unlzma -c $i || cat $i) \
2361 2>/dev/null > $TMP_DIR/rootfs
2362 lzma e $TMP_DIR/rootfs $i \
2363 $(lzma_switches $TMP_DIR/rootfs)
2364 status
2365 done
2367 create_iso $ISO $TMP_DIR/iso
2368 rm -rf $TMP_DIR ;;
2370 build-loram)
2371 # Build a Live CD for low ram systems.
2374 ISO=$2
2375 OUTPUT=$3
2376 mkdir -p $TMP_DIR/iso
2377 mount -o loop,ro -t iso9660 $ISO $TMP_DIR/iso
2378 if ! check_iso_for_loram ; then
2379 echo "$2 is not a valid SliTaz live CD. Abort."
2380 umount -d $TMP_DIR/iso
2381 rm -rf $TMP_DIR
2382 exit 1
2383 fi
2385 case "$4" in
2386 cdrom) build_loram_cdrom ;;
2387 smallcdrom) build_loram_cdrom small ;;
2388 http) build_loram_http ;;
2389 *) build_loram_ram ;;
2390 esac
2391 umount -d $TMP_DIR/iso
2392 rm -rf $TMP_DIR ;;
2395 frugal-install|-fi)
2396 ISO_IMAGE="$2"
2397 echo ""
2398 mkdir -p /boot/frugal
2399 if [ -f "$ISO_IMAGE" ]; then
2400 echo -n "Using ISO image: $ISO_IMAGE"
2401 mkdir -p /tmp/iso && mount -o loop $ISO_IMAGE /tmp/iso
2402 status
2403 echo -n "Installing the Kernel and rootfs..."
2404 cp -a /tmp/iso/boot/bzImage /boot/frugal
2405 cp -a /tmp/iso/boot/rootfs.gz /boot/frugal
2406 umount /tmp/iso
2407 status
2408 else
2409 echo -n "Using distro: $DISTRO"
2410 cd $DISTRO && status
2411 echo -n "Installing the Kernel and rootfs..."
2412 cp -a $DISTRO/rootcd/boot/bzImage /boot/frugal
2413 cp -a $DISTRO/rootcd/boot/rootfs.gz /boot/frugal
2414 status
2415 fi
2416 # Grub entry
2417 if ! grep -q "^kernel /boot/frugal/bzImage" /boot/grub/menu.lst; then
2418 echo -n "Configuring GRUB menu list..."
2419 cat >> /boot/grub/menu.lst << EOT
2420 title SliTaz GNU/Linux (frugal)
2421 root (hd0,0)
2422 kernel /boot/frugal/bzImage root=/dev/null
2423 initrd /boot/frugal/rootfs.gz
2424 EOT
2425 else
2426 echo -n "GRUB menu list is up-to-date..."
2427 fi
2428 status
2429 echo "" ;;
2431 emu-iso)
2432 # Emulate an ISO image with Qemu.
2433 if [ -n "$2" ] ; then
2434 iso=$2
2435 else
2436 iso=$DISTRO/$ISO_NAME.iso
2437 fi
2438 if [ ! -f "$iso" ]; then
2439 echo -e "\nUnable to find ISO : $iso\n"
2440 exit 0
2441 fi
2442 if [ ! -x "/usr/bin/qemu" ]; then
2443 echo -e "\nUnable to find Qemu binary. Please install: qemu\n"
2444 exit 0
2445 fi
2446 echo -e "\nStarting Qemu emulator:\n"
2447 echo -e "qemu $QEMU_OPTS $iso\n"
2448 qemu $QEMU_OPTS $iso ;;
2450 usage|*)
2451 # Clear and print usage also for all unknown commands.
2453 clear
2454 usage ;;
2455 esac
2457 exit 0