3 # A simple script help to maintain AutoProxy gfwList easily.
6 # Update local svn repository;
7 # Commit decoded changes(by others in your team) to local git repository
8 # with decoded message and authors name;
9 # Update "Last Modified" & "Checksum";
10 # Commit your changes to local git repository;
11 # Commit your encoded changes to remote svn server with encoded log;
12 # Plus some error handling.
15 # $svn checkout https://autoproxy-gfwlist.googlecode.com/svn/trunk/ gfwList --username your-google-user-name
18 # $openssl base64 -d -in gfwlist.txt -out list.txt
20 # $git commit -a -m "init"
22 # edit list.txt as usual;
23 # $./sendGFWList.sh "say something about this edit"
25 # 1: You can use "$git log" "$git show" "$git diff"...;
26 # 2: Do NOT commit "list.txt" to svn server (it won't by default);
27 # 3: Do NOT use any unicode character in the list, there is a known bug;
28 # 4: Do NOT "svn update", run this script to update / commit at any time.
29 ################################################################################
32 for cmd
in sed openssl
awk svn git perl
file
34 which $cmd &> /dev
/null
;
36 echo "Error: depends on $cmd, please install it first.";
41 # get formated author and log information
42 log
=$
(svn log
--xml -r BASE
:HEAD
) ||
exit 1;
43 log
=$
(echo $log |
awk -v RS
='' -F '</?author>|</?msg>' '{ for(i=6;i<NF;i+=4) printf "%s:%s;",$i,$(i+2); }') &&
48 while [ "$log" != "" ]
50 if (( $i%2 == 0 )); then # author
52 convertedLog
+=${temp%@*}; # don't include "@gmail.com"
57 temp
=$
( echo ${log%%;*} | openssl base64
-d );
65 # modified by others, commit to local git repository
66 if [ "$convertedLog" != "" ]; then
67 git
diff > temp.
patch &&
71 openssl base64
-d -in gfwlist.txt
-out list.txt
&&
72 .
/validateChecksum.pl list.txt
;
74 # recover, discard broken list.txt
75 git checkout list.txt
&& git apply temp.
patch && rm temp.
patch;
76 echo -e "\n\n\n*********************************************************\n";
77 echo "Error: gfwlist.txt from svn is invalid!!!";
78 echo "It must be a download error or somebody made a mistake.";
79 echo -e "\nYou can simply run this script again to fix the problem.";
81 echo "This would overwrite all commits till your last update!!!";
82 echo -e "\nIf you are confused, wait somebody else to fix it.";
83 echo "Please always report this to our maintainers' group!";
84 echo -e "\n*********************************************************\n\n\n";
88 echo -e $convertedLog | git commit
-a -F - &&
90 [ -s temp.
patch ] && git apply temp.
patch &&
93 if [ -s temp.
patch ]; then
94 echo -e "\n\033[31mError:\033[0m git apply failed, your work saved at temp.patch\n";
96 elif [ -a temp.
patch ]; then
102 if [ "$(git diff)" == "" ]; then
103 echo "Info: list.txt not modified.";
107 if [ "$*" == "" ]; then
108 echo "Error: empty log, please say something about this modification.";
112 # update date and checksum
113 .
/addChecksum.pl list.txt
&&
115 if [ "$(file -b list.txt)" != "ASCII text" ]; then
116 echo "Error: list.txt invalid, please make sure:";
117 echo "1. there is no non-ASCII characters;";
118 echo "2. configure your text editor to use unix style line break.";
122 # save local changes to git & svn
123 # if conflict or network problem occurs: do nothing & throw error message
124 git commit
-a -m "$*" &&
126 openssl base64
-in list.txt |
127 # convert dos new line to unix style, old mac style ignored
128 tr -d '\r' > gfwlist.txt
&&
130 # may be failed because of connection/authentication problems
131 svn ci gfwlist.txt
-m $
( echo "$*" | openssl base64 |
tr -d '\r\n' ) ||
133 # "svn ci" and "git commit" are atomic operations
134 git
reset HEAD^
1> /dev
/null
;
137 # BASE++ if committed
138 svn update
1> /dev
/null
;