-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·226 lines (187 loc) · 6.1 KB
/
install.sh
File metadata and controls
executable file
·226 lines (187 loc) · 6.1 KB
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
#!/bin/sh
set -e
REPO="QEDProtocol/psy-benchmark-verifier"
INSTALL_DIR="${TMPDIR:-/tmp}/psy"
VERSION=""
PSY_DATA_URL="https://psy-benchmark-round1-data.psy-protocol.xyz"
if [ -t 1 ] && command -v tput >/dev/null 2>&1; then
RED=$(tput setaf 1 2>/dev/null || echo "")
GREEN=$(tput setaf 2 2>/dev/null || echo "")
YELLOW=$(tput setaf 3 2>/dev/null || echo "")
BLUE=$(tput setaf 4 2>/dev/null || echo "")
RESET=$(tput sgr0 2>/dev/null || echo "")
else
RED="" GREEN="" YELLOW="" BLUE="" RESET=""
fi
info() { printf "%s[INFO]%s %s\n" "$BLUE" "$RESET" "$1"; }
success() { printf "%s[OK]%s %s\n" "$GREEN" "$RESET" "$1"; }
warn() { printf "%s[WARN]%s %s\n" "$YELLOW" "$RESET" "$1"; }
error() { printf "%s[ERROR]%s %s\n" "$RED" "$RESET" "$1" >&2; exit 1; }
detect_os() {
case "$(uname -s)" in
Linux*) echo "linux" ;;
Darwin*) echo "darwin" ;;
MINGW*|MSYS*|CYGWIN*) echo "windows" ;;
FreeBSD*) echo "freebsd" ;;
*) error "Unsupported OS: $(uname -s)" ;;
esac
}
detect_arch() {
case "$(uname -m)" in
x86_64|amd64) echo "amd64" ;;
aarch64|arm64) echo "arm64" ;;
armv7l|armv6l) echo "arm" ;;
i386|i686) echo "386" ;;
*) error "Unsupported arch: $(uname -m)" ;;
esac
}
detect_downloader() {
if command -v curl >/dev/null 2>&1; then
echo "curl"
elif command -v wget >/dev/null 2>&1; then
echo "wget"
else
error "curl or wget required"
fi
}
download() {
url="$1"
output="$2"
downloader=$(detect_downloader)
info "Downloading: $url"
case "$downloader" in
curl) curl -fsSL -o "$output" "$url" ;;
wget) wget -q -O "$output" "$url" ;;
esac
}
get_json_value() {
key="$1"
sed 's/,/\n/g' | grep "\"$key\"" | head -1 | sed "s/.*\"$key\"[[:space:]]*:[[:space:]]*\"\([^\"]*\)\".*/\1/"
}
get_latest_version() {
api_url="https://api.github.com/repos/$REPO/releases/latest"
downloader=$(detect_downloader)
info "Fetching latest version..." >&2
case "$downloader" in
curl) response=$(curl -fsSL "$api_url") ;;
wget) response=$(wget -qO- "$api_url") ;;
esac
version=$(echo "$response" | get_json_value "tag_name")
[ -z "$version" ] && error "Failed to get latest version"
echo "$version"
}
show_help() {
echo "Usage: install.sh [OPTIONS]"
echo "Install Psy CLI Prover (psy-cli). Requires JOB_ID and REALM_ID env vars to run."
echo ""
echo "Options:"
echo " -v, --version VERSION Use specific release version (default: latest)"
echo " -d, --dir DIR Install directory (default: \$TMPDIR/psy or /tmp/psy)"
echo " -l, --list List available binary assets and exit"
echo " -h, --help Show this help"
}
list_assets() {
info "Available binaries:"
echo " psy-cli_macos_arm64"
echo " psy-cli_ubuntu22.04_amd64"
echo " psy-cli_windows_x64"
}
try_download_asset() {
os="$1"
arch="$2"
ver="$3"
tmp_dir="$4"
# Map os/arch to asset name suffixes
case "$os" in
darwin)
case "$arch" in
arm64) asset_suffix="macos_arm64" ;;
*) error "Unsupported arch for macOS: $arch" ;;
esac
;;
linux)
case "$arch" in
amd64) asset_suffix="ubuntu22.04_amd64" ;;
*) error "Unsupported arch for Linux: $arch" ;;
esac
;;
windows)
case "$arch" in
amd64) asset_suffix="windows_x64" ;;
*) error "Unsupported arch for Windows: $arch" ;;
esac
;;
*) error "Unsupported OS: $os" ;;
esac
asset_name="psy-cli_${asset_suffix}"
url="https://github.com/$REPO/releases/download/$ver/$asset_name"
output="$tmp_dir/$asset_name"
printf " Downloading: %s ... " "$asset_name" >&2
if curl -fsSL --connect-timeout 30 --max-time 600 -o "$output" "$url" 2>/dev/null; then
echo "OK" >&2
chmod +x "$output"
echo "$output"
return 0
else
echo "not found" >&2
return 1
fi
}
extract() {
# No longer needed - downloading binary directly
:
}
find_binary() {
# No longer needed - downloading binary directly
:
}
main() {
info "Installing psy-cli (Psy CLI Prover) from $REPO"
OS=$(detect_os)
ARCH=$(detect_arch)
info "Platform: $OS/$ARCH"
[ -z "$VERSION" ] && VERSION=$(get_latest_version)
info "Version: $VERSION"
[ ! -d "$INSTALL_DIR" ] && { info "Creating: $INSTALL_DIR"; mkdir -p "$INSTALL_DIR"; }
FINAL_PATH="$INSTALL_DIR/psy-cli"
# Check if already installed with same version
if [ -f "$FINAL_PATH" ]; then
info "Binary already installed: $FINAL_PATH"
success "Done!"
return 0
fi
TMP_DIR=$(mktemp -d)
trap 'rm -rf "$TMP_DIR"' EXIT
DOWNLOAD_PATH=$(try_download_asset "$OS" "$ARCH" "$VERSION" "$TMP_DIR")
if [ -z "$DOWNLOAD_PATH" ]; then
warn "Auto-detection failed. Available assets:"
list_assets
echo ""
error "No matching binary found for $OS/$ARCH"
fi
rm -f "$FINAL_PATH"
cp "$DOWNLOAD_PATH" "$FINAL_PATH"
chmod +x "$FINAL_PATH"
# macOS Gatekeeper: remove quarantine attribute if present
if command -v xattr >/dev/null 2>&1; then
xattr -dr com.apple.quarantine "$FINAL_PATH" 2>/dev/null || true
fi
success "Installed: $FINAL_PATH"
success "Done!"
}
JOB_ID="${JOB_ID:-}"
REALM_ID="${REALM_ID:-}"
while [ $# -gt 0 ]; do
case "$1" in
-v|--version) VERSION="$2"; shift 2 ;;
-d|--dir) INSTALL_DIR="$2"; shift 2 ;;
-l|--list) info "Fetching assets for $REPO..."; list_assets; exit 0 ;;
-h|--help) show_help; exit 0 ;;
*) break ;;
esac
done
main
[ -z "$JOB_ID" ] && error "JOB_ID environment variable is required (24 bytes hex)"
[ -z "$REALM_ID" ] && error "REALM_ID environment variable is required (u32)"
info "Running: $INSTALL_DIR/psy-cli -b (stdin: realm_id,job_id)"
printf '%s,%s\n' "$REALM_ID" "$JOB_ID" | "$INSTALL_DIR/psy-cli" -b