-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
230 lines (194 loc) · 7.5 KB
/
Copy pathinstall.sh
File metadata and controls
230 lines (194 loc) · 7.5 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
227
228
229
230
#!/bin/sh
# EchoHub Client Installer
# Usage: curl -sSfL https://raw.githubusercontent.com/HueByte/EchoHub/master/scripts/install.sh | sh
#
# Options (pass as arguments or environment variables):
# --version X.Y.Z Install a specific version (default: latest)
# --install-dir DIR Install to a custom directory
# --help Show this help message
set -eu
REPO="HueByte/EchoHub"
BINARY_NAME="echohub"
INSTALL_DIR=""
VERSION=""
# ── Argument parsing ──────────────────────────────────────────────────────
while [ $# -gt 0 ]; do
case "$1" in
--version)
VERSION="$2"
shift 2
;;
--install-dir)
INSTALL_DIR="$2"
shift 2
;;
--help)
sed -n '2,8p' "$0" 2>/dev/null || true
echo ""
echo " curl -sSfL https://raw.githubusercontent.com/$REPO/master/scripts/install.sh | sh"
echo " curl ... | sh -s -- --version 0.2.11"
echo " curl ... | sh -s -- --install-dir /opt/echohub"
exit 0
;;
*)
echo "Unknown option: $1" >&2
exit 1
;;
esac
done
# ── Platform detection ────────────────────────────────────────────────────
detect_os() {
case "$(uname -s)" in
Linux*) echo "linux" ;;
Darwin*) echo "osx" ;;
*)
echo "Error: Unsupported operating system: $(uname -s)" >&2
echo "EchoHub supports Linux and macOS. For Windows, use: choco install echohub" >&2
exit 1
;;
esac
}
detect_arch() {
case "$(uname -m)" in
x86_64|amd64) echo "x64" ;;
aarch64|arm64) echo "arm64" ;;
*)
echo "Error: Unsupported architecture: $(uname -m)" >&2
echo "EchoHub supports x64 and arm64." >&2
exit 1
;;
esac
}
# ── Version resolution ────────────────────────────────────────────────────
resolve_version() {
if [ -n "$VERSION" ]; then
echo "$VERSION"
return
fi
# Fetch latest release tag from GitHub API
if command -v curl >/dev/null 2>&1; then
tag=$(curl -sSf "https://api.github.com/repos/$REPO/releases/latest" \
| grep '"tag_name"' | head -1 | sed 's/.*"tag_name"[[:space:]]*:[[:space:]]*"v\?\([^"]*\)".*/\1/')
elif command -v wget >/dev/null 2>&1; then
tag=$(wget -qO- "https://api.github.com/repos/$REPO/releases/latest" \
| grep '"tag_name"' | head -1 | sed 's/.*"tag_name"[[:space:]]*:[[:space:]]*"v\?\([^"]*\)".*/\1/')
else
echo "Error: curl or wget is required to detect the latest version." >&2
echo "Install curl/wget or specify a version with --version X.Y.Z" >&2
exit 1
fi
if [ -z "$tag" ]; then
echo "Error: Could not determine latest version from GitHub." >&2
exit 1
fi
echo "$tag"
}
# ── Install directory resolution ──────────────────────────────────────────
resolve_install_dir() {
if [ -n "$INSTALL_DIR" ]; then
echo "$INSTALL_DIR"
return
fi
# Prefer /usr/local/bin if writable, otherwise ~/.local/bin
if [ -w "/usr/local/bin" ]; then
echo "/usr/local/bin"
else
local_bin="$HOME/.local/bin"
mkdir -p "$local_bin"
echo "$local_bin"
fi
}
# ── Download helper ───────────────────────────────────────────────────────
download() {
url="$1"
output="$2"
if command -v curl >/dev/null 2>&1; then
curl -sSfL "$url" -o "$output"
elif command -v wget >/dev/null 2>&1; then
wget -qO "$output" "$url"
else
echo "Error: curl or wget is required." >&2
exit 1
fi
}
# ── PATH setup ────────────────────────────────────────────────────────────
add_to_path() {
dir="$1"
export_line="export PATH=\"${dir}:\$PATH\" # Added by EchoHub"
added=0
for profile in "$HOME/.profile" "$HOME/.bashrc" "$HOME/.zshrc"; do
if [ -f "$profile" ]; then
if grep -q "$dir" "$profile" 2>/dev/null; then
continue # Already present
fi
printf '\n%s\n' "$export_line" >> "$profile"
echo " Added to PATH in $(basename "$profile")"
added=1
fi
done
# If no profile existed, create .profile
if [ "$added" -eq 0 ]; then
printf '\n%s\n' "$export_line" >> "$HOME/.profile"
echo " Added to PATH in .profile"
fi
}
# ── Main ──────────────────────────────────────────────────────────────────
main() {
os=$(detect_os)
arch=$(detect_arch)
version=$(resolve_version)
install_dir=$(resolve_install_dir)
artifact="EchoHub-Client-${os}-${arch}.zip"
url="https://github.com/$REPO/releases/download/v${version}/${artifact}"
echo "EchoHub Installer"
echo " Version: v${version}"
echo " Platform: ${os}-${arch}"
echo " Install to: ${install_dir}"
echo ""
# Create temp directory with cleanup trap
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
echo "Downloading ${artifact}..."
download "$url" "$tmpdir/echohub.zip"
echo "Extracting..."
if command -v unzip >/dev/null 2>&1; then
unzip -qo "$tmpdir/echohub.zip" -d "$tmpdir/extract"
else
echo "Error: unzip is required to extract the archive." >&2
echo "Install it with: apt install unzip / brew install unzip" >&2
exit 1
fi
# The ZIP contains a client-{os}-{arch}/ subdirectory
src_dir="$tmpdir/extract/client-${os}-${arch}"
if [ ! -d "$src_dir" ]; then
# Fallback: look for any directory containing the binary
src_dir=$(find "$tmpdir/extract" -name "EchoHub.Client" -type f -printf '%h' -quit 2>/dev/null || true)
if [ -z "$src_dir" ]; then
echo "Error: Could not find EchoHub.Client binary in the archive." >&2
exit 1
fi
fi
# Install full directory to ~/.local/share/echohub and symlink the binary.
# Even single-file publishes may have content files (appsettings, assets)
# that the app expects next to the binary via AppContext.BaseDirectory.
app_dir="$HOME/.local/share/echohub"
rm -rf "$app_dir"
mkdir -p "$app_dir"
cp -r "$src_dir"/. "$app_dir/"
chmod +x "$app_dir/EchoHub.Client"
mkdir -p "$install_dir"
ln -sf "$app_dir/EchoHub.Client" "$install_dir/$BINARY_NAME"
echo ""
# Ensure install directory is on PATH
if ! command -v "$BINARY_NAME" >/dev/null 2>&1; then
add_to_path "$install_dir"
fi
echo "Installed successfully! Run 'echohub' to start."
echo ""
if ! echo "$PATH" | tr ':' '\n' | grep -qx "$install_dir"; then
echo "NOTE: Restart your shell or run the following to use echohub now:"
echo ""
echo " export PATH=\"${install_dir}:\$PATH\""
fi
}
main