~ubuntu-branches/debian/stretch/bitcoin/stretch

« back to all changes in this revision

Viewing changes to contrib/verifybinaries/verify.sh

  • Committer: Package Import Robot
  • Author(s): Anthony Towns
  • Date: 2016-10-21 17:13:13 UTC
  • mfrom: (1.3.2)
  • Revision ID: package-import@ubuntu.com-20161021171313-7eu2ltpbk0xag3q1
Tags: 0.13.0-0.1
* Non-maintainer upload.
* New upstream release.
* Allow compilation with gcc/g++ 6. (Closes: Bug#835963)
* Additional fixes for openssl 1.1 compatibility. (See Bug#828248)
* Check if -latomic is needed (it is on mips*).
* Remove reproducible build patch, since leveldb build system is
  no longer used in 0.13. (See Bug#791834)
* Update description since the blockchain is much more than "several GB"
  now. (Closes: Bug#835809)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
###   This script attempts to download the signature file SHA256SUMS.asc from bitcoin.org
 
4
###   It first checks if the signature passes, and then downloads the files specified in
 
5
###   the file, and checks if the hashes of these files match those that are specified
 
6
###   in the signature file.
 
7
###   The script returns 0 if everything passes the checks. It returns 1 if either the
 
8
###   signature check or the hash check doesn't pass. If an error occurs the return value is 2
 
9
 
 
10
function clean_up {
 
11
   for file in $*
 
12
   do
 
13
      rm "$file" 2> /dev/null
 
14
   done
 
15
}
 
16
 
 
17
WORKINGDIR="/tmp/bitcoin"
 
18
TMPFILE="hashes.tmp"
 
19
 
 
20
SIGNATUREFILENAME="SHA256SUMS.asc"
 
21
RCSUBDIR="test/"
 
22
BASEDIR="https://bitcoin.org/bin/"
 
23
VERSIONPREFIX="bitcoin-core-"
 
24
RCVERSIONSTRING="rc"
 
25
 
 
26
if [ ! -d "$WORKINGDIR" ]; then
 
27
   mkdir "$WORKINGDIR"
 
28
fi
 
29
 
 
30
cd "$WORKINGDIR"
 
31
 
 
32
#test if a version number has been passed as an argument
 
33
if [ -n "$1" ]; then
 
34
   #let's also check if the version number includes the prefix 'bitcoin-',
 
35
   #  and add this prefix if it doesn't
 
36
   if [[ $1 == "$VERSIONPREFIX"* ]]; then
 
37
      VERSION="$1"
 
38
   else
 
39
      VERSION="$VERSIONPREFIX$1"
 
40
   fi
 
41
 
 
42
   #now let's see if the version string contains "rc", and strip it off if it does
 
43
   #  and simultaneously add RCSUBDIR to BASEDIR, where we will look for SIGNATUREFILENAME
 
44
   if [[ $VERSION == *"$RCVERSIONSTRING"* ]]; then
 
45
      BASEDIR="$BASEDIR${VERSION/%-$RCVERSIONSTRING*}/"
 
46
      BASEDIR="$BASEDIR$RCSUBDIR"
 
47
   else
 
48
      BASEDIR="$BASEDIR$VERSION/"
 
49
   fi
 
50
 
 
51
   SIGNATUREFILE="$BASEDIR$SIGNATUREFILENAME"
 
52
else
 
53
   echo "Error: need to specify a version on the command line"
 
54
   exit 2
 
55
fi
 
56
 
 
57
#first we fetch the file containing the signature
 
58
WGETOUT=$(wget -N "$BASEDIR$SIGNATUREFILENAME" 2>&1)
 
59
 
 
60
#and then see if wget completed successfully
 
61
if [ $? -ne 0 ]; then
 
62
   echo "Error: couldn't fetch signature file. Have you specified the version number in the following format?"
 
63
   echo "[$VERSIONPREFIX]<version>-[$RCVERSIONSTRING[0-9]] (example: "$VERSIONPREFIX"0.10.4-"$RCVERSIONSTRING"1)"
 
64
   echo "wget output:"
 
65
   echo "$WGETOUT"|sed 's/^/\t/g'
 
66
   exit 2
 
67
fi
 
68
 
 
69
#then we check it
 
70
GPGOUT=$(gpg --yes --decrypt --output "$TMPFILE" "$SIGNATUREFILENAME" 2>&1)
 
71
 
 
72
#return value 0: good signature
 
73
#return value 1: bad signature
 
74
#return value 2: gpg error
 
75
 
 
76
RET="$?"
 
77
if [ $RET -ne 0 ]; then
 
78
   if [ $RET -eq 1 ]; then
 
79
      #and notify the user if it's bad
 
80
      echo "Bad signature."
 
81
   elif [ $RET -eq 2 ]; then
 
82
      #or if a gpg error has occurred
 
83
      echo "gpg error. Do you have the Bitcoin Core binary release signing key installed?"
 
84
   fi
 
85
 
 
86
   echo "gpg output:"
 
87
   echo "$GPGOUT"|sed 's/^/\t/g'
 
88
   clean_up $SIGNATUREFILENAME $TMPFILE
 
89
   exit "$RET"
 
90
fi
 
91
 
 
92
#here we extract the filenames from the signature file
 
93
FILES=$(awk '{print $2}' "$TMPFILE")
 
94
 
 
95
#and download these one by one
 
96
for file in in $FILES
 
97
do
 
98
   wget --quiet -N "$BASEDIR$file"
 
99
done
 
100
 
 
101
#check hashes
 
102
DIFF=$(diff <(sha256sum $FILES) "$TMPFILE")
 
103
 
 
104
if [ $? -eq 1 ]; then
 
105
   echo "Hashes don't match."
 
106
   echo "Offending files:"
 
107
   echo "$DIFF"|grep "^<"|awk '{print "\t"$3}'
 
108
   exit 1
 
109
elif [ $? -gt 1 ]; then
 
110
   echo "Error executing 'diff'"
 
111
   exit 2   
 
112
fi
 
113
 
 
114
#everything matches! clean up the mess
 
115
clean_up $FILES $SIGNATUREFILENAME $TMPFILE
 
116
 
 
117
echo -e "Verified hashes of \n$FILES"
 
118
 
 
119
exit 0