mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-11 02:11:01 +01:00
Revert code and implement skip permissions
This commit is contained in:
@@ -1,38 +1,29 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
set -euo pipefail
|
||||
#!/usr/bin/env bashio
|
||||
|
||||
PUID="$(bashio::config 'PUID' || echo 0)"
|
||||
PGID="$(bashio::config 'PGID' || echo 0)"
|
||||
##################
|
||||
# SYMLINK CONFIG #
|
||||
##################
|
||||
|
||||
bashio::log.info "Ensuring Plex library location and symlink ..."
|
||||
|
||||
# 1) Ensure base dir exists
|
||||
install -d -m 0775 /share/plex || mkdir -p /share/plex
|
||||
|
||||
# 2) Migrate once if needed
|
||||
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/
|
||||
if [ ! -d /share/plex ]; then
|
||||
echo "Creating /share/plex"
|
||||
mkdir -p /share/plex
|
||||
fi
|
||||
|
||||
# 3) Ensure target exists
|
||||
install -d -m 0775 /share/plex/Library || mkdir -p /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 [ -e /config/Library ] && [ ! -L /config/Library ]; then
|
||||
mv /config/Library "/config/Library.bak-$(date +%s)"
|
||||
else
|
||||
rm -f /config/Library || true
|
||||
fi
|
||||
ln -sfn /share/plex/Library /config/Library
|
||||
if [ ! -d /share/plex/Library ]; then
|
||||
echo "moving Library folder"
|
||||
mv /config/Library /share/plex
|
||||
ln -s /share/plex/Library /config
|
||||
echo "links done"
|
||||
else
|
||||
rm -r /config/Library
|
||||
ln -s /share/plex/Library /config
|
||||
echo "Using existing config"
|
||||
fi
|
||||
|
||||
# 5) Fix ownership and permissions **recursively** so Plex can write its DB
|
||||
if [ "$PUID" != "0" ] || [ "$PGID" != "0" ]; then
|
||||
chown -R "$PUID:$PGID" /share/plex/Library
|
||||
chmod -R u+rwX,g+rwX /share/plex/Library
|
||||
chmod g+s /share/plex/Library
|
||||
fi
|
||||
PUID="$(bashio::config 'PUID')"
|
||||
PGID="$(bashio::config 'PGID')"
|
||||
|
||||
bashio::log.info "Plex library directory and symlink are ready."
|
||||
if ! bashio::config.true "skip_permissions_check" && [ "${PUID:-0}" != "0" ] && [ "${PGID:-0}" != "0" ]; then
|
||||
chown -R "${PUID}:${PGID}" /share/plex
|
||||
chmod -R 777 /share/plex
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user