Files
Varaverk/Plugin/dev_install.sh
T

116 lines
4.8 KiB
Bash
Executable File

#!/bin/bash
# ==============================================================================================
# ============================= dev_install.sh =================================================
# ==============================================================================================
#
# PURPOSE
# ─────────────────────────────────────────────────────────────────────────────
# Symlinks the OS-appropriate plugin directory into the web server on first
# install or after the repo is moved. Run once by hand — never by a scheduler.
#
# Detects the running OS from /etc/*-version markers, picks the matching
# Plugin/<os>/ source directory, and creates a symlink at the web server's
# plugin location. All subsequent file changes under Plugin/<os>/ take effect
# immediately without re-running this script.
#
# ==============================================================================================
# OPERATIONAL SAFEGUARDS
# ==============================================================================================
#
# Idempotent Symlink
# Removes any existing symlink at the target before recreating it. Safe to
# re-run after a repo move without leaving stale paths.
#
# Real Directory Guard
# If the target exists as a real directory (not a symlink), the script refuses
# to proceed. Manual cleanup is required to avoid silently discarding an
# existing installation.
#
# Missing Source Guard
# Exits early if Plugin/<os>/ does not exist — catches a missing OS directory
# before any filesystem changes are made.
#
# ==============================================================================================
# CONFIGURATION
# ==============================================================================================
#
# No config vars. All paths are derived from $BASH_SOURCE and the detected OS.
#
# PLUGIN_NAME varaverk (hardcoded — must match the plugin's registered name)
#
# OS detection markers:
# /etc/unraid-version → unraid → /usr/local/emhttp/plugins/varaverk
# /etc/debian_version → debian → (target path not yet defined)
# /etc/arch-release → arch → (target path not yet defined)
#
# ==============================================================================================
# RUNTIME MODES
# ==============================================================================================
#
# ./dev_install.sh
# Auto-detects the running OS and installs.
#
# ./dev_install.sh <os>
# Overrides OS detection. Valid values: unraid, debian, arch.
# Useful when testing on a machine where the marker files differ.
#
# ==============================================================================================
set -euo pipefail
PLUGIN_NAME="varaverk"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# ── Detect OS ────────────────────────────────────────────────────────────────
detect_os() {
if [[ -f /etc/unraid-version ]]; then echo "unraid"
elif [[ -f /etc/debian_version ]]; then echo "debian"
elif [[ -f /etc/arch-release ]]; then echo "arch"
else echo "unknown"; fi
}
OS="${1:-$(detect_os)}" # accept override: ./dev_install.sh unraid
# ── OS-specific install target ────────────────────────────────────────────────
case "$OS" in
unraid)
SOURCE="$SCRIPT_DIR/unraid"
TARGET="/usr/local/emhttp/plugins/$PLUGIN_NAME"
;;
debian|arch)
echo "OS '$OS' detected but plugin target path not yet defined."
echo "Add the TARGET= line for this OS in dev_install.sh."
exit 1
;;
unknown|*)
echo "Unsupported OS — could not detect from /etc/*-version markers."
echo "Usage: $0 <os> (e.g. $0 unraid)"
exit 1
;;
esac
# ── Install ───────────────────────────────────────────────────────────────────
if [[ ! -d "$SOURCE" ]]; then
echo "ERROR: Plugin source not found: $SOURCE"
exit 1
fi
if [[ -L "$TARGET" ]]; then
echo "Removing existing symlink: $TARGET"
rm "$TARGET"
elif [[ -d "$TARGET" ]]; then
echo "ERROR: $TARGET exists as a real directory — remove it manually first."
exit 1
fi
ln -s "$SOURCE" "$TARGET"
echo ""
echo "OS: $OS"
echo "Source: $SOURCE"
echo "Target: $TARGET"
echo ""
echo "Plugin linked. Changes in Plugin/$OS/ take effect immediately."