mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-21 14:59:14 +02:00
Optimize
This commit is contained in:
@@ -1,25 +1,66 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bashio
|
||||||
|
|
||||||
|
set -Eeuo pipefail
|
||||||
|
|
||||||
##################
|
##################
|
||||||
# SYMLINK CONFIG #
|
# SYMLINK CONFIG #
|
||||||
##################
|
##################
|
||||||
|
|
||||||
|
# Helper: Fix ownership only if needed (on folder, not all files)
|
||||||
|
fix_owner_if_needed() {
|
||||||
|
local path="$1"
|
||||||
|
local want_uid="$2"
|
||||||
|
local want_gid="$3"
|
||||||
|
local curr_uid curr_gid
|
||||||
|
|
||||||
|
if [ -e "$path" ]; then
|
||||||
|
curr_uid=$(stat -c '%u' "$path")
|
||||||
|
curr_gid=$(stat -c '%g' "$path")
|
||||||
|
if [ "$curr_uid" -ne "$want_uid" ] || [ "$curr_gid" -ne "$want_gid" ]; then
|
||||||
|
echo "Fixing ownership: $path ($curr_uid:$curr_gid -> $want_uid:$want_gid)"
|
||||||
|
chown -R "$want_uid:$want_gid" "$path"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Helper: Fix mode only if needed (on folder, not all files)
|
||||||
|
fix_mode_if_needed() {
|
||||||
|
local path="$1"
|
||||||
|
local want_mode="$2"
|
||||||
|
local curr_mode
|
||||||
|
|
||||||
|
if [ -e "$path" ]; then
|
||||||
|
curr_mode=$(stat -c '%a' "$path")
|
||||||
|
if [ "$curr_mode" -ne "$want_mode" ]; then
|
||||||
|
echo "Fixing mode: $path ($curr_mode -> $want_mode)"
|
||||||
|
chmod -R "$want_mode" "$path"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Ensure /share/plex exists
|
||||||
if [ ! -d /share/plex ]; then
|
if [ ! -d /share/plex ]; then
|
||||||
echo "Creating /share/plex"
|
echo "Creating /share/plex"
|
||||||
mkdir -p /share/plex
|
mkdir -p /share/plex
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Library folder move/link
|
||||||
|
mkdir -p /config/Library
|
||||||
if [ ! -d /share/plex/Library ]; then
|
if [ ! -d /share/plex/Library ]; then
|
||||||
echo "moving Library folder"
|
echo "Moving Library folder"
|
||||||
mv /config/Library /share/plex
|
mv /config/Library /share/plex
|
||||||
ln -s /share/plex/Library /config
|
ln -s /share/plex/Library /config
|
||||||
echo "links done"
|
echo "Links done"
|
||||||
else
|
else
|
||||||
rm -r /config/Library
|
rm -rf /config/Library
|
||||||
ln -s /share/plex/Library /config
|
ln -s /share/plex/Library /config
|
||||||
echo "Using existing config"
|
echo "Using existing config"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
chown -R "$PUID:$PGID" /config/Library
|
# Only fix ownership/mode if needed (top-level only—*not* blindly every file)
|
||||||
chown -R "$PUID:$PGID" /share/plex
|
PUID="$(bashio::config "PUID")"
|
||||||
chmod -R 777 /share/plex
|
PGID="$(bashio::config "PGID")"
|
||||||
|
|
||||||
|
fix_owner_if_needed "/share/plex" "$PUID" "$PGID"
|
||||||
|
fix_owner_if_needed "/share/plex/Library" "$PUID" "$PGID"
|
||||||
|
fix_mode_if_needed "/share/plex" 777
|
||||||
|
|||||||
Reference in New Issue
Block a user