128 lines
3 KiB
Bash
128 lines
3 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
########################################
|
|
# Seby's Forgejo Instance Updater
|
|
########################################
|
|
|
|
########################################
|
|
# Styling
|
|
########################################
|
|
BOLD="\033[1m"
|
|
GREEN="\033[32m"
|
|
YELLOW="\033[33m"
|
|
RED="\033[31m"
|
|
BLUE="\033[34m"
|
|
RESET="\033[0m"
|
|
|
|
section() { printf "\n${BLUE}${BOLD}==> %s${RESET}\n" "$*"; }
|
|
say() { printf "${GREEN}✔ %s${RESET}\n" "$*"; }
|
|
warn() { printf "${YELLOW}⚠ %s${RESET}\n" "$*"; }
|
|
err() { printf "${RED}✖ %s${RESET}\n" "$*"; }
|
|
|
|
have() { command -v "$1" >/dev/null 2>&1; }
|
|
|
|
########################################
|
|
# Prompt helper (curl | bash safe)
|
|
########################################
|
|
TTY="/dev/tty"
|
|
|
|
prompt() {
|
|
local msg="$1"
|
|
local out
|
|
printf "${BOLD}%s${RESET}" "$msg" >"$TTY"
|
|
IFS= read -r out <"$TTY"
|
|
printf "%s" "$out"
|
|
}
|
|
|
|
confirm_default_no() {
|
|
local msg="$1"
|
|
local ans
|
|
ans="$(prompt "$msg [y/N]: ")"
|
|
[[ "${ans,,}" == "y" || "${ans,,}" == "yes" ]]
|
|
}
|
|
|
|
########################################
|
|
# Config
|
|
########################################
|
|
APP_DIR="forgejo"
|
|
|
|
########################################
|
|
# Header
|
|
########################################
|
|
clear
|
|
cat << "EOF"
|
|
|
|
________ _
|
|
|_ __ | (_)
|
|
| |_ \_|.--. _ .--. .--./) .---. __ .--.
|
|
| _| / .'`\ \[ `/'`\]/ /'`\;/ /__\\ [ |/ .'`\ \
|
|
_| |_ | \__. | | | \ \._//| \__., _ | || \__. |
|
|
|_____| '.__.' [___] .',__` '.__.'[ \_| | '.__.'
|
|
( ( __)) \____/
|
|
|
|
Forgejo Updater | v1.0
|
|
|
|
EOF
|
|
|
|
########################################
|
|
# Checks
|
|
########################################
|
|
section "Pre-flight Checks"
|
|
|
|
if ! have docker; then
|
|
err "Docker is not installed. Aborting."
|
|
exit 1
|
|
fi
|
|
say "Docker detected: $(docker --version)"
|
|
|
|
if ! docker compose version >/dev/null 2>&1; then
|
|
err "Docker Compose plugin not found. Aborting."
|
|
exit 1
|
|
fi
|
|
say "Docker Compose detected: $(docker compose version --short 2>/dev/null || docker compose version)"
|
|
|
|
if [[ ! -d "$APP_DIR" ]]; then
|
|
err "Directory '${APP_DIR}' not found in $(pwd). Aborting."
|
|
exit 1
|
|
fi
|
|
say "Found ${APP_DIR}/"
|
|
|
|
cd "$APP_DIR"
|
|
|
|
if [[ ! -f "docker-compose.yml" && ! -f "compose.yaml" && ! -f "compose.yml" ]]; then
|
|
err "No docker-compose file found in ${APP_DIR}/. Aborting."
|
|
exit 1
|
|
fi
|
|
|
|
########################################
|
|
# Update
|
|
########################################
|
|
section "Stopping Forgejo & Database"
|
|
docker compose down
|
|
say "Stopped"
|
|
|
|
section "Pulling Latest Images"
|
|
docker compose pull
|
|
say "Images updated"
|
|
|
|
section "Starting Forgejo & Database"
|
|
docker compose up -d
|
|
say "Forgejo is back up"
|
|
|
|
########################################
|
|
# Cleanup
|
|
########################################
|
|
section "Cleanup"
|
|
|
|
if confirm_default_no "Remove old/unused Docker images, containers, and cache?"; then
|
|
docker image prune -af
|
|
docker container prune -f
|
|
docker builder prune -af
|
|
say "Old Docker cache cleared"
|
|
else
|
|
warn "Skipping cleanup"
|
|
fi
|
|
|
|
section "Done"
|
|
say "Forgejo update complete."
|