forked from paritytech/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-parity.sh
executable file
·179 lines (146 loc) · 4.52 KB
/
get-parity.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
# Copyright 2015-2020 Parity Technologies (UK) Ltd.
## Update this with any new relase!
VERSION_STABLE="2.7.2"
##
RELEASE="stable"
ARCH=$(uname -m)
VANITY_SERVICE_URL="https://vanity-service.parity.io/parity-binaries?architecture=$ARCH&format=markdown"
check_os() {
if [ "$(uname)" = "Linux" ] ; then
PKG="linux" # linux is my default
elif [ "$(uname)" = "Darwin" ] ; then
PKG="darwin"
echo "Running on Apple"
else
echo "Unknown operating system"
echo "Please select your operating system"
echo "Choices:"
echo " linux - any linux distro"
echo " darwin - MacOS"
read -r PKG
fi
}
get_package() {
if [ "$RELEASE" = "stable" ]; then
LOOKUP_URL="$VANITY_SERVICE_URL&os=$PKG&version=v$VERSION_STABLE"
else
LOOKUP_URL="$VANITY_SERVICE_URL&os=$PKG&version=$RELEASE"
fi
MD=$(curl -Ss "${LOOKUP_URL}" | grep -v sha256 | grep " \[parity\]")
DOWNLOAD_FILE=$(echo "$MD" | grep -oE 'https://[^)]+')
}
check_upgrade() {
# Determine new Version
case "$RELEASE" in
"stable") NEW_VERSION=$VERSION_STABLE
;;
*) NEW_VERSION=$(echo "$DOWNLOAD_FILE" | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' | tr -d 'v')
;;
esac
# Determine old (installed) Version
parity_bin=$(which parity)
if [ -z "$parity_bin" ] ; then
OLD_VERSION="0.0.0"
else
OLD_VERSION=$(parity --version | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' | tr -d 'v')
fi
if [ "$NEW_VERSION" = "$OLD_VERSION" ] ; then
echo "Parity $NEW_VERSION already installed"
exit 1
fi
if version_gt "$NEW_VERSION" "$OLD_VERSION" ; then
echo "Upgrading parity from $OLD_VERSION to $NEW_VERSION"
else
echo "Existing version of parity: $OLD_VERSION is newer than the version you attempting to install: $NEW_VERSION"
exit 1
fi
}
install() {
TMPDIR=$(mktemp -d) && cd "$TMPDIR" || exit
curl -Ss -O "$DOWNLOAD_FILE"
check_sha256
if [ "$PKG" = "linux" ] ; then
sudo cp "$TMPDIR"/parity /usr/bin && sudo chmod +x /usr/bin/parity
fi
if [ "$PKG" = "darwin" ] ; then
sudo cp "$TMPDIR"/parity /usr/local/bin && sudo chmod +x /usr/local/bin/parity
fi
}
version_gt() {
test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1";
}
help() {
echo "Usage is: -r --release [ stable / beta / nightly ]"
}
check_sha256() {
# how to check for sha256?
SHA256_CHECK=$(which sha256sum 2> /dev/null)
if [[ -z $SHA256_CHECK ]] ; then
# no sha256sum? try with rhash ...
SHA256_CHECK=$(which rhash 2> /dev/null)
SHA256_CHECK="$SHA256_CHECK --sha256"
fi
if [ "$PKG" = "darwin" ] ; then
SHA256_CHECK="shasum -a 256"
fi
# see if we can call the binary to calculate sha256 sums
if ! ($SHA256_CHECK --version &> /dev/null) then
echo "Unable to check SHA256 checksum, please install sha256sum or rhash binary"
cleanup
exit 1
fi
# $SHA256_CHECK $TMPDIR/$DOWNLOAD_FILE
IS_CHECKSUM=$($SHA256_CHECK "$TMPDIR"/parity | awk '{print $1}')
MUST_CHECKSUM=$(curl -sS "$LOOKUP_URL" | grep ' \[parity\]' | awk '{print $NF}')
# debug # echo -e "is checksum:\t $IS_CHECKSUM"
# debug # echo -e "must checksum:\t $MUST_CHECKSUM"
if [[ $IS_CHECKSUM != "$MUST_CHECKSUM" ]]; then
echo "SHA256 Checksum missmatch, aboarding installation"
cleanup
exit 1
fi
}
cleanup() {
rm "$TMPDIR"/*
rmdir "$TMPDIR"
}
## MAIN ##
cat << EOF
+====================================================================================+
| [!] Parity Ethereum is now Open Ethereum! As a result, this script will no longer |
| be maintained, and there are no guarantees about availability of the binaries. |
| The new home for Open Ethereum is https://github.com/OpenEthereum/open-ethereum/ |
| Any further development of the project can be tracked from this page. |
| For more information, see: https://www.parity.io/parity-ethereum-openethereum-dao/ |
=====================================================================================+
EOF
sleep 2
## curl installed?
if ! which curl &> /dev/null ; then
echo '"curl" binary not found, please install and retry'
exit 1
fi
##
while [ "$1" != "" ]; do
case $1 in
-r | --release ) shift
RELEASE=$1
;;
* ) help
exit 1
esac
shift
done
echo "Release selected is: $RELEASE"
if [ "$RELEASE" == "beta" ]; then
echo "[!] As of v2.7.0, parity-ethereum now uses a single release track, 'stable'. All prior versions are now deprecated. In order to continue receiving updates to your parity-ethereum client, please switch to the 'stable' track."
exit 1
fi
check_os
get_package
if [ "$RELEASE" != "nightly" ] ; then
check_upgrade
fi
install
cleanup