tazlito view tazlito @ rev 186

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