From 8faa05263e8f7f41dad831b75d8fa2c3769d8c4d Mon Sep 17 00:00:00 2001 From: 911mxl <911mxl@92d94e00-0010-11de-bc25-5f29055a2a2d> Date: Sun, 18 Apr 2010 16:54:59 +0000 Subject: [PATCH] TWFjIGNvbXBsaWFudCBmb3Igc2VuZEdGV0xpc3Quc2gK --- addChecksum.pl | 8 ++++++++ sendGFWList.sh | 24 ++++++++++-------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/addChecksum.pl b/addChecksum.pl index b47045a..57c92a2 100755 --- a/addChecksum.pl +++ b/addChecksum.pl @@ -17,6 +17,9 @@ use strict; use warnings; use Digest::MD5 qw(md5_base64); +use File::stat; +use POSIX qw(locale_h); +use POSIX qw(strftime); die "Usage: $^X $0 subscription.txt\n" unless @ARGV; @@ -26,6 +29,11 @@ my $data = readFile($file); # Remove already existing checksum $data =~ s/^.*!\s*checksum[\s\-:]+([\w\+\/=]+).*\n//gmi; +# Update timestamp +setlocale(LC_TIME, "C"); +my $timestamp = strftime("%a, %d %b %Y %H:%M:%S %z", localtime(stat($file)->mtime)); +$data =~ s/^!\s*Last Modified:.*$/! Last Modified: $timestamp/mi; + # Calculate new checksum: remove all CR symbols and empty # lines and get an MD5 checksum of the result (base64-encoded, # without the trailing = characters). diff --git a/sendGFWList.sh b/sendGFWList.sh index 6342424..f44e611 100755 --- a/sendGFWList.sh +++ b/sendGFWList.sh @@ -15,7 +15,7 @@ # $svn checkout https://autoproxy-gfwlist.googlecode.com/svn/trunk/ gfwList --username your-google-user-name # $cd gfwList # $git init -# $base64 -d gfwlist.txt > list.txt +# $openssl base64 -d -in gfwlist.txt -out list.txt # $git add list.txt # $git commit -a -m "init" # Normal Usage: @@ -29,7 +29,7 @@ ################################################################################ # dependence -for cmd in sed date base64 gawk svn git perl file +for cmd in sed openssl awk svn git perl file do which $cmd &> /dev/null; if [ $? -ne 0 ]; then @@ -39,9 +39,8 @@ do done # get formated author and log information -log=$(svn log -r BASE:HEAD) || exit 1; -log=$(echo $log | gawk -v RS='------------------------------------------------------------------------'\ - 'NR > 2 { if (NF > 10) printf "%s:%s;", $3, $NF; }' ) && +log=$(svn log --xml -r BASE:HEAD) || exit 1; +log=$(echo $log | awk -v RS='' -F '|' '{ for(i=6;i list.txt && ./validateChecksum.pl list.txt; + openssl base64 -d -in gfwlist.txt -out list.txt && ./validateChecksum.pl list.txt; if [ $? -ne 0 ]; then echo "Error: gfwlist.txt from svn is invalid!"; echo "It must be a download error or somebody made a mistake."; @@ -101,7 +100,7 @@ if [ "$*" == "" ]; then exit 1; fi -if [ "$(file list.txt)" != "list.txt: ASCII text" ]; then +if [ "$(file -b list.txt)" != "ASCII text" ]; then echo "Error: list.txt, please make sure:"; echo "1. there is no non-ASCII characters;"; echo "2. configure your text editor to use unix style line break."; @@ -109,21 +108,18 @@ if [ "$(file list.txt)" != "list.txt: ASCII text" ]; then fi # update date and checksum -sed -i s/"Last Modified:.*$"/"Last Modified: $(date -Rr list.txt)"/ list.txt && ./addChecksum.pl list.txt && # save local changes to git & svn # if conflict or network problem occurs: do nothing & throw error message git commit -a -m "$*" && ( - base64 list.txt > gfwlist.txt && - - # may be running under Windows + Cygwin? + openssl base64 -in list.txt | # convert dos new line to unix style, old mac style ignored - sed -i 's/\r$//g' gfwlist.txt && + tr -d '\r' > gfwlist.txt && # may be failed because of connection/authentication problems - svn ci gfwlist.txt -m $( echo "$*" | base64 -w 0) || + svn ci gfwlist.txt -m $( echo "$*" | openssl base64 | tr -d '\n') || # "svn ci" and "git commit" are atomic operations git reset HEAD^ 1> /dev/null;