tazlito view tazlito @ rev 182

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