#!/bin/bash

## Check if VPN is set up correctly on all containers in the Arr Stack.

set -euo pipefail

# Use sudo if not running as root
SUDO=""
if [ "$(id -u)" -ne 0 ]; then
    SUDO="sudo"
fi

check_ip() {
    local container="$1"
    echo -n "Container: $container -> "
    if [[ "$container" == "gluetun" ]]; then
        # gluetun does not have curl so we download and cat the ip
        $SUDO docker exec "$container" wget -qO- ipconfig.io || echo "Error"
    else
        $SUDO docker exec "$container" curl -s ipconfig.io || echo "Error"
    fi
}

echo "Checking VPN-protected containers..."
check_ip "gluetun"
check_ip "prowlarr"
check_ip "qbittorrent"
check_ip "sabnzbd"

echo -e "\nChecking non-VPN containers (should show your public IP)..."
for container in radarr sonarr bazarr flaresolverr emby seerr; do
    check_ip "$container"
done
