tazlito view tazlito @ rev 388

tazlito-wiz(yad): correctly get versions in 'Additional packages' dialog.

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