bots-garden/sidekickpublic⑂ Fork 0
⑂ feature/security
Commits
⬇ Clone ▾
git clone https://git.rickub.com/bots-garden/sidekick.git
git clone ssh://git@rickub.com/bots-garden/sidekick.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

🛟 Updated. 0e8176f · on feature/security · k33g · 2d ago
install.sh · 58 lines · 1.9 KBBash Blame HistoryRaw
 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
#!/usr/bin/env bash
: <<'COMMENT'
Build sidekick and install it on this machine.

Usage:
  ./install.sh                         # installs to /usr/local/bin
  INSTALL_DIR="$HOME/.local/bin" ./install.sh   # installs without sudo

The web UI is embedded in the binary: the binary is all there is to install.
COMMENT

set -euo pipefail

BINARY_NAME="sidekick"
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"

# Build from the repository, whatever directory the script is started from.
cd "$(dirname "${BASH_SOURCE[0]}")"

if ! command -v go >/dev/null 2>&1; then
  echo "❌ Go is not installed (https://go.dev/dl/)"
  exit 1
fi

# The main package is in cmd/server, not at the root of the module. The
# binary is built outside the repository so it is never committed by mistake.
BUILD_DIR="$(mktemp -d)"
trap 'rm -rf "${BUILD_DIR}"' EXIT

# The version: the TAG of release.env when HEAD is that release, otherwise
# nothing is stamped and the binary reports the commit Go embeds (+ -dirty).
LDFLAGS="-s -w"
if [ -f release.env ]; then
  TAG="$(source release.env && printf '%s' "${TAG:-}")"
  if [ -n "${TAG}" ] && git tag --points-at HEAD 2>/dev/null | grep -qx -- "${TAG}"; then
    LDFLAGS="${LDFLAGS} -X main.version=${TAG}"
  fi
fi

echo "🔨 Building ${BINARY_NAME}..."
go build -trimpath -ldflags "${LDFLAGS}" -o "${BUILD_DIR}/${BINARY_NAME}" ./cmd/server
echo "   $("${BUILD_DIR}/${BINARY_NAME}" -version)"

# sudo only when the install directory is not writable by the current user.
SUDO=""
mkdir -p "${INSTALL_DIR}" 2>/dev/null || true
if [[ ! -w "${INSTALL_DIR}" ]]; then
  SUDO="sudo"
fi

echo "📦 Installing ${BINARY_NAME} to ${INSTALL_DIR}..."
${SUDO} mkdir -p "${INSTALL_DIR}"
${SUDO} install -m 755 "${BUILD_DIR}/${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"

echo "✅ Done: ${INSTALL_DIR}/${BINARY_NAME}"
if [[ "$(command -v "${BINARY_NAME}" || true)" != "${INSTALL_DIR}/${BINARY_NAME}" ]]; then
  echo "⚠️  ${INSTALL_DIR} is not first in your PATH for ${BINARY_NAME}"
fi