2020-03-09 17:19:53 +00:00
#!/bin/bash
set -eu
# Use this script to download the latest Prysm release binary.
2020-04-26 18:25:48 +00:00
# Usage: ./prysm.sh PROCESS [--download-only] FLAGS
2020-03-09 17:19:53 +00:00
# PROCESS can be one of beacon-chain or validator.
# FLAGS are the flags or arguments passed to the PROCESS.
2020-04-26 18:25:48 +00:00
# If --download-only flag is passed, binaries are checked for updates,
# downloaded if necessary, no process is started.
# Downloaded binaries are saved to ./dist.
# Use USE_PRYSM_VERSION to specify a specific release version.
2020-03-09 17:19:53 +00:00
# Example: USE_PRYSM_VERSION=v0.3.3 ./prysm.sh beacon-chain
2020-04-26 18:25:48 +00:00
readonly PRYLABS_SIGNING_KEY = 0AE0051D647BA3C1A917AF4072E33E4DF1A5036E
2020-04-23 14:57:21 +00:00
2020-03-09 17:19:53 +00:00
function color( ) {
2020-04-26 18:25:48 +00:00
# Usage: color "31;5" "string"
# Some valid values for color:
# - 5 blink, 1 strong, 4 underlined
# - fg: 31 red, 32 green, 33 yellow, 34 blue, 35 purple, 36 cyan, 37 white
# - bg: 40 black, 41 red, 44 blue, 45 purple
printf '\033[%sm%s\033[0m\n' " $@ "
2020-03-09 17:19:53 +00:00
}
# `readlink -f` that works on OSX too.
function get_realpath( ) {
if [ " $( uname -s) " = = "Darwin" ] ; then
local queue = " $1 "
2020-04-26 18:25:48 +00:00
if [ [ " ${ queue } " != /* ] ] ; then
2020-03-09 17:19:53 +00:00
# Make sure we start with an absolute path.
queue = " ${ PWD } / ${ queue } "
fi
local current = ""
while [ -n " ${ queue } " ] ; do
# Removing a trailing /.
queue = " ${ queue #/ } "
# Pull the first path segment off of queue.
local segment = " ${ queue %%/* } "
# If this is the last segment.
2020-04-26 18:25:48 +00:00
if [ [ " ${ queue } " != */* ] ] ; then
2020-03-09 17:19:53 +00:00
segment = " ${ queue } "
queue = ""
else
# Remove that first segment.
queue = " ${ queue #*/ } "
fi
local link = " ${ current } / ${ segment } "
2020-04-26 18:25:48 +00:00
if [ -h " ${ link } " ] ; then
2020-03-09 17:19:53 +00:00
link = " $( readlink " ${ link } " ) "
queue = " ${ link } / ${ queue } "
2020-04-26 18:25:48 +00:00
if [ [ " ${ link } " = = /* ] ] ; then
2020-03-09 17:19:53 +00:00
current = ""
fi
else
current = " ${ link } "
fi
done
echo " ${ current } "
else
readlink -f " $1 "
fi
}
# Complain if no arguments were provided.
if [ " $# " -lt 1 ] ; then
color "31" "Usage: ./prysm.sh PROCESS FLAGS."
2020-04-26 18:25:48 +00:00
color "31" " ./prysm.sh PROCESS --download-only."
2020-04-23 14:57:21 +00:00
color "31" "PROCESS can be beacon-chain, validator, or slasher."
2020-03-09 17:19:53 +00:00
exit 1
fi
readonly wrapper_dir = " $( dirname " $( get_realpath " ${ BASH_SOURCE [0] } " ) " ) /dist "
arch = $( uname -m)
arch = ${ arch /x86_64/amd64 }
arch = ${ arch /aarch64/arm64 }
2020-04-19 08:15:52 +00:00
readonly os_arch_suffix = " $( uname -s | tr '[:upper:]' '[:lower:]' ) - $arch "
2020-04-17 19:11:51 +00:00
system = ""
case " $OSTYPE " in
2020-04-26 18:25:48 +00:00
darwin*) system = "darwin" ; ;
linux*) system = "linux" ; ;
msys*) system = "windows" ; ;
cygwin*) system = "windows" ; ;
*) exit 1 ; ;
2020-04-17 19:11:51 +00:00
esac
2020-04-23 14:57:21 +00:00
readonly system
2020-04-19 08:15:52 +00:00
if [ " $system " = = "windows" ] ; then
2020-04-26 18:25:48 +00:00
arch = "amd64.exe"
2020-04-19 08:15:52 +00:00
elif [ [ " $os_arch_suffix " = = *"arm64" * ] ] ; then
2020-04-26 18:25:48 +00:00
arch = "arm64"
2020-04-17 19:11:51 +00:00
fi
2020-03-09 17:19:53 +00:00
2020-04-26 18:25:48 +00:00
if [ [ " $arch " = = "armv7l" ] ] ; then
color "31" "32-bit ARM is not supported. Please install a 64-bit operating system."
exit 1
2020-04-25 20:44:17 +00:00
fi
2020-03-09 17:19:53 +00:00
mkdir -p $wrapper_dir
function get_prysm_version( ) {
2020-04-26 18:25:48 +00:00
if [ [ -n ${ USE_PRYSM_VERSION :- } ] ] ; then
readonly reason = "specified in \$USE_PRYSM_VERSION"
readonly prysm_version = " ${ USE_PRYSM_VERSION } "
else
# Find the latest Prysm version available for download.
readonly reason = "automatically selected latest available version"
2020-05-28 10:00:19 +00:00
prysm_version = $( curl -f -s https://prysmaticlabs.com/releases/latest) || ( color "31" "Starting prysm requires an internet connection. If you are being blocked by your antivirus, you can re-run with --ssl-no-revoke" && exit 1)
2020-04-26 18:25:48 +00:00
readonly prysm_version
fi
2020-03-09 17:19:53 +00:00
}
2020-04-23 14:57:21 +00:00
function verify( ) {
2020-04-26 18:25:48 +00:00
file = $1
2020-04-26 14:09:09 +00:00
2020-04-26 18:25:48 +00:00
skip = ${ PRYSM_ALLOW_UNVERIFIED_BINARIES -0 }
if [ [ $skip = = 1 ] ] ; then
return 0
fi
2020-09-29 12:22:35 +00:00
checkSum = "shasum -a 256"
2020-04-26 18:25:48 +00:00
hash shasum 2>/dev/null || {
2020-09-29 12:22:35 +00:00
checkSum = "sha256sum"
hash sha256sum 2>/dev/null || {
echo >& 2 "SHA checksum utility not available. Either install one (shasum or sha256sum) or run with PRYSM_ALLOW_UNVERIFIED_BINARIES=1."
exit 1
}
2020-04-26 18:25:48 +00:00
}
hash gpg 2>/dev/null || {
echo >& 2 "gpg is not available. Either install it or run with PRYSM_ALLOW_UNVERIFIED_BINARIES=1."
exit 1
}
color "37" "Verifying binary integrity."
gpg --list-keys $PRYLABS_SIGNING_KEY >/dev/null 2>& 1 || curl --silent https://prysmaticlabs.com/releases/pgp_keys.asc | gpg --import
(
cd $wrapper_dir
2020-09-29 12:22:35 +00:00
$checkSum -c " ${ file } .sha256 " || failed_verification
2020-04-26 18:25:48 +00:00
)
(
cd $wrapper_dir
gpg -u $PRYLABS_SIGNING_KEY --verify " ${ file } .sig " $file || failed_verification
)
color "32;1" " Verified ${ file } has been signed by Prysmatic Labs. "
2020-04-23 14:57:21 +00:00
}
function failed_verification( ) {
2020-04-26 18:25:48 +00:00
MSG = $(
cat <<-END
2020-04-26 14:09:09 +00:00
Failed to verify Prysm binary. Please erase downloads in the
dist directory and run this script again. Alternatively, you can use a
A prior version by specifying environment variable USE_PRYSM_VERSION
with the specific version, as desired. Example: USE_PRYSM_VERSION = v1.0.0-alpha.5
If you must wish to continue running an unverified binary, specific the
environment variable PRYSM_ALLOW_UNVERIFIED_BINARIES = 1
END
2020-04-26 18:25:48 +00:00
)
color "31" " $MSG "
exit 1
2020-04-23 14:57:21 +00:00
}
2020-03-09 17:19:53 +00:00
get_prysm_version
color "37" " Latest Prysm version is $prysm_version . "
2020-04-17 19:11:51 +00:00
BEACON_CHAIN_REAL = " ${ wrapper_dir } /beacon-chain- ${ prysm_version } - ${ system } - ${ arch } "
VALIDATOR_REAL = " ${ wrapper_dir } /validator- ${ prysm_version } - ${ system } - ${ arch } "
2020-04-23 14:57:21 +00:00
SLASHER_REAL = " ${ wrapper_dir } /slasher- ${ prysm_version } - ${ system } - ${ arch } "
2020-04-26 18:25:48 +00:00
if [ [ $1 = = beacon-chain ] ] ; then
if [ [ ! -x $BEACON_CHAIN_REAL ] ] ; then
color "34" " Downloading beacon chain@ ${ prysm_version } to ${ BEACON_CHAIN_REAL } ( ${ reason } ) "
file = beacon-chain-${ prysm_version } -${ system } -${ arch }
curl -L " https://prysmaticlabs.com/releases/ ${ file } " -o $BEACON_CHAIN_REAL
curl --silent -L " https://prysmaticlabs.com/releases/ ${ file } .sha256 " -o " ${ wrapper_dir } / ${ file } .sha256 "
curl --silent -L " https://prysmaticlabs.com/releases/ ${ file } .sig " -o " ${ wrapper_dir } / ${ file } .sig "
chmod +x $BEACON_CHAIN_REAL
else
color "37" "Beacon chain is up to date."
fi
2020-04-23 14:57:21 +00:00
fi
2020-03-09 17:19:53 +00:00
2020-04-26 18:25:48 +00:00
if [ [ $1 = = validator ] ] ; then
if [ [ ! -x $VALIDATOR_REAL ] ] ; then
color "34" " Downloading validator@ ${ prysm_version } to ${ VALIDATOR_REAL } ( ${ reason } ) "
file = validator-${ prysm_version } -${ system } -${ arch }
curl -L " https://prysmaticlabs.com/releases/ ${ file } " -o $VALIDATOR_REAL
curl --silent -L " https://prysmaticlabs.com/releases/ ${ file } .sha256 " -o " ${ wrapper_dir } / ${ file } .sha256 "
curl --silent -L " https://prysmaticlabs.com/releases/ ${ file } .sig " -o " ${ wrapper_dir } / ${ file } .sig "
chmod +x $VALIDATOR_REAL
else
color "37" "Validator is up to date."
fi
2020-03-09 17:19:53 +00:00
fi
2020-04-23 14:57:21 +00:00
if [ [ $1 = = slasher ] ] ; then
2020-04-26 18:25:48 +00:00
if [ [ ! -x $SLASHER_REAL ] ] ; then
color "34" " Downloading slasher@ ${ prysm_version } to ${ SLASHER_REAL } ( ${ reason } ) "
file = slasher-${ prysm_version } -${ system } -${ arch }
curl -L " https://prysmaticlabs.com/releases/ ${ file } " -o $SLASHER_REAL
curl --silent -L " https://prysmaticlabs.com/releases/ ${ file } .sha256 " -o " ${ wrapper_dir } / ${ file } .sha256 "
curl --silent -L " https://prysmaticlabs.com/releases/ ${ file } .sig " -o " ${ wrapper_dir } / ${ file } .sig "
chmod +x $SLASHER_REAL
else
color "37" "Slasher is up to date."
fi
2020-03-09 17:19:53 +00:00
fi
case $1 in
2020-04-26 18:25:48 +00:00
beacon-chain)
2020-03-09 17:19:53 +00:00
readonly process = $BEACON_CHAIN_REAL
; ;
2020-04-26 18:25:48 +00:00
validator)
2020-03-09 17:19:53 +00:00
readonly process = $VALIDATOR_REAL
; ;
2020-04-26 18:25:48 +00:00
slasher)
2020-04-23 14:57:21 +00:00
readonly process = $SLASHER_REAL
; ;
2020-04-26 18:25:48 +00:00
*)
2020-05-05 13:23:09 +00:00
color "31" " Process ' $1 ' is not found! "
2020-03-09 17:19:53 +00:00
color "31" "Usage: ./prysm.sh PROCESS FLAGS."
2020-04-26 18:25:48 +00:00
color "31" " ./prysm.sh PROCESS --download-only."
2020-04-23 14:57:21 +00:00
color "31" "PROCESS can be beacon-chain, validator, or slasher."
2020-05-05 13:23:09 +00:00
exit 1
2020-03-09 17:19:53 +00:00
; ;
esac
2020-04-23 14:57:21 +00:00
verify $process
2020-04-26 21:24:32 +00:00
if [ [ " $# " -gt 1 ] ] && [ [ $2 = = --download-only ] ] ; then
2020-04-26 18:25:48 +00:00
color "37" "Only download operation is requested, done."
exit 0
fi
2020-04-23 15:24:45 +00:00
color "36" " Starting Prysm $1 ${ * : 2 } "
2020-04-17 19:11:51 +00:00
exec -a " $0 " " ${ process } " " ${ @ : 2 } "