set -u FROM=plexinc/pms-docker:1.41.4.9463-630c9f557 TO=plexinc/pms-docker:1.43.5.11029-6bf8af3f0 CLAIM="${CLAIM-}" N=plexspike J='Accept: application/json' mkdir -p /opt/upg/spike/media/movies docker network create $N >/dev/null 2>&1 || true run() { docker run -d --name $N --network $N -e TZ=Europe/Budapest ${CLAIM:+-e PLEX_CLAIM=$CLAIM} \ -e ADVERTISE_IP=https://plex.gate.invalid:443/ -v ${N}_config:/config -v ${N}_transcode:/transcode \ -v /opt/upg/spike/media:/media:ro "$1" >/dev/null; } waitid() { for i in $(seq 1 150); do b=$(curl -s -H "$J" http://$IP:32400/identity); case "$b" in *'"claimed"'*) case "$b" in *startState*) ;; *) echo "identity 200 with no startState after ~$((i*2))s"; return 0;; esac;; esac; sleep 2; done; echo "never started (last: $b)"; return 1; } call() { echo "--- $1 $2"; curl -sS -X "$1" -H "$J" -w '\n[http %{http_code}]\n' "http://$IP:32400$2" | head -c 1500; echo; } echo "### pull"; docker pull -q $FROM; docker pull -q $TO echo "### FROM $FROM (PLEX_CLAIM ${CLAIM:+set-to-junk}${CLAIM:-absent})" run $FROM; IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $N); echo "container ip $IP; caller = bench host via $(ip -4 route get $IP | head -1)" waitid call GET /identity call GET /library/sections call POST "/library/sections?name=FelhomSpike&type=movie&agent=tv.plex.agents.movie&scanner=Plex%20Movie&language=en-US&location=%2Fmedia%2Fmovies" sleep 3 call GET /library/sections echo "### negative control: no such section name"; curl -s -H "$J" http://$IP:32400/library/sections | grep -c NoSuchSection12345 echo "### claimed? (Preferences.xml PlexOnlineToken present = claimed; value never printed)" docker exec $N sh -c 'f="/config/Library/Application Support/Plex Media Server/Preferences.xml"; grep -o "PlexOnlineToken=\"[^\"]*\"" "$f" | sed "s/=\".*\"/=/" ; grep -c PlexOnlineToken "$f"; grep -o "AcceptedEULA=\"[^\"]*\"\|PublishServerOnPlexOnlineKey=\"[^\"]*\"" "$f"' docker logs $N 2>&1 | tail -15 echo "### SWAP to $TO" docker rm -f $N >/dev/null; run $TO; IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $N) waitid call GET /identity call GET /library/sections docker logs $N 2>&1 | tail -10 echo "### teardown" docker rm -f $N >/dev/null; docker volume rm ${N}_config ${N}_transcode >/dev/null; docker network rm $N >/dev/null; rm -rf /opt/upg/spike docker ps -aq | wc -l