-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·196 lines (179 loc) · 6.42 KB
/
install
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env bash
set -e
echo "Installing foundryup..."
FOUNDRY_DIR=${FOUNDRY_DIR-"$HOME/.foundry"}
FOUNDRY_BIN_DIR="$FOUNDRY_DIR/bin"
FOUNDRY_MAN_DIR="$FOUNDRY_DIR/share/man/man1"
# runs with Makefile to generate hash on CI
# shellcheck disable=SC2034
SCRIPT_COMMIT_SHA="${LOAD_SCRIPT_COMMIT_SHA}"
PLATFORM="$(uname -s)"
case $PLATFORM in
Linux)
PLATFORM="linux"
;;
Darwin)
PLATFORM="darwin"
;;
*)
echo "foundryup: unsupported platform: $PLATFORM"
exit 1
;;
esac
# shellcheck disable=SC2016
FOUNDRYUP='#!/usr/bin/env bash
set -e
FOUNDRY_DIR=${FOUNDRY_DIR-"$HOME/.foundry"}
FOUNDRY_BIN_DIR="$FOUNDRY_DIR/bin"
FOUNDRY_MAN_DIR="$FOUNDRY_DIR/share/man/man1"
while [[ $1 ]]; do
case $1 in
--) shift; break;;
-r|--repo) shift; FOUNDRYUP_REPO=$1;;
-b|--branch) shift; FOUNDRYUP_BRANCH=$1;;
-v|--version) shift; FOUNDRYUP_VERSION=$1;;
-h|--help) FOUNDRYUP_HELP="1";;
*) printf "foundryup: internal error: %q\\n" "$1"; exit 1
esac; shift
done
if [[ "$FOUNDRYUP_HELP" == "1" ]]; then
echo "Update or revert to a specific Foundry branch with ease.
USAGE:
foundryup <OPTIONS>
OPTIONS:
-h, --help Print help information
-v, --version Install a specific version
-b, --branch Install a specific branch
-r, --repo Install a forks main branch"
exit 0
fi
FOUNDRYUP_REPO=${FOUNDRYUP_REPO-gakonst/foundry}
if [[ "$FOUNDRYUP_REPO" == "gakonst/foundry" && -z "$FOUNDRYUP_BRANCH" ]]; then
FOUNDRYUP_VERSION=${FOUNDRYUP_VERSION-nightly}
FOUNDRYUP_TAG=$FOUNDRYUP_VERSION
# Normalize versions (handle channels, versions without v prefix
if [[ "$FOUNDRYUP_VERSION" == "nightly" ]]; then
# Locate real nightly tag
SHA=$(curl -sSf https://api.github.com/repos/${FOUNDRYUP_REPO}/git/refs/tags/nightly \
| grep -Eo '\''"sha"[^,]*'\'' \
| grep -Eo '\''[^:]*$'\'' \
| tr -d '\''"'\'' \
| tr -d '\'' '\'')
FOUNDRYUP_TAG="nightly-${SHA}"
elif [[ "$FOUNDRYUP_VERSION" == [[:digit:]]* ]]; then
# Add v prefix
FOUNDRYUP_VERSION="v${FOUNDRYUP_VERSION}"
FOUNDRYUP_TAG="${FOUNDRYUP_VERSION}"
fi
PLATFORM="$(uname -s)"
case $PLATFORM in
Linux)
PLATFORM="linux"
;;
Darwin)
PLATFORM="darwin"
;;
*)
echo "foundryup: unsupported platform: $PLATFORM"
exit 1
;;
esac
ARCHITECTURE="$(uname -m)"
if [ "${ARCHITECTURE}" = "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
ARCHITECTURE="arm64" # Rosetta.
else
ARCHITECTURE="amd64" # Intel.
fi
elif [ "${ARCHITECTURE}" = "arm64" ] ||[ "${ARCHITECTURE}" = "aarch64" ] ; then
ARCHITECTURE="arm64" # Arm.
else
ARCHITECTURE="amd64" # Amd.
fi
# Compute the URL of the release tarball in the Foundry repository.
RELEASE_URL="https://github.com/${FOUNDRYUP_REPO}/releases/download/${FOUNDRYUP_TAG}/"
BIN_TARBALL_URL="${RELEASE_URL}foundry_${FOUNDRYUP_VERSION}_${PLATFORM}_${ARCHITECTURE}.tar.gz"
MAN_TARBALL_URL="${RELEASE_URL}foundry_man_${FOUNDRYUP_VERSION}.tar.gz"
# Download the binaries tarball and unpack it into the .foundry bin directory.
curl -L $BIN_TARBALL_URL | tar -xvzC $FOUNDRY_BIN_DIR
# Download the man tarball and unpack it into the .foundry man directory.
curl -L $MAN_TARBALL_URL | tar -xvzC $FOUNDRY_MAN_DIR
echo foundryup: done!
else
FOUNDRYUP_BRANCH=${FOUNDRYUP_BRANCH-master}
if ! command -v cargo &> /dev/null ; then
# Error if cargo is not already installed.
echo "foundryup: cargo is not installed. Please install it first."
exit 1
fi
REPO_PATH="${FOUNDRY_DIR}/${FOUNDRYUP_REPO}"
if [ -d $REPO_PATH ]; then
# If the repo path exists move to it and do a force checkout, discarding any local changes
cd $REPO_PATH
git fetch
git reset --hard origin/${FOUNDRYUP_BRANCH}
else
# Repo path did not exist, grab the author from the repo, make a directory in .foundry, cd to it and clone.
IFS="/" read -ra AUTHOR <<< "$FOUNDRYUP_REPO"
mkdir -p "$FOUNDRY_DIR/$AUTHOR"
cd "$FOUNDRY_DIR/$AUTHOR"
git clone https://github.com/${FOUNDRYUP_REPO}
cd $REPO_PATH
git checkout ${FOUNDRYUP_BRANCH}
fi
# Build the repo and install it locally to the .foundry bin directory.
# --root appends /bin to the directory it is given, so we pass FOUNDRY_DIR.
cargo install --path ./cli --bins --locked --force --root $FOUNDRY_DIR
# If help2man is installed, use it to add Foundry man pages.
if command -v help2man &> /dev/null ; then
help2man -N $FOUNDRY_BIN_DIR/forge > $FOUNDRY_MAN_DIR/forge.1
help2man -N $FOUNDRY_BIN_DIR/cast > $FOUNDRY_MAN_DIR/cast.1
fi
echo "foundryup: done!"
fi'
BINARY="$FOUNDRY_BIN_DIR/foundryup"
# Create the .foundry bin directory and foundryup binary if it doesn't exist.
mkdir -p "$FOUNDRY_BIN_DIR"
echo "$FOUNDRYUP" >"$BINARY"
chmod +x "$BINARY"
# Create the man directory for future man files if it doesn't exist.
mkdir -p "$FOUNDRY_MAN_DIR"
# Store the correct profile file (i.e. .profile for bash or .zshrc for ZSH).
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 "foundryup: could not detect shell, manually add ${FOUNDRY_BIN_DIR} to your PATH."
exit 1
;;
esac
# Only add foundryup if it isn't already in PATH.
if [[ ":$PATH:" != *":${FOUNDRY_BIN_DIR}:"* ]]; then
if [[ $PLATFORM == 'darwin'* ]]; then
echo >>"$HOME"/.bash_profile && echo "export PATH=\"\$PATH:$FOUNDRY_BIN_DIR\"" >>"$HOME"/.bash_profile
fi
# Add the foundryup directory to the path and ensure the old PATH variables remain.
echo >>"$PROFILE" && echo "export PATH=\"\$PATH:$FOUNDRY_BIN_DIR\"" >>"$PROFILE"
fi
if [[ $SHELL == 'bash'* ]]; then
forge completions bash > /usr/local/etc/bash_completion.d/forge
cast completions bash > /usr/local/etc/bash_completion.d/cast
echo >> "/usr/local/etc/bash_completion.d/forge">>$$HOME/.bash_profile
echo >> "source /usr/local/etc/bash_completion.d/cast">>$$HOME/.bash_profile
# echo >>"[ -f /usr/local/etc/bash_completion.d ] && . /usr/local/etc/bash_completion.d ">>$$HOME/.bash_profile
fi
echo && echo "Detected your preferred shell is ${PREF_SHELL} and added foundryup to PATH. Run 'source ${PROFILE}' or start a new terminal session to use foundryup."
echo "Then, simply run 'foundryup' to install Foundry."
sleep 1
exit 0