cookutils rev 529 slitaz-tank

libcookiso.sh: Add gen_flavor and get_flavor functions.
author Christopher Rogers <slaxemulator@gmail.com>
date Sat Aug 25 09:30:31 2012 +0000 (2012-08-25)
parents 6e1095403ba9
children 671e832feff7
files lib/libcookiso.sh
line diff
     1.1 --- a/lib/libcookiso.sh	Sat Aug 25 07:24:43 2012 +0000
     1.2 +++ b/lib/libcookiso.sh	Sat Aug 25 09:30:31 2012 +0000
     1.3 @@ -8,6 +8,7 @@
     1.4  TMP_DIR=/tmp/cookiso-$$-$RANDOM
     1.5  TMP_MNT=/media/cookiso-$$-$RANDOM
     1.6  INITRAMFS=rootfs.gz
     1.7 +MIRROR=$DB/mirror
     1.8  [ -f "/etc/slitaz/cookiso.conf" ] && CONFIG_FILE="/etc/slitaz/cookiso.conf"
     1.9  [ -f "$TOP_DIR/cookiso.conf" ] && CONFIG_FILE="$TOP_DIR/cookiso.conf"
    1.10  DEFAULT_MIRROR="$MIRROR_URL/packages/$SLITAZ_VERSION/"
    1.11 @@ -373,8 +374,8 @@
    1.12  # Create an empty configuration file.
    1.13  empty_config_file()
    1.14  {
    1.15 -	cat >> tazlito.conf << "EOF"
    1.16 -# tazlito.conf: Tazlito (SliTaz Live Tool)
    1.17 +	cat >> cookiso.conf << "EOF"
    1.18 +# cookiso.conf: cookiso (SliTaz Live Tool)
    1.19  # configuration file.
    1.20  #
    1.21  
    1.22 @@ -779,6 +780,132 @@
    1.23  	cleanup
    1.24  }
    1.25  
    1.26 +# tazlito gen-flavor
    1.27 +gen_flavor(
    1.28 +	# Generate a new flavor from the last iso image generated.
    1.29 +	FLAVOR=${1%.flavor}
    1.30 +	newline
    1.31 +	echo -e "\033[1mFlavor generation\033[0m"
    1.32 +	separator
    1.33 +	if [ -z "$FLAVOR" ]; then
    1.34 +		echo -n "Flavor name : "
    1.35 +		read FLAVOR
    1.36 +		[ -z "$FLAVOR" ] && exit 1
    1.37 +	fi
    1.38 +	check_rootfs
    1.39 +	FILES="$FLAVOR.pkglist"
    1.40 +	echo -n "Creating file $FLAVOR.flavor..."
    1.41 +	for i in rootcd rootfs; do
    1.42 +		if [ -d "$ADDFILES/$i" ] ; then
    1.43 +			FILES="$FILES\n$FLAVOR.$i"
    1.44 +			( cd "$ADDFILES/$i"; find . | \
    1.45 +			  cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
    1.46 +		fi
    1.47 +	done
    1.48 +	status
    1.49 +	answer=`grep -s ^Description $FLAVOR.desc`
    1.50 +	answer=${answer#Description     : }
    1.51 +	if [ -z "$answer" ]; then
    1.52 +		echo -n "Description : "
    1.53 +		read answer
    1.54 +	fi
    1.55 +	echo -n "Compressing flavor $FLAVOR..."
    1.56 +	echo "Flavor          : $FLAVOR" > $FLAVOR.desc
    1.57 +	echo "Description     : $answer" >> $FLAVOR.desc
    1.58 +	( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
    1.59 +	\rm -f $FLAVOR.pkglist $FLAVOR.nonfree 2> /dev/null
    1.60 +	for i in $(ls $ROOTFS$INSTALLED); do
    1.61 +		eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
    1.62 +		EXTRAVERSION=""
    1.63 +		eval $(grep ^EXTRAVERSION= $ROOTFS$INSTALLED/$i/receipt)
    1.64 +		eval $(grep ^CATEGORY= $ROOTFS$INSTALLED/$i/receipt)
    1.65 +		if [ "$CATEGORY" = "non-free" -a "${i%%-*}" != "get" ]
    1.66 +		then
    1.67 +			echo "$i" >> $FLAVOR.nonfree
    1.68 +		else
    1.69 +			echo "$i-$VERSION$EXTRAVERSION" >> $FLAVOR.pkglist
    1.70 +		fi
    1.71 +	done
    1.72 +	[ -s $FLAVOR.nonfree ] && $FILES="$FILES\n$FLAVOR.nonfree"
    1.73 +	for i in $LOCALSTATE/undigest/*/mirror ; do
    1.74 +		[ -s $i ] && cat $i >> $FLAVOR.mirrors
    1.75 +	done
    1.76 +	[ -s $FLAVOR.mirrors ] && $FILES="$FILES\n$FLAVOR.mirrors"
    1.77 +	echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
    1.78 +		gzip -9 > $FLAVOR.flavor
    1.79 +	rm `echo -e $FILES`
    1.80 +	status
    1.81 +	separator
    1.82 +	echo "Flavor size : `du -sh $FLAVOR.flavor`"
    1.83 +	newline
    1.84 +}
    1.85 +
    1.86 +# tazlito get-flavor
    1.87 +get_flavor()
    1.88 +{
    1.89 +	# Get a flavor's files and prepare for gen-distro.
    1.90 +	FLAVOR=${2%.flavor}
    1.91 +	echo -e "\n\033[1mPreparing $FLAVOR distro flavor\033[0m"
    1.92 +	separator
    1.93 +	if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
    1.94 +		echo -n "Cleaning $DISTRO..."
    1.95 +		rm -R $DISTRO 2> /dev/null
    1.96 +		mkdir -p $DISTRO
    1.97 +		status
    1.98 +		mkdir $TMP_DIR
    1.99 +		echo -n "Extracting flavor $FLAVOR.flavor... "
   1.100 +		zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
   1.101 +		status
   1.102 +		echo -n "Creating distro-packages.list..."
   1.103 +		mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
   1.104 +		mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
   1.105 +		status
   1.106 +		if [ -f "$TMP_DIR/$FLAVOR-distro.sh" ]; then
   1.107 +			echo -n "Extracting distro.sh... "
   1.108 +			mv $TMP_DIR/$FLAVOR-distro.sh  distro.sh 2> /dev/null
   1.109 +			status
   1.110 +		fi
   1.111 +		infos="$FLAVOR.desc"
   1.112 +		for i in rootcd rootfs; do
   1.113 +			if [ -f $TMP_DIR/$FLAVOR.$i ]; then
   1.114 +				echo -n "Adding $i files... "
   1.115 +				mkdir -p "$ADDFILES/$i"
   1.116 +				zcat $TMP_DIR/$FLAVOR.$i | \
   1.117 +					( cd "$ADDFILES/$i"; cpio -id > /dev/null)
   1.118 +				zcat $TMP_DIR/$FLAVOR.$i | cpio -tv 2> /dev/null \
   1.119 +					> $TMP_DIR/$FLAVOR.list$i
   1.120 +				infos="$infos\n$FLAVOR.list$i"
   1.121 +				status
   1.122 +			fi
   1.123 +		done
   1.124 +		if [ -s $TMP_DIR/$FLAVOR.mirrors ]; then
   1.125 +			n=""
   1.126 +			while read line; do
   1.127 +				mkdir -p $LOCALSTATE/undigest/$FLAVOR$n
   1.128 +				echo "$line" > $LOCALSTATE/undigest/$FLAVOR$n/mirror
   1.129 +				n=$(( $n + 1 ))
   1.130 +			done < $TMP_DIR/$FLAVOR.mirrors
   1.131 +			infos="$infos\n$FLAVOR.mirrors"
   1.132 +			tazpkg recharge
   1.133 +		fi
   1.134 +		rm -f /etc/slitaz/rootfs.list
   1.135 +		grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc &&
   1.136 +			grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
   1.137 +			sed 's/.*: \(.*\)$/\1/' > /etc/slitaz/rootfs.list
   1.138 +		echo -n "Updating cookiso.conf..."
   1.139 +		[ -f cookiso.conf ] || cp /etc/slitaz/cookiso.conf .
   1.140 +		cat cookiso.conf | grep -v "^#VOLUM_NAME" | \
   1.141 +		sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
   1.142 +			> cookiso.conf.$$ && mv cookiso.conf.$$ cookiso.conf
   1.143 +		sed -i "s/ISO_NAME=.*/ISO_NAME=\"slitaz-$FLAVOR\"/" cookiso.conf
   1.144 +		status
   1.145 +		( cd $TMP_DIR ; echo -e $infos | cpio -o -H newc ) | \
   1.146 +			gzip -9 > /etc/slitaz/info
   1.147 +		rm -Rf $TMP_DIR
   1.148 +	fi
   1.149 +	separator
   1.150 +	echo -e "Flavor is ready to be generated by: cookiso gen-distro\n"
   1.151 +}
   1.152  
   1.153  # tazlito clean-distro
   1.154  clean_distro()