Files
family-planner/unraid/install.sh

98 lines
4.6 KiB
Bash
Raw Normal View History

#!/bin/bash
# ─────────────────────────────────────────────────────────────────────────────
# Family Planner — Unraid CLI Install Script
#
# Run from the Unraid terminal:
# bash /path/to/install.sh
#
# Or pipe directly (once the image is published):
# curl -fsSL https://raw.githubusercontent.com/your-username/family-planner/main/unraid/install.sh | bash
# ─────────────────────────────────────────────────────────────────────────────
set -euo pipefail
# ── Configurable defaults (edit these or they will be prompted) ───────────────
IMAGE="${IMAGE:-ghcr.io/your-username/family-planner:latest}"
CONTAINER_NAME="${CONTAINER_NAME:-family-planner}"
HOST_PORT="${HOST_PORT:-3001}"
DATA_PATH="${DATA_PATH:-/mnt/user/appdata/family-planner}"
PHOTOS_PATH="${PHOTOS_PATH:-/mnt/user/Photos}"
PUID="${PUID:-99}"
PGID="${PGID:-100}"
TZ="${TZ:-America/New_York}"
# ── Helper ────────────────────────────────────────────────────────────────────
info() { echo -e "\033[1;34m[INFO]\033[0m $*"; }
success() { echo -e "\033[1;32m[OK]\033[0m $*"; }
warn() { echo -e "\033[1;33m[WARN]\033[0m $*"; }
error() { echo -e "\033[1;31m[ERROR]\033[0m $*" >&2; exit 1; }
# ── Preflight ─────────────────────────────────────────────────────────────────
command -v docker &>/dev/null || error "Docker is not installed or not in PATH."
info "Family Planner — Unraid Installer"
echo ""
echo " Container : $CONTAINER_NAME"
echo " Image : $IMAGE"
echo " Port : $HOST_PORT → 3001"
echo " Data path : $DATA_PATH"
echo " Photos : $PHOTOS_PATH (read-only)"
echo " PUID/PGID : $PUID/$PGID"
echo " TZ : $TZ"
echo ""
read -rp "Proceed with these settings? [Y/n] " confirm
confirm="${confirm:-Y}"
[[ "$confirm" =~ ^[Yy]$ ]] || { info "Aborted."; exit 0; }
# ── Stop and remove existing container if present ─────────────────────────────
if docker inspect "$CONTAINER_NAME" &>/dev/null; then
warn "Container '$CONTAINER_NAME' already exists — stopping and removing it."
docker stop "$CONTAINER_NAME" &>/dev/null || true
docker rm "$CONTAINER_NAME" &>/dev/null || true
fi
# ── Ensure data directory exists ──────────────────────────────────────────────
mkdir -p "$DATA_PATH"
success "Data directory ready: $DATA_PATH"
# ── Pull the latest image ─────────────────────────────────────────────────────
info "Pulling image: $IMAGE"
docker pull "$IMAGE"
# ── Run the container ─────────────────────────────────────────────────────────
info "Starting container..."
docker run -d \
--name "$CONTAINER_NAME" \
--restart unless-stopped \
-p "${HOST_PORT}:3001" \
-v "${DATA_PATH}:/data" \
-v "${PHOTOS_PATH}:/photos:ro" \
-e "PUID=${PUID}" \
-e "PGID=${PGID}" \
-e "TZ=${TZ}" \
-e "PORT=3001" \
-e "DATA_DIR=/data" \
-e "PHOTOS_DIR=/photos" \
"$IMAGE"
# ── Verify startup ────────────────────────────────────────────────────────────
info "Waiting for container to become healthy..."
for i in $(seq 1 15); do
if docker exec "$CONTAINER_NAME" wget -qO- http://localhost:3001/api/settings &>/dev/null; then
success "Family Planner is up!"
break
fi
sleep 2
if [ "$i" -eq 15 ]; then
warn "Health check timed out. Check logs with: docker logs $CONTAINER_NAME"
fi
done
echo ""
success "Installation complete."
echo ""
echo " Open in browser : http://$(hostname -I | awk '{print $1}'):${HOST_PORT}"
echo " View logs : docker logs -f $CONTAINER_NAME"
echo " Stop : docker stop $CONTAINER_NAME"
echo " Update image : docker pull $IMAGE && docker stop $CONTAINER_NAME && bash $(realpath "$0")"
echo ""