tazlito rev 18

pave the road to flavors. Can find packages with 'tazpkg --repack'
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Dec 14 20:40:12 2007 +0000 (2007-12-14)
parents 6bc856bd158d
children bd901a157586
files tazlito
line diff
     1.1 --- a/tazlito	Fri Dec 14 19:51:19 2007 +0000
     1.2 +++ b/tazlito	Fri Dec 14 20:40:12 2007 +0000
     1.3 @@ -121,6 +121,33 @@
     1.4  	cd $here
     1.5  }
     1.6  
     1.7 +# echo the package name if the tazpkg is already installed
     1.8 +installed_package_name()
     1.9 +{
    1.10 +	local tazpkg
    1.11 +	local package
    1.12 +	local VERSION
    1.13 +	tazpkg=$1
    1.14 +	# try du find package name and version to be able
    1.15 +	# to repack it from installation
    1.16 +	# a dash (-) can exist in name *and* in version
    1.17 +	package=${tazpkg%-*}
    1.18 +	i=$package
    1.19 +	while true; do
    1.20 +		VERSION=""
    1.21 +		eval $(grep -s ^VERSION= $INSTALLED/$i/receipt)
    1.22 +		if [ "$i-$VERSION" = "$tazpkg" ]; then
    1.23 +			echo $i
    1.24 +			break
    1.25 +		fi
    1.26 +		case "$i" in
    1.27 +		*-*);;
    1.28 +		*) break;;
    1.29 +		esac
    1.30 +		i=${i%-*}
    1.31 +	done
    1.32 +}
    1.33 +
    1.34  # Check if user is root.
    1.35  check_root()
    1.36  {
    1.37 @@ -423,7 +450,7 @@
    1.38  			fi
    1.39  		fi
    1.40  		# Exit if no list name.
    1.41 -		if [ "$LIST_NAME" = "" ] ; then
    1.42 +		if [ ! -f "$LIST_NAME" ]; then
    1.43  			echo -e "\nNo packages list found or specified. Please read the doc.\n"
    1.44  			exit 0
    1.45  		fi
    1.46 @@ -431,21 +458,40 @@
    1.47  		echo ""
    1.48  		echo -e "\033[1mTazlito generating a distro\033[0m"
    1.49  		echo "================================================================================"
    1.50 +		# Misc checks
    1.51 +		[ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
    1.52 +		[ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
    1.53  		# Get the list of packages using cat for a file list.
    1.54  		LIST=`cat $LIST_NAME`
    1.55  		# Verify if all packages in list are presents in $PACKAGES_REPOSITORY.
    1.56 +		REPACK=""
    1.57 +		DOWNLOAD=""
    1.58  		for pkg in $LIST
    1.59  		do
    1.60  			pkg=${pkg%.tazpkg}
    1.61 -			if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] ; then
    1.62 -				echo -e "\nUnable to find $pkg in the repository."
    1.63 -				echo -e "Path : $PACKAGES_REPOSITORY\n"
    1.64 -				if [ -f $MIRROR ]; then
    1.65 -					yesorno "Download packages from mirror (Y/n) ? "
    1.66 -					[ "$answer" = "n" ] || break
    1.67 +			[ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
    1.68 +			PACKAGE=$(installed_package_name $pkg)
    1.69 +			[ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
    1.70 +			[ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
    1.71 +			echo -e "\nUnable to find $pkg in the repository."
    1.72 +			echo -e "Path : $PACKAGES_REPOSITORY\n"
    1.73 +			if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
    1.74 +				yesorno "Repack packages from rootfs (y/N) ? "
    1.75 +				REPACK="$answer"
    1.76 +				[ "$answer" = "y" ] || REPACK="n"
    1.77 +				[ "$DOWNLOAD" = "y" ] && break
    1.78 +			fi
    1.79 +			if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
    1.80 +				yesorno "Download packages from mirror (Y/n) ? "
    1.81 +				DOWNLOAD="$answer"
    1.82 +				if [ "$answer" = "n" ]; then
    1.83 +					[ -z "$PACKAGE" ] && exit 1
    1.84 +				else
    1.85 +					DOWNLOAD="y"
    1.86 +					[ -n "$REPACK" ] && break
    1.87  				fi
    1.88 -				exit 1
    1.89  			fi
    1.90 +			[ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
    1.91  		done
    1.92  		# Root fs stuff.
    1.93  		echo "Preparing the rootfs directory..."
    1.94 @@ -455,15 +501,23 @@
    1.95  		do
    1.96  			# First copy and extract the package in tmp dir.
    1.97  			pkg=${pkg%.tazpkg}
    1.98 +			PACKAGE=$(installed_package_name $pkg)
    1.99  			mkdir -p $TMP_DIR
   1.100  			if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
   1.101  				# look for package in cache
   1.102  				if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
   1.103  					ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
   1.104 -				else
   1.105 +				# look for package in running distribution
   1.106 +				elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
   1.107 +					tazpkg repack $PACKAGE && \
   1.108 +					  mv $pkg.tazpkg $PACKAGES_REPOSITORY 
   1.109 +				fi
   1.110 +			fi
   1.111 +			if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
   1.112  				# get package from mirror
   1.113 -					download $pkg.tazpkg && mv $pkg.tazpkg $PACKAGE_REPOSITORY
   1.114 -				fi
   1.115 +				[ "$DOWNLOAD" = "y" ] && \
   1.116 +				download $pkg.tazpkg && \
   1.117 +				mv $pkg.tazpkg $PACKAGES_REPOSITORY
   1.118  			fi
   1.119  			if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
   1.120  				echo "Missing package $pkg."