install.sh RawHistoryFolder
1#!/bin/sh
2set -e
3
4# Gordon installer script
5# Usage: curl -fsSL https://gordon.bnema.dev/install | bash
6
7REPO="bnema/gordon"
8INSTALL_DIR="/usr/local/bin"
9
10echo "Installing Gordon..."
11
12# Detect OS
13OS=$(uname -s | tr '[:upper:]' '[:lower:]')
14case "$OS" in
15 linux)
16 OS="linux"
17 ;;
18 darwin)
19 OS="darwin"
20 ;;
21 *)
22 echo "Error: Unsupported operating system: $OS"
23 exit 1
24 ;;
25esac
26
27# Detect architecture
28ARCH=$(uname -m)
29case "$ARCH" in
30 x86_64|amd64)
31 ARCH="amd64"
32 ;;
33 aarch64|arm64)
34 ARCH="arm64"
35 ;;
36 *)
37 echo "Error: Unsupported architecture: $ARCH"
38 exit 1
39 ;;
40esac
41
42echo "Detected: ${OS}/${ARCH}"
43
44# Construct download URL
45TARBALL="gordon_${OS}_${ARCH}.tar.gz"
46DOWNLOAD_URL="https://github.com/${REPO}/releases/latest/download/${TARBALL}"
47
48# Create temporary directory
49TMP_DIR=$(mktemp -d)
50trap 'rm -rf "$TMP_DIR"' EXIT
51
52# Download checksums file
53CHECKSUMS_URL="https://github.com/${REPO}/releases/latest/download/checksums.txt"
54echo "Downloading checksums..."
55if ! curl -fsSL "$CHECKSUMS_URL" -o "$TMP_DIR/checksums.txt"; then
56 echo "Error: Failed to download checksums file"
57 exit 1
58fi
59
60echo "Downloading ${TARBALL}..."
61if ! curl -fsSL "$DOWNLOAD_URL" -o "$TMP_DIR/$TARBALL"; then
62 echo "Error: Failed to download ${TARBALL}"
63 exit 1
64fi
65
66# Verify checksum
67echo "Verifying checksum..."
68EXPECTED_CHECKSUM=$(grep -E "[[:space:]]${TARBALL}\$" "$TMP_DIR/checksums.txt" | awk '{print $1}')
69if [ -z "$EXPECTED_CHECKSUM" ]; then
70 echo "Error: Could not find checksum for ${TARBALL} in checksums.txt"
71 exit 1
72fi
73
74# Calculate actual checksum (works on both Linux and macOS)
75if command -v sha256sum >/dev/null 2>&1; then
76 ACTUAL_CHECKSUM=$(sha256sum "$TMP_DIR/$TARBALL" | awk '{print $1}')
77elif command -v shasum >/dev/null 2>&1; then
78 ACTUAL_CHECKSUM=$(shasum -a 256 "$TMP_DIR/$TARBALL" | awk '{print $1}')
79else
80 echo "Error: Neither 'sha256sum' nor 'shasum' was found. Cannot verify checksum."
81 echo ""
82 echo "Please install one of these tools:"
83 echo " Debian/Ubuntu: sudo apt-get install coreutils"
84 echo " Fedora/RHEL: sudo dnf install coreutils"
85 echo " Alpine: apk add coreutils"
86 echo " macOS: shasum should be pre-installed"
87 exit 1
88fi
89
90if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]; then
91 echo "Error: Checksum verification failed!"
92 echo "Expected: $EXPECTED_CHECKSUM"
93 echo "Actual: $ACTUAL_CHECKSUM"
94 echo "The downloaded file may be corrupted or tampered with."
95 exit 1
96fi
97echo "Checksum verified successfully."
98
99echo "Extracting..."
100tar -xzf "$TMP_DIR/$TARBALL" -C "$TMP_DIR"
101
102echo "Installing to ${INSTALL_DIR}..."
103if [ -w "$INSTALL_DIR" ]; then
104 mv "$TMP_DIR/gordon" "$INSTALL_DIR/gordon"
105else
106 echo "sudo required to install to ${INSTALL_DIR}"
107 sudo mv "$TMP_DIR/gordon" "$INSTALL_DIR/gordon"
108fi
109
110# Verify installation
111if command -v gordon >/dev/null 2>&1; then
112 echo ""
113 echo "Gordon installed successfully!"
114 gordon version
115else
116 echo ""
117 echo "Installation complete. You may need to add ${INSTALL_DIR} to your PATH."
118fi