My DIY solution Re: Cygwin setup.exe: Clean historical setup packages
LiuYan 刘研
lovetide@21cn.com
Tue Dec 1 12:31:00 GMT 2009
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
More information about the Cygwin
mailing list