mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-05-28 11:24:04 +02:00
Update 90-create_links.sh
This commit is contained in:
@@ -1,42 +1,38 @@
|
|||||||
#!/usr/bin/with-contenv bashio
|
#!/usr/bin/with-contenv bashio
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# --- Config ---
|
|
||||||
PUID="$(bashio::config 'PUID' || echo 0)"
|
PUID="$(bashio::config 'PUID' || echo 0)"
|
||||||
PGID="$(bashio::config 'PGID' || echo 0)"
|
PGID="$(bashio::config 'PGID' || echo 0)"
|
||||||
|
|
||||||
bashio::log.info "Ensuring Plex library location and symlink ..."
|
bashio::log.info "Ensuring Plex library location and symlink ..."
|
||||||
|
|
||||||
# 1) Ensure base dir exists
|
# 1) Ensure base dir exists
|
||||||
install -d -m 0775 /share/plex
|
install -d -m 0775 /share/plex || mkdir -p /share/plex
|
||||||
|
|
||||||
# 2) If a real /config/Library exists and /share/plex/Library doesn't, migrate it once
|
# 2) Migrate once if needed
|
||||||
if [ -d /config/Library ] && [ ! -L /config/Library ] && [ ! -e /share/plex/Library ]; then
|
if [ -d /config/Library ] && [ ! -L /config/Library ] && [ ! -e /share/plex/Library ]; then
|
||||||
bashio::log.info "Migrating /config/Library to /share/plex/Library"
|
bashio::log.info "Migrating /config/Library to /share/plex/Library"
|
||||||
mv /config/Library /share/plex/ # results in /share/plex/Library
|
mv /config/Library /share/plex/
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 3) Ensure target exists (in case there was nothing to migrate)
|
# 3) Ensure target exists
|
||||||
install -d -m 0775 /share/plex/Library
|
install -d -m 0775 /share/plex/Library || mkdir -p /share/plex/Library
|
||||||
|
|
||||||
# 4) Ensure symlink /config/Library -> /share/plex/Library
|
# 4) Ensure symlink /config/Library -> /share/plex/Library
|
||||||
if [ ! -L /config/Library ] || [ "$(readlink -f /config/Library || true)" != "/share/plex/Library" ]; then
|
if [ ! -L /config/Library ] || [ "$(readlink -f /config/Library || true)" != "/share/plex/Library" ]; then
|
||||||
# If a leftover dir/file exists at /config/Library, back it up instead of deleting
|
|
||||||
if [ -e /config/Library ] && [ ! -L /config/Library ]; then
|
if [ -e /config/Library ] && [ ! -L /config/Library ]; then
|
||||||
TS="$(date +%s)"
|
mv /config/Library "/config/Library.bak-$(date +%s)"
|
||||||
# bashio::log.warning "Found non-symlink at /config/Library; backing up to /config/Library.bak-${TS}"
|
|
||||||
mv /config/Library "/config/Library.bak-${TS}"
|
|
||||||
else
|
else
|
||||||
rm -f /config/Library || true
|
rm -f /config/Library || true
|
||||||
fi
|
fi
|
||||||
ln -sfn /share/plex/Library /config/Library
|
ln -sfn /share/plex/Library /config/Library
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 5) Ownership & top-level perms (independent checks; avoid recursive 777)
|
# 5) Fix ownership and permissions **recursively** so Plex can write its DB
|
||||||
if [ "$PUID" != "0" ] || [ "$PGID" != "0" ]; then
|
if [ "$PUID" != "0" ] || [ "$PGID" != "0" ]; then
|
||||||
chown "$PUID:$PGID" /share/plex /share/plex/Library
|
chown -R "$PUID:$PGID" /share/plex/Library
|
||||||
# 2775 keeps group for new items created inside
|
chmod -R u+rwX,g+rwX /share/plex/Library
|
||||||
chmod 2775 /share/plex /share/plex/Library
|
chmod g+s /share/plex/Library
|
||||||
fi
|
fi
|
||||||
|
|
||||||
bashio::log.info "Plex library directory and symlink are ready."
|
bashio::log.info "Plex library directory and symlink are ready."
|
||||||
|
|||||||
Reference in New Issue
Block a user