modified: pixi.toml
[GalaxyCodeBases.git] / etc / agfw / autoproxy-gfwlist / sendGFWList.sh
blob55271cdbc321e5bfd0bb390fac235f3fa6100abc
1 #!/bin/bash
3 # A simple script help to maintain AutoProxy gfwList easily.
5 # Features:
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.
13 # Usage:
14 # Initialize:
15 # $svn checkout https://autoproxy-gfwlist.googlecode.com/svn/trunk/ gfwList --username your-google-user-name
16 # $cd gfwList
17 # $git init
18 # $openssl base64 -d -in gfwlist.txt -out list.txt
19 # $git add list.txt
20 # $git commit -a -m "init"
21 # Normal Usage:
22 # edit list.txt as usual;
23 # $./sendGFWList.sh "say something about this edit"
24 # Note:
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 ################################################################################
31 # dependence
32 for cmd in sed openssl awk svn git perl file
34 which $cmd &> /dev/null;
35 if [ $? -ne 0 ]; then
36 echo "Error: depends on $cmd, please install it first.";
37 exit 1;
39 done
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); }') &&
45 # convert from base64
46 i=0 &&
47 convertedLog="" &&
48 while [ "$log" != "" ]
50 if (( $i%2 == 0 )); then # author
51 temp=${log%%:*};
52 convertedLog+=${temp%@*}; # don't include "@gmail.com"
53 convertedLog+=": ";
54 # discard used string
55 log=${log#*:};
56 else # log, decode it
57 temp=$( echo ${log%%;*} | openssl base64 -d );
58 convertedLog+=$temp;
59 convertedLog+="\n";
60 log=${log#*;};
62 ((i++));
63 done
65 # modified by others, commit to local git repository
66 if [ "$convertedLog" != "" ]; then
67 git diff > temp.patch &&
69 svn update || exit 1;
71 openssl base64 -d -in gfwlist.txt -out list.txt &&
72 ./validateChecksum.pl list.txt;
73 if [ $? -ne 0 ]; then
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.";
80 echo "But wait...!"
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";
85 exit 1;
88 echo -e $convertedLog | git commit -a -F - &&
90 [ -s temp.patch ] && git apply temp.patch &&
91 rm 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";
95 exit 1;
96 elif [ -a temp.patch ]; then
97 # empty, remove it
98 rm temp.patch;
102 if [ "$(git diff)" == "" ]; then
103 echo "Info: list.txt not modified.";
104 exit 0;
107 if [ "$*" == "" ]; then
108 echo "Error: empty log, please say something about this modification.";
109 exit 1;
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.";
119 exit 1;
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;
135 ) &&
137 # BASE++ if committed
138 svn update 1> /dev/null;