diff --git a/Dockerfile b/Dockerfile index 5e324338..77b6b117 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,6 +30,7 @@ RUN \ ocl-icd-libopencl1 \ udev \ unrar \ + xmlstarlet \ wget && \ COMP_RT_RELEASE=$(curl -sX GET "https://api.github.com/repos/intel/compute-runtime/releases/latest" | jq -r '.tag_name') && \ COMP_RT_URLS=$(curl -sX GET "https://api.github.com/repos/intel/compute-runtime/releases/tags/${COMP_RT_RELEASE}" | jq -r '.body' | grep wget | sed 's|wget ||g') && \ diff --git a/Dockerfile.aarch64 b/Dockerfile.aarch64 index 1fe09cbb..73628364 100644 --- a/Dockerfile.aarch64 +++ b/Dockerfile.aarch64 @@ -25,6 +25,7 @@ RUN \ jq \ udev \ unrar \ + xmlstarlet \ wget && \ echo "**** install plex ****" && \ if [ -z ${PLEX_RELEASE+x} ]; then \ diff --git a/Dockerfile.armhf b/Dockerfile.armhf index 2c56acb4..fb2540dd 100644 --- a/Dockerfile.armhf +++ b/Dockerfile.armhf @@ -25,6 +25,7 @@ RUN \ jq \ udev \ unrar \ + xmlstarlet \ wget && \ echo "**** install plex ****" && \ if [ -z ${PLEX_RELEASE+x} ]; then \ diff --git a/root/etc/cont-init.d/70-plex-modify-preferences b/root/etc/cont-init.d/70-plex-modify-preferences new file mode 100644 index 00000000..076e25ef --- /dev/null +++ b/root/etc/cont-init.d/70-plex-modify-preferences @@ -0,0 +1,72 @@ +#!/usr/bin/with-contenv bash + +XML_CONFIG="/config/Library/Application Support/Plex Media Server/Preferences.xml" + +# Fallback to ALLOWED_NETWORKS value +NOAUTH_NETWORKS="${NOAUTH_NETWORKS:-$ALLOWED_NETWORKS}" + +update_or_insert_attr() { + # Usage: update_or_replace_attr + + local element attribute_name attribute_value xml_path + element="/Preferences" + attribute_name="${1:?}" + attribute_value="${2:?}" + xml_path="${3:?}" + + local response + response="$(xmlstarlet select --text --template --match "$element" --value-of "@${attribute_name}" "${xml_path}")" + + # Only write to file if the desired value differs from the current + if [[ "$response" == "$attribute_value" ]]; then + return + fi + + xmlstarlet edit --inplace --insert "$element" --type attr --name "$attribute_name" --value "$attribute_value" "$xml_path" +} + +ensure_xml_exists() { + # Usage: ensure_xml_exists + + if [[ -e "${1:?}" ]]; then + printf '%s\n' "File '$1' already exists. Skipping..." + return + fi + + local parent + parent="$(dirname "${1:?}")" + + if [[ ! -d "$parent" ]]; then + mkdir -p "$parent" + fi + + printf '%s\n' "" > "$1" + + chown -R abc:abc "$parent" +} + +main() { + ensure_xml_exists "$XML_CONFIG" + + # Comma delimited string of ip cidr blocks that should be considered local + if [[ -n "$ALLOWED_NETWORKS" ]]; then + update_or_insert_attr allowedNetworks "$ALLOWED_NETWORKS" "$XML_CONFIG" + fi + + # Comma delimited string of ip cidr blocks that shouldn't require auth + if [[ -n "$NOAUTH_NETWORKS" ]]; then + update_or_insert_attr LanNetworksBandwidth "$NOAUTH_NETWORKS" "$XML_CONFIG" + fi + + # Comma delimited string of https/http urls used to access server + if [[ -n "$ADVERTISE_URLS" ]]; then + update_or_insert_attr allowedNetworks "$ADVERTISE_URLS" "$XML_CONFIG" + fi + + # Human readable name used to identify server on clients + if [[ -n "$SERVER_NAME" ]]; then + update_or_insert_attr FriendlyName "$SERVER_NAME" "$XML_CONFIG" + fi +} + +main