Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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') && \
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.aarch64
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ RUN \
jq \
udev \
unrar \
xmlstarlet \
wget && \
echo "**** install plex ****" && \
if [ -z ${PLEX_RELEASE+x} ]; then \
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.armhf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ RUN \
jq \
udev \
unrar \
xmlstarlet \
wget && \
echo "**** install plex ****" && \
if [ -z ${PLEX_RELEASE+x} ]; then \
Expand Down
72 changes: 72 additions & 0 deletions root/etc/cont-init.d/70-plex-modify-preferences
Original file line number Diff line number Diff line change
@@ -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 <attribute> <value> <xmlpath>

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 <xml_path>

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' "<?xml version=\"1.0\" encoding=\"utf-8\"?><Preferences/>" > "$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