tazlito rev 107

tazlito upgrade-flavor/pack-flavor: estimate sizes
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Aug 21 13:44:40 2009 +0200 (2009-08-21)
parents b322fa520f21
children d2375d0fa398
files tazlito
line diff
     1.1 --- a/tazlito	Fri Aug 21 10:23:10 2009 +0200
     1.2 +++ b/tazlito	Fri Aug 21 13:44:40 2009 +0200
     1.3 @@ -444,6 +444,37 @@
     1.4  	exit 1
     1.5  }
     1.6  
     1.7 +human2cent()
     1.8 +{
     1.9 +case "$1" in
    1.10 +*k) echo $1 | sed 's/\(.*\).\(.\)k/\1\2/';;
    1.11 +*M) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)M/\1\2/') * 1024));;
    1.12 +*G) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)G/\1\2/') * 1024 * 1024));;
    1.13 +esac
    1.14 +}
    1.15 +
    1.16 +cent2human()
    1.17 +{
    1.18 +if [ $1 -lt 10000 ]; then
    1.19 +  echo "$(($1 / 10)).$(($1 % 10))k"
    1.20 +elif [ $1 -lt 10000000 ]; then
    1.21 +  echo "$(($1 / 10240)).$(( ($1/1024) % 10))M"
    1.22 +else
    1.23 +  echo "$(($1 / 10485760)).$(( ($1/1048576) % 10))G"
    1.24 +fi
    1.25 +}
    1.26 +
    1.27 +get_size()
    1.28 +{
    1.29 +awk "{ \
    1.30 +if (/^$(echo $1 | sed 's/[$+.\]/\\&/g')$/) get=1; \
    1.31 +if (/installed/ && get) { print ; get=0 } \
    1.32 +}" < /var/lib/tazpkg/packages.txt  | \
    1.33 +sed 's/ *\(.*\) .\(.*\) installed./\1 \2/' | while read packed unpacked; do
    1.34 +  echo "$(human2cent $packed) $(human2cent $unpacked)"
    1.35 +done
    1.36 +}
    1.37 +
    1.38  ####################
    1.39  # Tazlito commands #
    1.40  ####################
    1.41 @@ -767,11 +798,8 @@
    1.42  			mkdir $TMP_DIR
    1.43  			zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
    1.44  			echo -n "Update $FLAVOR package list..."
    1.45 -			sed -i -e 's/size\( *:\) \(.*\)/size\1 unknown/' \
    1.46 -			       -e 's/is ready/not built yet/' \
    1.47 -			       -e 's/date\( *:\) \(.*\)/date\1 not built yet/' \
    1.48 -					$TMP_DIR/$FLAVOR.desc
    1.49  			[ -s /var/lib/tazpkg/packages.list ] || tazpkg recharge
    1.50 +			packed_size=0; unpacked_size=0
    1.51  			while read org; do
    1.52  				i=0
    1.53  				pkg=$org
    1.54 @@ -780,6 +808,9 @@
    1.55  					i=$(($i + 1))
    1.56  					[ $i -gt 5 ] && break;
    1.57  				done
    1.58 +				set -- $(get_size $pkg)
    1.59 +				packed_size=$(( $packed_size + $1 ))
    1.60 +				unpacked_size=$(( $unpacked_size + $2 ))
    1.61  				for i in $(grep ^$pkg /var/lib/tazpkg/packages.list); do
    1.62  					echo $i
    1.63  					break
    1.64 @@ -787,6 +818,25 @@
    1.65  			done <  $TMP_DIR/$FLAVOR.pkglist \
    1.66  			     > $TMP_DIR/$FLAVOR.pkglist.$$
    1.67  			mv -f $TMP_DIR/$FLAVOR.pkglist.$$ $TMP_DIR/$FLAVOR.pkglist
    1.68 +			if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
    1.69 +				packed_size=$(($packed_size \
    1.70 +					+ $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
    1.71 +				unpacked_size=$(($unpacked_size \
    1.72 +					+ $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
    1.73 +			fi
    1.74 +			# Estimate lzma
    1.75 +			packed_size=$(($packed_size * 2 / 3))
    1.76 +			iso_size=$(( $packed_size + 26000 ))
    1.77 +			if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
    1.78 +				iso_size=$(($iso_size \
    1.79 +					+ $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
    1.80 +			fi
    1.81 +			sed -i -e '/Image is ready/d' \
    1.82 +			       -e "s/Rootfs size\( *:\) \(.*\)/Rootfs size\1 $(cent2human $unpacked_size) (estimated)/" \
    1.83 +			       -e "s/Initramfs size\( *:\) \(.*\)/Initramfs size\1 $(cent2human $packed_size) (estimated)/" \
    1.84 +			       -e "s/ISO image size\( *:\) \(.*\)/ISO image size\1 $(cent2human $iso_size) (estimated)/" \
    1.85 +			       -e "s/date\( *:\) \(.*\)/date\1 $(date +%Y%m%d\ \at\ \%H:%M:%S)/" \
    1.86 +					$TMP_DIR/$FLAVOR.desc
    1.87  			( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
    1.88  				$FLAVOR.flavor
    1.89  			status
    1.90 @@ -834,35 +884,56 @@
    1.91  		if [ -s $FLAVORS_REPOSITORY/$FLAVOR/desc.txt ]; then
    1.92  			mkdir $TMP_DIR
    1.93  			echo -n "Create $FLAVOR..."
    1.94 -			cat > $TMP_DIR/$FLAVOR.desc <<EOT
    1.95 -Flavor          : $FLAVOR
    1.96 -Description     : $(grep -v ^# $FLAVORS_REPOSITORY/$FLAVOR/desc.txt)
    1.97 -Build date      : $(date +%Y%m%d\ \at\ \%H:%M:%S)
    1.98 -Packages        : $(grep -v ^# $FLAVORS_REPOSITORY/$FLAVOR/pkglist.txt | wc -l)
    1.99 -Rootfs size     : unknown
   1.100 -Initramfs size  : unknown
   1.101 -ISO image size  : unknown
   1.102 -================================================================================
   1.103 -
   1.104 -EOT
   1.105  			[ -s /var/lib/tazpkg/packages.list ] || tazpkg recharge
   1.106 -			grep -v ^#  $FLAVORS_REPOSITORY/$FLAVOR/pkglist.txt | \
   1.107 +			packed_size=0; unpacked_size=0
   1.108 +			grep -v ^#  $FLAVORS_REPOSITORY/$FLAVOR/pkglist.txt > \
   1.109 +				$TMP_DIR/$FLAVOR.pkg
   1.110  			while read pkg; do
   1.111 +				set -- $(get_size $pkg)
   1.112 +				packed_size=$(( $packed_size + $1 ))
   1.113 +				unpacked_size=$(( $unpacked_size + $2 ))
   1.114  				for i in $(grep ^$pkg /var/lib/tazpkg/packages.list); do
   1.115  					echo $i
   1.116  					break
   1.117  				done
   1.118 -			done > $TMP_DIR/$FLAVOR.pkglist
   1.119 +			done > $TMP_DIR/$FLAVOR.pkglist < $TMP_DIR/$FLAVOR.pkg
   1.120 +			rm -f $TMP_DIR/$FLAVOR.pkg
   1.121  			for i in rootcd rootfs; do
   1.122  				[ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] || \
   1.123  					continue
   1.124  				( cd $FLAVORS_REPOSITORY/$FLAVOR/$i ; find . | \
   1.125  				cpio -o -H newc ) | gzip -9 >$TMP_DIR/$FLAVOR.$i
   1.126  			done
   1.127 +			if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
   1.128 +				packed_size=$(($packed_size \
   1.129 +					+ $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
   1.130 +				unpacked_size=$(($unpacked_size \
   1.131 +					+ $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
   1.132 +			fi
   1.133 +			# Estimate lzma
   1.134 +			packed_size=$(($packed_size * 2 / 3))
   1.135 +			iso_size=$(( $packed_size + 26000 ))
   1.136 +			if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
   1.137 +				iso_size=$(($iso_size \
   1.138 +					+ $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
   1.139 +			fi
   1.140 +			cat > $TMP_DIR/$FLAVOR.desc <<EOT
   1.141 +Flavor          : $FLAVOR
   1.142 +Description     : $(grep -v ^# $FLAVORS_REPOSITORY/$FLAVOR/desc.txt)
   1.143 +Build date      : $(date +%Y%m%d\ \at\ \%H:%M:%S)
   1.144 +Packages        : $(grep -v ^# $FLAVORS_REPOSITORY/$FLAVOR/pkglist.txt | wc -l)
   1.145 +Rootfs size     : $(cent2human $unpacked_size) (estimated)
   1.146 +Initramfs size  : $(cent2human $packed_size) (estimated)
   1.147 +ISO image size  : $(cent2human $iso_size) (estimated)
   1.148 +================================================================================
   1.149 +
   1.150 +EOT
   1.151  			( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
   1.152  				$FLAVOR.flavor
   1.153  			status
   1.154  			rm -Rf $TMP_DIR
   1.155 +		else
   1.156 +			echo "No $FLAVOR flavor in $FLAVORS_REPOSITORY."
   1.157  		fi
   1.158  		;;
   1.159  	get-flavor)