Skip to content

Commit 4f728eb

Browse files
committed
add install.sh
1 parent c3810ec commit 4f728eb

File tree

1 file changed

+235
-0
lines changed

1 file changed

+235
-0
lines changed

install.sh

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
#!/bin/sh
2+
set -e
3+
4+
REPO="QEDProtocol/psy-benchmark-verifier"
5+
INSTALL_DIR="$HOME/.psy"
6+
VERSION=""
7+
PSY_DATA_URL="https://psy-benchmark-round1-data.psy-protocol.xyz"
8+
9+
if [ -t 1 ] && command -v tput >/dev/null 2>&1; then
10+
RED=$(tput setaf 1 2>/dev/null || echo "")
11+
GREEN=$(tput setaf 2 2>/dev/null || echo "")
12+
YELLOW=$(tput setaf 3 2>/dev/null || echo "")
13+
BLUE=$(tput setaf 4 2>/dev/null || echo "")
14+
RESET=$(tput sgr0 2>/dev/null || echo "")
15+
else
16+
RED="" GREEN="" YELLOW="" BLUE="" RESET=""
17+
fi
18+
19+
info() { printf "%s[INFO]%s %s\n" "$BLUE" "$RESET" "$1"; }
20+
success() { printf "%s[OK]%s %s\n" "$GREEN" "$RESET" "$1"; }
21+
warn() { printf "%s[WARN]%s %s\n" "$YELLOW" "$RESET" "$1"; }
22+
error() { printf "%s[ERROR]%s %s\n" "$RED" "$RESET" "$1" >&2; exit 1; }
23+
24+
detect_os() {
25+
case "$(uname -s)" in
26+
Linux*) echo "linux" ;;
27+
Darwin*) echo "darwin" ;;
28+
MINGW*|MSYS*|CYGWIN*) echo "windows" ;;
29+
FreeBSD*) echo "freebsd" ;;
30+
*) error "Unsupported OS: $(uname -s)" ;;
31+
esac
32+
}
33+
34+
detect_arch() {
35+
case "$(uname -m)" in
36+
x86_64|amd64) echo "amd64" ;;
37+
aarch64|arm64) echo "arm64" ;;
38+
armv7l|armv6l) echo "arm" ;;
39+
i386|i686) echo "386" ;;
40+
*) error "Unsupported arch: $(uname -m)" ;;
41+
esac
42+
}
43+
44+
detect_downloader() {
45+
if command -v curl >/dev/null 2>&1; then
46+
echo "curl"
47+
elif command -v wget >/dev/null 2>&1; then
48+
echo "wget"
49+
else
50+
error "curl or wget required"
51+
fi
52+
}
53+
54+
download() {
55+
url="$1"
56+
output="$2"
57+
downloader=$(detect_downloader)
58+
59+
info "Downloading: $url"
60+
case "$downloader" in
61+
curl) curl -fsSL -o "$output" "$url" ;;
62+
wget) wget -q -O "$output" "$url" ;;
63+
esac
64+
}
65+
66+
get_json_value() {
67+
key="$1"
68+
sed 's/,/\n/g' | grep "\"$key\"" | head -1 | sed "s/.*\"$key\"[[:space:]]*:[[:space:]]*\"\([^\"]*\)\".*/\1/"
69+
}
70+
71+
get_latest_version() {
72+
api_url="https://api.github.com/repos/$REPO/releases/latest"
73+
downloader=$(detect_downloader)
74+
75+
info "Fetching latest version..." >&2
76+
case "$downloader" in
77+
curl) response=$(curl -fsSL "$api_url") ;;
78+
wget) response=$(wget -qO- "$api_url") ;;
79+
esac
80+
81+
version=$(echo "$response" | get_json_value "tag_name")
82+
[ -z "$version" ] && error "Failed to get latest version"
83+
echo "$version"
84+
}
85+
86+
list_assets() {
87+
info "Available binaries:"
88+
echo " psy_validator_cli_macos_arm64"
89+
echo " psy_validator_cli_ubuntu22.04_amd64"
90+
echo " psy_validator_cli_windows_x64"
91+
}
92+
93+
try_download_asset() {
94+
os="$1"
95+
arch="$2"
96+
ver="$3"
97+
tmp_dir="$4"
98+
99+
# Map os/arch to asset name suffixes
100+
case "$os" in
101+
darwin)
102+
case "$arch" in
103+
arm64) asset_suffix="macos_arm64" ;;
104+
*) error "Unsupported arch for macOS: $arch" ;;
105+
esac
106+
;;
107+
linux)
108+
case "$arch" in
109+
amd64) asset_suffix="ubuntu22.04_amd64" ;;
110+
*) error "Unsupported arch for Linux: $arch" ;;
111+
esac
112+
;;
113+
windows)
114+
case "$arch" in
115+
amd64) asset_suffix="windows_x64" ;;
116+
*) error "Unsupported arch for Windows: $arch" ;;
117+
esac
118+
;;
119+
*) error "Unsupported OS: $os" ;;
120+
esac
121+
122+
asset_name="psy_validator_cli_${asset_suffix}"
123+
url="https://github.com/$REPO/releases/download/$ver/$asset_name"
124+
output="$tmp_dir/$asset_name"
125+
126+
printf " Downloading: %s ... " "$asset_name" >&2
127+
if curl -fsSL --connect-timeout 5 --max-time 300 -o "$output" "$url" 2>/dev/null; then
128+
echo "OK" >&2
129+
chmod +x "$output"
130+
echo "$output"
131+
return 0
132+
else
133+
echo "not found" >&2
134+
return 1
135+
fi
136+
}
137+
138+
extract() {
139+
# No longer needed - downloading binary directly
140+
:
141+
}
142+
143+
find_binary() {
144+
# No longer needed - downloading binary directly
145+
:
146+
}
147+
148+
show_help() {
149+
cat << 'EOF'
150+
Usage: PROOF_ID=xxx install.sh [options]
151+
152+
Options:
153+
-v, --version VER Install specific version (default: latest)
154+
-d, --dir DIR Install directory (default: ~/.psy)
155+
-l, --list List available binaries
156+
-h, --help Show this help
157+
158+
Supported platforms:
159+
- macOS ARM64 (apple silicon)
160+
- Ubuntu 22.04 AMD64
161+
- Windows x64
162+
163+
Examples:
164+
PROOF_ID=888 curl -fsSL https://.../install.sh | sh
165+
PROOF_ID=888 ./install.sh
166+
PROOF_ID=888 ./install.sh -v v1.0.0
167+
EOF
168+
}
169+
170+
main() {
171+
info "Installing psy_validator_cli from $REPO"
172+
173+
OS=$(detect_os)
174+
ARCH=$(detect_arch)
175+
info "Platform: $OS/$ARCH"
176+
177+
[ -z "$VERSION" ] && VERSION=$(get_latest_version)
178+
info "Version: $VERSION"
179+
180+
[ ! -d "$INSTALL_DIR" ] && { info "Creating: $INSTALL_DIR"; mkdir -p "$INSTALL_DIR"; }
181+
182+
FINAL_PATH="$INSTALL_DIR/psy_validator_cli"
183+
184+
# Check if already installed with same version
185+
if [ -f "$FINAL_PATH" ]; then
186+
info "Binary already installed: $FINAL_PATH"
187+
success "Done!"
188+
return 0
189+
fi
190+
191+
TMP_DIR=$(mktemp -d)
192+
trap 'rm -rf "$TMP_DIR"' EXIT
193+
194+
DOWNLOAD_PATH=$(try_download_asset "$OS" "$ARCH" "$VERSION" "$TMP_DIR")
195+
196+
if [ -z "$DOWNLOAD_PATH" ]; then
197+
warn "Auto-detection failed. Available assets:"
198+
list_assets
199+
echo ""
200+
error "No matching binary found for $OS/$ARCH"
201+
fi
202+
203+
rm -f "$FINAL_PATH"
204+
cp "$DOWNLOAD_PATH" "$FINAL_PATH"
205+
chmod +x "$FINAL_PATH"
206+
207+
# macOS Gatekeeper: remove quarantine attribute if present
208+
if command -v xattr >/dev/null 2>&1; then
209+
xattr -dr com.apple.quarantine "$FINAL_PATH" 2>/dev/null || true
210+
fi
211+
212+
success "Installed: $FINAL_PATH"
213+
214+
success "Done!"
215+
}
216+
217+
PROOF_ID="${PROOF_ID:-}"
218+
219+
while [ $# -gt 0 ]; do
220+
case "$1" in
221+
-v|--version) VERSION="$2"; shift 2 ;;
222+
-d|--dir) INSTALL_DIR="$2"; shift 2 ;;
223+
-l|--list) info "Fetching assets for $REPO..."; list_assets; exit 0 ;;
224+
-h|--help) show_help; exit 0 ;;
225+
*) break ;;
226+
esac
227+
done
228+
229+
main
230+
231+
[ -z "$PROOF_ID" ] && error "PROOF_ID environment variable is required"
232+
233+
info "Running: $INSTALL_DIR/psy_validator_cli fetch-job -b \"$PSY_DATA_URL\" -p \"$PROOF_ID\""
234+
235+
exec "$INSTALL_DIR/psy_validator_cli" fetch-job -b "$PSY_DATA_URL" -p "$PROOF_ID"

0 commit comments

Comments
 (0)