-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevmrup
115 lines (95 loc) · 3.02 KB
/
evmrup
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
#!/usr/bin/env bash
set -e
# -----------------------------------------------------------
# Forked from Foundry.
# https://github.com/foundry-rs/foundry/tree/master/foundryup
# -----------------------------------------------------------
# Define variables
EVMR_DIR="${HOME}/.evm-runners"
EVMR_BIN_DIR="${EVMR_DIR}/bin"
ENV_FILE="${EVMR_DIR}/.env"
APP_NAME="evm-runners"
APP_NAME_ALT="evmr"
main() {
need_cmd curl
PLATFORM="$(uname -s)"
case $PLATFORM in
Linux)
PLATFORM="linux"
;;
Darwin)
PLATFORM="darwin"
;;
*)
err "unsupported platform: $PLATFORM"
;;
esac
# Determine architecture
ARCH="$(uname -m)"
if [ "$ARCH" = "x86_64" ]; then
# Redirect stderr to /dev/null to avoid printing errors if non Rosetta.
if [ "$(sysctl -n sysctl.proc_translated 2>/dev/null)" = "1" ]; then
ARCH="arm64" # Rosetta
else
ARCH="amd64" # Intel
fi
elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
ARCH="arm64" # Arm
else
ARCH="amd64" # Amd
fi
# Determine latest version
VERSION="$(curl -s https://api.github.com/repos/ethernautdao/evm-runners-cli/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')"
if [ -z "$VERSION" ]; then
err "failed to determine latest version"
fi
# Download release binary
DOWNLOAD_URL="https://github.com/ethernautdao/evm-runners-cli/releases/download/$VERSION/$APP_NAME-$PLATFORM-$ARCH"
say "Installing evm-runners version $VERSION for $PLATFORM-$ARCH"
# Download binary, make it executable, and move it to the bin directory
ensure curl -# -L $DOWNLOAD_URL -o $APP_NAME
ensure chmod +x $APP_NAME
ensure mv $APP_NAME $EVMR_BIN_DIR
# create evmr symlink
ensure ln -sf $EVMR_BIN_DIR/$APP_NAME $EVMR_BIN_DIR/$APP_NAME_ALT
# Create .env file and add/update the EVMR_VERSION environment variable
if [ ! -f "$ENV_FILE" ]; then
# If the .env file doesn't exist, create it and add EVMR_VERSION
echo "EVMR_VERSION=$VERSION" > "$ENV_FILE"
elif grep -q "^EVMR_VERSION=" "$ENV_FILE"; then
# If EVMR_VERSION exists, update it
sed -i "s/^EVMR_VERSION=.*/EVMR_VERSION=$VERSION/" "$ENV_FILE"
else
# If EVMR_VERSION doesn't exist, append it to the file
echo "EVMR_VERSION=$VERSION" >> "$ENV_FILE"
fi
echo && say "$APP_NAME version $VERSION installed successfully!"
echo && say "If this is your first install, start a new terminal session to use evm-runners."
say "Then run 'evmr help', or alternatively 'evm-runners help', to get started."
echo && say "To update evm-runners in the future, just run 'evmrup' again."
}
say() {
printf 'evmrup: %s\n' "$1"
}
warn() {
say "warning: ${1}" >&2
}
err() {
say "$1" >&2
exit 1
}
need_cmd() {
if ! check_cmd "$1"; then
err "need '$1' (command not found)"
fi
}
check_cmd() {
command -v "$1" > /dev/null 2>&1
}
# Run a command that should never fail. If the command fails execution
# will immediately terminate with an error showing the failing
# command.
ensure() {
if ! "$@"; then err "command failed: $*"; fi
}
main "$@" || exit 1