From 3a7dbab35c802c02f9e26644db6b5f9936ed0c1f Mon Sep 17 00:00:00 2001 From: gloof11 Date: Thu, 20 Jun 2024 21:54:50 +0900 Subject: [PATCH 1/2] Changed the IP checking service for "check-vpn" The original "check-vpn" used an endpoint that is no longer online. FIX: Replace the endpoint with ipinfo.io, a currently active service --- yams | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/yams b/yams index 9c62acb..075de33 100755 --- a/yams +++ b/yams @@ -1,7 +1,6 @@ #!/bin/bash set -euo pipefail - dc="docker compose -f -f " install_directory="" @@ -54,14 +53,14 @@ fi if [ "$option" == "check-vpn" ]; then echo "Getting your IP..." - your_ip=$(curl -s api.ipify.org) + your_ip=$(curl -s https://ipinfo.io/ip) echo "$your_ip" echo "Your local IP country is $(curl -s https://am.i.mullvad.net/country)" echo echo echo "Getting your qBittorrent IP..." - qbittorrent_ip=$(docker exec qbittorrent sh -c "curl -s api.ipify.org"); + qbittorrent_ip=$(docker exec qbittorrent sh -c 'curl -s https://ipinfo.io/ip'); if [ -n "$qbittorrent_ip" ]; then echo "$qbittorrent_ip" echo "Your country in qBittorrent is $(docker exec -it qbittorrent sh -c 'curl -s https://am.i.mullvad.net/country')" -- 2.39.5 From 3ff04b8448353f91ba72b8c3f1084e81f6f8f213 Mon Sep 17 00:00:00 2001 From: gloof11 Date: Fri, 21 Jun 2024 20:06:07 +0900 Subject: [PATCH 2/2] Added multiple IP checker endpoints The logic for getting the IP address is not within the "find_available_ip_endpoint" function in order to allow for proper error handling. If "send_error_message" were called in the function, the script would exit with no indication as to why. --- yams | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/yams b/yams index 075de33..4cb5420 100755 --- a/yams +++ b/yams @@ -29,6 +29,25 @@ send_error_message() { exit 255 } +find_available_ip_endpoint() { + ip_endpoints=( + "https://ipinfo.io/ip" + "https://api.ipify.org" + "https://checkip.amazonaws.com" + "https://tnedi.me" + "https://api.myip.la" + "https://wtfismyip.com/text" + ) + + for ip in ${ip_endpoints[@]}; do + endpoint=$(curl -s "$ip") + if [ "$endpoint" != "" ]; then + echo $ip + break + fi + done +} + if [ "$option" == "--help" ]; then help exit 0 @@ -53,14 +72,18 @@ fi if [ "$option" == "check-vpn" ]; then echo "Getting your IP..." - your_ip=$(curl -s https://ipinfo.io/ip) + ip_endpoint=$(find_available_ip_endpoint) + if [ "$ip_endpoint" == "" ]; then + send_error_message "No available endpoint to get IP address!" + fi + your_ip=$(curl -s $ip_endpoint) echo "$your_ip" echo "Your local IP country is $(curl -s https://am.i.mullvad.net/country)" echo echo echo "Getting your qBittorrent IP..." - qbittorrent_ip=$(docker exec qbittorrent sh -c 'curl -s https://ipinfo.io/ip'); + qbittorrent_ip=$(docker exec qbittorrent sh -c "curl -s $ip_endpoint"); if [ -n "$qbittorrent_ip" ]; then echo "$qbittorrent_ip" echo "Your country in qBittorrent is $(docker exec -it qbittorrent sh -c 'curl -s https://am.i.mullvad.net/country')" -- 2.39.5