mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-04 08:36:11 +02:00
200 lines
6.4 KiB
Bash
200 lines
6.4 KiB
Bash
#!/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.8"
|
|
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
|
|
}
|
|
|
|
# ── 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 the binary
|
|
mkdir -p "$install_dir"
|
|
cp "$src_dir/EchoHub.Client" "$install_dir/$BINARY_NAME"
|
|
chmod +x "$install_dir/$BINARY_NAME"
|
|
|
|
echo ""
|
|
|
|
# Verify
|
|
if command -v "$BINARY_NAME" >/dev/null 2>&1; then
|
|
echo "Installed successfully! Run 'echohub' to start."
|
|
else
|
|
echo "Installed to: ${install_dir}/${BINARY_NAME}"
|
|
echo ""
|
|
echo "WARNING: ${install_dir} is not in your PATH."
|
|
echo "Add it to your shell profile:"
|
|
echo ""
|
|
echo " echo 'export PATH=\"${install_dir}:\$PATH\"' >> ~/.bashrc"
|
|
echo " # or for zsh:"
|
|
echo " echo 'export PATH=\"${install_dir}:\$PATH\"' >> ~/.zshrc"
|
|
fi
|
|
}
|
|
|
|
main
|