tazlito view tazlito @ rev 350

tazlito: do not save pid files (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Jun 17 11:28:59 2014 +0200 (2014-06-17)
parents 72ee2d5247e9
children 9abc456b6494
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-2014 SliTaz - GNU General Public License.
11 #
12 # Authors : Christophe Lincoln <pankso@slitaz.org>
13 # Pascal Bellard <pascal.bellard@slitaz.org>
14 #
15 VERSION=5.2.3
17 . /lib/libtaz.sh
19 # Tazlito configuration variables to be shorter
20 # and to use words rather than numbers.
21 COMMAND=$1
22 LIST_NAME=$2
23 TMP_DIR=/tmp/tazlito-$$-$RANDOM
24 TMP_MNT=/media/tazlito-$$-$RANDOM
25 TOP_DIR=`pwd`
26 INITRAMFS=rootfs.gz
27 LOCALSTATE=/var/lib/tazpkg
28 INSTALLED=$LOCALSTATE/installed
29 CACHE_DIR=/var/cache/tazpkg
30 MIRROR=$LOCALSTATE/mirror
31 DEFAULT_MIRROR="http://mirror.slitaz.org/packages/`cat /etc/slitaz-release`/"
33 log=/var/log/tazlito.log
34 if check_root; then
35 newline > $log
36 fi
38 # Try to include config file, continue if command is gen-config or exit.
39 # The main config used by default is in /etc/tazlito.
40 if [ -f "/etc/tazlito/tazlito.conf" ] ; then
41 CONFIG_FILE="/etc/tazlito/tazlito.conf"
42 fi
43 # Specific distro config file can be put in a distro tree.
44 if [ -f "$TOP_DIR/tazlito.conf" ] ; then
45 CONFIG_FILE="$TOP_DIR/tazlito.conf"
46 fi
47 if [ ! "$CONFIG_FILE" = "" ] ; then
48 . $CONFIG_FILE
49 else
50 if [ "$COMMAND" = "gen-config" ] ; then
51 continue
52 else
53 echo "Unable to find any configuration file. Please read the docs"
54 echo "or run '`basename $0` gen-config' to get an empty config file."
55 exit 0
56 fi
57 fi
59 # While Tazpkg is not used the default mirror url file does not exist
60 # and user can't recharge the list of flavors.
61 if test $(id -u) = 0 ; then
62 if [ ! -f "$MIRROR" ]; then
63 echo "$DEFAULT_MIRROR" > $MIRROR
64 fi
65 fi
67 # Set the rootfs and rootcd path with $DISTRO
68 # configuration variable.
69 ROOTFS=$DISTRO/rootfs
70 ROOTCD=$DISTRO/rootcd
72 #####################
73 # Tazlito functions #
74 #####################
76 # Print the usage.
77 usage () {
78 cat << EOT
80 SliTaz Live Tool - Version: $(colorize 34 "$VERSION")
82 $(boldify "Usage:") $(basename $0) [command] [list|iso|flavor|compression] [dir|iso]
84 $(boldify "Commands:")
85 usage Print this short usage.
86 stats View Tazlito and distro configuration statistics.
87 gen-config Generate a new configuration file for a distro.
88 configure Configure the main config file or a specific tazlito.conf.
89 gen-iso Generate a new ISO from a distro tree.
90 gen-initiso Generate a new initramfs and ISO from the distro tree.
91 list-flavors List all available package lists on the mirror.
92 gen-flavor Generate a new live-CD description.
93 gen-liveflavor Generate a live-CD description from current system.
94 show-flavor Show live-CD description.
95 get-flavor Get a flavor's list of packages.
96 upgrade-flavor Update package list to the latest available versions.
97 extract-flavor Extract a (*.flavor) flavor into $FLAVORS_REPOSITORY.
98 pack-flavor Pack (and update) a flavor from $FLAVORS_REPOSITORY.
99 iso2flavor Create a flavor file from a SliTaz iso image.
100 check-list Check a distro-packages.list for updates.
101 extract-distro Extract an ISO to a directory and rebuild LiveCD tree.
102 gen-distro Generate a Live distro and ISO from a list of packages.
103 clean-distro Remove all files generated by gen-distro.
104 check-distro Help to check if distro is ready to release.
105 writeiso Use running system to generate a bootable ISO (with /home).
106 merge Merge multiple rootfs into one iso.
107 deduplicate Deduplicate files in a tree.
108 repack Recompress rootfs into iso with maximum ratio.
109 build-loram Generate a live-CD for low ram systems.
110 emu-iso Emulate an ISO image with Qemu.
111 burn-iso Burn ISO image to a cdrom using Wodim.
113 EOT
114 }
116 yesorno() {
117 echo -n "$1"
118 case "$DEFAULT_ANSWER" in
119 Y|y) answer="y";;
120 N|n) answer="n";;
121 *) read answer;;
122 esac
123 }
125 field() {
126 grep "^$1" "$2" | sed 's/.*: \([0-9KMG\.]*\).*/\1/'
127 }
129 todomsg() {
130 echo -e "\\033[70G[ \\033[1;31mTODO\\033[0;39m ]"
131 }
133 # Download a file from this mirror
134 download_from() {
135 local i
136 local mirrors
137 mirrors="$1"
138 shift
139 for i in $mirrors; do
140 case "$i" in
141 http://*|ftp://*) busybox wget -c $i$@ && break;;
142 *) cp $i/$1 . && break;;
143 esac
144 done
145 }
147 # Download a file trying all mirrors
148 download() {
149 local i
150 for i in $(cat $MIRROR $LOCALSTATE/undigest/*/mirror 2> /dev/null); do
151 download_from "$i" "$@" && break
152 done
153 }
155 # Execute hooks provided by some packages
156 genisohooks() {
157 local here=`pwd`
158 for i in $(ls $ROOTFS/etc/tazlito/*.$1 2> /dev/null); do
159 cd $ROOTFS
160 . $i $ROOTCD
161 done
162 cd $here
163 }
165 cleanup() {
166 if [ -d $TMP_MNT ]; then
167 umount $TMP_MNT
168 rmdir $TMP_MNT
169 rm -f /boot
170 fi
171 }
173 # Echo the package name if the tazpkg is already installed
174 installed_package_name() {
175 local tazpkg
176 local package
177 local VERSION
178 local EXTRAVERSION
179 tazpkg=$1
180 # Try to find package name and version to be able
181 # to repack it from installation
182 # A dash (-) can exist in name *and* in version
183 package=${tazpkg%-*}
184 i=$package
185 while true; do
186 VERSION=""
187 eval $(grep -s ^VERSION= $INSTALLED/$i/receipt)
188 EXTRAVERSION=""
189 eval $(grep -s ^EXTRAVERSION= $INSTALLED/$i/receipt)
190 if [ "$i-$VERSION$EXTRAVERSION" = "$tazpkg" ]; then
191 echo $i
192 break
193 fi
194 case "$i" in
195 *-*);;
196 *) break;;
197 esac
198 i=${i%-*}
199 done
200 }
202 # Check for the rootfs tree.
203 check_rootfs() {
204 if [ ! -d "$ROOTFS/etc" ] ; then
205 echo -e "\nUnable to find a distro rootfs...\n"
206 exit 0
207 fi
208 }
210 # Check for the boot dir into the root CD tree.
211 verify_rootcd()
212 {
213 if [ ! -d "$ROOTCD/boot" ] ; then
214 echo -e "\nUnable to find the rootcd boot directory...\n"
215 exit 0
216 fi
217 }
219 create_iso()
220 {
221 cd $2
222 echo -n "Computing md5..."
223 find * -type f ! -name md5sum -exec md5sum {} \; > md5sum
224 sed -i -e '/ boot\/isolinux\/isolinux.bin$/d' \
225 -e '/ boot\/isolinux\/boot.cat$/d' md5sum
226 status
227 cd - > /dev/null
228 newline
229 boldify "Generating ISO image"
230 separator
231 echo "Generating $1"
232 if [ $(ls $2/boot/vmlinuz* $2/boot/bzImage | wc -l) -eq 2 ]; then
233 if cmp $2/boot/vmlinuz* $2/boot/bzImage > /dev/null; then
234 rm -f $2/boot/bzImage
235 ln $2/boot/vmlinuz* $2/boot/bzImage
236 fi
237 fi
238 genisoimage -R -o $1 -b boot/isolinux/isolinux.bin \
239 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
240 -V "$VOLUM_NAME" -p "$PREPARED" -input-charset iso8859-1 \
241 -boot-info-table $2
242 if [ -x /usr/bin/isohybrid ]; then
243 echo -n "Creating hybrid ISO..."
244 /usr/bin/isohybrid $1 -entry 2 2> /dev/null
245 status
246 fi
247 if [ -s /etc/tazlito/info ]; then
248 if [ $(stat -c %s /etc/tazlito/info) -lt $(( 31*1024 )) ]; then
249 echo -n "Storing ISO info..."
250 dd if=/etc/tazlito/info bs=1k seek=1 of=$1 \
251 conv=notrunc 2> /dev/null
252 status
253 fi
254 fi
255 if [ -x /usr/bin/iso2exe ]; then
256 echo "Creating EXE header..."
257 /usr/bin/iso2exe $1 2> /dev/null
258 fi
259 }
261 # Generate a new ISO image using isolinux.
262 gen_livecd_isolinux()
263 {
264 # Some packages may want to alter iso
265 genisohooks iso
266 if [ ! -f "$ROOTCD/boot/isolinux/isolinux.bin" ]; then
267 echo -e "\nUnable to find isolinux binary.\n"
268 cleanup
269 exit 0
270 fi
271 # Set date for boot msg.
272 if grep -q 'XXXXXXXX' $ROOTCD/boot/isolinux/isolinux.*g; then
273 DATE=`date +%Y%m%d`
274 echo -n "Setting build date to: $DATE..."
275 sed -i "s/XXXXXXXX/$DATE/" $ROOTCD/boot/isolinux/isolinux.*g
276 status
277 fi
278 cd $DISTRO
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 separator
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 local proc=$(grep -s '^processor' < /proc/cpuinfo | wc -l)
309 echo "-d$(lzma_history_bits $1) -mt${proc:-1}"
310 }
312 lzma_set_size()
313 {
314 # Update size field for lzma'd file packed using -si switch
315 local n
316 local i
317 return # Need to fix kernel code ?
318 n=$(unlzma -c $1 | wc -c)
319 for i in $(seq 1 8); do
320 printf '\\\\x%02X' $(($n & 255))
321 n=$(($n >> 8))
322 done | xargs echo -en | dd of=$1 conv=notrunc bs=1 seek=5 2> /dev/null
323 }
325 align_to_32bits()
326 {
327 local size
328 size=$(stat -c %s ${1:-/dev/null})
329 [ $((${size:-0} & 3)) -ne 0 ] &&
330 dd if=/dev/zero bs=1 count=$((4 - ($size & 3))) >> $1 2> /dev/null
331 }
333 # Pack rootfs
334 pack_rootfs()
335 {
336 ( cd $1 ; find . -print | cpio -o -H newc ) | \
337 if [ "$COMPRESSION" = "none" ]; then
338 echo "Generating uncompressed initramfs... "
339 cat > $2
340 elif [ -x /usr/bin/lzma -a "$COMPRESSION" != "gzip" ]; then
341 echo -n "Generating lzma'ed initramfs... "
342 lzma e -si -so $(lzma_switches $1) > $2
343 lzma_set_size $2
344 else
345 echo "Generating gziped initramfs... "
346 gzip -9 > $2
347 fi
348 align_to_32bits $2
349 echo 1 > /tmp/rootfs
350 }
352 # Compression functions for writeiso.
353 write_initramfs()
354 {
355 if [ "$COMPRESSION" = "lzma" ]; then
356 echo -n "Creating rootfs.gz with lzma compression... "
357 cpio -o -H newc | lzma e -si -so > /rootfs.gz
358 lzma_set_size /rootfs.gz
359 elif [ "$COMPRESSION" = "gzip" ]; then
360 echo "Creating rootfs.gz with gzip compression... "
361 cpio -o -H newc | gzip -9 > /rootfs.gz
362 else
363 echo "Creating rootfs.gz without compression... "
364 cpio -o -H newc > /rootfs.gz
365 fi < /tmp/list
366 align_to_32bits /rootfs.gz
367 echo 1 > /tmp/rootfs
368 }
370 # Deduplicate files (MUST be on the same filesystem).
371 deduplicate()
372 {
373 find "$@" -type f -size +0c -xdev \
374 -exec stat -c '%s-%a-%u-%g %i %h %n' {} \; | sort | \
375 ( save=0; old_attr=""; old_inode=""; old_link=""; old_file=""
376 while read attr inode link file; do
377 [ -L "$file" ] && continue
378 if [ "$attr" = "$old_attr" -a "$inode" != "$old_inode" ]; then
379 if cmp "$file" "$old_file" >/dev/null 2>&1 ; then
380 rm -f "$file"
381 if ln "$old_file" "$file" 2> /dev/null; then
382 inode="$old_inode"
383 [ "$link" = "1" ] &&
384 save="$(($save+(${attr%%-*}+512)/1024))"
385 else
386 cp "$old_file" "$file"
387 fi
388 fi
389 fi
390 old_attr="$attr" ; old_inode="$inode" ; old_file="$file"
391 done
392 echo "$save Kbytes saved in duplicate files."
393 )
394 }
396 # Generate a new initramfs from the root filesystem.
397 gen_initramfs()
398 {
399 # Just in case CTRL+c
400 rm -f $DISTRO/gen
402 # Some packages may want to alter rootfs
403 genisohooks rootfs
404 cd $1
406 # Link duplicate files
407 deduplicate .
409 # Use lzma if installed. Display rootfs size in realtime.
410 rm -f /tmp/rootfs
411 pack_rootfs . $DISTRO/$(basename $1).gz &
412 sleep 2
413 echo -en "\nFilesystem size:"
414 while [ ! -f /tmp/rootfs ]
415 do
416 sleep 1
417 echo -en "\\033[18G`du -sh $DISTRO/$(basename $1).gz | awk '{print $1}'` "
418 done
419 echo -e "\n"
420 cd $DISTRO
421 mv $(basename $1).gz $ROOTCD/boot
422 }
424 distro_sizes() {
425 if [ "$time" ]; then
426 time=$(($(date +%s) - $time))
427 sec=$time
428 div=$(( ($time + 30) / 60))
429 [ "$div" != 0 ] && min="~ ${div}m"
430 echo "Build time : ${sec}s $min"
431 fi
432 cat << EOT
433 Build date : $(date +%Y%m%d)
434 Packages : $(ls -1 $ROOTFS*$INSTALLED/*/receipt | wc -l)
435 Rootfs size : $(du -csh $ROOTFS*/ | awk '{ s=$1 } END { print s }')
436 Initramfs size : $(du -csh $ROOTCD/boot/rootfs*.gz | awk '{ s=$1 } END { print s }')
437 ISO image size : $(du -sh $ISO_NAME.iso | awk '{ print $1 }')
438 EOT
439 separator
440 echo "Image is ready: $ISO_NAME.iso"
441 newline
442 }
444 # Print ISO and rootfs size.
445 distro_stats() {
446 newline
447 echo "$(boldify 'Distro statistics:') $DISTRO"
448 separator
449 distro_sizes
450 }
452 # Create an empty configuration file.
453 empty_config_file()
454 {
455 cat >> tazlito.conf << "EOF"
456 # tazlito.conf: Tazlito (SliTaz Live Tool) configuration file.
457 #
459 # Name of the ISO image to generate.
460 ISO_NAME=""
462 # ISO image volume name.
463 VOLUM_NAME="SliTaz"
465 # Name of the preparer.
466 PREPARED="$USER"
468 # Path to the packages repository and the packages.list.
469 PACKAGES_REPOSITORY=""
471 # Path to the distro tree to gen-distro from a
472 # list of packages.
473 DISTRO=""
475 # Path to the directory containing additional files
476 # to copy into the rootfs and rootcd of the LiveCD.
477 ADDFILES="$DISTRO/addfiles"
479 # Default answer for binary question (Y or N)
480 DEFAULT_ANSWER="ASK"
482 # Compression utility (lzma, gzip or none)
483 COMPRESSION="lzma"
484 EOF
485 }
487 # extract rootfs.gz somewhere
488 extract_rootfs()
489 {
490 (zcat $1 || unlzma -c $1 || cat $1) 2>/dev/null | \
491 (cd $2; cpio -idm > /dev/null)
492 }
494 # Remove duplicate files
495 mergefs()
496 {
497 echo -n "Merge $(basename $1) ($(du -hs $1 | awk '{ print $1}')) into "
498 echo -n "$(basename $2) ($(du -hs $2 | awk '{ print $1}'))"
499 # merge symlinks files and devices
500 ( cd $1; find ) | while read file; do
501 if [ -L $1/$file ]; then
502 [ -L $2/$file ] &&
503 [ "$(readlink $1/$file)" == "$(readlink $2/$file)" ] &&
504 rm -f $2/$file
505 elif [ -f $1/$file ]; then
506 [ -f $2/$file ] &&
507 cmp $1/$file $2/$file > /dev/null 2>&1 && rm -f $2/$file
508 [ -f $2/$file ] &&
509 [ "$(basename $file)" == "volatile.cpio.gz" ] &&
510 [ "$(dirname $(dirname $file))" == \
511 ".$INSTALLED" ] && rm -f $2/$file
512 elif [ -b $1/$file ]; then
513 [ -b $2/$file ] &&
514 [ "$(stat -c '%a:%u:%g:%t:%T' $1/$file)" == \
515 "$(stat -c '%a:%u:%g:%t:%T' $2/$file)" ] &&
516 rm -f $2/$file
517 elif [ -c $1/$file ]; then
518 [ -c $2/$file ] &&
519 [ "$(stat -c '%a:%u:%g:%t:%T' $1/$file)" == \
520 "$(stat -c '%a:%u:%g:%t:%T' $2/$file)" ] &&
521 rm -f $2/$file
522 fi
523 done
525 # cleanup directories
526 ( cd $1; find . -type d ) | sed '1!G;h;$!d' | while read file; do
527 [ -d $2/$file ] && rmdir $2/$file 2> /dev/null
528 done
529 true
530 status
531 }
533 cleanup_merge()
534 {
535 rm -rf $TMP_DIR
536 exit 1
537 }
539 human2cent()
540 {
541 case "$1" in
542 *k) echo $1 | sed 's/\(.*\).\(.\)k/\1\2/';;
543 *M) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)M/\1\2/') * 1024));;
544 *G) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)G/\1\2/') * 1024 * 1024));;
545 esac
546 }
548 cent2human()
549 {
550 if [ $1 -lt 10000 ]; then
551 echo "$(($1 / 10)).$(($1 % 10))k"
552 elif [ $1 -lt 10000000 ]; then
553 echo "$(($1 / 10240)).$(( ($1/1024) % 10))M"
554 else
555 echo "$(($1 / 10485760)).$(( ($1/1048576) % 10))G"
556 fi
557 }
559 get_size()
560 {
561 cat $LOCALSTATE/packages.list $TMP_DIR/packages.list 2>/dev/null | awk "{ \
562 if (/^$(echo $1 | sed 's/[$+.\]/\\&/g')$/) get=1; \
563 if (/installed/ && get == 1) { print ; get++ } \
564 }
565 END { if (get < 2) print \" 0.0k (0.0k installed)\" }" | \
566 sed 's/ *\(.*\) .\(.*\) installed./\1 \2/' | while read packed unpacked; do
567 echo "$(human2cent $packed) $(human2cent $unpacked)"
568 done
569 }
571 # Display package list with version, set packed_size and unpacked_size
572 get_pkglist()
573 {
574 packed_size=0; unpacked_size=0
575 grep -v ^# $FLAVORS_REPOSITORY/$1/packages.list > $TMP_DIR/flavor.pkg
576 while read pkg; do
577 set -- $(get_size $pkg)
578 packed_size=$(( $packed_size + $1 ))
579 unpacked_size=$(( $unpacked_size + $2 ))
580 for i in $(grep -hs ^$pkg $LOCALSTATE/packages.list \
581 $TMP_DIR/packages.list); do
582 echo $i
583 break
584 done
585 done < $TMP_DIR/flavor.pkg
586 rm -f $TMP_DIR/flavor.pkg
587 }
589 # Update isolinux config files for multiple rootfs
590 update_bootconfig()
591 {
592 local files
593 echo -n "Updating boot config files..."
594 files="$(grep -l 'include common' $1/*.cfg)"
595 for file in $files ; do
596 awk -v n=$(echo $2 | awk '{ print NF/2 }') '{
597 if (/label/) label=$0;
598 else if (/kernel/) kernel=$0;
599 else if (/append/) {
600 i=index($0,"rootfs.gz");
601 append=substr($0,i+9);
602 }
603 else if (/include/) {
604 for (i = 1; i <= n; i++) {
605 print label i
606 print kernel;
607 initrd="initrd=/boot/rootfs" n ".gz"
608 for (j = n - 1; j >= i; j--) {
609 initrd=initrd ",/boot/rootfs" j ".gz";
610 }
611 printf "\tappend %s%s\n",initrd,append;
612 print "";
613 }
614 print;
615 }
616 else print;
617 }' < $file > $file.$$
618 mv -f $file.$$ $file
619 done
620 sel="$(echo $2 | awk '{
621 for (i=1; i<=NF; i++)
622 if (i % 2 == 0) printf " slitaz%d",i/2
623 else printf " %s",$i
624 }')"
625 [ -s $1/common.cfg ] && cat >> $1/common.cfg <<EOT
627 label slitaz
628 kernel /boot/isolinux/ifmem.c32
629 append$sel noram
631 label noram
632 config noram.cfg
634 EOT
635 # Update vesamenu
636 if [ -s $1/isolinux.cfg ]; then
637 files="$files $1/isolinux.cfg"
638 awk -v n=$(echo $2 | awk '{ print NF/2 }') -v "sel=$sel" '
639 BEGIN {
640 kernel=" COM32 c32box.c32"
641 }
642 {
643 if (/ROWS/) print "MENU ROW " n+$3;
644 else if (/TIMEOUTROW/) print "MENU TIMEOUTROW " n+$3;
645 else if (/TABMSGROW/) print "MENU TABMSGROW " n+$3;
646 else if (/CMDLINEROW/) print "MENU CMDLINEROW " n+$3;
647 else if (/VSHIFT/) {
648 x=$3-n;
649 if (x < 0) x=0;
650 print "MENU VSHIFT " x;
651 }
652 else if (/rootfs.gz/) {
653 linux=""
654 if (/bzImage/) {
655 linux="linux /boot/bzImage "
656 }
657 i=index($0,"rootfs.gz");
658 append=substr($0,i+9);
659 print " kernel /boot/isolinux/ifmem.c32"
660 print " append" sel " noram"
661 print ""
662 print "label noram"
663 print " MENU HIDE"
664 print " config noram.cfg"
665 print ""
666 for (i = 1; i <= n; i++) {
667 print "LABEL slitaz" i
668 print " MENU LABEL SliTaz slitaz" i " Live"
669 print kernel;
670 initrd="initrd=/boot/rootfs" n ".gz"
671 for (j = n - 1; j >= i; j--) {
672 initrd=initrd ",/boot/rootfs" j ".gz";
673 }
674 printf "\tappend %s%s%s\n",linux,initrd,append;
675 print "";
676 }
677 }
678 else if (/bzImage/) kernel=$0;
679 else print;
680 }' < $1/isolinux.cfg > $1/isolinux.cfg.$$
681 mv $1/isolinux.cfg.$$ $1/isolinux.cfg
682 fi
683 [ -s $1/c32box.c32 ] && sed -i -e '/kernel.*ifmem/d' \
684 -e 's/append \([0-9]\)/append ifmem \1/' $1/isolinux.cfg
685 cat > $1/noram.cfg <<EOT
686 implicit 0
687 prompt 1
688 timeout 80
689 $(grep '^F[0-9]' $1/isolinux.cfg)
691 $([ -s $1/isolinux.msg ] && echo display isolinux.msg)
692 say Not enough RAM to boot slitaz. Trying hacker mode...
693 default hacker
694 label hacker
695 KERNEL /boot/bzImage
696 append rw root=/dev/null vga=normal
698 label reboot
699 EOT
700 if [ -s $1/c32box.c32 ]; then
701 cat >> $1/noram.cfg <<EOT
702 COM32 c32box.c32
703 append reboot
705 label poweroff
706 COM32 c32box.c32
707 append poweroff
709 EOT
710 else
711 echo " com32 reboot.c32" >> $1/noram.cfg
712 fi
713 # Restore real label names
714 [ -s $1/common.cfg ] && files="$1/common.cfg $files"
715 echo $2 | awk '{ for (i=NF; i>1; i-=2) printf "%d/%s\n",i/2,$i }' | \
716 while read pat; do
717 sed -i "s/slitaz$pat/" $files
718 done
719 status
720 }
722 # Install a missing package
723 install_package()
724 {
725 echo -n "Install package $1 "
726 [ -n "$2" ] && echo -n "for kernel $2 "
727 echo -n "?"
728 read answer
729 case "$answer" in
730 y*|Y*|o*|O*)
731 # We dont want package on host cache.
732 echo -n "Getting and installing package: $1"
733 yes y | tazpkg get-install $1 2>&1 >> $log || exit 1
734 status ;;
735 *)
736 return 1 ;;
737 esac
738 }
740 # Check iso for loram transformation
741 check_iso_for_loram()
742 {
743 [ -s $TMP_DIR/iso/boot/rootfs.gz ] ||
744 [ -s $TMP_DIR/iso/boot/rootfs1.gz ]
745 }
747 # Build initial rootfs for loram ISO ram/cdrom/http
748 build_initfs()
749 {
750 urliso="mirror.slitaz.org mirror.switch.ch/ftp/mirror/slitaz \
751 download.tuxfamily.org/slitaz slitaz.c3sl.ufpr.br"
752 version=$(ls $TMP_DIR/iso/boot/vmlinuz-* | sed 's/.*vmlinuz-//')
753 if [ -z "$version" ]; then
754 cat <<EOT
755 Can't find the kernel version.
756 No file /boot/vmlinuz-<version> in ISO image.
757 Abort.
758 EOT
759 exit 1
760 fi
761 [ -s /usr/share/boot/busybox-static ] || install_package busybox-static
762 need_lib=false
763 mkdir -p $TMP_DIR/initfs/bin $TMP_DIR/initfs/dev $TMP_DIR/initfs/run \
764 $TMP_DIR/initfs/mnt $TMP_DIR/initfs/proc $TMP_DIR/initfs/tmp \
765 $TMP_DIR/initfs/sys $TMP_DIR/initfs/lib/modules
766 ln -s bin $TMP_DIR/initfs/sbin
767 ln -s . $TMP_DIR/initfs/usr
768 while [ ! -f /lib/modules/$version/kernel/fs/aufs/aufs.ko.?z ]; do
769 install_package aufs $version || return 1
770 done
771 cp /init $TMP_DIR/initfs/
772 # bootfloppybox will need floppy.ko.?z, /dev/fd0, /dev/tty0
773 cp /lib/modules/$version/kernel/drivers/block/floppy.ko.?z \
774 $TMP_DIR/initfs/lib/modules 2> /dev/null
775 cp -a /dev/tty0 /dev/fd0 $TMP_DIR/initfs/dev 2> /dev/null
776 cp /lib/modules/$version/kernel/fs/aufs/aufs.ko.?z \
777 $TMP_DIR/initfs/lib/modules
778 if [ "$1" == "cdrom" ]; then
779 sed -i '/mod squashfs/d' $TMP_DIR/initfs/init
780 else
781 [ ! -f /usr/sbin/mksquashfs ] && ! install_package squashfs && return 1
782 while [ ! -f /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.?z ]; do
783 install_package linux-squashfs $version || return 1
784 done
785 cp /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.?z \
786 $TMP_DIR/initfs/lib/modules
787 ls /sbin/unsquashfs /usr/lib/liblzma.so* $INSTALLED/squashfs/* | \
788 cpio -o -H newc > $TMP_DIR/initfs/extractfs.cpio
789 fi
790 for i in $(ls /dev/[hs]d[a-f]*); do
791 cp -a $i $TMP_DIR/initfs/dev
792 done
793 if [ "$1" == "http" ]; then
794 mkdir $TMP_DIR/initfs/etc
795 ln -s /proc/mounts $TMP_DIR/initfs/etc/mtab
796 cp /usr/share/udhcpc/default.script $TMP_DIR/initfs/lib/udhcpc
797 sed -i 's|/sbin/||' $TMP_DIR/initfs/lib/udhcpc
798 cp -a /dev/fuse $TMP_DIR/initfs/dev
799 if ! $need_lib && [ -x /usr/share/boot/fusermount-static ]; then
800 cp /usr/share/boot/fusermount-static $TMP_DIR/initfs/bin/httpfs
801 else
802 cp /usr/bin/fusermount $TMP_DIR/initfs/bin
803 need_lib=true
804 fi
805 if ! $need_lib && [ -x /usr/share/boot/httpfs-static ]; then
806 cp /usr/share/boot/httpfs-static $TMP_DIR/initfs/bin/httpfs
807 else
808 [ ! -f /usr/bin/httpfs ] && ! install_package httpfs-fuse && return 1
809 cp /usr/bin/httpfs $TMP_DIR/initfs/bin
810 cp -a /lib/librt* $TMP_DIR/initfs/lib
811 cp -a /lib/libdl* $TMP_DIR/initfs/lib
812 cp -a /lib/libpthread* $TMP_DIR/initfs/lib
813 cp -a /usr/lib/libfuse* $TMP_DIR/initfs/lib
814 cp -a /lib/libresolv* $TMP_DIR/initfs/lib
815 cp -a /lib/libnss_dns* $TMP_DIR/initfs/lib
816 need_lib=true
817 fi
818 cd $TMP_DIR/initfs
819 echo "Getting slitaz-release..."
820 for i in $TMP_DIR/iso/boot/rootfs*.gz; do
821 ( zcat $i 2> /dev/null || unlzma -c $i) | \
822 cpio -idmu etc/slitaz-release > /dev/null
823 done
824 cd - > /dev/null
825 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"
826 echo -n "List of urls to insert: "
827 read -t 30 urliso2
828 urliso="$urliso2 $urliso"
829 fi
830 if ! $need_lib && [ -x /usr/share/boot/busybox-static ]; then
831 cp /usr/share/boot/busybox-static $TMP_DIR/initfs/bin/busybox
832 sed -i 's/LD_T.*ot/newline/;s/".*ld-.*) /"/' $TMP_DIR/initfs/init
833 else
834 cp /bin/busybox $TMP_DIR/initfs/bin
835 need_lib=true
836 fi
837 for i in $($TMP_DIR/initfs/bin/busybox | awk \
838 '{ if (s) printf "%s",$0 } /Currently/ { s=1 }' | sed 's/,//g'); do
839 ln $TMP_DIR/initfs/bin/busybox $TMP_DIR/initfs/bin/$i
840 done
841 for i in /dev/console /dev/loop* /dev/null /dev/tty /dev/zero \
842 /dev/kmem /dev/mem /dev/random /dev/urandom; do
843 cp -a $i $TMP_DIR/initfs/dev
844 done
845 $need_lib && for i in /lib/ld-* /lib/lib[cm].so* /lib/lib[cm]-* ; do
846 cp -a $i $TMP_DIR/initfs/lib
847 done
848 [ "$1" == "http" ] && cat > $TMP_DIR/initfs/init <<EOTEOT
849 #!/bin/sh
851 getarg()
852 {
853 grep -q " \$1=" /proc/cmdline || return 1
854 eval \$2=\$(sed "s/.* \$1=\\\\([^ ]*\\\\).*/\\\\1/" < /proc/cmdline)
855 return 0
856 }
858 copy_rootfs()
859 {
860 total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g')
861 need=\$(du -c \${path}rootfs* | tail -n 1 | cut -f1)
862 [ \$(( \$total / \$need )) -gt 1 ] || return 1
863 if ! grep -q " keep-loram" /proc/cmdline && cp \${path}rootfs* /mnt; then
864 path=/mnt/
865 return 0
866 else
867 rm -f /mnt/rootfs*
868 return 1
869 fi
870 }
872 echo "Switching / to tmpfs..."
873 mount -t proc proc /proc
874 size="\$(grep rootfssize= < /proc/cmdline | \\
875 sed 's/.*rootfssize=\\([0-9]*[kmg%]\\).*/-o size=\\1/')"
876 [ -n "\$size" ] || size="-o size=90%"
878 while read var default; do
879 eval \$var=\$default
880 getarg \$var \$var
881 done <<EOT
882 eth eth0
883 dns 208.67.222.222,208.67.220.220
884 netmask 255.255.255.0
885 gw
886 ip
887 EOT
888 if [ -n "\$ip" ]; then
889 ifconfig \$eth \$ip netmask \$netmask up
890 route add default gateway \$gw
891 for i in \$(echo \$dns | sed 's/,/ /g'); do
892 echo "nameserver \$i" >> /etc/resolv.conf
893 done
894 else
895 udhcpc -f -q -s /lib/udhcpc -i \$eth
896 fi
897 for i in $urliso ; do
898 [ -n "\$URLISO" ] && URLISO="\$URLISO,"
899 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"
900 done
901 getarg urliso URLISO
902 DIR=fs
903 if getarg loram DIR; then
904 DEVICE=\${DIR%,*}
905 DIR=/\${DIR#*,}
906 fi
907 mount -t tmpfs \$size tmpfs /mnt
908 path2=/mnt/.httpfs/
909 path=/mnt/.cdrom/
910 mkdir -p /mnt/.rw \$path \$path2
911 while [ ! -d \$path/boot ]; do
912 for i in \$(echo \$URLISO | sed 's/,/ /g'); do
913 httpfs \$i \$path2 && break
914 done
915 mount -o loop,ro -t iso9660 \$path2/*.iso \$path
916 done
918 memfree=\$(grep MemFree /proc/meminfo | sed 's/[^0-9]//g')
919 umount /proc
920 branch=br=/mnt/.rw:/mnt/.cdrom/\$DIR
921 if [ ! -d /mnt/.cdrom/\$DIR/etc ]; then
922 branch=br=/mnt/.rw
923 for i in \${path}rootfs* ; do
924 fs=\${i#*root}
925 branch=\$branch:/mnt/.\$fs
926 mkdir -p /mnt/.rw/mnt/.\$fs /mnt/.\$fs /mnt/.rw/mnt/.cdrom
927 insmod /lib/squashfs.ko.gz 2> /dev/null
928 mount -o loop,ro -t squashfs \${path}root\$fs /mnt/.\$fs
929 done
930 else
931 mkdir -p /mnt/.rw/mnt/.httpfs
932 fi
933 insmod /lib/aufs.ko.gz
934 mount -t aufs -o \$branch none /mnt
935 [ -x /bin/httpfs ] && sed -i 's/DHCP="yes"/DHCP="no"/' /mnt/etc/network.conf
936 [ \$memfree -lt 30000 ] && sed -i 's/ slim//' /mnt/etc/rcS.conf
937 [ -x /mnt/sbin/init ] && exec /bin/switch_root mnt /sbin/init || sh
938 EOTEOT
939 chmod +x $TMP_DIR/initfs/init
940 for i in $TMP_DIR/initfs/lib/modules/*z ; do
941 unxz $i || gunzip $i || lzma d $i ${i%.gz}
942 rm -f $i
943 gzip -9 ${i%.gz}
944 done 2> /dev/null
945 ( cd $TMP_DIR/initfs ; find | busybox cpio -o -H newc 2> /dev/null) | \
946 lzma e $TMP_DIR/initfs.gz -si
947 lzma_set_size $TMP_DIR/initfs.gz
948 rm -rf $TMP_DIR/initfs
949 align_to_32bits $TMP_DIR/initfs.gz
950 return 0
951 }
953 # Move each initramfs to squashfs
954 build_loram_rootfs()
955 {
956 rootfs_sizes=""
957 for i in $TMP_DIR/iso/boot/rootfs*.gz; do
958 mkdir -p $TMP_DIR/fs
959 cd $TMP_DIR/fs
960 ( zcat $i 2> /dev/null || unlzma -c $i) | cpio -idm
961 cd - > /dev/null
962 rootfs=$TMP_DIR/$(basename $i)
963 /usr/sbin/mksquashfs $TMP_DIR/fs $rootfs -comp xz -Xbcj x86
964 cd $TMP_DIR
965 rootfs_sizes="$rootfs_sizes $(( $(du -s $TMP_DIR/fs | cut -f1) - $(du -s $rootfs | cut -f1) ))"
966 ( cd $(dirname $rootfs); echo $(basename $rootfs) | \
967 cpio -o -H newc ) > $rootfs.cpio
968 rm -f $rootfs
969 mv $rootfs.cpio $rootfs
970 cd - > /dev/null
971 rm -rf $TMP_DIR/fs
972 done
973 }
975 # Move meta boot configuration files to basic configuration files
976 # because meta loram flavor is useless when rootfs is not loaded in ram
977 unmeta_boot()
978 {
979 local root=${1:-$TMP_DIR/loramiso}
980 if [ -f $root/boot/isolinux/noram.cfg ]; then
981 # We keep enough information to do unloram...
982 [ -s $root/boot/isolinux/common.cfg ] &&
983 sed -i 's/label slitaz/label orgslitaz/' \
984 $root/boot/isolinux/common.cfg
985 set -- $(grep 'append ifmem [0-9]' $root/boot/isolinux/isolinux.cfg)
986 shift
987 sed -i '/ifmem/{NNNNNNNNd};/^LABEL/{N;/LABEL SliTaz [^L]/{NNNd}}' \
988 $root/boot/isolinux/isolinux.cfg
989 [ -n "$3" ] || set -- $(grep 'append [0-9]' $root/boot/isolinux/common.cfg)
990 sed -i "s/label $3\$/label slitaz/;s|=/boot/rootfs\(.*\).gz |=/boot/rootfs.gz |" \
991 $root/boot/isolinux/*.cfg
992 fi
993 }
995 # Move rootfs to squashfs filesystem(s) to the cdrom writeable with aufs.
996 # These squashfs may be loaded in ram at boot time.
997 # Rootfs are also copied to cdrom for tiny ramsize systems.
998 # Meta flavors are converted to normal flavors.
999 build_loram_cdrom()
1001 build_initfs cdrom || return 1
1002 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1003 mkdir $TMP_DIR/loramiso/fs
1004 cd $TMP_DIR/loramiso/fs
1005 for i in $( ls ../boot/root* | sort -r ) ; do
1006 ( zcat $i 2> /dev/null || unlzma -c $i ) | cpio -idmu
1007 rm -f $i
1008 done
1009 mkdir -p $TMP_DIR/loramiso/fs/mnt/.cdrom
1010 cd - > /dev/null
1011 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
1012 unmeta_boot
1013 VOLUM_NAME="SliTaz_LoRAM_CDROM"
1014 sed -i "s|root=|isofs= rodev=/dev/cdrom/fs &|;s/.ive/cdrom/" \
1015 $TMP_DIR/loramiso/boot/isolinux/*.cfg
1016 create_iso $OUTPUT $TMP_DIR/loramiso
1019 # Create http bootstrap to load and remove loram_cdrom
1020 # Meta flavors are converted to normal flavors.
1021 build_loram_http()
1023 build_initfs http || return 1
1024 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1025 rm -f $TMP_DIR/loramiso/boot/rootfs*
1026 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
1027 unmeta_boot
1028 create_iso $OUTPUT $TMP_DIR/loramiso
1031 # Update meta flavor selection sizes.
1032 # Reduce sizes with rootfs gains.
1033 update_metaiso_sizes()
1035 for cfg in $(grep -El '(append|ifmem) [0-9]' $TMP_DIR/loramiso/boot/isolinux/*.cfg)
1036 do
1037 local append="$(grep -E '(append|ifmem) [0-9]' $cfg)"
1038 local sizes="$rootfs_sizes"
1039 local new
1040 set -- $append
1041 shift
1042 [ "$1" == "ifmem" ] && shift
1043 new=""
1044 while [ -n "$2" ]; do
1045 local s
1046 case "$1" in
1047 *G) s=$(( ${1%G} * 1024 * 1024 ));;
1048 *M) s=$(( ${1%M} * 1024 ));;
1049 *) s=${1%K};;
1050 esac
1051 sizes=${sizes#* }
1052 for i in $sizes ; do
1053 s=$(( $s - $i ))
1054 done
1055 new="$new $s $2"
1056 shift 2
1057 done
1058 sed -i -e "/append [0-9]/s/append .*/append$new $1/" -e \
1059 "/append ifmem [0-9]/s/append .*/append ifmem$new $1/" $cfg
1060 sed -i 's|\(initrd=\)\(/boot/rootfs.\.gz\)|\1/boot/rootfs.gz,\2|' $cfg
1061 sed -i '/LABEL base/{NNNNp;s|base .ive|cdrom|;s|base|cdrom|;s|,[^ ]*||}' $cfg
1062 done
1065 # Move rootfs to a squashfs filesystem into the initramfs writeable with aufs.
1066 # Meta flavor selection sizes are updated.
1067 build_loram_ram()
1069 build_initfs ram || return 1
1070 build_loram_rootfs
1071 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1072 rm -f $TMP_DIR/loramiso/boot/bzImage
1073 ln $TMP_DIR/loramiso/boot/vmlinuz* $TMP_DIR/loramiso/boot/bzImage
1074 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
1075 cp $TMP_DIR/rootfs* $TMP_DIR/loramiso/boot
1076 update_metaiso_sizes
1077 create_iso $OUTPUT $TMP_DIR/loramiso
1080 # Remove files installed by packages
1081 find_flavor_rootfs()
1083 for i in $1/etc/tazlito/*.extract; do
1084 [ -e $i ] || continue
1085 chroot $1 /bin/sh ${i#$1}
1086 done
1088 # Clean hardlinks and files patched by genisofs in /boot
1089 for i in isolinux/isolinux.bin isolinux/boot.cat bzImage ; do
1090 rm -f $1/boot/$i
1091 done
1093 # Clean files generated in post_install
1094 rm -f $1/lib/modules/*/modules.* $1/etc/mtab \
1095 $1/dev/core $1/dev/fd $1/dev/std*
1097 # Verify md5
1098 cat $1$INSTALLED/*/md5sum | \
1099 while read md5 file; do
1100 [ -e $1$file ] || continue
1101 [ "$(md5sum < $1$file)" == "$md5 -" ] &&
1102 rm -f $1$file
1103 done
1105 # Check configuration files
1106 for i in $1$INSTALLED/*/volatile.cpio.gz; do
1107 [ -e $i ] || continue
1108 mkdir /tmp/volatile$$
1109 zcat $i | ( cd /tmp/volatile$$ ; cpio -idmu > /dev/null 2>&1 )
1110 ( cd /tmp/volatile$$ ; find * -type f 2> /dev/null) | \
1111 while read file ; do
1112 [ -e $1/$file ] || continue
1113 cmp -s /tmp/volatile$$/$file $1/$file && rm -f $1/$file
1114 done
1115 rm -rf /tmp/volatile$$
1116 done
1118 # Remove other files blindly
1119 for i in $1$INSTALLED/*/files.list; do
1120 for file in $(cat $i); do
1121 [ $1$file -nt $i ] && continue
1122 [ -f $1$file -a ! -L $1$file ] && continue
1123 [ -d $1$file ] || rm -f $1$file
1124 done
1125 done
1127 # Remove tazpkg files and tmp files
1128 rm -rf $1$INSTALLED* $1/tmp $1/var/tmp
1129 rm -f $1$LOCALSTATE/*packages* $1$LOCALSTATE/files.list.lzma \
1130 $1$LOCALSTATE/mirror* $1/var/cache/*/* \
1131 $1/var/lock/* $1/var/log/* $1/var/run/* $1/var/run/*/* \
1132 $1/var/lib/* $1/var/lib/dbus/* 2> /dev/null
1134 # Cleanup directory tree
1135 cd $1
1136 find * -type d | sort -r | while read dir; do
1137 rmdir $dir 2> /dev/null
1138 done
1139 cd - > /dev/null
1142 ####################
1143 # Tazlito commands #
1144 ####################
1146 case "$COMMAND" in
1147 stats)
1148 # Tazlito general statistics from the config file.
1150 newline
1151 boldify "Tazlito statistics"
1152 separator
1153 echo "\
1154 Config file : $CONFIG_FILE
1155 ISO name : $ISO_NAME.iso
1156 Volume name : $VOLUM_NAME
1157 Prepared : $PREPARED
1158 Packages repository : $PACKAGES_REPOSITORY
1159 Distro directory : $DISTRO"
1160 if [ ! "$ADDFILES" = "" ] ; then
1161 echo -e "Additional files : $ADDFILES"
1162 fi
1163 separator && newline ;;
1165 list-addfiles)
1166 # Simple list of additional files in the rootfs
1167 newline
1168 cd $ADDFILES
1169 find rootfs -type f
1170 newline ;;
1172 gen-config)
1173 # Generate a new config file in the current dir or the specified
1174 # directory by $2.
1176 if [ -n "$2" ] ; then
1177 mkdir -p $2 && cd $2
1178 fi
1179 echo -n "Generating empty tazlito.conf..."
1180 empty_config_file
1181 status
1182 newline
1183 if [ -f "tazlito.conf" ] ; then
1184 echo "Configuration file is ready to edit."
1185 echo "File location : `pwd`/tazlito.conf"
1186 newline
1187 fi ;;
1189 configure)
1190 # Configure a tazlito.conf config file. Start by getting
1191 # a empty config file and sed it.
1193 if [ -f "tazlito.conf" ] ; then
1194 rm tazlito.conf
1195 else
1196 if test $(id -u) = 0 ; then
1197 cd /etc
1198 else
1199 echo "You must be root to configure the main config file or in"
1200 echo "the same directory of the file you want to configure."
1201 exit 0
1202 fi
1203 fi
1204 empty_config_file
1205 echo""
1206 echo -e "\033[1mConfiguring :\033[0m `pwd`/tazlito.conf"
1207 separator
1208 # ISO name.
1209 echo -n "ISO name : " ; read answer
1210 sed -i s#'ISO_NAME=\"\"'#"ISO_NAME=\"$answer\""# tazlito.conf
1211 # Volume name.
1212 echo -n "Volume name : " ; read answer
1213 sed -i s/'VOLUM_NAME=\"SliTaz\"'/"VOLUM_NAME=\"$answer\""/ tazlito.conf
1214 # Packages repository.
1215 echo -n "Packages repository : " ; read answer
1216 sed -i s#'PACKAGES_REPOSITORY=\"\"'#"PACKAGES_REPOSITORY=\"$answer\""# tazlito.conf
1217 # Distro path.
1218 echo -n "Distro path : " ; read answer
1219 sed -i s#'DISTRO=\"\"'#"DISTRO=\"$answer\""# tazlito.conf
1220 separator
1221 echo "Config file is ready to use."
1222 echo "You can now extract an ISO or generate a distro."
1223 newline ;;
1225 gen-iso)
1226 # Simply generate a new iso.
1228 check_root
1229 verify_rootcd
1230 gen_livecd_isolinux
1231 distro_stats ;;
1233 gen-initiso)
1234 # Simply generate a new initramfs with a new iso.
1236 check_root
1237 verify_rootcd
1238 gen_initramfs $ROOTFS
1239 gen_livecd_isolinux
1240 distro_stats ;;
1242 extract-distro)
1243 # Extract an ISO image to a directory and rebuild the LiveCD tree.
1245 check_root
1246 ISO_IMAGE=$2
1247 if [ -z "$ISO_IMAGE" ] ; then
1248 echo -e "\nPlease specify the path to the ISO image."
1249 echo -e "Example : `basename $0` image.iso /path/target\n"
1250 exit 0
1251 fi
1252 # Set the distro path by checking for $3 on cmdline.
1253 if [ -n "$3" ] ; then
1254 TARGET=$3
1255 else
1256 TARGET=$DISTRO
1257 fi
1258 # Exit if existing distro is found.
1259 if [ -d "$TARGET/rootfs" ] ; then
1260 echo -e "\nA rootfs exists in : $TARGET"
1261 echo -e "Please clean the distro tree or change directory path.\n"
1262 exit 0
1263 fi
1264 newline
1265 echo -e "\033[1mTazlito extracting :\033[0m `basename $ISO_IMAGE`"
1266 separator
1267 # Start to mount the ISO.
1268 newline
1269 echo "Mounting ISO image..."
1270 mkdir -p $TMP_DIR
1271 # Get ISO file size.
1272 isosize=`du -sh $ISO_IMAGE | cut -f1`
1273 mount -o loop $ISO_IMAGE $TMP_DIR
1274 sleep 2
1275 # Prepare target dir, copy the kernel and the rootfs.
1276 mkdir -p $TARGET/rootfs
1277 mkdir -p $TARGET/rootcd/boot
1278 echo -n "Copying the Linux kernel..."
1279 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
1280 ln $TARGET/rootcd/boot/vmlinuz* $TARGET/rootcd/boot/bzImage
1281 else
1282 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
1283 fi
1284 status
1285 echo -n "Copying isolinux files..."
1286 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
1287 for i in $(ls $TMP_DIR); do
1288 [ "$i" = "boot" ] && continue
1289 cp -a $TMP_DIR/$i $TARGET/rootcd
1290 done
1291 status
1292 if [ -d $TMP_DIR/boot/syslinux ]; then
1293 echo -n "Copying syslinux files..."
1294 cp -a $TMP_DIR/boot/syslinux $TARGET/rootcd/boot
1295 status
1296 fi
1297 if [ -d $TMP_DIR/boot/extlinux ]; then
1298 echo -n "Copying extlinux files..."
1299 cp -a $TMP_DIR/boot/extlinux $TARGET/rootcd/boot
1300 status
1301 fi
1302 if [ -d $TMP_DIR/boot/grub ]; then
1303 echo -n "Copying GRUB files..."
1304 cp -a $TMP_DIR/boot/grub $TARGET/rootcd/boot
1305 status
1306 fi
1308 echo -n "Copying the rootfs..."
1309 cp $TMP_DIR/boot/rootfs.?z $TARGET/rootcd/boot
1310 status
1311 # Extract initramfs.
1312 cd $TARGET/rootfs
1313 echo -n "Extracting the rootfs... "
1314 extract_rootfs ../rootcd/boot/rootfs.gz $TARGET/rootfs
1315 # unpack /usr
1316 for i in etc/tazlito/*.extract; do
1317 [ -f "$i" ] && . $i ../rootcd
1318 done
1319 # Umount and remove temp directory and cd to $TARGET to get stats.
1320 umount $TMP_DIR && rm -rf $TMP_DIR
1321 cd ..
1322 newline
1323 separator
1324 echo "Extracted : `basename $ISO_IMAGE` ($isosize)"
1325 echo "Distro tree : `pwd`"
1326 echo "Rootfs size : `du -sh rootfs`"
1327 echo "Rootcd size : `du -sh rootcd`"
1328 separator
1329 newline ;;
1331 list-flavors)
1332 # Show available flavors.
1333 if [ ! -s /etc/tazlito/flavors.list -o "$2" == "--recharge" ]; then
1334 download flavors.list -O - > /etc/tazlito/flavors.list
1335 fi
1336 newline
1337 boldify "List of flavors"
1338 separator
1339 cat /etc/tazlito/flavors.list
1340 newline ;;
1342 show-flavor)
1343 # Show flavor description.
1344 FLAVOR=${2%.flavor}
1345 if [ ! -f "$FLAVOR.flavor" ]; then
1346 echo "File $FLAVOR.flavor not found."
1347 exit 1
1348 fi
1349 mkdir $TMP_DIR
1350 zcat < $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i > /dev/null)
1351 if [ "$3" = "--brief" ]; then
1352 if [ "$4" != "--noheader" ]; then
1353 echo "Name ISO Rootfs Description"
1354 separator
1355 fi
1356 printf "%-16.16s %6.6s %6.6s %s\n" "$FLAVOR" \
1357 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
1358 "$(field 'Rootfs size' $TMP_DIR/$FLAVOR.desc)" \
1359 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
1360 else
1361 separator
1362 cat $TMP_DIR/$FLAVOR.desc
1363 fi
1364 rm -Rf $TMP_DIR ;;
1366 gen-liveflavor)
1367 # Generate a new flavor from the live system.
1368 FLAVOR=${2%.flavor}
1369 DESC=""
1370 case "$FLAVOR" in
1371 '') echo -n "Flavor name : "
1372 read FLAVOR
1373 [ -z "$FLAVOR" ] && exit 1;;
1374 -?|-h*|--help) echo -e "
1376 SliTaz Live Tool - Version: $VERSION
1377 \033[1mUsage: \033[0m `basename $0` gen-liveflavor flavor-name [flavor-patch-file]
1378 \033[1mflavor-patch-file format: \033[0m
1379 code data
1380 + package to add
1381 - package to remove
1382 ! non-free package to add
1383 ? display message
1384 @ flavor description
1386 \033[1mExample: \033[0m
1387 @ Developer tools for slitaz maintainers
1388 + slitaz-toolchain
1389 + mercurial
1391 exit 1;;
1392 esac
1393 mv /etc/tazlito/distro-packages.list \
1394 /etc/tazlito/distro-packages.list.$$ 2> /dev/null
1395 rm -f distro-packages.list non-free.list 2> /dev/null
1396 tazpkg recharge
1397 [ -n "$3" ] && while read action pkg; do
1398 case "$action" in
1399 +) yes | tazpkg get-install $pkg 2>&1 >> $log || exit 1 ;;
1400 -) yes | tazpkg remove $pkg ;;
1401 !) echo $pkg >> non-free.list ;;
1402 @) DESC="$pkg" ;;
1403 \?) echo -en "$pkg"; read action ;;
1404 esac
1405 done < $3
1406 yes '' | tazlito gen-distro
1407 echo "$DESC" | tazlito gen-flavor "$FLAVOR"
1408 mv /etc/tazlito/distro-packages.list.$$ \
1409 /etc/tazlito/distro-packages.list 2> /dev/null ;;
1411 gen-flavor)
1412 # Generate a new flavor from the last iso image generated.
1413 FLAVOR=${2%.flavor}
1414 newline
1415 boldify "Flavor generation"
1416 separator
1417 if [ -z "$FLAVOR" ]; then
1418 echo -n "Flavor name : "
1419 read FLAVOR
1420 [ -z "$FLAVOR" ] && exit 1
1421 fi
1422 check_rootfs
1423 FILES="$FLAVOR.pkglist"
1424 echo -n "Creating file $FLAVOR.flavor..."
1425 for i in rootcd rootfs; do
1426 if [ -d "$ADDFILES/$i" ] ; then
1427 FILES="$FILES\n$FLAVOR.$i"
1428 ( cd "$ADDFILES/$i"; find . | \
1429 cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
1430 fi
1431 done
1432 status
1433 answer=`grep -s ^Description $FLAVOR.desc`
1434 answer=${answer#Description : }
1435 if [ -z "$answer" ]; then
1436 echo -n "Description : "
1437 read answer
1438 fi
1439 echo -n "Compressing flavor $FLAVOR..."
1440 echo "Flavor : $FLAVOR" > $FLAVOR.desc
1441 echo "Description : $answer" >> $FLAVOR.desc
1442 ( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
1443 \rm -f $FLAVOR.pkglist $FLAVOR.nonfree 2> /dev/null
1444 for i in $(ls $ROOTFS$INSTALLED); do
1445 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
1446 EXTRAVERSION=""
1447 eval $(grep ^EXTRAVERSION= $ROOTFS$INSTALLED/$i/receipt)
1448 eval $(grep ^CATEGORY= $ROOTFS$INSTALLED/$i/receipt)
1449 if [ "$CATEGORY" = "non-free" -a "${i%%-*}" != "get" ]
1450 then
1451 echo "$i" >> $FLAVOR.nonfree
1452 else
1453 echo "$i-$VERSION$EXTRAVERSION" >> $FLAVOR.pkglist
1454 fi
1455 done
1456 [ -s $FLAVOR.nonfree ] && $FILES="$FILES\n$FLAVOR.nonfree"
1457 for i in $LOCALSTATE/undigest/*/mirror ; do
1458 [ -s $i ] && cat $i >> $FLAVOR.mirrors
1459 done
1460 [ -s $FLAVOR.mirrors ] && $FILES="$FILES\n$FLAVOR.mirrors"
1461 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
1462 gzip -9 > $FLAVOR.flavor
1463 rm `echo -e $FILES`
1464 status
1465 separator
1466 echo "Flavor size : `du -sh $FLAVOR.flavor`"
1467 newline ;;
1469 upgrade-flavor)
1470 # Update package list to the latest versions available.
1471 FLAVOR=${2%.flavor}
1472 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1473 mkdir $TMP_DIR
1474 zcat < $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1475 echo -n "Updating $FLAVOR package list..."
1476 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1477 packed_size=0; unpacked_size=0
1478 while read org; do
1479 i=0
1480 pkg=$org
1481 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
1482 pkg=${pkg%-*}
1483 i=$(($i + 1))
1484 [ $i -gt 5 ] && break;
1485 done
1486 set -- $(get_size $pkg)
1487 packed_size=$(( $packed_size + $1 ))
1488 unpacked_size=$(( $unpacked_size + $2 ))
1489 for i in $(grep ^$pkg $LOCALSTATE/packages.list); do
1490 echo $i
1491 break
1492 done
1493 done < $TMP_DIR/$FLAVOR.pkglist \
1494 > $TMP_DIR/$FLAVOR.pkglist.$$
1495 mv -f $TMP_DIR/$FLAVOR.pkglist.$$ $TMP_DIR/$FLAVOR.pkglist
1496 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1497 packed_size=$(($packed_size \
1498 + $(wc -c < $TMP_DIR/$FLAVOR.rootfs) / 100 ))
1499 unpacked_size=$(($unpacked_size \
1500 + $(zcat < $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1501 fi
1502 # Estimate lzma
1503 packed_size=$(($packed_size * 2 / 3))
1504 iso_size=$(( $packed_size + 26000 ))
1505 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1506 iso_size=$(($iso_size \
1507 + $(zcat < $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1508 fi
1509 sed -i -e '/Image is ready/d' \
1510 -e "s/Rootfs size\( *:\) \(.*\)/Rootfs size\1 $(cent2human $unpacked_size) (estimated)/" \
1511 -e "s/Initramfs size\( *:\) \(.*\)/Initramfs size\1 $(cent2human $packed_size) (estimated)/" \
1512 -e "s/ISO image size\( *:\) \(.*\)/ISO image size\1 $(cent2human $iso_size) (estimated)/" \
1513 -e "s/date\( *:\) \(.*\)/date\1 $(date +%Y%m%d\ \at\ \%H:%M:%S)/" \
1514 $TMP_DIR/$FLAVOR.desc
1515 ( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
1516 $FLAVOR.flavor
1517 status
1518 rm -Rf $TMP_DIR
1519 fi ;;
1521 extract-flavor)
1522 # Extract a flavor into $FLAVORS_REPOSITORY.
1523 FLAVOR=${2%.flavor}
1524 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1525 mkdir $TMP_DIR
1526 zcat < $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1527 echo -n "Extracting $FLAVOR..."
1528 rm -rf $FLAVORS_REPOSITORY/$FLAVOR 2> /dev/null
1529 mkdir -p $FLAVORS_REPOSITORY/$FLAVOR
1530 cp $TMP_DIR/$FLAVOR.receipt $FLAVORS_REPOSITORY/$FLAVOR/receipt
1531 #~ echo "FLAVOR=\"$FLAVOR\"" > $FLAVORS_REPOSITORY/$FLAVOR/receipt
1532 #~ grep ^Description $TMP_DIR/$FLAVOR.desc | \
1533 #~ sed 's/.*: \(.*\)$/SHORT_DESC="\1"/' >> \
1534 #~ $FLAVORS_REPOSITORY/$FLAVOR/receipt
1535 #~ grep ^Version $TMP_DIR/$FLAVOR.desc | \
1536 #~ sed 's/.*: \(.*\)$/VERSION="\1"/' >> \
1537 #~ $FLAVORS_REPOSITORY/$FLAVOR/receipt
1538 #~ grep ^Maintainer $TMP_DIR/$FLAVOR.desc | \
1539 #~ sed 's/.*: \(.*\)$/MAINTAINER="\1"/' >> \
1540 #~ $FLAVORS_REPOSITORY/$FLAVOR/receipt
1541 #~ grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc && \
1542 #~ grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1543 #~ sed 's/.*: \(.*\)$/ROOTFS_SELECTION="\1"/' >> \
1544 #~ $FLAVORS_REPOSITORY/$FLAVOR/receipt
1545 #~ grep '^Rootfs size' $TMP_DIR/$FLAVOR.desc | \
1546 #~ sed 's/.*: \(.*\)$/ROOTFS_SIZE="\1"/' >> \
1547 #~ $FLAVORS_REPOSITORY/$FLAVOR/receipt
1548 #~ grep ^Initramfs $TMP_DIR/$FLAVOR.desc | \
1549 #~ sed 's/.*: \(.*\)$/INITRAMFS_SIZE="\1"/' >> \
1550 #~ $FLAVORS_REPOSITORY/$FLAVOR/receipt
1551 #~ grep ^ISO $TMP_DIR/$FLAVOR.desc | \
1552 #~ sed 's/.*: \(.*\)$/ISO_SIZE="\1"/' >> \
1553 #~ $FLAVORS_REPOSITORY/$FLAVOR/receipt
1554 for i in rootcd rootfs; do
1555 [ -f $TMP_DIR/$FLAVOR.$i ] || continue
1556 mkdir $FLAVORS_REPOSITORY/$FLAVOR/$i
1557 zcat < $TMP_DIR/$FLAVOR.$i | \
1558 (cd $FLAVORS_REPOSITORY/$FLAVOR/$i; \
1559 cpio -idm > /dev/null)
1560 done
1561 [ -s $TMP_DIR/$FLAVOR.mirrors ] &&
1562 cp $TMP_DIR/$FLAVOR.mirrors \
1563 $FLAVORS_REPOSITORY/$FLAVOR/mirrors
1564 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1565 while read org; do
1566 i=0
1567 pkg=$org
1568 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
1569 pkg=${pkg%-*}
1570 i=$(($i + 1))
1571 [ $i -gt 5 ] && break;
1572 done
1573 echo $pkg
1574 done < $TMP_DIR/$FLAVOR.pkglist \
1575 > $FLAVORS_REPOSITORY/$FLAVOR/packages.list
1576 status
1577 rm -Rf $TMP_DIR
1578 fi ;;
1580 pack-flavor)
1581 # Create a flavor from $FLAVORS_REPOSITORY.
1582 FLAVOR=${2%.flavor}
1583 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/receipt ]; then
1584 mkdir $TMP_DIR
1585 echo -n "Creating flavor $FLAVOR..."
1586 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1587 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/mirrors ]; then
1588 cp $FLAVORS_REPOSITORY/$FLAVOR/mirrors \
1589 $TMP_DIR/$FLAVOR.mirrors
1590 for i in $(cat $TMP_DIR/$FLAVOR.mirrors); do
1591 wget -O - $i/packages.list >> $TMP_DIR/packages.list
1592 done
1593 fi
1594 # add distro.sh if exists
1595 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/distro.sh ]; then
1596 cp $FLAVORS_REPOSITORY/$FLAVOR/distro.sh $TMP_DIR/$FLAVOR-distro.sh
1597 fi
1599 # Get receipt in .flavor
1600 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/receipt ]; then
1601 cp $FLAVORS_REPOSITORY/$FLAVOR/receipt $TMP_DIR/$FLAVOR.receipt
1602 fi
1604 # Build the package list.
1606 # On peut inclure une liste venant d'une autre saveur avec le mot clé @include
1607 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/packages.list ]; then
1608 INCLUDE=$(grep '^@include' $FLAVORS_REPOSITORY/$FLAVOR/packages.list)
1609 if [ ! -z "$INCLUDE" ]; then
1610 INCLUDE=${INCLUDE#@include }
1611 [ -s "$FLAVORS_REPOSITORY/$INCLUDE/packages.list" ] && \
1612 get_pkglist $INCLUDE > $TMP_DIR/$FLAVOR.pkglist || \
1613 echo -e "\nERROR: Can't find include package list from $INCLUDE\n"
1614 fi
1615 # Generate the final/initial package list
1616 [ -s $FLAVORS_REPOSITORY/$FLAVOR/packages.list ] && \
1617 get_pkglist $FLAVOR >> $TMP_DIR/$FLAVOR.pkglist
1618 fi
1619 if grep -q ^ROOTFS_SELECTION \
1620 $FLAVORS_REPOSITORY/$FLAVOR/receipt; then
1621 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1622 set -- $ROOTFS_SELECTION
1623 [ -n "$FRUGAL_RAM" ] || FRUGAL_RAM=$1
1624 [ -f $FLAVORS_REPOSITORY/$2/packages.list ] ||
1625 tazlito extract-flavor $2
1626 get_pkglist $2 > $TMP_DIR/$FLAVOR.pkglist
1627 for i in rootcd rootfs; do
1628 mkdir $TMP_DIR/$i
1629 # Copy extra files from the first flavor
1630 [ -d $FLAVORS_REPOSITORY/$2/$i ] &&
1631 cp -a $FLAVORS_REPOSITORY/$2/$i $TMP_DIR
1632 # Overload extra files by meta flavor
1633 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] &&
1634 cp -a $FLAVORS_REPOSITORY/$FLAVOR/$i $TMP_DIR
1635 [ -n "$(ls $TMP_DIR/$i)" ] &&
1636 ( cd $TMP_DIR/$i ; find . | cpio -o -H newc 2> /dev/null ) | \
1637 gzip -9 >$TMP_DIR/$FLAVOR.$i
1638 rm -rf $TMP_DIR/$i
1639 done
1640 else
1641 for i in rootcd rootfs; do
1642 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] || \
1643 continue
1644 ( cd $FLAVORS_REPOSITORY/$FLAVOR/$i ; \
1645 find . | cpio -o -H newc 2> /dev/null ) | \
1646 gzip -9 >$TMP_DIR/$FLAVOR.$i
1647 done
1648 fi
1649 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1650 packed_size=$(($packed_size \
1651 + $(wc -c < $TMP_DIR/$FLAVOR.rootfs) / 100 ))
1652 unpacked_size=$(($unpacked_size \
1653 + $(zcat < $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1654 fi
1655 # Estimate lzma
1656 packed_size=$(($packed_size * 2 / 3))
1657 iso_size=$(( $packed_size + 26000 ))
1658 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1659 iso_size=$(($iso_size \
1660 + $(zcat < $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1661 fi
1662 VERSION=""
1663 MAINTAINER=""
1664 ROOTFS_SELECTION=""
1665 ROOTFS_SIZE="$(cent2human $unpacked_size) (estimated)"
1666 INITRAMFS_SIZE="$(cent2human $packed_size) (estimated)"
1667 ISO_SIZE="$(cent2human $iso_size) (estimated)"
1668 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1669 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1670 Flavor : $FLAVOR
1671 Description : $SHORT_DESC
1672 EOT
1673 [ -n "$VERSION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1674 Version : $VERSION
1675 EOT
1676 [ -n "$MAINTAINER" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1677 Maintainer : $MAINTAINER
1678 EOT
1679 [ -n "$FRUGAL_RAM" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1680 LiveCD RAM size : $FRUGAL_RAM
1681 EOT
1682 [ -n "$ROOTFS_SELECTION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1683 Rootfs list : $ROOTFS_SELECTION
1684 EOT
1685 cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1686 Build date : $(date +%Y%m%d\ \at\ \%H:%M:%S)
1687 Packages : $(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l)
1688 Rootfs size : $ROOTFS_SIZE
1689 Initramfs size : $INITRAMFS_SIZE
1690 ISO image size : $ISO_SIZE
1691 ================================================================================
1693 EOT
1694 rm -f $TMP_DIR/packages.list
1695 ( cd $TMP_DIR ; ls | cpio -o -H newc 2> /dev/null) | \
1696 gzip -9 > $FLAVOR.flavor
1697 status
1698 rm -Rf $TMP_DIR
1699 else
1700 echo "No $FLAVOR flavor in $FLAVORS_REPOSITORY."
1701 fi ;;
1703 get-flavor)
1704 # Get a flavor's files and prepare for gen-distro.
1705 FLAVOR=${2%.flavor}
1706 echo -e "\n\033[1mPreparing $FLAVOR distro flavor\033[0m"
1707 separator
1708 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1709 echo -n "Cleaning $DISTRO..."
1710 rm -R $DISTRO 2> /dev/null
1711 mkdir -p $DISTRO
1712 status
1713 mkdir $TMP_DIR
1714 echo -n "Extracting flavor $FLAVOR.flavor... "
1715 zcat < $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i --quiet >/dev/null )
1716 status
1717 echo -n "Creating distro-packages.list..."
1718 mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
1719 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
1720 status
1721 if [ -f "$TMP_DIR/$FLAVOR-distro.sh" ]; then
1722 echo -n "Extracting distro.sh... "
1723 mv $TMP_DIR/$FLAVOR-distro.sh distro.sh 2> /dev/null
1724 status
1725 fi
1726 if [ -f "$TMP_DIR/$FLAVOR.receipt" ]; then
1727 echo -n "Extracting receipt... "
1728 mv $TMP_DIR/$FLAVOR.receipt receipt 2> /dev/null
1729 status
1730 fi
1731 infos="$FLAVOR.desc"
1732 for i in rootcd rootfs; do
1733 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
1734 echo -n "Adding $i files... "
1735 mkdir -p "$ADDFILES/$i"
1736 zcat < $TMP_DIR/$FLAVOR.$i | \
1737 ( cd "$ADDFILES/$i"; cpio -id --quiet > /dev/null)
1738 zcat < $TMP_DIR/$FLAVOR.$i | cpio -tv 2> /dev/null \
1739 > $TMP_DIR/$FLAVOR.list$i
1740 infos="$infos\n$FLAVOR.list$i"
1741 status
1742 fi
1743 done
1744 if [ -s $TMP_DIR/$FLAVOR.mirrors ]; then
1745 n=""
1746 while read line; do
1747 mkdir -p $LOCALSTATE/undigest/$FLAVOR$n
1748 echo "$line" > $LOCALSTATE/undigest/$FLAVOR$n/mirror
1749 n=$(( $n + 1 ))
1750 done < $TMP_DIR/$FLAVOR.mirrors
1751 infos="$infos\n$FLAVOR.mirrors"
1752 tazpkg recharge
1753 fi
1754 rm -f /etc/tazlito/rootfs.list
1755 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc &&
1756 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1757 sed 's/.*: \(.*\)$/\1/' > /etc/tazlito/rootfs.list
1758 echo -n "Updating tazlito.conf..."
1759 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
1760 grep -v "^#VOLUM_NAME" < tazlito.conf | \
1761 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
1762 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
1763 sed -i "s/ISO_NAME=.*/ISO_NAME=\"slitaz-$FLAVOR\"/" tazlito.conf
1764 status
1765 ( cd $TMP_DIR ; echo -e $infos | cpio -o -H newc ) | \
1766 gzip -9 > /etc/tazlito/info
1767 rm -Rf $TMP_DIR
1768 fi
1769 separator
1770 echo -e "Flavor is ready to be generated by: tazlito gen-distro\n" ;;
1772 iso2flavor)
1773 if [ -z "$3" -o ! -s "$2" ]; then
1774 cat <<EOT
1775 Usage : tazlito iso2flavor image.iso flavor_name
1777 Create a file flavor_name.flavor from the cdrom image file image.iso
1778 EOT
1779 exit 1
1780 fi
1781 FLAVOR=${3%.flavor}
1782 mkdir -p $TMP_DIR/iso $TMP_DIR/rootfs
1783 mount -o loop,ro $2 $TMP_DIR/iso
1784 if [ -s $TMP_DIR/iso/boot/rootfs1.gz ]; then
1785 echo "META flavors are not supported."
1786 umount -d $TMP_DIR/iso
1787 elif [ ! -s $TMP_DIR/iso/boot/rootfs.gz ]; then
1788 echo "No /boot/rootfs.gz in iso image. Needs a SliTaz iso."
1789 umount -d $TMP_DIR/iso
1790 else
1791 ( unlzma -c $TMP_DIR/iso/boot/rootfs.gz || \
1792 zcat $TMP_DIR/iso/boot/rootfs.gz ) | \
1793 ( cd $TMP_DIR/rootfs ; cpio -idmu > /dev/null 2>&1 )
1794 if [ ! -s $TMP_DIR/rootfs/etc/slitaz-release ]; then
1795 echo "No file /etc/slitaz-release in /boot/rootfs.gz of iso image. Needs a non loram SliTaz iso."
1796 umount -d $TMP_DIR/iso
1797 else
1798 ROOTFS_SIZE=$(du -hs $TMP_DIR/rootfs | awk '{ print $1 }')
1799 RAM_SIZE=$(du -s $TMP_DIR/rootfs | awk '{ print 32*int(($1+36000)/32768) "M" }')
1800 cp -a $TMP_DIR/iso $TMP_DIR/rootcd
1801 ISO_SIZE=$(df -h $TMP_DIR/iso | awk 'END { print $2 }')
1802 BUILD_DATE=$(date +%Y%m%d\ \at\ \%H:%M:%S -r $TMP_DIR/iso/md5sum)
1803 umount -d $TMP_DIR/iso
1804 INITRAMFS_SIZE=$(du -chs $TMP_DIR/rootcd/boot/rootfs.gz | awk '{ s=$1 } END { print $1 }')
1805 rm -f $TMP_DIR/rootcd/boot/rootfs.gz $TMP_DIR/rootcd/md5sum
1806 mv $TMP_DIR/rootcd/boot $TMP_DIR/rootfs
1807 sed 's/.* \(.*\).tazpkg*/\1/' > $TMP_DIR/$FLAVOR.pkglist \
1808 < $TMP_DIR/rootfs$INSTALLED.md5
1809 #[ -s $TMP_DIR/rootfs/etc/tazlito/distro-packages.list ] &&
1810 # mv $TMP_DIR/rootfs/etc/tazlito/distro-packages.list $TMP_DIR/$FLAVOR.pkglist
1811 PKGCNT=$(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l | awk '{ print $1 }')
1812 find_flavor_rootfs $TMP_DIR/rootfs
1813 [ -d $TMP_DIR/rootfs/boot ] && mv $TMP_DIR/rootfs/boot $TMP_DIR/rootcd
1814 [ -n "$(ls $TMP_DIR/rootfs)" ] && ( cd $TMP_DIR/rootfs ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootfs
1815 [ -n "$(ls $TMP_DIR/rootcd)" ] && ( cd $TMP_DIR/rootcd ; find * | cpio -o -H newc ) | gzip -9 > $TMP_DIR/$FLAVOR.rootcd
1816 rm -rf $TMP_DIR/rootcd $TMP_DIR/rootfs
1817 VERSION=""; MAINTAINER=""
1818 echo -en "Flavor short description \007: "; read -t 30 DESCRIPTION
1819 if [ -n "$DESCRIPTION" ]; then
1820 echo -en "Flavor version : "; read -t 30 VERSION
1821 echo -en "Flavor maintainer (your email) : "; read -t 30 MAINTAINER
1822 fi
1823 [ -n "$DESCRIPTION" ] || DESCRIPTION="Slitaz $FLAVOR flavor"
1824 [ -n "$VERSION" ] || VERSION="1.0"
1825 [ -n "$MAINTAINER" ] || MAINTAINER="nobody@slitaz.org"
1826 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1827 Flavor : $FLAVOR
1828 Description : $DESCRIPTION
1829 Version : $VERSION
1830 Maintainer : $MAINTAINER
1831 LiveCD RAM size : $RAM_SIZE
1832 Build date : $BUILD_DATE
1833 Packages : $PKGCNT
1834 Rootfs size : $ROOTFS_SIZE
1835 Initramfs size : $INITRAMFS_SIZE
1836 ISO image size : $ISO_SIZE
1837 ================================================================================
1839 EOT
1840 ( cd $TMP_DIR ; ls $FLAVOR.* | cpio -o -H newc ) | gzip -9 > $FLAVOR.flavor
1841 cat <<EOT
1842 Tazlito can't detect each file installed during a package post_install.
1843 You should extract this flavor (tazlito extract-flavor $FLAVOR),
1844 check the files in /home/slitaz/flavors/$(cat /etc/slitaz-release)/$FLAVOR/rootfs tree and remove
1845 files generated by post_installs.
1846 Check /home/slitaz/flavors/$(cat /etc/slitaz-release)/$FLAVOR/receipt too and repack the flavor
1847 (tazlito pack-flavor $FLAVOR)
1848 EOT
1849 fi
1850 fi
1851 rm -rf $TMP_DIR ;;
1853 check-list)
1854 # Use current packages list in $PWD by default.
1855 DISTRO_PKGS_LIST=distro-packages.list
1856 [ -d "$2" ] && DISTRO_PKGS_LIST=$2/distro-packages.list
1857 [ -f "$2" ] && DISTRO_PKGS_LIST=$2
1858 [ ! -f $DISTRO_PKGS_LIST ] && echo "No packages list found." && exit 0
1859 newline
1860 boldify "LiveCD packages list check"
1861 separator
1862 for pkg in $(cat $DISTRO_PKGS_LIST)
1863 do
1864 if ! grep -q "$pkg" $LOCALSTATE/packages.list; then
1865 echo "Updating: $pkg"
1866 up=$(($up + 1))
1867 fi
1868 done
1869 [ -z $up ] && echo -e "List is up-to-date\n" && exit 0
1870 separator
1871 echo -e "Updates: $up\n" ;;
1873 gen-distro)
1874 # Generate a live distro tree with a set of packages.
1876 check_root
1877 time=$(date +%s)
1879 # Libtaz will set $iso or $cdrom
1880 CDROM=""
1881 [ "$iso" ] && CDROM="-o loop $iso"
1882 [ "$cdrom" ] && CDROM="/dev/cdrom"
1883 # Check if a package list was specified on cmdline.
1884 if [ -f "$2" ]; then
1885 LIST_NAME=$2
1886 else
1887 LIST_NAME="distro-packages.list"
1888 fi
1890 if [ -d "$ROOTFS" ] ; then
1891 # Delete $ROOTFS if --force is set on command line
1892 if [ "$forced" ]; then
1893 rm -rf $ROOTFS $ROOTCD
1894 else
1895 echo -e "\nA rootfs exists in : $DISTRO"
1896 echo -e "Please clean the distro tree or change directory path.\n"
1897 exit 0
1898 fi
1899 fi
1901 # Build list with installed packages
1902 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
1903 for i in $(ls $INSTALLED); do
1904 if grep -q ^_realver $INSTALLED/$i/receipt ; then
1905 VERSION=$(. $INSTALLED/$i/receipt 2>/dev/null ; echo $VERSION)
1906 else
1907 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
1908 fi
1909 EXTRAVERSION=""
1910 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
1911 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
1912 done
1913 fi
1914 # Exit if no list name.
1915 if [ ! -f "$LIST_NAME" ]; then
1916 echo -e "\nNo packages list found or specified. Please read the docs.\n"
1917 exit 0
1918 fi
1919 # Start generation.
1920 newline
1921 boldify "Tazlito generating a distro"
1922 separator
1923 # Misc checks
1924 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
1925 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
1926 # Get the list of packages using cat for a file list.
1927 LIST=`cat $LIST_NAME`
1928 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
1929 REPACK=""
1930 DOWNLOAD=""
1931 for pkg in $LIST
1932 do
1933 [ "$pkg" = "" ] && continue
1934 pkg=${pkg%.tazpkg}
1935 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
1936 PACKAGE=$(installed_package_name $pkg)
1937 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
1938 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
1939 echo -e "\nUnable to find $pkg in the repository."
1940 echo -e "Path : $PACKAGES_REPOSITORY\n"
1941 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
1942 yesorno "Repack packages from rootfs (y/N) ? "
1943 REPACK="$answer"
1944 [ "$answer" = "y" ] || REPACK="n"
1945 [ "$DOWNLOAD" = "y" ] && break
1946 fi
1947 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
1948 yesorno "Download packages from mirror (Y/n) ? "
1949 DOWNLOAD="$answer"
1950 if [ "$answer" = "n" ]; then
1951 [ -z "$PACKAGE" ] && exit 1
1952 else
1953 DOWNLOAD="y"
1954 [ -n "$REPACK" ] && break
1955 fi
1956 fi
1957 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
1958 done
1960 # Mount cdrom to be able to repack boot-loader packages
1961 if [ ! -e /boot -a -n "$CDROM" ]; then
1962 mkdir $TMP_MNT
1963 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
1964 ln -s $TMP_MNT/boot /
1965 if [ ! -d "$ADDFILES/rootcd" ] ; then
1966 mkdir -p $ADDFILES/rootcd
1967 for i in $(ls $TMP_MNT); do
1968 [ "$i" = "boot" ] && continue
1969 cp -a $TMP_MNT/$i $ADDFILES/rootcd
1970 done
1971 fi
1972 else
1973 rmdir $TMP_MNT
1974 fi
1975 fi
1977 # Rootfs stuff.
1978 echo "Preparing the rootfs directory..."
1979 mkdir -p $ROOTFS
1980 for pkg in $LIST
1981 do
1982 [ "$pkg" = "" ] && continue
1983 # First copy and extract the package in tmp dir.
1984 pkg=${pkg%.tazpkg}
1985 PACKAGE=$(installed_package_name $pkg)
1986 mkdir -p $TMP_DIR
1987 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1988 # Look for package in cache
1989 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
1990 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
1991 # Look for package in running distribution
1992 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
1993 tazpkg repack $PACKAGE && \
1994 mv $pkg.tazpkg $PACKAGES_REPOSITORY
1995 fi
1996 fi
1997 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
1998 # Get package from mirror
1999 [ "$DOWNLOAD" = "y" ] && \
2000 download $pkg.tazpkg && \
2001 mv $pkg.tazpkg $PACKAGES_REPOSITORY
2002 fi
2003 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
2004 echo "Missing package: $pkg"
2005 cleanup
2006 exit 1
2007 fi
2008 done
2009 if [ -f non-free.list ]; then
2010 echo "Preparing non-free packages..."
2011 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
2012 for pkg in $(cat non-free.list); do
2013 if [ ! -d $INSTALLED/$pkg ]; then
2014 if [ ! -d $INSTALLED/get-$pkg ]; then
2015 tazpkg get-install get-$pkg
2016 fi
2017 get-$pkg
2018 fi
2019 tazpkg repack $pkg
2020 pkg=$(ls $pkg*.tazpkg)
2021 grep -q "^$pkg$" $LIST_NAME || \
2022 echo $pkg >>$LIST_NAME
2023 mv $pkg $PACKAGES_REPOSITORY
2024 done
2025 fi
2026 cp $LIST_NAME $DISTRO/distro-packages.list
2027 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/distro-packages.list > $DISTRO/list-packages
2028 cd $PACKAGES_REPOSITORY
2029 for pkg in $(cat $DISTRO/list-packages)
2030 do
2031 echo -n "Installing package: $pkg"
2032 yes y | tazpkg -i $pkg --root=$ROOTFS 2>&1 >> $log || exit 1
2033 status
2034 done
2035 rm -f $ROOTFS/var/lib/tazpkg/packages.*
2036 cd $DISTRO
2037 cp distro-packages.list $ROOTFS/etc/tazlito
2038 # Copy all files from $ADDFILES/rootfs to the rootfs.
2039 if [ -d "$ADDFILES/rootfs" ] ; then
2040 echo -n "Copying addfiles content to the rootfs... "
2041 cp -a $ADDFILES/rootfs/* $ROOTFS
2042 status
2043 fi
2044 echo -n "Root filesystem is generated..." && status
2045 # Root CD part.
2046 echo -n "Preparing the rootcd directory..."
2047 mkdir -p $ROOTCD
2048 status
2049 # Move the boot dir with the Linux kernel from rootfs.
2050 # The boot dir goes directly on the CD.
2051 if [ -d "$ROOTFS/boot" ] ; then
2052 echo -n "Moving the boot directory..."
2053 mv $ROOTFS/boot $ROOTCD
2054 cd $ROOTCD/boot
2055 ln vmlinuz-* bzImage
2056 status
2057 fi
2058 cd $DISTRO
2059 # Copy all files from $ADDFILES/rootcd to the rootcd.
2060 if [ -d "$ADDFILES/rootcd" ] ; then
2061 echo -n "Copying addfiles content to the rootcd... "
2062 cp -a $ADDFILES/rootcd/* $ROOTCD
2063 status
2064 fi
2065 # Execute the distro script used to perform tasks in the rootfs
2066 # before compression. Give rootfs path in arg
2067 [ -z $DISTRO_SCRIPT ] && DISTRO_SCRIPT=$TOP_DIR/distro.sh
2068 if [ -x $DISTRO_SCRIPT ]; then
2069 echo "Executing distro script..."
2070 sh $DISTRO_SCRIPT $DISTRO
2071 fi
2073 # Execute the custom_rules found in receipt.
2074 if [ -s $TOP_DIR/receipt ]; then
2075 if grep -q ^custom_rules $TOP_DIR/receipt; then
2076 echo -e "Executing: custom_rules\n"
2077 . $TOP_DIR/receipt
2078 custom_rules || echo -e "\nERROR: custom_rules failed\n"
2079 fi
2080 fi
2082 # Multi-rootfs
2083 if [ -s /etc/tazlito/rootfs.list ]; then
2084 FLAVOR_LIST="$(awk '{ for (i = 2; i <= NF; i+=2) \
2085 printf("%s ",$i) }' < /etc/tazlito/rootfs.list)"
2086 [ -s $ROOTCD/boot/isolinux/isolinux.msg ] &&
2087 sed -i "s/ *//;s/)/), flavors $FLAVOR_LIST/" \
2088 $ROOTCD/boot/isolinux/isolinux.msg 2> /dev/null
2089 [ -f $ROOTCD/boot/isolinux/ifmem.c32 -o \
2090 -f $ROOTCD/boot/isolinux/c32box.c32 ] ||
2091 cp /boot/isolinux/c32box.c32 $ROOTCD/boot/isolinux 2> /dev/null ||
2092 cp /boot/isolinux/ifmem.c32 $ROOTCD/boot/isolinux
2093 n=0
2094 last=$ROOTFS
2095 while read flavor; do
2096 n=$(($n+1))
2097 newline
2098 boldify "Building $flavor rootfs..."
2099 [ -s $TOP_DIR/$flavor.flavor ] &&
2100 cp $TOP_DIR/$flavor.flavor .
2101 if [ ! -s $flavor.flavor ]; then
2102 # We may have it in $FLAVORS_REPOSITORY
2103 if [ -d "$FLAVORS_REPOSITORY/$flavor" ]; then
2104 tazlito pack-flavor $flavor
2105 else
2106 download $flavor.flavor
2107 fi
2108 fi
2109 echo -n "Extracting $flavor.pkglist and $flavor.rootfs..."
2110 zcat < $flavor.flavor | cpio -i --quiet \
2111 $flavor.pkglist $flavor.rootfs
2112 sed 's/.*/&.tazpkg/' < $flavor.pkglist \
2113 > $DISTRO/list-packages0$n
2114 status
2115 mkdir ${ROOTFS}0$n
2116 # Install packages
2117 cd ${PACKAGES_REPOSITORY}
2118 for pkg in $(cat $DISTRO/list-packages0$n)
2119 do
2120 echo -n "Installing package: $pkg"
2121 yes y | tazpkg -i $pkg --root=${ROOTFS}0$n 2>&1 >> $log || exit 1
2122 status
2123 done
2124 rm -rf ${ROOTFS}0$n/boot ${ROOTFS}0$n/var/lib/tazpkg/packages.*
2125 cd $DISTRO
2126 if [ -s $flavor.rootfs ]; then
2127 echo -n "Adding $flavor rootfs extra files..."
2128 zcat < $flavor.rootfs | ( cd ${ROOTFS}0$n ; cpio -idmu )
2129 fi
2130 echo -n "Moving list-packages0$n to rootfs0$n"
2131 mv $DISTRO/list-packages0$n ${ROOTFS}0$n/etc/tazlito/distro-packages.list
2132 status
2133 rm -f $flavor.flavor install-list
2134 mergefs ${ROOTFS}0$n $last
2135 last=${ROOTFS}0$n
2136 done <<EOT
2137 $(awk '{ for (i = 4; i <= NF; i+=2) print $i; }' < /etc/tazlito/rootfs.list)
2138 EOT
2139 i=$(($n+1))
2140 while [ $n -gt 0 ]; do
2141 mv ${ROOTFS}0$n ${ROOTFS}$i
2142 echo "Compressing ${ROOTFS}0$n ($(du -hs ${ROOTFS}$i | awk '{ print $1 }'))..."
2143 gen_initramfs ${ROOTFS}$i
2144 n=$(($n-1))
2145 i=$(($i-1))
2146 done
2147 mv $ROOTFS ${ROOTFS}$i
2148 gen_initramfs ${ROOTFS}$i
2149 update_bootconfig $ROOTCD/boot/isolinux \
2150 "$(cat /etc/tazlito/rootfs.list)"
2151 else
2152 # Initramfs and ISO image stuff.
2153 gen_initramfs $ROOTFS
2154 fi
2155 gen_livecd_isolinux
2156 distro_stats
2157 cleanup ;;
2159 clean-distro)
2160 # Remove old distro tree.
2162 check_root
2163 newline
2164 boldify "Cleaning : $DISTRO"
2165 separator
2166 if [ -d "$DISTRO" ] ; then
2167 if [ -d "$ROOTFS" ] ; then
2168 echo -n "Removing the rootfs..."
2169 rm -f $DISTRO/$INITRAMFS
2170 rm -rf $ROOTFS
2171 status
2172 fi
2173 if [ -d "$ROOTCD" ] ; then
2174 echo -n "Removing the rootcd..."
2175 rm -rf $ROOTCD
2176 status
2177 fi
2178 echo -n "Removing eventual ISO image..."
2179 rm -f $DISTRO/$ISO_NAME.iso
2180 rm -f $DISTRO/$ISO_NAME.md5
2181 status
2182 fi
2183 separator
2184 newline ;;
2186 check-distro)
2187 # Check for a few LiveCD needed files not installed by packages.
2189 check_rootfs
2190 newline
2191 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
2192 separator
2193 # SliTaz release info.
2194 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
2195 echo "Missing release info : /etc/slitaz-release"
2196 else
2197 release=`cat $ROOTFS/etc/slitaz-release`
2198 echo -n "Release : $release"
2199 status
2200 fi
2201 # Tazpkg mirror.
2202 if [ ! -f "$ROOTFS$LOCALSTATE/mirror" ]; then
2203 echo -n "Mirror URL : Missing $LOCALSTATE/mirror"
2204 todomsg
2205 else
2206 echo -n "Mirror configuration exists..."
2207 status
2208 fi
2209 # Isolinux msg
2210 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.*g; then
2211 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
2212 todomsg
2213 else
2214 echo -n "Isolinux message seems good..."
2215 status
2216 fi
2217 separator
2218 newline ;;
2220 writeiso)
2221 # Writefs to ISO image including /home unlike gen-distro we dont use
2222 # packages to generate a rootfs, we build a compressed rootfs with all
2223 # the current filesystem similar to 'tazusb writefs'.
2225 DISTRO="/home/slitaz/distro"
2226 ROOTCD="$DISTRO/rootcd"
2227 if [ -z $2 ]; then
2228 COMPRESSION=none
2229 else
2230 COMPRESSION=$2
2231 fi
2232 if [ -z $3 ]; then
2233 ISO_NAME="slitaz"
2234 else
2235 ISO_NAME="$3"
2236 fi
2237 check_root
2238 # Start info
2239 newline
2240 boldify "Write filesystem to ISO"
2241 separator
2242 cat << EOT
2243 The command writeiso will write the current filesystem into a suitable cpio
2244 archive (rootfs.gz) and generate a bootable ISO image (slitaz.iso).
2246 $(boldify "Archive compression:") $(colorize 36 "$COMPRESSION")
2248 EOT
2249 # Save some space
2250 rm /var/cache/tazpkg/* -r -f
2251 rm -rf /home/slitaz/distro
2253 # Optionally remove sound card selection and screen resolution.
2254 echo "Do you wish to remove the sound card and screen configs ? "
2255 echo -n "Press ENTER to keep or answer (No|yes|exit): "
2256 read anser
2257 case $anser in
2258 e|E|"exit"|Exit)
2259 exit 0 ;;
2260 y|Y|yes|Yes)
2261 echo -n "Removing current sound card and screen configurations..."
2262 rm -f /var/lib/sound-card-driver
2263 rm -f /var/lib/alsa/asound.state
2264 rm -f /etc/X11/xorg.conf ;;
2265 *)
2266 echo -n "Keeping current sound card and screen configurations..." ;;
2267 esac
2268 status && newline
2270 # Optionally remove i18n settings
2271 echo "Do you wish to remove local/keymap settings ? "
2272 echo -n "Press ENTER to keep or answer (No|yes|exit): "
2273 read anser
2274 case $anser in
2275 e|E|"exit"|Exit)
2276 exit 0 ;;
2277 y|Y|yes|Yes)
2278 echo "Removing current locale/keymap settings..."
2279 newline > /etc/locale.conf
2280 newline > /etc/keymap.conf ;;
2281 *)
2282 echo "Keeping current locale/keymap settings..." ;;
2283 esac
2284 status
2286 # Clean-up files by default
2287 newline > /etc/udev/rules.d/70-persistent-net.rules
2288 newline > /etc/udev/rules.d/70-persistant-cd.rules
2290 # Create list of files including default user files since it is defined in /etc/passwd
2291 # and some new users might have been added.
2292 cd /
2293 find bin etc init sbin var dev lib root usr home >/tmp/list
2295 for dir in proc sys tmp mnt media media/cdrom media/flash \
2296 media/usbdisk run run/udev
2297 do
2298 echo $dir >>/tmp/list
2299 done
2300 sed -i '/^\/var\/run\/.*pid$/d' /tmp/list
2302 # Generate initramfs with specified compression and display rootfs
2303 # size in realtime.
2304 rm -f /tmp/rootfs
2305 write_initramfs &
2306 sleep 2
2307 cd - > /dev/null
2308 echo -en "\nFilesystem size:"
2309 while [ ! -f /tmp/rootfs ]
2310 do
2311 sleep 1
2312 echo -en "\\033[18G`du -sh /rootfs.gz | awk '{print $1}'` "
2313 done
2314 echo -e "\n"
2316 # Move freshly generated rootfs to the cdrom.
2317 mkdir -p $ROOTCD/boot
2318 mv -f /rootfs.gz $ROOTCD/boot
2320 # Now we need the kernel and isolinux files.
2321 if mount /dev/cdrom /media/cdrom 2>/dev/null; then
2322 cp /media/cdrom/boot/bzImage $ROOTCD/boot
2323 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
2324 unmeta_boot $ROOTCD
2325 umount /media/cdrom
2326 elif mount |grep /media/cdrom; then
2327 cp /media/cdrom/boot/bzImage $ROOTCD/boot
2328 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
2329 unmeta_boot $ROOTCD
2330 umount /media/cdrom;
2331 else
2332 echo -e "
2333 When SliTaz is running in RAM the kernel and bootloader files are kept
2334 on the cdrom. Please insert a LiveCD or loop mount the slitaz.iso to
2335 /media/cdrom to let Tazlito copy the files.\n"
2336 echo -en "----\nENTER to continue..."; read i
2337 exit 1
2338 fi
2340 # Generate the iso image.
2341 cd $DISTRO
2342 echo "Generating ISO image..."
2343 genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
2344 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
2345 -V "SliTaz" -input-charset iso8859-1 -boot-info-table $ROOTCD
2346 if [ -x /usr/bin/isohybrid ]; then
2347 echo -n "Creating hybrid ISO..."
2348 /usr/bin/isohybrid $ISO_NAME.iso -entry 2 2> /dev/null
2349 status
2350 fi
2351 echo -n "Creating the ISO md5sum..."
2352 md5sum $ISO_NAME.iso > $ISO_NAME.md5
2353 status
2355 separator
2356 echo "ISO image: $(du -sh /home/slitaz/distro/$ISO_NAME.iso)"
2357 newline
2358 echo -n "Exit or burn ISO to cdrom (Exit|burn)? "; read anser
2359 case $anser in
2360 burn)
2361 umount /dev/cdrom 2> /dev/null
2362 eject
2363 echo -n "Please insert a blank cdrom and press ENTER..."
2364 read i && sleep 2
2365 tazlito burn-iso /home/slitaz/distro/$ISO_NAME.iso
2366 echo -en "----\nENTER to continue..."; read i ;;
2367 *)
2368 exit 0 ;;
2369 esac ;;
2371 burn-iso)
2372 # Guess cdrom device, ask user and burn the ISO.
2374 check_root
2375 DRIVE_NAME=$(grep "drive name" < /proc/sys/dev/cdrom/info | cut -f 3)
2376 DRIVE_SPEED=$(grep "drive speed" < /proc/sys/dev/cdrom/info | cut -f 3)
2377 # We can specify an alternative ISO from the cmdline.
2378 if [ -n "$2" ] ; then
2379 iso=$2
2380 else
2381 iso=$DISTRO/$ISO_NAME.iso
2382 fi
2383 if [ ! -f "$iso" ]; then
2384 echo -e "\nUnable to find ISO : $iso\n"
2385 exit 0
2386 fi
2387 newline
2388 boldify "Tazlito burn ISO"
2389 separator
2390 echo "Cdrom device : /dev/$DRIVE_NAME"
2391 echo "Drive speed : $DRIVE_SPEED"
2392 echo "ISO image : $iso"
2393 separator
2394 newline
2395 yesorno "Burn ISO image (y/N) ? "
2396 if [ "$answer" == "y" ]; then
2397 newline
2398 echo "Starting Wodim to burn the iso..." && sleep 2
2399 separator
2400 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
2401 separator
2402 echo "ISO image is burned to cdrom."
2403 else
2404 echo -e "\nExiting. No ISO burned."
2405 fi
2406 newline ;;
2408 merge)
2409 # Merge multiple rootfs into one iso.
2411 if [ -z "$2" ]; then
2412 cat << EOT
2413 Usage: tazlito merge size1 iso size2 rootfs2 [sizeN rootfsN]...
2415 Merge multiple rootfs into one iso. Rootfs are like russian dolls
2416 i.e: rootfsN is a subset of rootfsN-1
2417 rootfs1 is found in iso, sizeN is the RAM size needed to launch rootfsN.
2418 The boot loader will select the rootfs according to the RAM size detected.
2420 Example:
2421 $ tazlito merge 160M slitaz-core.iso 96M rootfs-justx.gz 32M rootfs-base.gz
2423 Will start slitaz-core with 160M+ RAM, slitaz-justX with 96M-160M RAM,
2424 slitaz-base with 32M-96M RAM and display an error message if RAM < 32M.
2426 EOT
2427 exit 2
2428 fi
2430 shift # skip merge
2431 append="$1 slitaz1"
2432 shift # skip size1
2433 mkdir -p $TMP_DIR/mnt $TMP_DIR/rootfs1
2435 ISO=$1.merged
2436 # Extract filesystems
2437 echo -n "Mounting $1"
2438 mount -o loop,ro $1 $TMP_DIR/mnt 2> /dev/null
2439 status || cleanup_merge
2440 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2441 rm -f $TMP_DIR/iso/boot/bzImage
2442 ln $TMP_DIR/iso/boot/vmlinuz* $TMP_DIR/iso/boot/bzImage
2443 umount -d $TMP_DIR/mnt
2444 if [ -f $TMP_DIR/iso/boot/rootfs1.gz ]; then
2445 echo "$1 is already a merged iso. Aborting."
2446 cleanup_merge
2447 fi
2448 if [ ! -f $TMP_DIR/iso/boot/isolinux/ifmem.c32 -a
2449 ! -f $TMP_DIR/iso/boot/isolinux/c32box.c32 ]; then
2450 if [ ! -f /boot/isolinux/ifmem.c32 -a
2451 ! -f /boot/isolinux/c32box.c32 ]; then
2452 cat <<EOT
2453 No file /boot/isolinux/ifmem.c32
2454 Please install syslinux package !
2455 EOT
2456 rm -rf $TMP_DIR
2457 exit 1
2458 fi
2459 cp /boot/isolinux/c32box.c32 $TMP_DIR/iso/boot/isolinux 2> /dev/null ||
2460 cp /boot/isolinux/ifmem.c32 $TMP_DIR/iso/boot/isolinux
2461 fi
2463 echo -n "Extracting iso/rootfs.gz"
2464 extract_rootfs $TMP_DIR/iso/boot/rootfs.gz $TMP_DIR/rootfs1 &&
2465 [ -d $TMP_DIR/rootfs1/etc ]
2466 status || cleanup_merge
2467 n=1
2468 while [ -n "$2" ]; do
2469 shift # skip rootfs N-1
2470 p=$n
2471 n=$(($n + 1))
2472 append="$append $1 slitaz$n"
2473 shift # skip size N
2474 mkdir -p $TMP_DIR/rootfs$n
2475 echo -n "Extracting $1"
2476 extract_rootfs $1 $TMP_DIR/rootfs$n &&
2477 [ -d $TMP_DIR/rootfs$n/etc ]
2478 status || cleanup_merge
2479 mergefs $TMP_DIR/rootfs$n $TMP_DIR/rootfs$p
2480 echo "Creating rootfs$p.gz"
2481 pack_rootfs $TMP_DIR/rootfs$p $TMP_DIR/iso/boot/rootfs$p.gz
2482 status
2483 done
2484 echo "Creating rootfs$n.gz"
2485 pack_rootfs $TMP_DIR/rootfs$n $TMP_DIR/iso/boot/rootfs$n.gz
2486 status
2487 rm -f $TMP_DIR/iso/boot/rootfs.gz
2488 update_bootconfig $TMP_DIR/iso/boot/isolinux "$append"
2489 create_iso $ISO $TMP_DIR/iso
2490 rm -rf $TMP_DIR ;;
2492 repack)
2493 # Repack an iso with maximum lzma compression ratio.
2495 ISO=$2
2496 mkdir -p $TMP_DIR/mnt
2498 # Extract filesystems
2499 echo -n "Mounting $ISO"
2500 mount -o loop,ro $ISO $TMP_DIR/mnt 2> /dev/null
2501 status || cleanup_merge
2502 cp -a $TMP_DIR/mnt $TMP_DIR/iso
2503 umount -d $TMP_DIR/mnt
2505 for i in $TMP_DIR/iso/boot/rootfs* ; do
2506 echo -n "Repacking $(basename $i)"
2507 (zcat $i 2> /dev/null || unlzma -c $i || cat $i) \
2508 2>/dev/null > $TMP_DIR/rootfs
2509 lzma e $TMP_DIR/rootfs $i \
2510 $(lzma_switches $TMP_DIR/rootfs)
2511 align_to_32bits $i
2512 status
2513 done
2515 create_iso $ISO $TMP_DIR/iso
2516 rm -rf $TMP_DIR ;;
2518 build-loram)
2519 # Build a Live CD for low ram systems.
2521 ISO=$2
2522 OUTPUT=$3
2523 if [ -z "$3" ]; then
2524 echo "Usage: tazlito $1 input.iso output.iso [cdrom|smallcdrom|http|ram]"
2525 exit 1
2526 fi
2527 mkdir -p $TMP_DIR/iso
2528 mount -o loop,ro -t iso9660 $ISO $TMP_DIR/iso
2529 loopdev=$( (losetup -a 2>/dev/null || losetup) | grep $ISO | cut -d: -f1)
2530 if ! check_iso_for_loram ; then
2531 echo "$2 is not a valid SliTaz live CD. Abort."
2532 umount -d $TMP_DIR/iso
2533 rm -rf $TMP_DIR
2534 exit 1
2535 fi
2536 case "$4" in
2537 cdrom) build_loram_cdrom ;;
2538 http) build_loram_http ;;
2539 *) build_loram_ram ;;
2540 esac
2541 umount $TMP_DIR/iso # no -d: needs /proc
2542 losetup -d $loopdev
2543 rm -rf $TMP_DIR ;;
2545 emu-iso)
2546 # Emulate an ISO image with Qemu.
2547 if [ -n "$2" ] ; then
2548 iso=$2
2549 else
2550 iso=$DISTRO/$ISO_NAME.iso
2551 fi
2552 if [ ! -f "$iso" ]; then
2553 echo -e "\nUnable to find ISO : $iso\n"
2554 exit 0
2555 fi
2556 if [ ! -x "/usr/bin/qemu" ]; then
2557 echo -e "\nUnable to find Qemu binary. Please install: qemu\n"
2558 exit 0
2559 fi
2560 echo -e "\nStarting Qemu emulator:\n"
2561 echo -e "qemu $QEMU_OPTS $iso\n"
2562 qemu $QEMU_OPTS $iso ;;
2564 deduplicate)
2565 # Deduplicate files in a tree
2566 shift
2567 deduplicate "$@" ;;
2569 usage|*)
2570 # Print usage also for all unknown commands.
2571 usage ;;
2572 esac
2574 exit 0