forked from calfzhou/autoproxy-gfwlist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendGFWList.sh
executable file
·138 lines (121 loc) · 4.24 KB
/
sendGFWList.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
#
# A simple script help to maintain AutoProxy gfwList easily.
#
# Features:
# Update local svn repository;
# Commit decoded changes(by others in your team) to local git repository
# with decoded message and authors name;
# Update "Last Modified" & "Checksum";
# Commit your changes to local git repository;
# Commit your encoded changes to remote svn server with encoded log;
# Plus some error handling.
# Usage:
# Initialize:
# $svn checkout https://autoproxy-gfwlist.googlecode.com/svn/trunk/ gfwList --username your-google-user-name
# $cd gfwList
# $git init
# $openssl base64 -d -in gfwlist.txt -out list.txt
# $git add list.txt
# $git commit -a -m "init"
# Normal Usage:
# edit list.txt as usual;
# $./sendGFWList.sh "say something about this edit"
# Note:
# 1: You can use "$git log" "$git show" "$git diff"...;
# 2: Do NOT commit "list.txt" to svn server (it won't by default);
# 3: Do NOT use any unicode character in the list, there is a known bug;
# 4: Do NOT "svn update", run this script to update / commit at any time.
################################################################################
# dependence
for cmd in sed openssl awk svn git perl file
do
which $cmd &> /dev/null;
if [ $? -ne 0 ]; then
echo "Error: depends on $cmd, please install it first.";
exit 1;
fi
done
# get formated author and log information
log=$(svn log --xml -r BASE:HEAD) || exit 1;
log=$(echo $log | awk -v RS='' -F '</?author>|</?msg>' '{ for(i=6;i<NF;i+=4) printf "%s:%s;",$i,$(i+2); }') &&
# convert from base64
i=0 &&
convertedLog="" &&
while [ "$log" != "" ]
do
if (( $i%2 == 0 )); then # author
temp=${log%%:*};
convertedLog+=${temp%@*}; # don't include "@gmail.com"
convertedLog+=": ";
# discard used string
log=${log#*:};
else # log, decode it
temp=$( echo ${log%%;*} | openssl base64 -d );
convertedLog+=$temp;
convertedLog+="\n";
log=${log#*;};
fi
((i++));
done
# modified by others, commit to local git repository
if [ "$convertedLog" != "" ]; then
git diff > temp.patch &&
svn update || exit 1;
openssl base64 -d -in gfwlist.txt -out list.txt &&
./validateChecksum.pl list.txt;
if [ $? -ne 0 ]; then
# recover, discard broken list.txt
git checkout list.txt && git apply temp.patch && rm temp.patch;
echo -e "\n\n\n*********************************************************\n";
echo "Error: gfwlist.txt from svn is invalid!!!";
echo "It must be a download error or somebody made a mistake.";
echo -e "\nYou can simply run this script again to fix the problem.";
echo "But wait...!"
echo "This would overwrite all commits till your last update!!!";
echo -e "\nIf you are confused, wait somebody else to fix it.";
echo "Please always report this to our maintainers' group!";
echo -e "\n*********************************************************\n\n\n";
exit 1;
fi
echo -e $convertedLog | git commit -a -F - &&
[ -s temp.patch ] && git apply temp.patch &&
rm temp.patch;
if [ -s temp.patch ]; then
echo -e "\n\033[31mError:\033[0m git apply failed, your work saved at temp.patch\n";
exit 1;
elif [ -a temp.patch ]; then
# empty, remove it
rm temp.patch;
fi
fi
if [ "$(git diff)" == "" ]; then
echo "Info: list.txt not modified.";
exit 0;
fi
if [ "$*" == "" ]; then
echo "Error: empty log, please say something about this modification.";
exit 1;
fi
# update date and checksum
./addChecksum.pl list.txt &&
if [ "$(file -b list.txt)" != "ASCII text" ]; then
echo "Error: list.txt invalid, please make sure:";
echo "1. there is no non-ASCII characters;";
echo "2. configure your text editor to use unix style line break.";
exit 1;
fi
# save local changes to git & svn
# if conflict or network problem occurs: do nothing & throw error message
git commit -a -m "$*" &&
(
openssl base64 -in list.txt |
# convert dos new line to unix style, old mac style ignored
tr -d '\r' > gfwlist.txt &&
# may be failed because of connection/authentication problems
svn ci gfwlist.txt -m $( echo "$*" | openssl base64 | tr -d '\r\n' ) ||
# "svn ci" and "git commit" are atomic operations
git reset HEAD^ 1> /dev/null;
) &&
# BASE++ if committed
svn update 1> /dev/null;