Zachary Kotlarek il y a 11 ans
Parent
commit
75372d09f2
1 fichiers modifiés avec 9 ajouts et 7 suppressions
  1. 9 7
      pms/PMSCheck.sh

+ 9 - 7
pms/PMSCheck.sh

@@ -1,7 +1,6 @@
 #!/bin/bash
 #!/bin/bash
 
 
 # Config
 # Config
-CURL_TIMEOUT=15
 RESTART_DELAY=600
 RESTART_DELAY=600
 UNWATCHED_SECTION="2"
 UNWATCHED_SECTION="2"
 UNWATCHED_SLEEP=60
 UNWATCHED_SLEEP=60
@@ -9,6 +8,9 @@ UNWATCHED_RETRIES=5
 MIN_UNWATCHED_COUNT=10
 MIN_UNWATCHED_COUNT=10
 MAX_VSIZE=$(( 10 * 1024 * 1024 )) # 10 GB in kB
 MAX_VSIZE=$(( 10 * 1024 * 1024 )) # 10 GB in kB
 ADMIN_EMAIL="zach@kotlarek.com"
 ADMIN_EMAIL="zach@kotlarek.com"
+IFS=''
+CURL_TIMEOUT=15
+CURL_OPTS=(--silent --connect-timeout 5 --max-time $CURL_TIMEOUT)
 
 
 # Construct URL components from the environment
 # Construct URL components from the environment
 if [ -z "${PMS_URL}" ]; then
 if [ -z "${PMS_URL}" ]; then
@@ -20,10 +22,10 @@ if [ -z "${PMS_URL}" ]; then
 	fi
 	fi
 	PMS_URL="http://${PMS_HOST}:${PMS_PORT}"
 	PMS_URL="http://${PMS_HOST}:${PMS_PORT}"
 fi
 fi
-PMS_AUTH=""
-if [ -n "${PMS_TOKEN}" ]; then
-	PMS_AUTH="X-Plex-Token=${PMS_TOKEN}"
+if [ -z "${PMS_TOKEN}" ]; then
+	echo "No PMS_TOKEN provided" 1>&2
 fi
 fi
+CURL_OPTS+=(-H "X-Plex-Token: ${PMS_TOKEN}")
 
 
 # Heady allows 0 unwatched
 # Heady allows 0 unwatched
 if hostname | grep -qi heady; then
 if hostname | grep -qi heady; then
@@ -50,7 +52,7 @@ while [ $LOOP -ne 0 ]; do
 
 
 	# Ask Plex for the top-level status page
 	# Ask Plex for the top-level status page
 	if [ -z "${FAILED}" ]; then
 	if [ -z "${FAILED}" ]; then
-		PAGE="`curl --silent --max-time "${CURL_TIMEOUT}" "${PMS_URL}/?${PMS_AUTH}"`"
+		PAGE="`curl ${CURL_OPTS[@]} "${PMS_URL}/"`"
 		if [ -z "${PAGE}" ]; then
 		if [ -z "${PAGE}" ]; then
 			FAILED="HTTP timeout"
 			FAILED="HTTP timeout"
 		else
 		else
@@ -64,12 +66,12 @@ while [ $LOOP -ne 0 ]; do
 	# Ask Plex for a list of unwatched TV series
 	# Ask Plex for a list of unwatched TV series
 	UNWATCHED_TIMEOUT=$(( $CURL_TIMEOUT ))
 	UNWATCHED_TIMEOUT=$(( $CURL_TIMEOUT ))
 	if [ -z "${FAILED}" ]; then
 	if [ -z "${FAILED}" ]; then
-		UNWATCHED_URL="${PMS_URL}/library/sections/${UNWATCHED_SECTION}/all?${PMS_AUTH}&type=2&unwatched=1&sort=titleSort:asc&X-Plex-Container-Start=0&X-Plex-Container-Size=10000"
+		UNWATCHED_URL="${PMS_URL}/library/sections/${UNWATCHED_SECTION}/all?type=2&unwatched=1&sort=titleSort:asc&X-Plex-Container-Start=0&X-Plex-Container-Size=10000"
 		TRY=1
 		TRY=1
 		FAILED="Too few unwatched series"
 		FAILED="Too few unwatched series"
 		while [ $TRY -le $UNWATCHED_RETRIES ] && [ -n "${FAILED}" ]; do
 		while [ $TRY -le $UNWATCHED_RETRIES ] && [ -n "${FAILED}" ]; do
 			TRY=$(( $TRY + 1 ))
 			TRY=$(( $TRY + 1 ))
-			PAGE="`curl --silent --max-time "${UNWATCHED_TIMEOUT}" "${UNWATCHED_URL}"`"
+			PAGE="`curl ${CURL_OPTS[@]} --max-time "${UNWATCHED_TIMEOUT}" "${UNWATCHED_URL}"`"
 			COUNT="`echo "${PAGE}" | grep '</Directory>' | wc -l`"
 			COUNT="`echo "${PAGE}" | grep '</Directory>' | wc -l`"
 			if [ $COUNT -ge $MIN_UNWATCHED_COUNT ]; then
 			if [ $COUNT -ge $MIN_UNWATCHED_COUNT ]; then
 				FAILED=""
 				FAILED=""