This repository has been archived by the owner on Mar 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
shenlongup
executable file
·168 lines (138 loc) · 4.43 KB
/
shenlongup
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
#!/bin/sh
NAME="shenlong"
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/shenlong/main"
INSTALLER_URL="https://raw.githubusercontent.com/$PROJECT_REPO/$INSTALLER"
# Store the correct profile file
add_to_shell() {
mkdir -p $PROJECT_BIN
mkdir -p $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 shenlong Release
# pull releaes tarball by platform and architecture
# (ref: https://github.com/a16z/helios/blob/master/heliosup/heliosup)
install_shenlong() {
PLATFORM="$(uname -s)"
case $PLATFORM in
Linux)
PLATFORM="linux"
;;
Darwin)
PLATFORM="darwin"
;;
*)
err "unsupported platform: $PLATFORM"
;;
esac
ARCHITECTURE="$(uname -m)"
if [ "${ARCHITECTURE}" = "x86_64" ]; then
if [ "$(sysctl -n sysctl.proc_translated 2>/dev/null)" = "1" ]; then
ARCHITECTURE="arm64" # Rosetta.
else
ARCHITECTURE="amd64" # Intel.
fi
elif [ "${ARCHITECTURE}" = "arm64" ] ||[ "${ARCHITECTURE}" = "aarch64" ] ; then
ARCHITECTURE="arm64" # Arm.
else
ARCHITECTURE="amd64" # Amd.
fi
echo "Pulling $NAME release..."
TARBALL_URL="https://github.com/$PROJECT_REPO/releases/download/${LATEST_VER}/${NAME}_${PLATFORM}_${ARCHITECTURE}.tar.gz"
find $PROJECT_BIN ! -name "$INSTALLER" -type f -exec rm {} +
echo "Unpacking shenlong release...\n"
curl -L $TARBALL_URL | tar -xzC $PROJECT_BIN
echo "$NAME installed at version: ${LATEST_VER}\n"
}
# Clone shenlong Repo
# install based on latest commit
install_shenlong_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
DEFAULT=$(rustup default | grep nightly)
if [ $? -ne 0 ]; then
echo "please set the following:"
echo "\trustup toolchain install nightly"
echo "\trustup default nightly\n"
exit 1
fi
WRK_DIR=$(pwd)
echo "Pulling $NAME repo..."
git clone --quiet https://github.com/keep-starknet-strange/shenlong.git $PROJECT_TMP/shenlong
cd $PROJECT_TMP/shenlong
echo "Building $NAME...\n"
cargo build -q --all --release
find $PROJECT_BIN ! -name "$INSTALLER" -type f -exec rm {} +
mv ./target/release/shenlong $PROJECT_BIN
shenlong_VER=$(shenlong --version | awk '{print $2}')
cd $WRK_DIR
rm -rf $PROJECT_TMP/shenlong
echo "$NAME installed at version: ${shenlong_VER}\n"
}
# Create shenlong root if doesn't exist
if [ ! -d "$PROJECT_ROOT" ]; then
echo "Installing $NAME root..."
add_to_shell
fi
# check latest version
LATEST_VER=$(curl -sL https://api.github.com/repos/$PROJECT_REPO/releases/latest | grep -o '"tag_name": "[^"]*' | grep -o '[^"]*$')
# TODO:
# remove ([ $? -ne 0 ]) after first release
# Build latest dev version if directed
if [ "$1" = "dev" ] || [ $? -ne 0 ]; then
install_shenlong_manually
else
# Pull latest release if there is a new version
CURRENT_VER=$(shenlong --version | awk '{print $2}')
if [ "$LATEST_TAG" = "v$CURRENT_VER" ]; then
echo "$NAME is currently running the latest version: $LATEST_VER"
else
echo "$NAME being updated to $LATEST_VER"
install_shenlong
fi
fi
echo "$NAME root installed at: $PROJECT_ROOT"
if [ ! -z "$PROFILE" ]; then echo "\trun 'source $PROFILE' to activate path"; 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