This is the mail archive of the
cygwin
mailing list for the Cygwin project.
My DIY solution Re: Cygwin setup.exe: Clean historical setup packages
- From: LiuYan åç <lovetide at 21cn dot com>
- To: cygwin at cygwin dot com
- Date: Tue, 1 Dec 2009 04:31:48 -0800 (PST)
- Subject: My DIY solution Re: Cygwin setup.exe: Clean historical setup packages
- References: <26569064.post@talk.nabble.com> <20091130154011.GB29734@ednor.casa.cgf.cx>
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.
download it from nabble.com:
http://old.nabble.com/file/p26590979/cleanOldPackages_UTF8.sh
cleanOldPackages_UTF8.sh
or copy the following code to a .sh file:
<pre>
#
# åæèææäæåä setup.exe çåççåäïçåæèä
# Put this script file to the directory which contains setup.exe, and
execute it
#
echo
"################################################################################"
echo " æç Cygwin æåèå
"
echo " Clean Old Install Packages of Cygwin
"
echo "
"
echo " by LiuYan<lovetideïqq.com> 2009-12-01
"
echo
"################################################################################"
echo
echo "Usage çæï"
echo " $0 [-d] [-g][-l]"
echo " -d Do delete file if file is old æèåéæä"
echo " -g, -l Generate file delete commands to a script file çæåéæäèæ"
echo
o_delete=false
o_list=false
while getopts "dgl" option
do
case $option in
d)
o_delete=true
;;
g|l)
o_list=true
rm_command_list_file=rm_old_packages_`date +%F`.sh
rm -f "$rm_command_list_file"
;;
*)
;;
esac
done
SCRIPT_BASE_DIR=`dirname $0`
#echo "SCRIPT_BASE_DIR=$SCRIPT_BASE_DIR"
BeginTime=`date "+%F %T %N"`
# ææææåçåäç setup.ini å setup-2.ini æä
# Search setup.exe or setup-2.exe in sub-directories
setup_ini_file_list=`find $SCRIPT_BASE_DIR -name setup.ini -or -name
setup-2.ini`
echo "$setup_ini_file_list" > cop_setup_ini_file_list.txt
# åæ setup.ini äçâæææäåèâäæåçåäçæäïæçäåâæææäåèâäçææä
# 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=0
for setup_ini_file in $setup_ini_file_list
do
echo
MIRROR_BASE_DIR=`dirname $setup_ini_file`
setup_ini_file_short_name=`basename $setup_ini_file`
if [ $setup_ini_file_short_name == "setup-2.ini" ]
then
PACKAGE_BASE_DIR="$MIRROR_BASE_DIR/release-2/"
else
PACKAGE_BASE_DIR="$MIRROR_BASE_DIR/release/"
fi
echo "INI file : $setup_ini_file"
echo "Package directory: $PACKAGE_BASE_DIR"
echo "Processing ..."
# åå setup.ini äçâæææäåèâ
# Get the "Newest File List" from setup.ini
newest_file_list=`gawk -F ' ' '/install:|source:/{print $2}'
$setup_ini_file`
newest_file_list_file=cop_newest_file_list${setup_ini_file//\//__}.txt
echo "$newest_file_list" > $newest_file_list_file
# éååèåæäåïåéäåâæææäåèâäçæä
# Search install package directory recursively, delete files not exist in
"Newest File List"
local_file_list=`find "$PACKAGE_BASE_DIR" -type f`
package_old_file_count=0
for local_file in $local_file_list
do
local_file_in_setup_ini_format=${local_file#${MIRROR_BASE_DIR}/}
file_is_fresh=false
## via grep
grep -i "$local_file_in_setup_ini_format" $newest_file_list_file >
/dev/null
if [ $? -eq 0 ]
then
file_is_fresh=true
fi
# via bash conditional expression (=~ binary operator)
#if [[ $newest_file_list =~ $local_file_in_setup_ini_format ]]
#then
# file_is_fresh=true
#fi
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=$?
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=`date "+%F %T %N"`
echo
echo "Total $total_old_file_count old files"
echo "BeginTime: $BeginTime"
echo "EndTime : $EndTime"
</pre>
Christopher Faylor-8 wrote:
>
> 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.
>
> So, why not just remove your local setup packages directory? There is no
> reason to keep it around.
>
> cgf
>
> --
> 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
>
>
>
--
View this message in context: http://old.nabble.com/Cygwin-setup.exe%3A-Clean-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