-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·126 lines (104 loc) · 3.31 KB
/
install.sh
File metadata and controls
executable file
·126 lines (104 loc) · 3.31 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
#!/usr/bin/env bash
# Quick-start installer for the Autonomi `ant` CLI.
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/WithAutonomi/ant-client/main/install.sh | bash
#
# Environment variables:
# ANT_VERSION — install a specific version (e.g. "0.1.1"). Defaults to latest.
# INSTALL_DIR — override install directory (default: ~/.local/bin on Linux, /usr/local/bin on macOS).
set -euo pipefail
REPO="WithAutonomi/ant-client"
BINARY_NAME="ant"
# --- helpers ----------------------------------------------------------------
say() { printf '%s\n' "$*"; }
err() { say "Error: $*" >&2; exit 1; }
need() {
command -v "$1" > /dev/null 2>&1 || err "need '$1' (command not found)"
}
detect_target() {
local os arch
os="$(uname -s)"
arch="$(uname -m)"
case "$os" in
Linux)
case "$arch" in
x86_64) echo "x86_64-unknown-linux-musl" ;;
aarch64) echo "aarch64-unknown-linux-musl" ;;
*) err "unsupported Linux architecture: $arch" ;;
esac
;;
Darwin)
case "$arch" in
x86_64) echo "x86_64-apple-darwin" ;;
arm64) echo "aarch64-apple-darwin" ;;
*) err "unsupported macOS architecture: $arch" ;;
esac
;;
*) err "unsupported OS: $os" ;;
esac
}
config_dir() {
local os
os="$(uname -s)"
case "$os" in
Linux) echo "${XDG_CONFIG_HOME:-$HOME/.config}/ant" ;;
Darwin) echo "$HOME/Library/Application Support/ant" ;;
*) err "unsupported OS: $os" ;;
esac
}
default_install_dir() {
local os
os="$(uname -s)"
case "$os" in
Linux) echo "$HOME/.local/bin" ;;
Darwin) echo "/usr/local/bin" ;;
*) err "unsupported OS: $os" ;;
esac
}
latest_version() {
curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name"' \
| sed -E 's/.*"ant-cli-v([^"]+)".*/\1/'
}
# --- main -------------------------------------------------------------------
need curl
need tar
TARGET="$(detect_target)"
VERSION="${ANT_VERSION:-$(latest_version)}"
INSTALL_DIR="${INSTALL_DIR:-$(default_install_dir)}"
say "Installing ant ${VERSION} for ${TARGET}..."
ARCHIVE="${BINARY_NAME}-${VERSION}-${TARGET}.tar.gz"
URL="https://github.com/${REPO}/releases/download/ant-cli-v${VERSION}/${ARCHIVE}"
TMPDIR="$(mktemp -d)"
trap 'rm -rf "$TMPDIR"' EXIT
say "Downloading ${URL}..."
curl -fSL -o "${TMPDIR}/${ARCHIVE}" "$URL"
say "Extracting..."
tar xzf "${TMPDIR}/${ARCHIVE}" -C "$TMPDIR"
# Install binary
mkdir -p "$INSTALL_DIR"
cp "${TMPDIR}/${BINARY_NAME}-${VERSION}-${TARGET}/${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"
chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
say "Installed ${BINARY_NAME} to ${INSTALL_DIR}/${BINARY_NAME}"
# Install bootstrap config
CONF_DIR="$(config_dir)"
mkdir -p "$CONF_DIR"
if [ ! -f "${CONF_DIR}/bootstrap_peers.toml" ]; then
cp "${TMPDIR}/${BINARY_NAME}-${VERSION}-${TARGET}/bootstrap_peers.toml" "${CONF_DIR}/bootstrap_peers.toml"
say "Installed bootstrap config to ${CONF_DIR}/bootstrap_peers.toml"
else
say "Bootstrap config already exists at ${CONF_DIR}/bootstrap_peers.toml — skipping"
fi
# Check PATH
case ":$PATH:" in
*":${INSTALL_DIR}:"*) ;;
*)
say ""
say "WARNING: ${INSTALL_DIR} is not in your PATH."
say "Add it with:"
say " export PATH=\"${INSTALL_DIR}:\$PATH\""
;;
esac
say ""
say "Done! Run 'ant --help' to get started."