-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·93 lines (79 loc) · 2.76 KB
/
install.sh
File metadata and controls
executable file
·93 lines (79 loc) · 2.76 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
#!/bin/sh
set -e
REPO="Calhooon/bsv-wallet-cli"
BIN_NAME="bsv-wallet"
# --- Detect OS and architecture ---
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Darwin) OS_TAG="apple-darwin" ;;
Linux) OS_TAG="unknown-linux-gnu" ;;
*) printf "Error: unsupported OS: %s\n" "$OS"; exit 1 ;;
esac
case "$ARCH" in
x86_64) ARCH_TAG="x86_64" ;;
aarch64|arm64) ARCH_TAG="aarch64" ;;
*) printf "Error: unsupported architecture: %s\n" "$ARCH"; exit 1 ;;
esac
TARGET="${ARCH_TAG}-${OS_TAG}"
ASSET_NAME="${BIN_NAME}-${TARGET}.tar.gz"
printf "Detected platform: %s-%s (%s)\n" "$OS" "$ARCH" "$TARGET"
# --- Choose install directory ---
if [ -w /usr/local/bin ]; then
INSTALL_DIR="/usr/local/bin"
else
INSTALL_DIR="$HOME/.local/bin"
mkdir -p "$INSTALL_DIR"
fi
# --- Try downloading a pre-built binary from GitHub releases ---
install_from_release() {
RELEASE_URL="https://github.com/${REPO}/releases/latest/download/${ASSET_NAME}"
printf "Checking for pre-built binary at GitHub releases...\n"
TMPDIR_DL="$(mktemp -d)"
HTTP_CODE=$(curl -sL -o "$TMPDIR_DL/$ASSET_NAME" -w "%{http_code}" "$RELEASE_URL" 2>/dev/null) || HTTP_CODE=0
if [ "$HTTP_CODE" = "200" ] && [ -s "$TMPDIR_DL/$ASSET_NAME" ]; then
printf "Downloading %s ... done.\n" "$ASSET_NAME"
tar -xzf "$TMPDIR_DL/$ASSET_NAME" -C "$TMPDIR_DL"
if [ -f "$TMPDIR_DL/$BIN_NAME" ]; then
mv "$TMPDIR_DL/$BIN_NAME" "$INSTALL_DIR/$BIN_NAME"
chmod +x "$INSTALL_DIR/$BIN_NAME"
rm -rf "$TMPDIR_DL"
return 0
fi
rm -rf "$TMPDIR_DL"
else
rm -rf "$TMPDIR_DL"
fi
return 1
}
# --- Fallback: build from source via cargo ---
install_from_source() {
if command -v cargo >/dev/null 2>&1; then
printf "No pre-built binary found. Building from source with cargo...\n"
cargo install --git "https://github.com/${REPO}.git" bsv-wallet-cli
return 0
fi
return 1
}
# --- Main install flow ---
if install_from_release; then
printf "Installed %s to %s\n" "$BIN_NAME" "$INSTALL_DIR/$BIN_NAME"
elif install_from_source; then
printf "Installed %s via cargo.\n" "$BIN_NAME"
else
printf "Error: cargo is not installed.\n"
printf "Install Rust first: https://rustup.rs\n"
printf " curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh\n"
exit 1
fi
# --- Verify installation ---
if ! command -v "$BIN_NAME" >/dev/null 2>&1; then
printf "\nNote: %s was installed to %s\n" "$BIN_NAME" "$INSTALL_DIR"
printf "Add it to your PATH if needed:\n"
printf " export PATH=\"%s:\$PATH\"\n" "$INSTALL_DIR"
fi
# --- Getting started ---
printf "\n--- Getting started ---\n"
printf " bsv-wallet init\n"
printf " bsv-wallet address\n"
printf " bsv-wallet daemon\n"