89 lines
2.2 KiB
Bash
Executable File
89 lines
2.2 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
REPO="ogulcancelik/herdr"
|
|
BIN="herdr"
|
|
INSTALL_DIR="${HERDR_INSTALL_DIR:-$HOME/.local/bin}"
|
|
|
|
main() {
|
|
echo ""
|
|
echo " ,ww"
|
|
echo " wWWWWWWW_) herdr installer"
|
|
echo " \`WWWWWW' herdr.dev"
|
|
echo " II II"
|
|
echo ""
|
|
|
|
# detect platform
|
|
OS="$(uname -s)"
|
|
case "$OS" in
|
|
Linux) os="linux" ;;
|
|
Darwin) os="macos" ;;
|
|
*) err "unsupported OS: $OS" ;;
|
|
esac
|
|
|
|
ARCH="$(uname -m)"
|
|
case "$ARCH" in
|
|
x86_64|amd64) arch="x86_64" ;;
|
|
aarch64|arm64) arch="aarch64" ;;
|
|
*) err "unsupported architecture: $ARCH" ;;
|
|
esac
|
|
|
|
log "detected ${os}/${arch}"
|
|
|
|
# check dependencies
|
|
need curl
|
|
|
|
# download the latest binary directly via GitHub's stable redirect.
|
|
# this avoids the releases API, which can return transient 403s.
|
|
ASSET="${BIN}-${os}-${arch}"
|
|
URL="https://github.com/${REPO}/releases/latest/download/${ASSET}"
|
|
|
|
log "downloading latest release..."
|
|
TMP="$(mktemp -d)"
|
|
trap 'rm -rf "$TMP"' EXIT
|
|
|
|
if ! curl -fsSL --retry 3 --connect-timeout 10 --max-time 120 "$URL" -o "${TMP}/${BIN}"; then
|
|
err "download failed. check https://github.com/${REPO}/releases"
|
|
fi
|
|
|
|
# install
|
|
mkdir -p "$INSTALL_DIR"
|
|
mv "${TMP}/${BIN}" "${INSTALL_DIR}/${BIN}"
|
|
chmod +x "${INSTALL_DIR}/${BIN}"
|
|
|
|
log "installed ${BIN} to ${INSTALL_DIR}/${BIN}"
|
|
|
|
# check PATH
|
|
case ":${PATH}:" in
|
|
*":${INSTALL_DIR}:"*) ;;
|
|
*)
|
|
echo ""
|
|
warn "${INSTALL_DIR} is not in your PATH"
|
|
echo " add it to your shell config:"
|
|
echo ""
|
|
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
|
|
echo ""
|
|
;;
|
|
esac
|
|
|
|
# verify
|
|
if command -v "$BIN" >/dev/null 2>&1; then
|
|
echo ""
|
|
log "ready. run 'herdr' to get started."
|
|
fi
|
|
|
|
echo ""
|
|
}
|
|
|
|
log() { printf ' \033[32m>\033[0m %s\n' "$1"; }
|
|
warn() { printf ' \033[33m!\033[0m %s\n' "$1"; }
|
|
err() { printf ' \033[31m✗\033[0m %s\n' "$1" >&2; exit 1; }
|
|
|
|
need() {
|
|
if ! command -v "$1" >/dev/null 2>&1; then
|
|
err "requires '$1' — please install it first"
|
|
fi
|
|
}
|
|
|
|
main "$@"
|