tazpkg rev 273

tazpkg/install should remove obsolate files
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Jun 21 11:25:59 2009 +0200 (2009-06-21)
parents 757764404261
children 6f2b0bcdb41f
files tazpkg
line diff
     1.1 --- a/tazpkg	Mon Jun 15 17:29:49 2009 +0000
     1.2 +++ b/tazpkg	Sun Jun 21 11:25:59 2009 +0200
     1.3 @@ -391,13 +391,15 @@
     1.4  		if grep -q ^pre_depends $TMP_DIR/receipt; then
     1.5  			pre_depends $ROOT
     1.6  		fi
     1.7 -		# keep modifers list on upgrade
     1.8 -		cp $ROOT$INSTALLED/$PACKAGE/modifiers $TMP_DIR 2> /dev/null
     1.9 +		# keep modifers and file list on upgrade
    1.10 +		cp $ROOT$INSTALLED/$PACKAGE/modifiers \
    1.11 +		   $ROOT$INSTALLED/$PACKAGE/files.list $TMP_DIR 2> /dev/null
    1.12  		rm -rf $ROOT$INSTALLED/$PACKAGE 2> /dev/null
    1.13  		# Make the installed package data dir to store
    1.14  		# the receipt and the files list.
    1.15  		mkdir -p $ROOT$INSTALLED/$PACKAGE
    1.16  		cp $TMP_DIR/modifiers $ROOT$INSTALLED/$PACKAGE 2> /dev/null
    1.17 +		cp $TMP_DIR/files.list $ROOT$INSTALLED/$PACKAGE 2> /dev/null
    1.18  		rm -rf $TMP_DIR 2> /dev/null
    1.19  		sed -i "/ $(basename $PACKAGE_FILE)$/d" \
    1.20  			$ROOT$LOCALSTATE/installed.md5 2> /dev/null
    1.21 @@ -424,27 +426,38 @@
    1.22  	CONFIG_FILES=""
    1.23  	# Include temporary receipt to get the right variables.
    1.24  	. $PWD/receipt
    1.25 +	cd $ROOT$INSTALLED
    1.26  	if [ $SELF_INSTALL -ne 0 -a -n "$ROOT" ]; then
    1.27  		echo -n "Checking post install dependencies... "
    1.28  		[ -f $INSTALLED/$PACKAGE/receipt ]
    1.29  		if ! status; then
    1.30  			echo "Please run 'tazpkg install $PACKAGE_FILE' in / and retry."
    1.31 -			cd .. && rm -rf $TMP_DIR
    1.32 +			rm -rf $TMP_DIR
    1.33  			exit 1
    1.34  		fi
    1.35  	fi
    1.36 +	# Get files to remove if upgrading
    1.37 +	if [ -f $PACKAGE/files.list ]; then
    1.38 +		while read file; do
    1.39 +			grep -q "^$file$" $TMP_DIR/files.list && continue
    1.40 +			for i in $(cat $PACKAGE/modifiers 2> /dev/null ; 
    1.41 +			    grep -sl $PACKAGE */modifiers | cut -d/ -f1 ); do
    1.42 +				grep -q "^$file$" $i/files.list && continue 2
    1.43 +			done
    1.44 +			echo $file
    1.45 +		done < $PACKAGE/files.list > $TMP_DIR/files2remove.list
    1.46 +	fi
    1.47  	# Remember modified packages
    1.48  	for i in $(grep -v '\[' files.list); do
    1.49  		[ -e "$ROOT$i" ] || continue
    1.50  		[ -d "$ROOT$i" ] && continue
    1.51 -		for j in $(grep -l "^$i$" $ROOT$INSTALLED/*/files.list); do
    1.52 +		for j in $(grep -l "^$i$" */files.list); do
    1.53  			local dir
    1.54  			dir=$(dirname $j)
    1.55 -			[ "$j" = "$ROOT$INSTALLED/$PACKAGE/files.list" ] && continue
    1.56 -			if grep -qs ^$(basename $dir)$ \
    1.57 -				  $ROOT$INSTALLED/$PACKAGE/modifiers; then
    1.58 +			[ "$j" = "$PACKAGE/files.list" ] && continue
    1.59 +			if grep -qs ^$dir$ $PACKAGE/modifiers; then
    1.60  				# Do not overload an overloaded file !
    1.61 -				rm .$i 2> /dev/null
    1.62 +				rm $TMP_DIR$i 2> /dev/null
    1.63  				continue
    1.64  			fi
    1.65  			grep -qs ^$PACKAGE$ $dir/modifiers && continue
    1.66 @@ -457,6 +470,7 @@
    1.67  			echo "$PACKAGE" >> $dir/modifiers
    1.68  		done
    1.69  	done
    1.70 +	cd $TMP_DIR
    1.71  	cp receipt files.list $ROOT$INSTALLED/$PACKAGE
    1.72  	# Copy the description if found.
    1.73  	if [ -f "description.txt" ]; then
    1.74 @@ -489,6 +503,18 @@
    1.75  	echo -n "Installing $PACKAGE... "
    1.76  	cp -a fs/* $ROOT/
    1.77  	status
    1.78 +	if [ -s files2remove.list ]; then
    1.79 +		echo -n "Removing old $PACKAGE... "
    1.80 +		while read file; do
    1.81 +			rm -f $ROOT$file
    1.82 +			dir=$(dirname $ROOT$file)
    1.83 +			while true; do
    1.84 +				rmdir $dir 2> /dev/null || break
    1.85 +				dir=$(dirname $dir)
    1.86 +			done
    1.87 +		done < files2remove.list
    1.88 +		status
    1.89 +	fi
    1.90  	# Remove the temporary random directory.
    1.91  	echo -n "Removing all tmp files... "
    1.92  	cd .. && rm -rf $TMP_DIR
    1.93 @@ -503,7 +529,6 @@
    1.94  	echo ""
    1.95  	# Log this activity
    1.96  	[ -n "$ROOT" ] || log Installed
    1.97 -
    1.98  }
    1.99  
   1.100  # Check for loop in deps tree.