make setup.sh idempotent so it can be safely re-run
This commit is contained in:
@@ -3,6 +3,7 @@ set -euo pipefail
|
|||||||
|
|
||||||
# Server setup script for a fresh Rocky Linux 9 (or compatible) install.
|
# Server setup script for a fresh Rocky Linux 9 (or compatible) install.
|
||||||
# Run as root after cloning the repo to /opt/hantim.
|
# Run as root after cloning the repo to /opt/hantim.
|
||||||
|
# Safe to re-run — all steps are idempotent.
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# 1. dnf install -y git
|
# 1. dnf install -y git
|
||||||
@@ -30,34 +31,45 @@ fi
|
|||||||
echo "==> Installing dependencies..."
|
echo "==> Installing dependencies..."
|
||||||
dnf install -y git-crypt npm
|
dnf install -y git-crypt npm
|
||||||
|
|
||||||
|
if ! command -v bw &>/dev/null; then
|
||||||
echo "==> Installing Bitwarden CLI..."
|
echo "==> Installing Bitwarden CLI..."
|
||||||
npm install -g @bitwarden/cli
|
npm install -g @bitwarden/cli
|
||||||
|
fi
|
||||||
|
|
||||||
# --- Unlock git-crypt via Bitwarden ---
|
# --- Unlock git-crypt via Bitwarden ---
|
||||||
|
|
||||||
|
cd "$REPO_DIR"
|
||||||
|
if git-crypt status 2>/dev/null | grep -q '^\*\*\*ENCRYPTED\*\*\*'; then
|
||||||
echo "==> Fetching git-crypt key from Bitwarden..."
|
echo "==> Fetching git-crypt key from Bitwarden..."
|
||||||
echo " Log in to Bitwarden when prompted."
|
echo " Log in to Bitwarden when prompted."
|
||||||
|
if bw status 2>/dev/null | grep -q '"status":"unauthenticated"'; then
|
||||||
bw login
|
bw login
|
||||||
|
fi
|
||||||
BW_SESSION=$(bw unlock --raw)
|
BW_SESSION=$(bw unlock --raw)
|
||||||
bw get notes hantim-git-crypt-key --session "$BW_SESSION" | base64 -d > /tmp/git-crypt-key
|
bw get notes hantim-git-crypt-key --session "$BW_SESSION" | base64 -d > /tmp/git-crypt-key
|
||||||
|
|
||||||
cd "$REPO_DIR"
|
|
||||||
git-crypt unlock /tmp/git-crypt-key
|
git-crypt unlock /tmp/git-crypt-key
|
||||||
rm /tmp/git-crypt-key
|
rm /tmp/git-crypt-key
|
||||||
bw lock
|
bw lock
|
||||||
|
else
|
||||||
|
echo "==> git-crypt already unlocked, skipping."
|
||||||
|
fi
|
||||||
|
|
||||||
# --- Install Docker ---
|
# --- Install Docker ---
|
||||||
|
|
||||||
|
if ! command -v docker &>/dev/null; then
|
||||||
echo "==> Installing Docker..."
|
echo "==> Installing Docker..."
|
||||||
dnf install -y dnf-plugins-core
|
dnf install -y dnf-plugins-core
|
||||||
dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
|
dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
|
||||||
dnf install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
dnf install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
||||||
|
fi
|
||||||
systemctl enable --now docker
|
systemctl enable --now docker
|
||||||
|
|
||||||
# --- Create deploy user ---
|
# --- Create deploy user ---
|
||||||
|
|
||||||
|
if ! id deploy &>/dev/null; then
|
||||||
echo "==> Creating deploy user..."
|
echo "==> Creating deploy user..."
|
||||||
useradd -r -s /usr/sbin/nologin deploy
|
useradd -r -s /usr/sbin/nologin deploy
|
||||||
|
fi
|
||||||
usermod -aG docker deploy
|
usermod -aG docker deploy
|
||||||
|
|
||||||
echo "==> Setting up deploy SSH key..."
|
echo "==> Setting up deploy SSH key..."
|
||||||
@@ -76,7 +88,7 @@ echo "==> Making scripts executable..."
|
|||||||
chmod +x "$REPO_DIR/scripts/"*.sh
|
chmod +x "$REPO_DIR/scripts/"*.sh
|
||||||
|
|
||||||
echo "==> Creating shared Docker network..."
|
echo "==> Creating shared Docker network..."
|
||||||
docker network create shared || true
|
docker network create shared 2>/dev/null || true
|
||||||
|
|
||||||
echo "==> Logging into Gitea registry..."
|
echo "==> Logging into Gitea registry..."
|
||||||
echo "Run manually: docker login git.timothykim.net"
|
echo "Run manually: docker login git.timothykim.net"
|
||||||
|
|||||||
Reference in New Issue
Block a user