57 lines
1.9 KiB
Bash
57 lines
1.9 KiB
Bash
#!/bin/bash
|
|
|
|
# Non-interactive installer for Ubuntu hosts.
|
|
# - Assumes docker and docker compose plugin are already installed
|
|
# - Installs repo under /opt/ploughshares (uses current repo copy)
|
|
# - Ensures .env exists (creates from .env.example if missing)
|
|
# - Installs systemd unit and timer for stack management and daily restart
|
|
# - Enables and starts services
|
|
|
|
set -euo pipefail
|
|
|
|
if [ "${EUID:-$(id -u)}" -ne 0 ]; then
|
|
echo "This install.sh must be run as root (sudo)."
|
|
exit 1
|
|
fi
|
|
|
|
SRC_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
DEST_DIR="/opt/ploughshares"
|
|
SYSTEMD_DIR="/etc/systemd/system"
|
|
|
|
echo "=== Using existing Docker and compose installation ==="
|
|
|
|
echo "=== Deploying repo to $DEST_DIR ==="
|
|
mkdir -p "$DEST_DIR"
|
|
rsync -a --delete "$SRC_DIR/" "$DEST_DIR/"
|
|
|
|
echo "=== Ensuring .env exists ==="
|
|
if [ ! -f "$DEST_DIR/.env" ]; then
|
|
if [ -f "$DEST_DIR/.env.example" ]; then
|
|
cp "$DEST_DIR/.env.example" "$DEST_DIR/.env"
|
|
echo "Created $DEST_DIR/.env from example. Update secrets as needed."
|
|
else
|
|
touch "$DEST_DIR/.env"
|
|
echo "Created empty $DEST_DIR/.env."
|
|
fi
|
|
fi
|
|
|
|
echo "=== Installing systemd unit and timer ==="
|
|
install -m 0644 "$DEST_DIR/systemd/ploughshares-compose.service" "$SYSTEMD_DIR/ploughshares-compose.service"
|
|
install -m 0644 "$DEST_DIR/systemd/ploughshares-daily-restart.service" "$SYSTEMD_DIR/ploughshares-daily-restart.service"
|
|
install -m 0644 "$DEST_DIR/systemd/ploughshares-daily-restart.timer" "$SYSTEMD_DIR/ploughshares-daily-restart.timer"
|
|
|
|
systemctl daemon-reload
|
|
systemctl enable ploughshares-compose.service
|
|
systemctl start ploughshares-compose.service
|
|
|
|
systemctl enable ploughshares-daily-restart.timer
|
|
systemctl start ploughshares-daily-restart.timer
|
|
|
|
echo "=== Verifying services ==="
|
|
systemctl --no-pager status ploughshares-compose.service | sed -n '1,20p'
|
|
systemctl --no-pager status ploughshares-daily-restart.timer | sed -n '1,20p'
|
|
|
|
echo "Install complete. Repo at $DEST_DIR. Edit $DEST_DIR/.env to set secrets."
|
|
|
|
|