-
Notifications
You must be signed in to change notification settings - Fork 19
/
upgrade-monero.sh
executable file
Β·385 lines (340 loc) Β· 13.2 KB
/
upgrade-monero.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
#!/bin/bash
#
# Bash script used to install the newest version of the Monero cli on Linux.
# Script will properly validate downloads, verify gpg signatures and checksums.
# Tested with v0.15.0.5 - v0.17.1.0
# See upgrade-monero-old.sh for older versions signed by Fluffy.
#
# REQUIREMENTS:
#
# 1. Import GPG Key for BinaryFate:
# gpg --keyserver hkps://keyserver.ubuntu.com --recv-key 81AC591FE9C4B65C5806AFC3F0AF4D462A0BDF92
#
# 2. Trust it:
# echo -e "trust\n5\ny\n" | gpg --command-fd 0 --edit-key 81AC591FE9C4B65C5806AFC3F0AF4D462A0BDF92
#
# 3. Configure the settings below (see CONFIGURATION) to match your system.
#
# EXAMPLE USAGE:
#
# ./upgrade-monero.sh
#
# Upgrading the Monero daemon
# ===========================
# * Downloading Hashes: https://www.getmonero.org/downloads/hashes.txt
# Saved as: /tmp/monero_hashes_17975.txt
# Signature data?: [CONFIRMED]
# * New version: v0.15.0.5
# * Destination: /home/USER/bin/
# * Downloading Release: https://downloads.getmonero.org/cli/monero-linux-x64-v0.15.0.5.tar.bz2
#
# Checking for BinaryFate's gpg key in keyring... [key found]
#
# Verifying gpg signature in monero_hashes_17975.txt:
# gpg: Signature made Wed 18 Mar 2020 10:51:04 PM CET
# gpg: Good signature from "binaryFate <[email protected]>" [ultimate]
# Primary key fingerprint: 81AC 591F E9C4 B65C 5806 AFC3 F0AF 4D46 2A0B DF92
# Signature VERIFIED.
#
# Verifying hashes:
# * Expected: 6cae57cdfc89d85c612980c6a71a0483bbfc1b0f56bbb30e87e933e7ba6fc7e7
# * Actual: 6cae57cdfc89d85c612980c6a71a0483bbfc1b0f56bbb30e87e933e7ba6fc7e7
# * Gitian: 6cae57cdfc89d85c612980c6a71a0483bbfc1b0f56bbb30e87e933e7ba6fc7e7
# Hashes match.
#
# Extracting files from monero-linux-x64-v0.15.0.5.tar.bz2... Done.
# - Renaming extracted folder... Done.
#
# Moving extracted folder to /home/USER/bin/... Done.
# Replacing soft links:
# 'monerod' -> 'monero-v0.15.0.5/monerod'
# 'monero-wallet-cli' -> 'monero-v0.15.0.5/monero-wallet-cli'
# 'monero-wallet-rpc' -> 'monero-v0.15.0.5/monero-wallet-rpc'
#
# Confirming installation... CONFIRMED: Monero 'Carbon Chamaeleon' (v0.15.0.5-release)
# You can now delete the downloaded files in /tmp
#
# DONE.
################################################################################
# AUTHOR: Jonathan Cross 0xC0C076132FFA7695 (jonathancross.com)
# LICENSE: WTFPL - https://github.com/jonathancross/jc-docs/blob/master/LICENSE
# BUGS: https://github.com/jonathancross/jc-docs/issues/new
################################################################################
################################################################################
# BEGIN CONFIGURATION
################################################################################
# Folder locations, please change as needed:
TMP=/tmp # Folder (without trailing slash) where files are downloaded to.
DEST=~/bin # Destination (without trailing slash) where we will install.
# TODO: Add configuration options for commands needed such as openssl.
# Items below can be modified, but in most cases should work fine as-is.
# GitHub user trusted to have created Gitian assert files for this release:
GH_USER=TheCharlatan
# OpenPGP Fingerprint for the above user (ignored currently):
# GH_USER_KEY_FPR="9A8FC 55F3 B04B A314 6F34 92E7 9303 B33A 3052 24CB"
# Repo URL for Gitian assert files:
GITIAN_REPO="https://raw.githubusercontent.com/monero-project/gitian.sigs"
# File containing release hashes. This tells us the version number as well:
HASHES_URL='https://www.getmonero.org/downloads/hashes.txt'
# egrep pattern for Linux archive file (unfortunately this changes regularly):
NEW_VERSION_PATTERN='monero-linux-x64-v[0-9.]+.tar.bz2'
# Prefix (without version number) of the folder extracted from the bzip archive:
EXTRACTED_FOLDER_PREFIX="monero-x86_64-linux-gnu-"
# URL prefix containing the release (without filename):
BZIP_URL_PREFIX='https://downloads.getmonero.org/cli/'
# BinaryFate's PGP key fingerprint:
GPG_KEY_FPR='81AC 591F E9C4 B65C 5806 AFC3 F0AF 4D46 2A0B DF92'
# Hard code expected UID in gpg key to check for fakes:
GPG_KEY_UID='binaryFate <[email protected]>'
# URL for Gitian signatures built reproducibly:
GITIAN_URL='https://github.com/monero-project/gitian.sigs'
################################################################################
# END CONFIGURATION
################################################################################
WARNING_MSG="
--------------------------------------------------------------------------------
This may be the result of a download error, dev mistake or foul play.
DO NOT PROCEED until you determine the cause."
echo "
Upgrading the Monero daemon
==========================="
# Make sure DEST exists:
if [[ ! -d "${DEST}/" ]]; then
echo "ERROR: Could not find DEST ($DEST).
You must configure this as path to the destination folder.";
exit 1;
fi
# Make sure TMP exists:
if [[ ! -d "${TMP}/" ]]; then
echo "ERROR: Could not find TMP ($TMP).
You must configure this as a full path to the directory used for temp files.";
exit 1;
fi
cd "${TMP}"
# Temporary file name for hashes to make sure unique.
HASHES_FILE="monero_hashes_$$.txt"
# Get HASHES_FILE from HASHES_URL:
if [[ -f "${TMP}/${HASHES_FILE}" ]]; then
echo " * Signed Hashes: ${TMP}/${HASHES_FILE}"
else
echo " * Downloading Hashes: ${HASHES_URL}"
if curl --silent "${HASHES_URL}" --output "${HASHES_FILE}"; then
echo " Saved as: ${TMP}/${HASHES_FILE}"
# Check if HASHES_FILE actually downloaded (they keep changing location)
echo -n " Signature data?: "
if grep -q "BEGIN PGP SIGNED MESSAGE" "${HASHES_FILE}"; then
echo " [CONFIRMED]"
else
echo " [ERROR: Not a GPG signature]"
exit 1
fi
else
echo "ERROR: Could not download ${TMP}/${HASHES_FILE}"
exit 1
fi
fi
# Extract version number and file name:
NEW_VERSION_PATTERN_PREFIX="${NEW_VERSION_PATTERN%[*}"
NEW_BZIP=$(egrep --only-matching "${NEW_VERSION_PATTERN}" "${HASHES_FILE}")
# Check if we got something:
if [[ "${NEW_BZIP}" != *"${NEW_VERSION_PATTERN_PREFIX}"* ]]; then
echo "ERROR: Could not extract new version info from hashes.txt using NEW_VERSION_PATTERN.
NEW_VERSION_PATTERN = ${NEW_VERSION_PATTERN}
HASHES_FILE = ${TMP}/${HASHES_FILE}
Maybe file name format changed?"
exit 1
fi
# Continue now that we know we have something:
NEW_VER=${NEW_BZIP##*-} # Strip off prefix
NEW_VER=${NEW_VER%.tar.bz2} # Strip off suffix
# Determine the major version (used later for URLs):
VER_REGEX='v(0\.[0-9][0-9])\.'
[[ $NEW_VER =~ $VER_REGEX ]] && VER_MAJOR="${BASH_REMATCH[1]}"
NEW_TAR="${NEW_VER}.tar" # Add back the .tar suffix
EXTRACTED_FOLDER_NAME="${EXTRACTED_FOLDER_PREFIX}${NEW_VER}"
NEW_VERSION_FOLDER="monero-${NEW_VER}"
BZIP_URL="${BZIP_URL_PREFIX}${NEW_BZIP}"
echo " * New version: ${NEW_VER}"
echo " * Destination: ${DEST}/"
# Check if this version is already installed:
if [[ -d "${DEST}/${NEW_VERSION_FOLDER}" ]]; then
echo "
Seems this version is already installed:
${DEST}/${NEW_VERSION_FOLDER}
Nothing to do, exiting.
"
exit 0
fi
# Download BZIP file:
if [[ -f "${TMP}/${NEW_BZIP}" ]]; then
echo " * Release file already downloaded: ${TMP}/${NEW_BZIP}"
else
echo " * Downloading Release: ${BZIP_URL}"
printf " "
if curl --progress-bar "${BZIP_URL}" --output "${TMP}/${NEW_BZIP}"; then
echo " Saved as: ${TMP}/${NEW_BZIP}"
else
echo "ERROR: Could not download ${TMP}/${NEW_BZIP}"
exit 1
fi
fi
echo ''
# Check if we have the GPG signing key in the local keyring:
# TODO: Put this in a for loop to also get $GH_USER_KEY_FPR
GPG_KEY_HANDLE="${GPG_KEY_FPR:30}" # Extract last 64 bits
GPG_KEY_HANDLE="${GPG_KEY_HANDLE// /}" # Remove spaces
echo -n "Checking for BinaryFate's gpg key in keyring..."
if gpg -k 0x${GPG_KEY_HANDLE} &> /dev/null; then
echo " [key found]"
else
echo " [key NOT found]"
echo -n "Importing from keyserver..."
if gpg --keyserver keyserver.ubuntu.com --recv-key "${GPG_KEY_FPR}" &> /dev/null; then
echo " [OK]"
else
echo "
ERROR: Could not import this key from the keyserver:
${GPG_KEY_FPR}
Please import manually and try this script again."
exit 1
fi
fi
# Use GPG key to verify hashes.txt:
echo -e "\nVerifying gpg signature in ${HASHES_FILE}:"
SIG_ERROR=1
SIG_RESULT="$(gpg --verbose --verify ${HASHES_FILE} 2>&1)"
# Did the command complete successfully?
if [[ "$?" == '0' ]]; then
# Is the signature valid?
if [[ "${SIG_RESULT}" == *"Good signature from"* ]]; then
# Was the signature made with the correct key?
if [[ "${SIG_RESULT}" == *"${GPG_KEY_FPR}"* ]]; then
SIG_ERROR=0
# Print simplified results:
echo "${SIG_RESULT}" | grep --perl-regexp '(Signature made|Good signature from|Primary key fingerprint)'
echo "Signature VERIFIED."
fi
fi
fi
# Check the results of the signature verification:
if [[ "${SIG_ERROR}" == "1" ]]; then
echo "ERROR: Bad signature for BinaryFate's key:
${GPG_KEY_FPR}"
if [[ "${SIG_RESULT}" == *"primary key ${GPG_KEY_HANDLE}"* ]]; then
echo "Key was correct, but signature is invalid (file may have been modified?)."
elif [[ "${SIG_RESULT}" == *"no signature found"* ]]; then
echo "Signature is invalid / modified or doesn't exist."
else
echo "WARNING: File signed using incorrect key."
if [[ "${SIG_RESULT}" == *"${GPG_KEY_UID}"* ]]; then
echo " Key looks like an impostor pretending to be ${GPG_KEY_UID}."
fi
fi
echo "
Signature debugging info:
${SIG_RESULT}
${WARNING_MSG}"
exit 1
fi
# Verify file checksums against those in hashes.txt
echo -e "\nVerifying hashes:"
HASH_EXPECTED="$(grep "${NEW_BZIP}" "${HASHES_FILE}")"
HASH_EXPECTED="${HASH_EXPECTED%% *}" # Remove everything after first space.
echo " * Expected: ${HASH_EXPECTED}"
HASH_ACTUAL="$(openssl dgst -sha256 "${NEW_BZIP}" | cut -d ' ' -f 2)"
HASH_ACTUAL="${HASH_ACTUAL%% *}" # Remove everything after first space.
echo " * Actual: ${HASH_ACTUAL}"
if [[ "${HASH_EXPECTED}" != "${HASH_ACTUAL}" ]]; then
echo "
ERROR: Hashes DO NOT match.
You can manually verify by comparing with hashes found here:
${HASHES_URL}
And / or here:
${GITIAN_URL}
${WARNING_MSG}"
exit 1
fi
# Build the URL to the Gitian assert file we will check for a hash match:
GITIAN_ASSERT_FILE="monero-linux-${VER_MAJOR}-build.assert"
GITIAN_ASSERT_URL="${GITIAN_REPO}/master/${NEW_VER}-linux/${GH_USER}/${GITIAN_ASSERT_FILE}"
GITIAN_ASSERT_DOWNLOAD_ERROR=1 # Assume an error unless we know we succeed below.
# Downloading Gitian assert file and sig from GitHub to cross-check:
if curl -s --remote-name-all ${GITIAN_ASSERT_URL}{,.sig}; then
# Check if the files were actually downloaded:
if [[ -f "${GITIAN_ASSERT_FILE}" && -f "${GITIAN_ASSERT_FILE}.sig" ]]; then
GITIAN_ASSERT_DOWNLOAD_ERROR=0
fi
fi
if [[ "${GITIAN_ASSERT_DOWNLOAD_ERROR}" == "1" ]]; then
echo "ERROR: Failed to download assert file for ${NEW_VER} from:"
echo "${GITIAN_ASSERT_URL}"
exit 1
fi
###############################################################################
# TODO: check the signature on the assert file using $GH_USER_KEY_FPR.
###############################################################################
# Compare Gitian hash to ours:
GITIAN_ASSERT_HASH=$(grep --only-matching "${HASH_ACTUAL}" "${GITIAN_ASSERT_FILE}")
if [[ "x${GITIAN_ASSERT_HASH}" == "x${HASH_ACTUAL}" ]]; then
echo " * Gitian: ${GITIAN_ASSERT_HASH}"
echo "Hashes match."
else
echo "ERROR: Gitian hash DOES NOT match ours.
You can manually verify by comparing hash above to those found here:
${GITIAN_ASSERT_URL}
${WARNING_MSG}"
exit 1
fi
# FINISHED CHECKING HASHES
echo -en "
Extracting files from ${NEW_BZIP}... "
if tar --extract --bzip2 --file "${NEW_BZIP}"; then
echo "Done."
echo -n " - Renaming extracted folder..."
if [[ -d "${NEW_VERSION_FOLDER}" ]]; then
echo -en " [cleaning up old files] "
rm -rf "${NEW_VERSION_FOLDER}"
fi
if mv -f "${EXTRACTED_FOLDER_NAME}" "${NEW_VERSION_FOLDER}"; then
echo " Done."
else
echo "ERROR: Failed to rename ${EXTRACTED_FOLDER_NAME} to ${NEW_VERSION_FOLDER}."
echo " Script probably needs to be updated with new folder name."
exit 1
fi
else
echo "ERROR: Failed to expand ${NEW_BZIP}"
exit 1
fi
# Create softlinks if possible:
if [[ -d "${NEW_VERSION_FOLDER}" ]]; then
echo -en "\nMoving extracted folder to ${DEST}/... "
cp -Rf "${NEW_VERSION_FOLDER}" "${DEST}/"
cd "${DEST}/"
echo -e "Done.\nReplacing soft links:"
for APP in monerod monero-wallet-cli monero-wallet-rpc; do
printf ' '
ln -sfv "${NEW_VERSION_FOLDER}/${APP}" "${APP}"
done
echo -en "\nConfirming installation..."
INSTALLED_VER="$(${DEST}/monerod --version)"
PATH_VER="$(monerod --version)"
if [[ "$INSTALLED_VER" == "$PATH_VER" ]]; then
echo " CONFIRMED: $PATH_VER"
echo "You can now delete the downloaded files in $TMP"
else
echo -e "\nWARNING: ${DEST}/monerod doesn't seem to be in your PATH."
echo -e " Instead we found $(which monerod)"
fi
else
echo '
NOTE: Folder name has changed, you must manually install:
NEW_VERSION_FOLDER=new_name_of_extracted_folder_here;
cp -R "${NEW_VERSION_FOLDER}" "'${DEST}/'";
cd "'${DEST}/'";
for APP in monerod monero-wallet-cli monero-wallet-rpc;
do ln -sfv "${NEW_VERSION_FOLDER}/${APP}" "${APP}";
done;
';
fi
echo -e "\nDONE."