mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-03 22:34:11 +02:00
Refactor
This commit is contained in:
@@ -1,36 +1,42 @@
|
|||||||
#!/usr/bin/env bashio
|
#!/usr/bin/with-contenv bashio
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
##################
|
# --- Config ---
|
||||||
# SYMLINK CONFIG #
|
PUID="$(bashio::config 'PUID' || echo 0)"
|
||||||
##################
|
PGID="$(bashio::config 'PGID' || echo 0)"
|
||||||
|
|
||||||
if [ ! -d /share/plex ]; then
|
bashio::log.info "Ensuring Plex library location and symlink ..."
|
||||||
echo "Creating /share/plex"
|
|
||||||
mkdir -p /share/plex
|
# 1) Ensure base dir exists
|
||||||
|
install -d -m 0775 /share/plex
|
||||||
|
|
||||||
|
# 2) If a real /config/Library exists and /share/plex/Library doesn't, migrate it once
|
||||||
|
if [ -d /config/Library ] && [ ! -L /config/Library ] && [ ! -e /share/plex/Library ]; then
|
||||||
|
bashio::log.info "Migrating /config/Library to /share/plex/Library"
|
||||||
|
mv /config/Library /share/plex/ # results in /share/plex/Library
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -d /share/plex/Library ] && [ -d /config/Library ]; then
|
# 3) Ensure target exists (in case there was nothing to migrate)
|
||||||
echo "moving Library folder"
|
install -d -m 0775 /share/plex/Library
|
||||||
mv /config/Library /share/plex
|
|
||||||
else
|
|
||||||
rm -r /config/Library
|
|
||||||
echo "Using existing config"
|
|
||||||
fi
|
|
||||||
ln -sf /share/plex/Library /config
|
|
||||||
|
|
||||||
# Only fix ownership/mode if needed (top-level only—*not* blindly every file)
|
# 4) Ensure symlink /config/Library -> /share/plex/Library
|
||||||
PUID="$(bashio::config "PUID")"
|
if [ ! -L /config/Library ] || [ "$(readlink -f /config/Library || true)" != "/share/plex/Library" ]; then
|
||||||
PGID="$(bashio::config "PGID")"
|
# If a leftover dir/file exists at /config/Library, back it up instead of deleting
|
||||||
PUID="${PUID:-0}"
|
if [ -e /config/Library ] && [ ! -L /config/Library ]; then
|
||||||
PGID="${PGID:-0}"
|
TS="$(date +%s)"
|
||||||
|
bashio::log.warning "Found non-symlink at /config/Library; backing up to /config/Library.bak-${TS}"
|
||||||
# Only run fixes if not root (UID/GID != 0)
|
mv /config/Library "/config/Library.bak-${TS}"
|
||||||
if [ "$PUID" != "0" ] && [ "$PGID" != "0" ]; then
|
else
|
||||||
WANTED_MODE="777"
|
rm -f /config/Library || true
|
||||||
CURRENT_MODE=$(stat -c '%a' /share/plex)
|
fi
|
||||||
if [ "$CURRENT_MODE" != "$WANTED_MODE" ]; then
|
ln -sfn /share/plex/Library /config/Library
|
||||||
bashio::log.warning "Providing adequate permissions, please wait"
|
|
||||||
chown -R "$PUID:$PGID" /share/plex
|
|
||||||
chmod -R 777 /share/plex
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 5) Ownership & top-level perms (independent checks; avoid recursive 777)
|
||||||
|
if [ "$PUID" != "0" ] || [ "$PGID" != "0" ]; then
|
||||||
|
chown "$PUID:$PGID" /share/plex /share/plex/Library
|
||||||
|
# 2775 keeps group for new items created inside
|
||||||
|
chmod 2775 /share/plex /share/plex/Library
|
||||||
|
fi
|
||||||
|
|
||||||
|
bashio::log.info "Plex library directory and symlink are ready."
|
||||||
|
|||||||
Reference in New Issue
Block a user