forked from risc0/risc0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·232 lines (185 loc) · 4.83 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/usr/bin/env bash
# Copyright 2024 RISC Zero, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -euo pipefail
RZUP_URL="${RZUP_URL:-https://risc0-artifacts.s3.us-west-2.amazonaws.com/rzup}"
# Override the download path with the ENV_PATH environment variable (i.e. stage)
ENV_PATH=${ENV_PATH:-prod}
QUIET=no
RZUP_BIN_DIR="${HOME}/.risc0/bin"
usage() {
cat <<EOF
install
The installer for rzup, from RISC Zero.
Usage: install [OPTIONS]
Options:
-v, --verbose
Enable verbose output
-q, --quiet
Disable progress output
-h, --help
Print help
EOF
}
cleanup() {
[ -n "${_dir:-}" ] && [ -d "$_dir" ] && rm -rf "$_dir"
}
trap cleanup EXIT
main() {
downloader --check
need_cmd uname
need_cmd mktemp
need_cmd chmod
need_cmd mkdir
need_cmd rm
need_cmd rmdir
need_cmd mv
check_rust_installed
get_architecture
_arch="$RETVAL"
assert_nz "$_arch" "arch"
_url="${RZUP_URL}/${ENV_PATH}/${_arch}/rzup"
_dir="$(ensure mktemp -d)"
_file="${_dir}/rzup"
[ -f "$RZUP_BIN_DIR/rzup" ] && rm "$RZUP_BIN_DIR/rzup"
for arg in "$@"; do
case "$arg" in
--help)
usage
exit 0
;;
-q | --quiet) QUIET=yes ;;
*) ;;
esac
done
info 'Downloading installer'
ensure mkdir -p "$_dir"
ensure downloader "$_url" "$_file"
ensure chmod u+x "$_file"
[ ! -x "$_file" ] && err "Cannot execute $_file"
ensure mkdir -p "$RZUP_BIN_DIR"
ensure mv "$_file" "$RZUP_BIN_DIR"
info "rzup has been installed to $RZUP_BIN_DIR"
detect_shell
update_profile
display_post_install_message
}
check_rust_installed() {
check_cmd rustc || err "Rust is not installed. Please install Rust from https://rustup.rs/ and run this script again."
}
get_architecture() {
_ostype="$(uname -s)"
_cputype="$(uname -m)"
case "$_ostype" in
Linux) _ostype=linux ;;
Darwin) _ostype=darwin ;;
*) err "Unsupported OS type: $_ostype" ;;
esac
case "$_cputype" in
x86_64 | amd64) _cputype=x86_64 ;;
aarch64 | arm64) _cputype=arm64 ;;
*) err "Unsupported CPU type: $_cputype" ;;
esac
case "$_cputype $_ostype" in
"x86_64 linux") _arch=Linux-X64 ;;
"arm64 darwin" ) _arch=macOS-ARM64 ;;
*) err "Unsupported CPU arch pairing: $_cputype $_ostype" ;;
esac
RETVAL="$_arch"
}
detect_shell() {
case $SHELL in
*/zsh)
PROFILE="${ZDOTDIR:-"$HOME"}/.zshrc"
PREF_SHELL='zsh'
;;
*/bash)
PROFILE="$HOME/.bashrc"
PREF_SHELL='bash'
;;
*/fish)
PROFILE="$HOME/.config/fish/config.fish"
PREF_SHELL='fish'
;;
*/ash)
PROFILE="$HOME/.profile"
PREF_SHELL='ash'
;;
*)
err "Could not detect shell. Please manually add ${RZUP_BIN_DIR} to your PATH."
;;
esac
info "Detected your preferred shell as ${PREF_SHELL}"
}
update_profile() {
if [[ ":$PATH:" != *":${RZUP_BIN_DIR}:"* ]] && [[ -n "$PROFILE" ]]; then
info "Adding rzup to PATH in ${PROFILE}"
{
echo
echo "# Add rzup to PATH"
echo "export PATH=\"\$PATH:$RZUP_BIN_DIR\""
} >> "$PROFILE"
else
info "rzup is already in your PATH or manual configuration is required"
fi
}
display_post_install_message() {
cat <<EOF
🎉 rzup installed successfully!
To get started, you may need to restart your current shell to reload your PATH.
If rzup is not immediately available, you can configure your current shell by running:
. "${PROFILE}" # For bash/zsh/ash/dash/pdksh
source "${PROFILE}" # For fish
Run the following command to install the zkVM:
rzup install
EOF
}
info() {
[ "$QUIET" = "no" ] && printf 'info: %s\n' "$1" >&2
}
err() {
printf 'error: %s\n' "$1" >&2
exit 1
}
warn() {
printf 'warn: %s\n' "$1" >&2
}
need_cmd() {
check_cmd "$1" || err "Command not found: $1"
}
check_cmd() {
command -v "$1" >/dev/null 2>&1
}
assert_nz() {
[ -z "$1" ] && err "$2"
}
ensure() {
"$@" || err "Command failed: $*"
}
downloader() {
if [ "$1" = --check ]; then
check_cmd curl || check_cmd wget || err "Need 'curl' or 'wget' (neither found)"
else
_url="$1"
_file="$2"
if check_cmd curl; then
curl --silent --show-error --fail --location "$_url" --output "$_file" || err "Failed to download with curl"
elif check_cmd wget; then
wget --quiet --output-document="$2" "$1" || err "Failed to download with wget"
else
err "Need 'curl' or 'wget' (neither command found)"
fi
fi
}
main "$@" || exit 1