X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Message-ID: <26590979.post@talk.nabble.com> Date: Tue, 1 Dec 2009 04:31:48 -0800 (PST) From: =?UTF-8?Q?LiuYan_=E5=88=98=E7=A0=94?= To: cygwin AT cygwin DOT com Subject: My DIY solution Re: Cygwin setup.exe: Clean historical setup packages In-Reply-To: <20091130154011.GB29734@ednor.casa.cgf.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable References: <26569064 DOT post AT talk DOT nabble DOT com> <20091130154011 DOT GB29734 AT ednor DOT casa DOT cgf DOT cx> X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com After I viewed setup.ini, I decide to write a little script to do this. Currently, it scans all the sub-directory of cygwin local package directory, and delete all the old files which not listed in setup.ini or setup-2.ini. Wish it can help someone like me.=20 download it from nabble.com: http://old.nabble.com/file/p26590979/cleanOldPackages_UTF8.sh cleanOldPackages_UTF8.sh=20 or copy the following code to a .sh file:
#
# =E5=B0=86=E6=9C=AC=E8=84=9A=E6=9C=AC=E6=96=87=E4=BB=B6=E6=94=BE=E5=88=B0=
=E4=B8=8E setup.exe =E7=9B=B8=E5=90=8C=E7=9A=84=E7=9B=AE=E5=BD=95=E4=B8=8B=
=EF=BC=8C=E7=84=B6=E5=90=8E=E6=89=A7=E8=A1=8C=E4=B9=8B
# Put this script file to the directory which contains setup.exe, and
execute it
#

echo
"##########################################################################=
######"
echo "                   =E6=B8=85=E7=90=86 Cygwin =E6=97=A7=E5=AE=89=E8=A3=
=85=E5=8C=85=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
"
echo "            Clean Old Install Packages of Cygwin=20=20=20=20=20=20=20=
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
"
echo "=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=
=20=20=20=20=20=20
"
echo "           by LiuYan 2009-12-01=20=20=20=20=
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=
=20
"
echo
"##########################################################################=
######"
echo
echo "Usage =E7=94=A8=E6=B3=95=EF=BC=9A"
echo "    $0 [-d] [-g][-l]"
echo "      -d  Do delete file if file is old =E6=89=A7=E8=A1=8C=E5=88=A0=
=E9=99=A4=E6=93=8D=E4=BD=9C"
echo "      -g, -l  Generate file delete commands to a script file =E7=94=
=9F=E6=88=90=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=E8=84=9A=E6=9C=AC"
echo

o_delete=3Dfalse
o_list=3Dfalse
while getopts "dgl" option
do
	case $option in
		d)
			o_delete=3Dtrue
			;;
		g|l)
			o_list=3Dtrue
			rm_command_list_file=3Drm_old_packages_`date +%F`.sh
			rm -f "$rm_command_list_file"
			;;
		*)
			;;
	esac
done

SCRIPT_BASE_DIR=3D`dirname $0`
#echo "SCRIPT_BASE_DIR=3D$SCRIPT_BASE_DIR"
BeginTime=3D`date "+%F %T %N"`

# =E6=9F=A5=E6=89=BE=E6=89=80=E6=9C=89=E5=AD=90=E7=9B=AE=E5=BD=95=E4=B8=8B=
=E7=9A=84 setup.ini =E5=92=8C setup-2.ini =E6=96=87=E4=BB=B6
# Search setup.exe or setup-2.exe in sub-directories

setup_ini_file_list=3D`find $SCRIPT_BASE_DIR -name setup.ini -or -name
setup-2.ini`
echo "$setup_ini_file_list" > cop_setup_ini_file_list.txt

# =E5=AF=B9=E6=AF=94 setup.ini =E4=B8=AD=E7=9A=84=E2=80=9C=E6=9C=80=E6=96=
=B0=E6=96=87=E4=BB=B6=E5=88=97=E8=A1=A8=E2=80=9D=E4=B8=8E=E6=9C=AC=E5=9C=B0=
=E7=9B=AE=E5=BD=95=E4=B8=AD=E7=9A=84=E6=96=87=E4=BB=B6=EF=BC=8C=E6=B8=85=E7=
=90=86=E4=B8=8D=E5=9C=A8=E2=80=9C=E6=9C=80=E6=96=B0=E6=96=87=E4=BB=B6=E5=88=
=97=E8=A1=A8=E2=80=9D=E4=B8=AD=E7=9A=84=E6=97=A7=E6=96=87=E4=BB=B6
# Compair the "Newest File List" in setup.ini and the local files, clean old
files which not exist in "Newest File List"

total_old_file_count=3D0
for setup_ini_file in $setup_ini_file_list
do
	echo
	MIRROR_BASE_DIR=3D`dirname $setup_ini_file`
	setup_ini_file_short_name=3D`basename $setup_ini_file`
=09
	if [ $setup_ini_file_short_name =3D=3D "setup-2.ini" ]
	then
		PACKAGE_BASE_DIR=3D"$MIRROR_BASE_DIR/release-2/"
	else
		PACKAGE_BASE_DIR=3D"$MIRROR_BASE_DIR/release/"
	fi

	echo "INI file         : $setup_ini_file"
	echo "Package directory: $PACKAGE_BASE_DIR"
	echo "Processing ..."
=09
	# =E5=BE=97=E5=88=B0 setup.ini =E4=B8=AD=E7=9A=84=E2=80=9C=E6=9C=80=E6=96=
=B0=E6=96=87=E4=BB=B6=E5=88=97=E8=A1=A8=E2=80=9D
	# Get the "Newest File List" from setup.ini

	newest_file_list=3D`gawk -F ' ' '/install:|source:/{print $2}'
$setup_ini_file`
	newest_file_list_file=3Dcop_newest_file_list${setup_ini_file//\//__}.txt
	echo "$newest_file_list" > $newest_file_list_file
=09
	# =E9=81=8D=E5=8E=86=E5=AE=89=E8=A3=85=E5=8C=85=E6=96=87=E4=BB=B6=E5=A4=B9=
=EF=BC=8C=E5=88=A0=E9=99=A4=E4=B8=8D=E5=9C=A8=E2=80=9C=E6=9C=80=E6=96=B0=E6=
=96=87=E4=BB=B6=E5=88=97=E8=A1=A8=E2=80=9D=E4=B8=AD=E7=9A=84=E6=96=87=E4=BB=
=B6
	# Search install package directory recursively, delete files not exist in
"Newest File List"
=09
	local_file_list=3D`find "$PACKAGE_BASE_DIR" -type f`
	package_old_file_count=3D0
	for local_file in $local_file_list
	do
		local_file_in_setup_ini_format=3D${local_file#${MIRROR_BASE_DIR}/}
=09=09
		file_is_fresh=3Dfalse
		## via grep
		grep -i "$local_file_in_setup_ini_format" $newest_file_list_file >
/dev/null
		if [ $? -eq 0 ]
		then
			file_is_fresh=3Dtrue
		fi

		# via bash conditional expression (=3D~ binary operator)
		#if [[ $newest_file_list =3D~ $local_file_in_setup_ini_format ]]
		#then
		#	file_is_fresh=3Dtrue
		#fi
=09=09
		if $file_is_fresh
		then
			echo "  $local_file_in_setup_ini_format"
		else
			echo "X $local_file_in_setup_ini_format"
			(( total_old_file_count ++ ))
			(( package_old_file_count ++ ))

			if $o_list
			then
				echo "rm -f \"$local_file\"" >> $rm_command_list_file
			fi
			if $o_delete
			then
				rm -f $local_file
				exit_code=3D$?
				echo -n "Delete $local_file ..."
				if [ $exit_code -eq 0 ]
				then
					echo Done!
				else
					echo Failed with code $exit_code!
				fi

			fi
		fi
	done
	echo "$package_old_file_count old files in $PACKAGE_BASE_DIR"
done

EndTime=3D`date "+%F %T %N"`
echo
echo "Total $total_old_file_count old files"
echo "BeginTime: $BeginTime"
echo "EndTime  : $EndTime"
Christopher Faylor-8 wrote: >=20 > On Sun, Nov 29, 2009 at 07:19:07PM -0800, LiuYan ?????? wrote: >> >>I'm using Cygwin for several years, it help me very much in my work. >> >>There's a tiny issue: after downloaded in several years, the total size of >>my local setup packages directory had grown up to G bytes, while a fresh >>setup packages of mine are only <40M bytes. >=20 > So, why not just remove your local setup packages directory? There is no > reason to keep it around. >=20 > cgf >=20 > -- > Problem reports: http://cygwin.com/problems.html > FAQ: http://cygwin.com/faq/ > Documentation: http://cygwin.com/docs.html > Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple >=20 >=20 >=20 --=20 View this message in context: http://old.nabble.com/Cygwin-setup.exe%3A-Cle= an-historical-setup-packages-tp26569064p26590979.html Sent from the Cygwin list mailing list archive at Nabble.com. -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple