-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔨 Refactor install.sh and add evmrup
- Loading branch information
Showing
2 changed files
with
146 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#!/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" | ||
|
||
VERSION="v0.4.1" | ||
|
||
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 | ||
|
||
# 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'." | ||
} | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,118 +1,45 @@ | ||
#!/bin/bash | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
echo "Installing evmrup..." | ||
|
||
# Define variables | ||
APP_NAME="evm-runners" | ||
APP_NAME_ALT="evmr" | ||
EVMR_DIR="${HOME}/.${APP_NAME}" | ||
EVMR_DIR="${HOME}/.evm-runners" | ||
EVMR_BIN_DIR="${EVMR_DIR}/bin" | ||
GITHUB_USER="ethernautdao" | ||
GITHUB_REPO="evm-runners-cli" | ||
VERSION="v0.4.1" | ||
|
||
main() { | ||
say "Installing evm-runners..." | ||
|
||
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 | ||
|
||
# Download release binary | ||
DOWNLOAD_URL="https://github.com/$GITHUB_USER/$GITHUB_REPO/releases/download/$VERSION/$APP_NAME-$PLATFORM-$ARCH" | ||
EVMRUP_URL="https://raw.githubusercontent.com/ethernautdao/evm-runners-cli/main/evmrup" | ||
EVMRUP_PATH="$EVMR_BIN_DIR/evmrup" | ||
|
||
echo | ||
say "Downloading the binary from '$DOWNLOAD_URL'" | ||
# Create bin directory if it doesn't exist and download evmrup | ||
mkdir -p "$EVMR_BIN_DIR" | ||
curl -# -L $EVMRUP_URL -o $EVMRUP_PATH | ||
chmod +x $EVMRUP_PATH | ||
|
||
curl -L "$DOWNLOAD_URL" -o "$APP_NAME" | ||
# Determine shell | ||
SHELL_NAME="$(basename "$SHELL")" | ||
|
||
# Set executable permissions | ||
chmod +x "$APP_NAME" | ||
|
||
echo | ||
say "Moving the binary to $EVMR_BIN_DIR" | ||
echo | ||
|
||
mkdir -p "$EVMR_BIN_DIR" | ||
mv "$APP_NAME" "$EVMR_BIN_DIR" | ||
ln -sf "$EVMR_BIN_DIR/$APP_NAME" "$EVMR_BIN_DIR/$APP_NAME_ALT" | ||
|
||
# Determine shell | ||
SHELL_NAME="$(basename "$SHELL")" | ||
|
||
# Update PATH environment variable in the appropriate shell configuration file | ||
if [ "$SHELL_NAME" = "bash" ]; then | ||
# Determine appropriate shell configuration file | ||
if [ "$SHELL_NAME" = "bash" ]; then | ||
CONFIG=$HOME/.bashrc | ||
elif [ "$SHELL_NAME" = "zsh" ]; then | ||
elif [ "$SHELL_NAME" = "zsh" ]; then | ||
CONFIG=$HOME/.zshrc | ||
elif [ "$SHELL_NAME" = "fish" ]; then | ||
elif [ "$SHELL_NAME" = "fish" ]; then | ||
CONFIG=$HOME/.config/fish/config.fish | ||
else | ||
err "unsupported shell: $SHELL_NAME, manually add ${EVMR_BIN_DIR} to your PATH." | ||
fi | ||
|
||
say "Updating PATH..." | ||
|
||
# Update PATH environment variable in the shell configuration file | ||
if [[ ":$PATH:" != *":${EVMR_BIN_DIR}:"* ]]; then | ||
echo >> $CONFIG && echo "export PATH=\"\$PATH:$EVMR_BIN_DIR\"" >> $CONFIG | ||
say "Updated $CONFIG with PATH modification" | ||
else | ||
say "$CONFIG already contains PATH modification" | ||
fi | ||
|
||
# Create .env file and add/update the EVMR_VERSION environment variable | ||
ENV_FILE="${EVMR_DIR}/.env" | ||
|
||
if 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 "Run 'source $CONFIG' or start a new terminal session to use evm-runners." | ||
say "Then run 'evmr help', or alternatively 'evm-runners help', to get started." | ||
} | ||
|
||
say() { | ||
printf '%s\n' "$1" | ||
} | ||
|
||
warn() { | ||
say "warning: ${1}" >&2 | ||
} | ||
|
||
err() { | ||
say "$1" >&2 | ||
exit 1 | ||
} | ||
|
||
main "$@" || exit 1 | ||
else | ||
echo "unsupported shell: $SHELL_NAME, manually add ${EVMR_BIN_DIR} to your PATH." | ||
exit 1 | ||
fi | ||
|
||
# Update PATH environment variable in the shell configuration file if it doesn't exist | ||
if [[ ":$PATH:" != *":${EVMR_BIN_DIR}:"* ]]; then | ||
echo >> $CONFIG && echo "export PATH=\"\$PATH:$EVMR_BIN_DIR\"" >> $CONFIG | ||
echo "Updated $CONFIG with PATH modification" | ||
else | ||
echo "$CONFIG already contains PATH modification" | ||
fi | ||
|
||
echo && echo "Detected shell is $SHELL_NAME and added $EVMR_BIN_DIR to PATH." | ||
echo "Continue with installing evm-runners ..." && echo | ||
|
||
# Run evmrup | ||
$EVMRUP_PATH |