tazlito view tazlito @ rev 170

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