Files
ssh-access-tui/scripts/install.sh
T
2026-07-22 14:14:53 +03:00

56 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Installs ssh-access-tui on a Linux jump host from a prebuilt binary
# (no Go toolchain on the production host, deliberately — build once in
# CI/dev, ship the binary): checks its two external dependencies
# (ssh-keygen, 7z), installs the journal-tailer and backup systemd units,
# and runs the tool's own "install" step (sshd Match block + directories).
set -euo pipefail
if [ "$(id -u)" -ne 0 ]; then
echo "Run as root (sudo $0)." >&2
exit 1
fi
SRC_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BIN_PATH="/usr/local/bin/ssh-access-tui"
BACKUP_SCRIPT_PATH="/usr/local/bin/ssh-access-tui-backup.sh"
if ! command -v ssh-keygen >/dev/null 2>&1; then
echo "ssh-keygen not found — install openssh-client." >&2
exit 1
fi
if ! command -v 7z >/dev/null 2>&1; then
echo "7z not found — install p7zip-full (apt) or p7zip (rpm)." >&2
exit 1
fi
if ! command -v git >/dev/null 2>&1; then
echo "git not found — required for state versioning/backup." >&2
exit 1
fi
if [ ! -x "$SRC_DIR/ssh-access-tui" ]; then
echo "Prebuilt binary not found at $SRC_DIR/ssh-access-tui." >&2
echo "Build it elsewhere (dev machine/CI): CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ssh-access-tui ./cmd/ssh-access-tui" >&2
echo "then copy it next to this script and re-run. This script never builds on the production host." >&2
exit 1
fi
install -m 0750 "$SRC_DIR/ssh-access-tui" "$BIN_PATH"
install -m 0750 "$SRC_DIR/scripts/ssh-access-tui-backup.sh" "$BACKUP_SCRIPT_PATH"
install -m 0644 "$SRC_DIR/scripts/ssh-access-tui-audit.service" /etc/systemd/system/ssh-access-tui-audit.service
install -m 0644 "$SRC_DIR/scripts/ssh-access-tui-backup.service" /etc/systemd/system/ssh-access-tui-backup.service
install -m 0644 "$SRC_DIR/scripts/ssh-access-tui-backup.timer" /etc/systemd/system/ssh-access-tui-backup.timer
systemctl daemon-reload
"$BIN_PATH" install
systemctl enable --now ssh-access-tui-audit.service
systemctl enable --now ssh-access-tui-backup.timer
echo
echo "Установка завершена."
echo "Запуск TUI: sudo ssh-access-tui"
echo "Настройте git-бэкап: git -C /var/lib/ssh-access-tui/state remote add origin <url>"
echo "Инструкция для админа: $SRC_DIR/docs/ADMIN_GUIDE.md"