diff --git a/update-panel.sh b/update-panel.sh index 0d877e8..aad16fd 100755 --- a/update-panel.sh +++ b/update-panel.sh @@ -1,5 +1,127 @@ -#!/bin/bash -cd calagopus +#!/usr/bin/env bash +set -euo pipefail + +######################################## +# Seby's Calagopus Wings 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="calagopus" + +######################################## +# Header +######################################## +clear +cat << "EOF" + + ____ _ + / ___|__ _| | __ _ __ _ ___ _ __ _ _ ___ +| | / _` | |/ _` |/ _` |/ _ \| '_ \| | | / __| +| |__| (_| | | (_| | (_| | (_) | |_) | |_| \__ \ + \____\__,_|_|\__,_|\__, |\___/| .__/ \__,_|___/ + |___/ |_| + + Calagopus Wings 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 Wings" docker compose down +say "Stopped" + +section "Pulling Latest Images" docker compose pull +say "Images updated" + +section "Starting Wings" docker compose up -d +say "Wings 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 "Calagopus Wings update complete."