mirror of
https://github.com/gfwlist/gfwlist.git
synced 2024-11-10 10:15:19 +00:00
bW9yZSByb2J1c3QgZXJyb3IgaGFuZGluZwo=
This commit is contained in:
parent
c03d47a40e
commit
29f8b91814
@ -29,17 +29,17 @@
|
|||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
# dependence
|
# dependence
|
||||||
for cmd in sed date base64 gawk svn git perl
|
for cmd in sed date base64 gawk svn git perl file
|
||||||
do
|
do
|
||||||
which $cmd &> /dev/null;
|
which $cmd &> /dev/null;
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Depends on $cmd, please install it first.";
|
echo "Error: depends on $cmd, please install it first.";
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# get formated author and log information
|
# get formated author and log information
|
||||||
log=$(svn log -r BASE:HEAD) &&
|
log=$(svn log -r BASE:HEAD) || exit 1;
|
||||||
log=$(echo $log | gawk -v RS='------------------------------------------------------------------------'\
|
log=$(echo $log | gawk -v RS='------------------------------------------------------------------------'\
|
||||||
'NR > 2 { if (NF > 10) printf "%s:%s;", $3, $NF; }' ) &&
|
'NR > 2 { if (NF > 10) printf "%s:%s;", $3, $NF; }' ) &&
|
||||||
|
|
||||||
@ -55,7 +55,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%%;*} | base64 -d );
|
||||||
convertedLog+=$temp;
|
convertedLog+=$temp;
|
||||||
convertedLog+="\n";
|
convertedLog+="\n";
|
||||||
log=${log#*;};
|
log=${log#*;};
|
||||||
@ -63,54 +63,66 @@ do
|
|||||||
((i++));
|
((i++));
|
||||||
done
|
done
|
||||||
|
|
||||||
# modified by others, commit to local git repository.
|
# modified by others, commit to local git repository
|
||||||
if [ "$convertedLog" != "" ]; then
|
if [ "$convertedLog" != "" ]; then
|
||||||
svn update &&
|
git diff > temp.patch &&
|
||||||
|
|
||||||
# save local modification
|
svn update || exit 1;
|
||||||
[ -n "$(git diff)" ] && git diff > temp.patch;
|
|
||||||
|
|
||||||
base64 -d gfwlist.txt > list.txt &&
|
base64 -d gfwlist.txt > list.txt && ./validateChecksum.pl list.txt;
|
||||||
echo -e $convertedLog | git commit -a -F - ;
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Error: gfwlist.txt from svn is invalid!";
|
||||||
|
echo "It must be a download error or somebody made a mistake.";
|
||||||
|
echo "Please check with the last committer or report to maintainers group.";
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e $convertedLog | git commit -a -F - &&
|
||||||
|
|
||||||
# apply local modification
|
|
||||||
[ -s temp.patch ] && git apply temp.patch &&
|
[ -s temp.patch ] && git apply temp.patch &&
|
||||||
rm temp.patch;
|
rm temp.patch &&
|
||||||
|
|
||||||
|
# remove (if exist) empty temp.patch
|
||||||
|
[ ! -s temp.patch -a -e temp.patch ] && rm temp.patch;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$(git diff)" == "" ]; then
|
if [ "$(git diff)" == "" ]; then
|
||||||
echo "list.txt not modified.";
|
echo "Info: list.txt not modified.";
|
||||||
exit 0;
|
exit 0;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$*" == "" ]; then
|
if [ "$*" == "" ]; then
|
||||||
echo "Empty log, please say something about this modification.";
|
echo "Error: empty log, please say something about this modification.";
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# make sure the list doesn't contain unicode chars
|
if [ "$(file list.txt)" != "list.txt: ASCII text" ]; then
|
||||||
file list.txt | grep ASCII 1> /dev/null ||
|
echo "Error: list.txt, please make sure:";
|
||||||
(
|
echo "1. there is no non-ASCII characters;";
|
||||||
echo "List contains non-ASCII characters, please remove them." &&
|
echo "2. configure your text editor to use unix style line break.";
|
||||||
exit 1;
|
exit 1;
|
||||||
) &&
|
fi
|
||||||
|
|
||||||
# update date and checksum
|
# update date and checksum
|
||||||
sed -i s/"Last Modified:.*$"/"Last Modified: $(date -R -r list.txt)"/ list.txt &&
|
sed -i s/"Last Modified:.*$"/"Last Modified: $(date -Rr list.txt)"/ list.txt &&
|
||||||
./addChecksum.pl list.txt &&
|
./addChecksum.pl list.txt &&
|
||||||
|
|
||||||
# save self change to git. exit directly if conflicting.
|
# save local changes to git & svn
|
||||||
|
# if conflict or network problem occurs: do nothing & throw error message
|
||||||
git commit -a -m "$*" &&
|
git commit -a -m "$*" &&
|
||||||
|
|
||||||
# commit to remote svn server
|
|
||||||
base64 list.txt > gfwlist.txt &&
|
|
||||||
(
|
(
|
||||||
# "svn ci" and "git commit" are atomic operations
|
base64 list.txt > gfwlist.txt &&
|
||||||
|
|
||||||
|
# may be running under Windows + Cygwin?
|
||||||
|
# convert dos new line to unix style, old mac style ignored
|
||||||
|
sed -i 's/\r$//g' 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 "$*" | base64 -w 0) ||
|
||||||
# "svn ci" may be failed because of connection problems.
|
|
||||||
|
# "svn ci" and "git commit" are atomic operations
|
||||||
git reset HEAD^ 1> /dev/null;
|
git reset HEAD^ 1> /dev/null;
|
||||||
) &&
|
) &&
|
||||||
|
|
||||||
# BASE++, HEAD++, if committed.
|
# BASE++ if committed
|
||||||
svn update 1> /dev/null;
|
svn update 1> /dev/null;
|
||||||
|
|
||||||
|
55
validateChecksum.pl
Executable file
55
validateChecksum.pl
Executable file
@ -0,0 +1,55 @@
|
|||||||
|
#!/usr/bin/perl
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
# This is a reference script to validate the checksum in downloadable #
|
||||||
|
# subscription. This performs the same validation as Adblock Plus when it #
|
||||||
|
# downloads the subscription. #
|
||||||
|
# #
|
||||||
|
# To validate a subscription file, run the script like this: #
|
||||||
|
# #
|
||||||
|
# perl validateChecksum.pl subscription.txt #
|
||||||
|
# #
|
||||||
|
# Note: your subscription file should be saved in UTF-8 encoding, otherwise #
|
||||||
|
# the validation result might be incorrect. #
|
||||||
|
# #
|
||||||
|
# 20100418: Stolen from ABP with minor modification for AutoProxy project #
|
||||||
|
#############################################################################
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use Digest::MD5 qw(md5_base64);
|
||||||
|
|
||||||
|
die "Usage: $^X $0 subscription.txt\n" unless @ARGV;
|
||||||
|
|
||||||
|
my $file = $ARGV[0];
|
||||||
|
my $data = readFile($file);
|
||||||
|
|
||||||
|
# Normalize data
|
||||||
|
$data =~ s/\r//g;
|
||||||
|
$data =~ s/\n+/\n/g;
|
||||||
|
|
||||||
|
# Extract checksum
|
||||||
|
|
||||||
|
# Remove checksum
|
||||||
|
$data =~ s/^\s*!\s*checksum[\s\-:]+([\w\+\/=]+).*\n//mi;
|
||||||
|
my $checksum = $1;
|
||||||
|
die "Error: couldn't find a checksum in the file\n" unless $checksum;
|
||||||
|
|
||||||
|
# Calculate new checksum
|
||||||
|
my $checksumExpected = md5_base64($data);
|
||||||
|
|
||||||
|
# Compare checksums
|
||||||
|
die "Error: invalid checksum\n" unless $checksum eq $checksumExpected;
|
||||||
|
|
||||||
|
sub readFile
|
||||||
|
{
|
||||||
|
my $file = shift;
|
||||||
|
|
||||||
|
open(local *FILE, "<", $file) || die "Error: could not read file '$file'";
|
||||||
|
binmode(FILE);
|
||||||
|
local $/;
|
||||||
|
my $result = <FILE>;
|
||||||
|
close(FILE);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user