diff options
Diffstat (limited to 'install.sh')
| -rwxr-xr-x | install.sh | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..851f73d --- /dev/null +++ b/install.sh @@ -0,0 +1,90 @@ +#!/usr/bin/env sh +set -e + +detect_os() { + case "$(uname -s)" in + Linux*) echo "linux";; + Darwin*) echo "darwin";; + *) + echo "error: unsupported OS $(uname -s)" >&2 + exit 1 + ;; + esac +} + +detect_arch() { + case "$(uname -m)" in + x86_64|amd64) echo "amd64";; + aarch64|arm64) echo "arm64";; + *) + echo "error: unsupported architecture $(uname -m)" >&2 + exit 1 + ;; + esac +} + +checksum_tool() { + if command -v sha256sum >/dev/null 2>&1; then + echo "sha256sum -c" + elif command -v shasum >/dev/null 2>&1; then + echo "shasum -a 256 -c" + else + echo "" + fi +} + +INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}" +OS=$(detect_os) +ARCH=$(detect_arch) + +echo "installing eno ($OS-$ARCH) to $INSTALL_DIR..." + +command -v curl >/dev/null 2>&1 || { echo "error: curl is required" >&2; exit 1; } + +RELEASE_INFO=$(curl -fsSL "https://gitlab.com/api/v4/projects/whiteboardguy%2Feno/releases/permalink/latest") +TAG=$(echo "$RELEASE_INFO" | sed -n 's/.*"tag_name":"\([^"]*\)".*/\1/p') + +if [ -n "$TAG" ]; then + VERSION="${TAG#v}" + ARCHIVE_NAME="eno-${VERSION}-${OS}-${ARCH}.tar.gz" + ARCHIVE_URL="https://gitlab.com/whiteboardguy/eno/-/releases/${TAG}/downloads/${ARCHIVE_NAME}" + CHECKSUM_URL="https://gitlab.com/whiteboardguy/eno/-/releases/${TAG}/downloads/checksums.txt" + TMPDIR=$(mktemp -d) + trap 'rm -rf "$TMPDIR"' EXIT + + if curl -fsSL -o "$TMPDIR/eno.tar.gz" "$ARCHIVE_URL" && \ + curl -fsSL -o "$TMPDIR/checksums.txt" "$CHECKSUM_URL"; then + + CHK_TOOL=$(checksum_tool) + if [ -n "$CHK_TOOL" ]; then + cd "$TMPDIR" + grep "$ARCHIVE_NAME" checksums.txt | $CHK_TOOL >/dev/null 2>&1 || { + echo "error: checksum verification failed" >&2 + exit 1 + } + cd - >/dev/null + fi + + mkdir -p "$INSTALL_DIR" + cd "$TMPDIR" + tar xzf eno.tar.gz + BINARY=$(find . -name eno -type f | head -1) + [ -z "$BINARY" ] && { echo "error: binary not found in archive" >&2; exit 1; } + install -m 755 "$BINARY" "$INSTALL_DIR/eno" + + echo "installed eno $TAG to $INSTALL_DIR/eno" + case ":$PATH:" in + *":$INSTALL_DIR:"*) ;; + *) echo "note: add $INSTALL_DIR to your PATH" ;; + esac + exit 0 + fi + + echo "pre-built binary not available for $OS-$ARCH, trying go install..." +else + echo "no releases found, trying go install..." +fi + +command -v go >/dev/null 2>&1 || { echo "error: go is required for source install" >&2; echo "see https://go.dev/dl/ to install Go" >&2; exit 1; } +go install gitlab.com/whiteboardguy/eno/cmd/eno@latest +echo "installed via go install to $(go env GOPATH)/bin/eno" |