tazlito view tazlito @ rev 173

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