mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-30 00:17:40 +01:00
Improve Plex data location migration
This commit is contained in:
@@ -4,36 +4,38 @@
|
||||
# SYMLINK CONFIG #
|
||||
##################
|
||||
|
||||
echo "Database stored in /share/plex"
|
||||
DATA_LOCATION="$(bashio::config 'data_location')"
|
||||
|
||||
if [ ! -d "/share/plex/Plex Media Server" ]; then
|
||||
echo "... creating /share/plex/Plex Media Server"
|
||||
mkdir -p "/share/plex/Plex Media Server"
|
||||
echo "Database stored in ${DATA_LOCATION}"
|
||||
|
||||
if [ ! -d "${DATA_LOCATION}/Plex Media Server" ]; then
|
||||
echo "... creating ${DATA_LOCATION}/Plex Media Server"
|
||||
mkdir -p "${DATA_LOCATION}/Plex Media Server"
|
||||
fi
|
||||
|
||||
if [ -d "/config/Library/Application Support/Plex Media Server" ]; then
|
||||
echo "... creating /symlink"
|
||||
rm -r "/config/Library/Application Support/*"
|
||||
ln -s "/share/plex/Plex Media Server" "/config/Library/Application Support"
|
||||
ln -s "${DATA_LOCATION}/Plex Media Server" "/config/Library/Application Support"
|
||||
fi
|
||||
|
||||
if [ ! -d "/config/Library/Application Support" ]; then
|
||||
echo "... creating /symlink"
|
||||
mkdir -p "/config/Library/Application Support"
|
||||
ln -s "/share/plex/Plex Media Server" "/config/Library/Application Support"
|
||||
ln -s "${DATA_LOCATION}/Plex Media Server" "/config/Library/Application Support"
|
||||
fi
|
||||
|
||||
# Adapt permissions if needed
|
||||
if ! bashio::config.true "skip_permissions_check" && [ "${PUID:-0}" != "0" ] && [ "${PGID:-0}" != "0" ]; then
|
||||
echo "... setting permissions, this might take a long time. If it takes too long at each boot, you could instead activate skip_permissions_check in the addon options"
|
||||
chmod -R 755 /share/plex
|
||||
chown -R "$PUID:$PGID" /share/plex
|
||||
chmod -R 755 "${DATA_LOCATION}"
|
||||
chown -R "$PUID:$PGID" "${DATA_LOCATION}"
|
||||
elif bashio::config.true "skip_permissions_check"; then
|
||||
bashio::log.warning "... skipping permissions check as 'skip_permissions_check' is set"
|
||||
fi
|
||||
|
||||
# Clear Codecs folder if checked
|
||||
if bashio::config.true "clear_codecs_folder" && [[ -d "/share/plex/Plex Media Server/Codecs" ]]; then
|
||||
if bashio::config.true "clear_codecs_folder" && [[ -d "${DATA_LOCATION}/Plex Media Server/Codecs" ]]; then
|
||||
echo "... deleting codecs folder"
|
||||
rm -r "/share/plex/Plex Media Server/Codecs"
|
||||
rm -r "${DATA_LOCATION}/Plex Media Server/Codecs"
|
||||
fi
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user