@@ -3,39 +3,46 @@
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
|
||||
SONARR_URL_BASE="${SONARR_URL_BASE:-}"
|
||||
URL_BASE="${URL_BASE:-}"
|
||||
|
||||
if [ ! -f /var/lib/sonarr/init ]; then
|
||||
if [ ! -f /var/lib/sonarr/config.xml ]; then
|
||||
echo '<Config/>' > /var/lib/sonarr/config.xml
|
||||
|
||||
xmlstarlet ed -L \
|
||||
-s /Config -t elem -n LaunchBrowser -v "False" \
|
||||
-s /Config -t elem -n ApiKey -v "$SONARR_API_KEY" \
|
||||
-s /Config -t elem -n AuthenticationMethod -v "External" \
|
||||
-s /Config -t elem -n AuthenticationRequired -v "DisabledForLocalAddresses" \
|
||||
-s /Config -t elem -n LogLevel -v "info" \
|
||||
-s /Config -t elem -n UrlBase -v "$SONARR_URL_BASE" \
|
||||
-s /Config -t elem -n InstanceName -v "${SONARR_INSTANCE_NAME:-Sonarr}" \
|
||||
-s /Config -t elem -n AnalyticsEnabled -v "False" \
|
||||
/var/lib/sonarr/config.xml
|
||||
fi
|
||||
|
||||
set_config_value() {
|
||||
name="$1"
|
||||
value="$2"
|
||||
|
||||
CONFIG_FILE="/var/lib/sonarr/config.xml"
|
||||
|
||||
if xmlstarlet sel -t -v "/Config/$name" "$CONFIG_FILE" >/dev/null 2>&1; then
|
||||
xmlstarlet ed -L -u "/Config/$name" -v "$value" "$CONFIG_FILE"
|
||||
else
|
||||
xmlstarlet ed -L -s "/Config" -t elem -n "$name" -v "$value" "$CONFIG_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
set_config_value "LaunchBrowser" "False"
|
||||
set_config_value "ApiKey" "$API_KEY"
|
||||
set_config_value "AuthenticationMethod" "External"
|
||||
set_config_value "AuthenticationRequired" "DisabledForLocalAddresses"
|
||||
set_config_value "LogLevel" "info"
|
||||
set_config_value "UrlBase" "$URL_BASE"
|
||||
set_config_value "InstanceName" "${INSTANCE_NAME:-Sonarr}"
|
||||
set_config_value "AnalyticsEnabled" "False"
|
||||
|
||||
Sonarr -data=/var/lib/sonarr -nobrowser "$@" &
|
||||
PID=$!
|
||||
|
||||
SONARR_HOST="http://localhost:8989$SONARR_URL_BASE"
|
||||
HOST="http://localhost:8989$URL_BASE"
|
||||
|
||||
if [ ! -f /var/lib/sonarr/init ]; then
|
||||
curl -sf --retry 10 --retry-connrefused \
|
||||
-H "X-Api-Key: $SONARR_API_KEY" \
|
||||
"$SONARR_HOST/api/v1/health"
|
||||
curl -sf --retry 10 --retry-connrefused \
|
||||
-H "X-Api-Key: $API_KEY" \
|
||||
"$HOST/api/v1/health"
|
||||
|
||||
if [ -f /etc/sonarr/setup.sh ]; then
|
||||
# shellcheck disable=SC1091
|
||||
. /etc/sonarr/setup.sh
|
||||
fi
|
||||
|
||||
touch /var/lib/sonarr/init
|
||||
if [ -f /etc/sonarr/setup.sh ]; then
|
||||
# shellcheck disable=SC1091
|
||||
. /etc/sonarr/setup.sh
|
||||
fi
|
||||
|
||||
trap 'kill -INT "$PID"' INT TERM
|
||||
|
Reference in New Issue
Block a user