forked from eigerco/beerus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
beerusup
executable file
·151 lines (123 loc) · 3.93 KB
/
beerusup
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
#!/bin/sh
NAME="beerus"
INSTALLER="${NAME}up"
PROJECT_ROOT="$HOME/.$NAME"
PROJECT_BIN="$PROJECT_ROOT/bin"
PROJECT_TMP="$PROJECT_ROOT/tmp"
INSTALLER_PATH="$PROJECT_BIN/$INSTALLER"
PROJECT_REPO="keep-starknet-strange/beerus"
INSTALLER_URL="https://raw.githubusercontent.com/$PROJECT_REPO/main/$INSTALLER"
# check latest version
LATEST_VER=$(curl -sL https://api.github.com/repos/$PROJECT_REPO/releases/latest | grep -o '"tag_name": "[^"]*' | grep -o '[^"]*$')
# Store the correct profile file
add_to_shell() {
mkdir -p $PROJECT_BIN $PROJECT_TMP
curl -sL $INSTALLER_URL -o $INSTALLER_PATH
chmod +x "$INSTALLER_PATH"
case $SHELL in
*/zsh)
PROFILE=$HOME/.zshrc
PREF_SHELL=zsh
;;
*/bash)
PROFILE=$HOME/.bashrc
PREF_SHELL=bash
;;
*/fish)
PROFILE=$HOME/.config/fish/config.fish
PREF_SHELL=fish
;;
*)
echo "$INSTALLER: could not detect shell, manually add ${PROJECT_ROOT} to your PATH."
exit 1
esac
IN_PROFILE=$(grep $NAME $PROFILE)
if [ $? -ne 0 ]; then
echo "export PATH=\"\$PATH:$PROJECT_BIN\"" >> $PROFILE
fi
}
# Install latest Beerus Release
# pull releaes tarball by platform and architecture
# (ref: https://github.com/a16z/helios/blob/master/heliosup/heliosup)
install_beerus() {
PLATFORM="$(uname -s)"
case $PLATFORM in
Linux)
PLATFORM="linux"
;;
Darwin)
PLATFORM="darwin"
;;
*)
err "unsupported platform: $PLATFORM"
;;
esac
ARCHITECTURE="$(uname -m)"
echo "Pulling $NAME release..."
PLATFORM_RELEASE="${NAME}-${PLATFORM}-${ARCHITECTURE}"
TARBALL_URL="https://github.com/$PROJECT_REPO/releases/download/${LATEST_VER}/${PLATFORM_RELEASE}.tar.gz"
find $PROJECT_BIN ! -name "$INSTALLER" -type f -exec rm {} +
echo "Unpacking Beerus release...\n"
curl -sL $TARBALL_URL | tar -xzC $PROJECT_BIN
echo "$NAME installed at version: ${LATEST_VER}\n"
}
# Clone Beerus Repo
# install based on latest commit
install_beerus_manually() {
if ! command -v cargo > /dev/null
then
echo "please install rustlang: https://www.rust-lang.org/tools/install"
exit 1
fi
if ! command -v rustup > /dev/null
then
echo "please install rustup: https://rustup.rs"
exit 1
fi
if ! command -v git > /dev/null
then
echo "please install git"
exit 1
fi
WRK_DIR=$(pwd)
echo "Pulling $NAME repo..."
rm -rf $PROJECT_TMP/beerus
git clone --quiet https://github.com/keep-starknet-strange/beerus.git $PROJECT_TMP/beerus
cd $PROJECT_TMP/beerus
echo "Building $NAME...\n"
cargo build -q --release
find $PROJECT_BIN ! -name "$INSTALLER" -type f -exec rm {} +
mv ./target/release/beerus $PROJECT_BIN
mv ./target/release/beerus-rpc $PROJECT_BIN
BEERUS_VER=$($PROJECT_BIN/beerus --version | awk '{print $2}')
cd $WRK_DIR
rm -rf $PROJECT_TMP/beerus
echo "$NAME installed at version: ${BEERUS_VER}\n"
}
# Create Beerus root if doesn't exist
if [ ! -d "$PROJECT_ROOT" ]; then
echo "Installing $NAME root..."
add_to_shell
fi
# Build latest dev version if directed
if [ "$1" = "dev" ] ; then
install_beerus_manually
else
# Pull latest release if there is a new version
CURRENT_VER=$($PROJECT_BIN/beerus --version 2> /dev/null | awk '{print $2}')
if [ "$LATEST_VER" = "v$CURRENT_VER" ]; then
echo "$NAME is currently running the latest version: $LATEST_VER"
else
echo "$NAME being updated to $LATEST_VER"
install_beerus
fi
fi
echo "$NAME root installed at: $PROJECT_ROOT"
if [ ! -z "$PROFILE" ]; then
echo "Run 'source $PROFILE' to activate path or start a new terminal session to use Beerus."
echo "Then, run 'beerus --help'."
fi
echo "\nSet config:"
echo "\tETHEREUM_EXECUTION_RPC_URL\n\tETHEREUM_CONSENSUS_RPC_URL\n\tSTARKNET_RPC_URL"
echo "\tETHEREUM_NETWORK(defaults to 'goerli')"
exit 0