mirror of
https://github.com/gfwlist/gfwlist.git
synced 2024-12-24 23:55:18 +00:00
TWFjIGNvbXBsaWFudCBmb3Igc2VuZEdGV0xpc3Quc2gK
This commit is contained in:
parent
6f3ddd0424
commit
8faa05263e
@ -17,6 +17,9 @@
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Digest::MD5 qw(md5_base64);
|
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;
|
die "Usage: $^X $0 subscription.txt\n" unless @ARGV;
|
||||||
|
|
||||||
@ -26,6 +29,11 @@ my $data = readFile($file);
|
|||||||
# Remove already existing checksum
|
# Remove already existing checksum
|
||||||
$data =~ s/^.*!\s*checksum[\s\-:]+([\w\+\/=]+).*\n//gmi;
|
$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
|
# Calculate new checksum: remove all CR symbols and empty
|
||||||
# lines and get an MD5 checksum of the result (base64-encoded,
|
# lines and get an MD5 checksum of the result (base64-encoded,
|
||||||
# without the trailing = characters).
|
# without the trailing = characters).
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
# $svn checkout https://autoproxy-gfwlist.googlecode.com/svn/trunk/ gfwList --username your-google-user-name
|
# $svn checkout https://autoproxy-gfwlist.googlecode.com/svn/trunk/ gfwList --username your-google-user-name
|
||||||
# $cd gfwList
|
# $cd gfwList
|
||||||
# $git init
|
# $git init
|
||||||
# $base64 -d gfwlist.txt > list.txt
|
# $openssl base64 -d -in gfwlist.txt -out list.txt
|
||||||
# $git add list.txt
|
# $git add list.txt
|
||||||
# $git commit -a -m "init"
|
# $git commit -a -m "init"
|
||||||
# Normal Usage:
|
# Normal Usage:
|
||||||
@ -29,7 +29,7 @@
|
|||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
# dependence
|
# dependence
|
||||||
for cmd in sed date base64 gawk svn git perl file
|
for cmd in sed openssl awk svn git perl file
|
||||||
do
|
do
|
||||||
which $cmd &> /dev/null;
|
which $cmd &> /dev/null;
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
@ -39,9 +39,8 @@ do
|
|||||||
done
|
done
|
||||||
|
|
||||||
# get formated author and log information
|
# get formated author and log information
|
||||||
log=$(svn log -r BASE:HEAD) || exit 1;
|
log=$(svn log --xml -r BASE:HEAD) || exit 1;
|
||||||
log=$(echo $log | gawk -v RS='------------------------------------------------------------------------'\
|
log=$(echo $log | awk -v RS='' -F '</?author>|</?msg>' '{ for(i=6;i<NF;i+=4) printf "%s:%s;",$i,$(i+2); }' ) &&
|
||||||
'NR > 2 { if (NF > 10) printf "%s:%s;", $3, $NF; }' ) &&
|
|
||||||
|
|
||||||
# convert from base64
|
# convert from base64
|
||||||
i=0 &&
|
i=0 &&
|
||||||
@ -55,7 +54,7 @@ do
|
|||||||
# discard used string
|
# discard used string
|
||||||
log=${log#*:};
|
log=${log#*:};
|
||||||
else # log, decode it
|
else # log, decode it
|
||||||
temp=$( echo ${log%%;*} | base64 -d );
|
temp=$( echo ${log%%;*} | openssl base64 -d );
|
||||||
convertedLog+=$temp;
|
convertedLog+=$temp;
|
||||||
convertedLog+="\n";
|
convertedLog+="\n";
|
||||||
log=${log#*;};
|
log=${log#*;};
|
||||||
@ -69,7 +68,7 @@ if [ "$convertedLog" != "" ]; then
|
|||||||
|
|
||||||
svn update || exit 1;
|
svn update || exit 1;
|
||||||
|
|
||||||
base64 -d gfwlist.txt > list.txt && ./validateChecksum.pl list.txt;
|
openssl base64 -d -in gfwlist.txt -out list.txt && ./validateChecksum.pl list.txt;
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error: gfwlist.txt from svn is invalid!";
|
echo "Error: gfwlist.txt from svn is invalid!";
|
||||||
echo "It must be a download error or somebody made a mistake.";
|
echo "It must be a download error or somebody made a mistake.";
|
||||||
@ -101,7 +100,7 @@ if [ "$*" == "" ]; then
|
|||||||
exit 1;
|
exit 1;
|
||||||
fi
|
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 "Error: list.txt, please make sure:";
|
||||||
echo "1. there is no non-ASCII characters;";
|
echo "1. there is no non-ASCII characters;";
|
||||||
echo "2. configure your text editor to use unix style line break.";
|
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
|
fi
|
||||||
|
|
||||||
# update date and checksum
|
# update date and checksum
|
||||||
sed -i s/"Last Modified:.*$"/"Last Modified: $(date -Rr list.txt)"/ list.txt &&
|
|
||||||
./addChecksum.pl list.txt &&
|
./addChecksum.pl list.txt &&
|
||||||
|
|
||||||
# save local changes to git & svn
|
# save local changes to git & svn
|
||||||
# if conflict or network problem occurs: do nothing & throw error message
|
# if conflict or network problem occurs: do nothing & throw error message
|
||||||
git commit -a -m "$*" &&
|
git commit -a -m "$*" &&
|
||||||
(
|
(
|
||||||
base64 list.txt > gfwlist.txt &&
|
openssl base64 -in list.txt |
|
||||||
|
|
||||||
# may be running under Windows + Cygwin?
|
|
||||||
# convert dos new line to unix style, old mac style ignored
|
# 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
|
# 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
|
# "svn ci" and "git commit" are atomic operations
|
||||||
git reset HEAD^ 1> /dev/null;
|
git reset HEAD^ 1> /dev/null;
|
||||||
|
Loading…
Reference in New Issue
Block a user