Improve Plex data location migration

This commit is contained in:
Alexandre
2026-01-28 15:12:49 +01:00
parent e72eed170a
commit 2133c368f6
5 changed files with 55 additions and 22 deletions

View File

@@ -4,25 +4,49 @@
# SYMLINK CONFIG #
##################
if [ ! -d /share/plex ]; then
echo "Creating /share/plex"
mkdir -p /share/plex
DATA_LOCATION="$(bashio::config 'data_location')"
OLD_LOCATION=""
if [ -L /config/Library ]; then
old_library_path="$(readlink -f /config/Library)"
if [ -n "$old_library_path" ]; then
OLD_LOCATION="$(dirname "$old_library_path")"
fi
fi
if [ ! -d /share/plex/Library ]; then
if [ -z "$OLD_LOCATION" ] && [ -d "/share/plex" ]; then
OLD_LOCATION="/share/plex"
fi
if [ -n "$OLD_LOCATION" ] && [ "$DATA_LOCATION" != "$OLD_LOCATION" ] && [ -d "$OLD_LOCATION" ]; then
if [ -d "${DATA_LOCATION}" ] && [ "$(ls -A "${DATA_LOCATION}" 2>/dev/null)" ]; then
echo "Skipping migration: ${DATA_LOCATION} already contains data"
else
echo "Migrating existing ${OLD_LOCATION} data to ${DATA_LOCATION}"
mkdir -p "${DATA_LOCATION}"
cp -a "${OLD_LOCATION}/." "${DATA_LOCATION}/" || true
fi
fi
if [ ! -d "${DATA_LOCATION}" ]; then
echo "Creating ${DATA_LOCATION}"
mkdir -p "${DATA_LOCATION}"
fi
if [ ! -d "${DATA_LOCATION}/Library" ]; then
echo "moving Library folder"
mv /config/Library /share/plex
ln -s /share/plex/Library /config
mv /config/Library "${DATA_LOCATION}"
ln -s "${DATA_LOCATION}/Library" /config
echo "links done"
else
rm -r /config/Library
ln -s /share/plex/Library /config
ln -s "${DATA_LOCATION}/Library" /config
echo "Using existing config"
fi
# Adapt permissions if needed
if ! bashio::config.true "skip_permissions_check" && [ "${PUID:-0}" != "0" ] && [ "${PGID:-0}" != "0" ]; then
bashio::log.info "Updating permissions"
chown -R "$PUID:$PGID" /share/plex
chmod -R 777 /share/plex
chown -R "$PUID:$PGID" "${DATA_LOCATION}"
chmod -R 777 "${DATA_LOCATION}"
fi