refactor: install.sh always installs Go and builds from source — no binary downloads
- Removed all pre-built binary download logic from install.sh - install.sh now installs Go (via apt/dnf/apk) if not present - Always builds from source — ensures latest code, correct platform - Removed dist/ binaries from local disk (not tracked in git)
This commit is contained in:
parent
ce2efd9be7
commit
c83b2ccc83
1 changed files with 44 additions and 35 deletions
65
install.sh
65
install.sh
|
|
@ -98,24 +98,29 @@ if [ "${1:-}" = "-update" ]; then
|
||||||
info "Stopping service..."
|
info "Stopping service..."
|
||||||
sudo_if systemctl stop "$SERVICE_NAME" 2>/dev/null || true
|
sudo_if systemctl stop "$SERVICE_NAME" 2>/dev/null || true
|
||||||
|
|
||||||
|
# Ensure Go is installed for building from source.
|
||||||
|
if ! command -v go &>/dev/null; then
|
||||||
|
info "Installing Go..."
|
||||||
|
if command -v apt-get &>/dev/null; then
|
||||||
|
sudo_if apt-get update -qq && sudo_if apt-get install -y -qq golang-go 2>&1 | tail -1
|
||||||
|
elif command -v dnf &>/dev/null; then
|
||||||
|
sudo_if dnf install -y golang 2>&1 | tail -1
|
||||||
|
elif command -v apk &>/dev/null; then
|
||||||
|
sudo_if apk add go 2>&1 | tail -1
|
||||||
|
else
|
||||||
|
err "No package manager found. Please install Go 1.23+ manually."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
info "Rebuilding binary..."
|
info "Rebuilding binary..."
|
||||||
if command -v go &>/dev/null; then
|
|
||||||
export GOMODCACHE="${INSTALL_DIR}/.go/mod"
|
export GOMODCACHE="${INSTALL_DIR}/.go/mod"
|
||||||
export GOPATH="${INSTALL_DIR}/.go"
|
export GOPATH="${INSTALL_DIR}/.go"
|
||||||
export GOCACHE="${INSTALL_DIR}/.go/build"
|
export GOCACHE="${INSTALL_DIR}/.go/build"
|
||||||
mkdir -p "${GOMODCACHE}" "${GOCACHE}" 2>/dev/null || sudo_if mkdir -p "${GOMODCACHE}" "${GOCACHE}"
|
mkdir -p "${GOMODCACHE}" "${GOCACHE}" 2>/dev/null || sudo_if mkdir -p "${GOMODCACHE}" "${GOCACHE}"
|
||||||
# Ensure build cache and old binary are writable by the app user.
|
|
||||||
sudo_if chown -R "${APP_USER:-${SUDO_USER:-$(whoami)}}" "${INSTALL_DIR}/.go" "${INSTALL_DIR}/app" 2>/dev/null || true
|
sudo_if chown -R "${APP_USER:-${SUDO_USER:-$(whoami)}}" "${INSTALL_DIR}/.go" "${INSTALL_DIR}/app" 2>/dev/null || true
|
||||||
sudo_if rm -f app
|
sudo_if rm -f app
|
||||||
CGO_ENABLED=0 go build -buildvcs=false -ldflags="-s -w" -o app .
|
CGO_ENABLED=0 go build -buildvcs=false -ldflags="-s -w" -o app .
|
||||||
else
|
|
||||||
warn "Go not found — downloading pre-built binary..."
|
|
||||||
TAG=$(curl -fsSL https://git.lohmar.co.uk/api/v1/repos/cclohmar/ReceiptNext/releases/latest \
|
|
||||||
| python3 -c "import json,sys; print(json.load(sys.stdin).get('tag_name','v1.0.0'))" 2>/dev/null || echo "v1.0.0")
|
|
||||||
ARCH="$(uname -m)"; [ "$ARCH" = "x86_64" ] && ARCH="amd64"; [ "$ARCH" = "aarch64" ] && ARCH="arm64"
|
|
||||||
sudo_if curl -fsSL -o app "https://git.lohmar.co.uk/cclohmar/ReceiptNext/releases/download/${TAG}/app-linux-${ARCH}"
|
|
||||||
sudo_if chmod +x app
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Fix ownership of all files (build cache may be root-owned from earlier builds).
|
# Fix ownership of all files (build cache may be root-owned from earlier builds).
|
||||||
sudo_if chown -R "${APP_USER:-${SUDO_USER:-$(whoami)}}:${APP_USER:-${SUDO_USER:-$(whoami)}}" "$INSTALL_DIR" 2>/dev/null || true
|
sudo_if chown -R "${APP_USER:-${SUDO_USER:-$(whoami)}}:${APP_USER:-${SUDO_USER:-$(whoami)}}" "$INSTALL_DIR" 2>/dev/null || true
|
||||||
|
|
@ -205,25 +210,29 @@ case "$ARCH" in
|
||||||
*) err "Unsupported architecture: $ARCH"; exit 1 ;;
|
*) err "Unsupported architecture: $ARCH"; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if command -v go &>/dev/null; then
|
# Ensure Go is installed for building from source.
|
||||||
info "Building binary from source (pure Go, no CGO)..."
|
if ! command -v go &>/dev/null; then
|
||||||
# Use a writable cache — the user's home (/app/) may not be writable
|
info "Installing Go..."
|
||||||
export GOMODCACHE="${INSTALL_DIR}/.go/mod"
|
if command -v apt-get &>/dev/null; then
|
||||||
export GOPATH="${INSTALL_DIR}/.go"
|
sudo_if apt-get update -qq && sudo_if apt-get install -y -qq golang-go 2>&1 | tail -1
|
||||||
export GOCACHE="${INSTALL_DIR}/.go/build"
|
elif command -v dnf &>/dev/null; then
|
||||||
mkdir -p "${GOMODCACHE}" "${GOCACHE}" 2>/dev/null || sudo_if mkdir -p "${GOMODCACHE}" "${GOCACHE}"
|
sudo_if dnf install -y golang 2>&1 | tail -1
|
||||||
# Ensure cache is owned by the app user.
|
elif command -v apk &>/dev/null; then
|
||||||
sudo_if chown -R "$(whoami):$(whoami)" "${INSTALL_DIR}/.go" "${INSTALL_DIR}/app" 2>/dev/null || true
|
sudo_if apk add go 2>&1 | tail -1
|
||||||
sudo_if rm -f app
|
else
|
||||||
CGO_ENABLED=0 go build -buildvcs=false -ldflags="-s -w" -o app .
|
err "No package manager found. Please install Go 1.23+ manually."
|
||||||
else
|
exit 1
|
||||||
info "Go not found — downloading pre-built binary..."
|
fi
|
||||||
TAG=$(curl -fsSL https://git.lohmar.co.uk/api/v1/repos/cclohmar/ReceiptNext/releases/latest \
|
|
||||||
| python3 -c "import json,sys; print(json.load(sys.stdin).get('tag_name','v1.0.0'))" 2>/dev/null || echo "v1.0.0")
|
|
||||||
URL="https://git.lohmar.co.uk/cclohmar/ReceiptNext/releases/download/${TAG}/app-linux-${ARCH}"
|
|
||||||
sudo_if curl -fsSL -o app "$URL"
|
|
||||||
sudo_if chmod +x app
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
info "Building binary from source (pure Go, no CGO)..."
|
||||||
|
export GOMODCACHE="${INSTALL_DIR}/.go/mod"
|
||||||
|
export GOPATH="${INSTALL_DIR}/.go"
|
||||||
|
export GOCACHE="${INSTALL_DIR}/.go/build"
|
||||||
|
mkdir -p "${GOMODCACHE}" "${GOCACHE}" 2>/dev/null || sudo_if mkdir -p "${GOMODCACHE}" "${GOCACHE}"
|
||||||
|
sudo_if chown -R "$(whoami):$(whoami)" "${INSTALL_DIR}/.go" "${INSTALL_DIR}/app" 2>/dev/null || true
|
||||||
|
sudo_if rm -f app
|
||||||
|
CGO_ENABLED=0 go build -buildvcs=false -ldflags="-s -w" -o app .
|
||||||
info "Binary ready: $INSTALL_DIR/app"
|
info "Binary ready: $INSTALL_DIR/app"
|
||||||
|
|
||||||
# ── 3. Create runtime directories ────────────────────────────────
|
# ── 3. Create runtime directories ────────────────────────────────
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue