cookutils rev 526 slitaz-tank

libcookiso.sh: Change tazlito to cookiso. Add some more functions from tazlito.
author Christopher Rogers <slaxemulator@gmail.com>
date Sat Aug 25 06:45:02 2012 +0000 (2012-08-25)
parents a1d274eeaf00
children 0c124623a7cd
files lib/libcookiso.sh
line diff
     1.1 --- a/lib/libcookiso.sh	Fri Aug 24 22:05:20 2012 +0000
     1.2 +++ b/lib/libcookiso.sh	Sat Aug 25 06:45:02 2012 +0000
     1.3 @@ -12,7 +12,7 @@
     1.4  [ -f "$TOP_DIR/cookiso.conf" ] && CONFIG_FILE="$TOP_DIR/cookiso.conf"
     1.5  DEFAULT_MIRROR="$MIRROR_URL/packages/$SLITAZ_VERSION/"
     1.6  
     1.7 -log=/var/log/tazlito.log
     1.8 +log=/var/log/cookiso.log
     1.9  if check_root; then
    1.10  	newline > $log
    1.11  fi
    1.12 @@ -89,8 +89,8 @@
    1.13  # Execute hooks provided by some packages
    1.14  genisohooks()
    1.15  {
    1.16 -	local here=`pwd`
    1.17 -	for i in $(ls $ROOTFS/etc/tazlito/*.$1 2> /dev/null); do
    1.18 +	local here=$(pwd)
    1.19 +	for i in $(ls $ROOTFS/etc/slitaz/*.$1 2> /dev/null); do
    1.20  		cd $ROOTFS
    1.21  		. $i $ROOTCD
    1.22  	done
    1.23 @@ -183,10 +183,10 @@
    1.24  		/usr/bin/isohybrid $1 -entry 2 2> /dev/null
    1.25  		status
    1.26  	fi
    1.27 -	if [ -s /etc/tazlito/info ]; then
    1.28 -		if [ $(stat -c %s /etc/tazlito/info) -lt $(( 31*1024 )) ]; then
    1.29 +	if [ -s /etc/slitaz/info ]; then
    1.30 +		if [ $(stat -c %s /etc/slitaz/info) -lt $(( 31*1024 )) ]; then
    1.31  			echo -n "Storing ISO info..."
    1.32 -			dd if=/etc/tazlito/info bs=1k seek=1 of=$1 \
    1.33 +			dd if=/etc/slitaz/info bs=1k seek=1 of=$1 \
    1.34  				conv=notrunc 2> /dev/null
    1.35  			status
    1.36  		fi
    1.37 @@ -370,6 +370,144 @@
    1.38  	distro_sizes
    1.39  }
    1.40  
    1.41 +# Create an empty configuration file.
    1.42 +empty_config_file()
    1.43 +{
    1.44 +	cat >> tazlito.conf << "EOF"
    1.45 +# tazlito.conf: Tazlito (SliTaz Live Tool)
    1.46 +# configuration file.
    1.47 +#
    1.48 +
    1.49 +# Name of the ISO image to generate.
    1.50 +ISO_NAME=""
    1.51 +
    1.52 +# ISO image volume name.
    1.53 +VOLUM_NAME="SliTaz"
    1.54 +
    1.55 +# Name of the preparer.
    1.56 +PREPARED="$USER"
    1.57 +
    1.58 +# Path to the packages repository and the packages.list.
    1.59 +PACKAGES_REPOSITORY=""
    1.60 +
    1.61 +# Path to the distro tree to gen-distro from a
    1.62 +# list of packages.
    1.63 +DISTRO=""
    1.64 +
    1.65 +# Path to the directory containing additional files
    1.66 +# to copy into the rootfs and rootcd of the LiveCD.
    1.67 +ADDFILES="$DISTRO/addfiles"
    1.68 +
    1.69 +# Default answer for binary question (Y or N)
    1.70 +DEFAULT_ANSWER="ASK"
    1.71 +
    1.72 +# Compression utility (lzma, gzip or none)
    1.73 +COMPRESSION="lzma"
    1.74 +EOF
    1.75 +}
    1.76 +
    1.77 +# Display package list with version, set packed_size and unpacked_size
    1.78 +get_pkglist()
    1.79 +{
    1.80 +packed_size=0; unpacked_size=0
    1.81 +grep -v ^#  $FLAVORS_REPOSITORY/$1/packages.list > $TMP_DIR/flavor.pkg
    1.82 +while read pkg; do
    1.83 +	set -- $(get_size $pkg)
    1.84 +	packed_size=$(( $packed_size + $1 ))
    1.85 +	unpacked_size=$(( $unpacked_size + $2 ))
    1.86 +	for i in $(grep -hs ^$pkg $LOCALSTATE/packages.list \
    1.87 +				  $TMP_DIR/packages.list); do
    1.88 +		echo $i
    1.89 +		break
    1.90 +	done
    1.91 +done < $TMP_DIR/flavor.pkg
    1.92 +rm -f $TMP_DIR/flavor.pkg
    1.93 +}
    1.94 +
    1.95 +human2cent()
    1.96 +{
    1.97 +case "$1" in
    1.98 +*k) echo $1 | sed 's/\(.*\).\(.\)k/\1\2/';;
    1.99 +*M) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)M/\1\2/') * 1024));;
   1.100 +*G) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)G/\1\2/') * 1024 * 1024));;
   1.101 +esac
   1.102 +}
   1.103 +
   1.104 +cent2human()
   1.105 +{
   1.106 +if [ $1 -lt 10000 ]; then
   1.107 +  echo "$(($1 / 10)).$(($1 % 10))k"
   1.108 +elif [ $1 -lt 10000000 ]; then
   1.109 +  echo "$(($1 / 10240)).$(( ($1/1024) % 10))M"
   1.110 +else
   1.111 +  echo "$(($1 / 10485760)).$(( ($1/1048576) % 10))G"
   1.112 +fi
   1.113 +}
   1.114 +
   1.115 +get_size()
   1.116 +{
   1.117 +cat $LOCALSTATE/packages.list $TMP_DIR/packages.list 2>/dev/null | awk "{ \
   1.118 +if (/^$(echo $1 | sed 's/[$+.\]/\\&/g')$/) get=1; \
   1.119 +if (/installed/ && get == 1) { print ; get++ } \
   1.120 +}
   1.121 +END { if (get < 2) print \" 0.0k  (0.0k installed)\" }" | \
   1.122 +sed 's/ *\(.*\) .\(.*\) installed./\1 \2/' | while read packed unpacked; do
   1.123 +  echo "$(human2cent $packed) $(human2cent $unpacked)"
   1.124 +done
   1.125 +}
   1.126 +
   1.127 +# extract rootfs.gz somewhere
   1.128 +extract_rootfs()
   1.129 +{
   1.130 +	(zcat $1 || unlzma -c $1 || cat $1) 2>/dev/null | \
   1.131 +		(cd $2; cpio -idm > /dev/null)
   1.132 +}
   1.133 +
   1.134 +# Remove duplicate files
   1.135 +mergefs()
   1.136 +{
   1.137 +	echo -n "Merge $(basename $1) ($(du -hs $1 | awk '{ print $1}')) into "
   1.138 +	echo -n       "$(basename $2) ($(du -hs $2 | awk '{ print $1}'))"
   1.139 +	# merge symlinks files and devices
   1.140 +	( cd $1; find ) | while read file; do
   1.141 +		if [ -L $1/$file ]; then
   1.142 +			[ -L $2/$file ] &&
   1.143 +			[ "$(readlink $1/$file)" == "$(readlink $2/$file)" ] &&
   1.144 +			rm -f $2/$file
   1.145 +		elif [ -f $1/$file ]; then
   1.146 +			[ -f $2/$file ] &&
   1.147 +			cmp $1/$file $2/$file > /dev/null 2>&1 && rm -f $2/$file
   1.148 +			[ -f $2/$file ] &&
   1.149 +			[ "$(basename $file)" == "volatile.cpio.gz" ] &&
   1.150 +			[ "$(dirname $(dirname $file))" == \
   1.151 +			  ".$INSTALLED" ] && rm -f $2/$file
   1.152 +		elif [ -b $1/$file ]; then
   1.153 +			[ -b $2/$file ] &&
   1.154 +			[ "$(stat -c '%a:%u:%g:%t:%T' $1/$file)" == \
   1.155 +			  "$(stat -c '%a:%u:%g:%t:%T' $2/$file)" ] &&
   1.156 +			rm -f $2/$file
   1.157 +		elif [ -c $1/$file ]; then
   1.158 +			[ -c $2/$file ] &&
   1.159 +			[ "$(stat -c '%a:%u:%g:%t:%T' $1/$file)" == \
   1.160 +			  "$(stat -c '%a:%u:%g:%t:%T' $2/$file)" ] &&
   1.161 +			rm -f $2/$file
   1.162 +		fi
   1.163 +	done
   1.164 +
   1.165 +	# cleanup directories
   1.166 +	( cd $1; find -type d ) | sed '1!G;h;$!d' | while read file; do
   1.167 +		[ -d $2/$file ] && rmdir $2/$file 2> /dev/null
   1.168 +	done
   1.169 +	true
   1.170 +	status
   1.171 +}
   1.172 +
   1.173 +cleanup_merge()
   1.174 +{
   1.175 +	rm -rf $TMP_DIR
   1.176 +	exit 1
   1.177 +}
   1.178 +
   1.179  # tazlito gen-distro
   1.180  gen_distro()
   1.181  {
   1.182 @@ -416,7 +554,7 @@
   1.183  	if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
   1.184  		# Build list with installed packages
   1.185  		for i in $(ls $INSTALLED); do
   1.186 -			eval $(grep ^VERSION= $INSTALLED/$i/receipt))
   1.187 +			eval $(grep ^VERSION= $INSTALLED/$i/receipt)
   1.188  			EXTRAVERSION=""
   1.189  			eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
   1.190  			echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
   1.191 @@ -518,7 +656,7 @@
   1.192  	done
   1.193  	if [ -f non-free.list ]; then
   1.194  		echo "Preparing non-free packages..."
   1.195 -		cp non-free.list $ROOTFS/etc/tazlito/non-free.list
   1.196 +		cp non-free.list $ROOTFS/etc/slitaz/non-free.list
   1.197  		for pkg in $(cat non-free.list); do
   1.198  			if [ ! -d $INSTALLED/$pkg ]; then
   1.199  				if [ ! -d $INSTALLED/get-$pkg ]; then
   1.200 @@ -544,7 +682,7 @@
   1.201  	done
   1.202  	rm -f $ROOTFS/$DB/packages.*
   1.203  	cd $DISTRO
   1.204 -	cp $DISTRO_LIST $ROOTFS/etc/tazlito
   1.205 +	cp $DISTRO_LIST $ROOTFS/etc/slitaz
   1.206  	# Copy all files from $ADDFILES/rootfs to the rootfs.
   1.207  	if [ -d "$ADDFILES/rootfs" ] ; then
   1.208  		echo -n "Copying addfiles content to the rootfs... "
   1.209 @@ -579,9 +717,9 @@
   1.210  		echo "Executing distro script..."
   1.211  		sh $DISTRO_SCRIPT $DISTRO
   1.212  	fi
   1.213 -	if [ -s /etc/tazlito/rootfs.list ]; then
   1.214 +	if [ -s /etc/slitaz/rootfs.list ]; then
   1.215  		FLAVOR_LIST="$(awk '{ for (i = 2; i <= NF; i+=2) \
   1.216 -		  printf("%s ",$i) }' < /etc/tazlito/rootfs.list)"
   1.217 +		  printf("%s ",$i) }' < /etc/slitaz/rootfs.list)"
   1.218  		sed -i "s/ *//;s/)/), flavors $FLAVOR_LIST/" \
   1.219  		  $ROOTCD/boot/isolinux/isolinux.msg 2> /dev/null
   1.220  		[ -f $ROOTCD/boot/isolinux/ifmem.c32 ] ||
   1.221 @@ -593,31 +731,32 @@
   1.222  			echo "Building $flavor rootfs..."
   1.223  			if [ -d $flavors/$flavor ]; then
   1.224  				cp -a $flavors
   1.225 -			[ -s $TOP_DIR/$flavor.flavor ] &&
   1.226 -				cp $TOP_DIR/$flavor.flavor .
   1.227 -			[ -s $flavor.flavor ] || download $flavor.flavor
   1.228 -			zcat $flavor.flavor | cpio -i \
   1.229 -				$flavor.pkglist $flavor.rootfs
   1.230 -			sed 's/.*/&.tazpkg/' < $flavor.pkglist \
   1.231 -				> $DISTRO/list-packages0$n
   1.232 -			mkdir ${ROOTFS}0$n
   1.233 -			cd $PACKAGES_REPOSITORY
   1.234 -			yes y | tazpkg install-list \
   1.235 -				$DISTRO/list-packages0$n --root=${ROOTFS}0$n
   1.236 -			rm -rf ${ROOTFS}0$n/boot ${ROOTFS}0$n/$DB/packages.*
   1.237 -			status
   1.238 -			cd $DISTRO
   1.239 -			if [ -s $flavor.rootfs ]; then
   1.240 -				echo "Adding $flavor rootfs extra files..."
   1.241 -				zcat $flavor.rootfs | \
   1.242 -				( cd ${ROOTFS}0$n ; cpio -idmu )
   1.243 +				[ -s $TOP_DIR/$flavor.flavor ] &&
   1.244 +					cp $TOP_DIR/$flavor.flavor .
   1.245 +				[ -s $flavor.flavor ] || download $flavor.flavor
   1.246 +				zcat $flavor.flavor | cpio -i \
   1.247 +					$flavor.pkglist $flavor.rootfs
   1.248 +				sed 's/.*/&.tazpkg/' < $flavor.pkglist \
   1.249 +					> $DISTRO/list-packages0$n
   1.250 +				mkdir ${ROOTFS}0$n
   1.251 +				cd $PACKAGES_REPOSITORY
   1.252 +				yes y | tazpkg install-list \
   1.253 +					$DISTRO/list-packages0$n --root=${ROOTFS}0$n
   1.254 +				rm -rf ${ROOTFS}0$n/boot ${ROOTFS}0$n/$DB/packages.*
   1.255 +				status
   1.256 +				cd $DISTRO
   1.257 +				if [ -s $flavor.rootfs ]; then
   1.258 +					echo "Adding $flavor rootfs extra files..."
   1.259 +					zcat $flavor.rootfs | \
   1.260 +					( cd ${ROOTFS}0$n ; cpio -idmu )
   1.261 +				fi
   1.262 +				mv $flavor.pkglist ${ROOTFS}0$n/etc/slitaz/$DISTRO_LIST
   1.263 +				rm -f $flavor.flavor install-list
   1.264 +				mergefs ${ROOTFS}0$n $last
   1.265 +				last=${ROOTFS}0$n
   1.266  			fi
   1.267 -			mv $flavor.pkglist ${ROOTFS}0$n/etc/tazlito/$DISTRO_LIST
   1.268 -			rm -f $flavor.flavor install-list
   1.269 -			mergefs ${ROOTFS}0$n $last
   1.270 -			last=${ROOTFS}0$n
   1.271  		done <<EOT
   1.272 -$(awk '{ for (i = 4; i <= NF; i+=2) print $i; }' < /etc/tazlito/rootfs.list)
   1.273 +$(awk '{ for (i = 4; i <= NF; i+=2) print $i; }' < /etc/slitaz/rootfs.list)
   1.274  EOT
   1.275  		i=$(($n+1))
   1.276  		while [ $n -gt 0 ]; do
   1.277 @@ -630,7 +769,7 @@
   1.278  		mv $ROOTFS ${ROOTFS}$i
   1.279  		gen_initramfs ${ROOTFS}$i
   1.280  		update_bootconfig $ROOTCD/boot/isolinux \
   1.281 -			"$(cat /etc/tazlito/rootfs.list)"
   1.282 +			"$(cat /etc/slitaz/rootfs.list)"
   1.283  	else
   1.284  		# Initramfs and ISO image stuff.
   1.285  		gen_initramfs $ROOTFS
   1.286 @@ -640,6 +779,7 @@
   1.287  	cleanup
   1.288  }
   1.289  
   1.290 +
   1.291  # tazlito clean-distro
   1.292  clean_distro()
   1.293  {
   1.294 @@ -954,7 +1094,7 @@
   1.295  	echo -n "Extracting the rootfs... "
   1.296  	extract_rootfs $TARGET/rootfs/rootcd/boot/$INITRAMFS $TARGET/rootfs
   1.297  	# unpack /usr
   1.298 -	for i in etc/tazlito/*.extract; do
   1.299 +	for i in etc/slitaz/*.extract; do
   1.300  		[ -f "$i" ] && . $i ../rootcd
   1.301  	done
   1.302  	# Umount and remove temp directory and cd to $TARGET to get stats.
   1.303 @@ -1157,7 +1297,7 @@
   1.304  		echo -e "
   1.305  When SliTaz is running in RAM the kernel and bootloader files are kept
   1.306  on the cdrom. Please insert a LiveCD or loop mount the slitaz.iso to
   1.307 -/media/cdrom to let Tazlito copy the files.\n"
   1.308 +/media/cdrom to let cookiso copy the files.\n"
   1.309  		echo -en "----\nENTER to continue..."; read i
   1.310  		exit 1
   1.311  	fi
   1.312 @@ -1186,7 +1326,7 @@
   1.313  			eject
   1.314  			echo -n "Please insert a blank cdrom and press ENTER..."
   1.315  			read i && sleep 2
   1.316 -			tazlito burn-iso $DISTRO/$ISO_NAME.iso
   1.317 +			burn_iso $DISTRO/$ISO_NAME.iso
   1.318  			echo -en "----\nENTER to continue..."; read i ;;
   1.319  		*)
   1.320  			exit 0 ;;