-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·140 lines (119 loc) · 3.52 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·140 lines (119 loc) · 3.52 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
#!/usr/bin/env bash
set -euo pipefail
REPO="${TRENDRADAR_REPO:-codefromkarl/TrendRadar-Rust}"
VERSION="${TRENDRADAR_VERSION:-latest}"
INSTALL_DIR="${TRENDRADAR_INSTALL_DIR:-$HOME/.local/bin}"
BIN_NAME="${TRENDRADAR_BIN_NAME:-trendradar}"
usage() {
cat <<'EOF'
Usage: ./install.sh [--version <tag|latest>] [--dir <path>] [--repo <owner/repo>] [--help]
Install the prebuilt `trendradar` binary from GitHub Releases.
Options:
--version <tag|latest> Release tag to install. Default: latest
--dir <path> Install directory. Default: $HOME/.local/bin
--repo <owner/repo> GitHub repository. Default: codefromkarl/TrendRadar-Rust
--help Show this help message
Environment overrides:
TRENDRADAR_VERSION
TRENDRADAR_INSTALL_DIR
TRENDRADAR_REPO
TRENDRADAR_BIN_NAME
Supported targets:
- Linux x86_64
- macOS arm64
Windows users should download the release asset manually.
EOF
}
log() {
printf '[install] %s\n' "$1"
}
fail() {
printf '[install] ERROR: %s\n' "$1" >&2
exit 1
}
while [[ $# -gt 0 ]]; do
case "$1" in
--version)
[[ $# -ge 2 ]] || fail "--version requires a value"
VERSION="$2"
shift 2
;;
--dir)
[[ $# -ge 2 ]] || fail "--dir requires a value"
INSTALL_DIR="$2"
shift 2
;;
--repo)
[[ $# -ge 2 ]] || fail "--repo requires a value"
REPO="$2"
shift 2
;;
--help|-h)
usage
exit 0
;;
*)
fail "unknown argument: $1"
;;
esac
done
detect_asset() {
local os arch
os="$(uname -s)"
arch="$(uname -m)"
case "${os}:${arch}" in
Linux:x86_64|Linux:amd64)
printf 'trendradar-linux-x86_64'
;;
Darwin:arm64|Darwin:aarch64)
printf 'trendradar-macos-aarch64'
;;
MINGW64_NT-*:x86_64|MSYS_NT-*:x86_64|CYGWIN_NT-*:x86_64)
fail "Windows shell detected; please download trendradar-windows-x86_64.exe from Releases manually"
;;
*)
fail "unsupported platform: ${os} ${arch}"
;;
esac
}
download_with() {
local url="$1"
local output="$2"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$url" -o "$output"
elif command -v wget >/dev/null 2>&1; then
wget -qO "$output" "$url"
else
fail "curl or wget is required to download release assets"
fi
}
normalize_version() {
if [[ "$VERSION" == "latest" ]]; then
printf 'latest'
elif [[ "$VERSION" == v* ]]; then
printf '%s' "$VERSION"
else
printf 'v%s' "$VERSION"
fi
}
asset_name="$(detect_asset)"
normalized_version="$(normalize_version)"
if [[ "$normalized_version" == "latest" ]]; then
download_url="https://github.com/${REPO}/releases/latest/download/${asset_name}"
else
download_url="https://github.com/${REPO}/releases/download/${normalized_version}/${asset_name}"
fi
tmp_file="$(mktemp "${TMPDIR:-/tmp}/trendradar-install.XXXXXX")"
trap 'rm -f "$tmp_file"' EXIT
log "downloading ${download_url}"
download_with "$download_url" "$tmp_file"
mkdir -p "$INSTALL_DIR"
chmod +x "$tmp_file"
install -m 0755 "$tmp_file" "${INSTALL_DIR}/${BIN_NAME}"
log "installed ${BIN_NAME} to ${INSTALL_DIR}/${BIN_NAME}"
if command -v "$BIN_NAME" >/dev/null 2>&1; then
log "binary is already on PATH"
else
log "add ${INSTALL_DIR} to PATH if needed"
fi
log "run '${BIN_NAME} --help' to verify the installation"