Skip to content
Open
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
28 changes: 16 additions & 12 deletions universal/functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ logfileSetup () {
getArrAppInfo () {
# Get Arr App information
if [ -z "$arrUrl" ] || [ -z "$arrApiKey" ]; then
arrUrlBase="$(cat /config/config.xml | xq | jq -r .Config.UrlBase)"
if [ "$arrUrlBase" == "null" ]; then
arrUrlBase="$(sed -n 's:.*<UrlBase>\(.*\)</UrlBase>.*:\1:p' /config/config.xml | head -n1)"
if [ -z "$arrUrlBase" ]; then
arrUrlBase=""
else
arrUrlBase="/$(echo "$arrUrlBase" | sed "s/\///")"
arrUrlBase="/$(echo "$arrUrlBase" | sed 's:^/*::; s:/*$::')"
fi
arrName="$(cat /config/config.xml | xq | jq -r .Config.InstanceName)"
arrApiKey="$(cat /config/config.xml | xq | jq -r .Config.ApiKey)"
arrPort="$(cat /config/config.xml | xq | jq -r .Config.Port)"
arrName="$(sed -n 's:.*<InstanceName>\(.*\)</InstanceName>.*:\1:p' /config/config.xml | head -n1)"
arrApiKey="$(sed -n 's:.*<ApiKey>\(.*\)</ApiKey>.*:\1:p' /config/config.xml | head -n1)"
arrPort="$(sed -n 's:.*<Port>\(.*\)</Port>.*:\1:p' /config/config.xml | head -n1)"
arrUrl="http://127.0.0.1:${arrPort}${arrUrlBase}"
fi
}
Expand All @@ -39,15 +39,19 @@ verifyApiAccess () {
do
arrApiTest=""
arrApiVersion=""
if [ -z "$arrApiTest" ]; then
arrApiVersion="v3"
arrApiTest="$(curl -s "$arrUrl/api/$arrApiVersion/system/status?apikey=$arrApiKey" | jq -r .instanceName)"
fi

# Try API v3 first (current standard for Lidarr/Radarr/Sonarr)
arrApiVersion="v3"
arrApiTest="$(curl -fsS "$arrUrl/api/$arrApiVersion/system/status?apikey=$arrApiKey" 2>/dev/null | jq -er '.instanceName // .appName // empty' 2>/dev/null || true)"

# Fall back to v1 for older installations
if [ -z "$arrApiTest" ]; then
arrApiVersion="v1"
arrApiTest="$(curl -s "$arrUrl/api/$arrApiVersion/system/status?apikey=$arrApiKey" | jq -r .instanceName)"
arrApiTest="$(curl -fsS "$arrUrl/api/$arrApiVersion/system/status?apikey=$arrApiKey" 2>/dev/null | jq -er '.instanceName // .appName // empty' 2>/dev/null || true)"
fi
if [ ! -z "$arrApiTest" ]; then

if [ -n "$arrApiTest" ]; then
log "Connected to $arrName using API $arrApiVersion"
break
else
log "$arrName is not ready, sleeping until valid response..."
Expand Down