yams/yams

117 lines
3.2 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
dc="docker compose -f <filename> -f <custom_file_filename>"
install_directory="<install_directory>"
option=${1:-"--help"}
help() {
echo "yams - Yet Another Media Server"
echo
echo "Usage: yams [--help|restart|stop|start|destroy|check-vpn|update]"
echo "options:"
echo "--help displays this help message"
echo "restart restarts yams services"
echo "stop stops all yams services"
echo "start starts yams services"
echo "destroy destroy yams services so you can start from scratch"
echo "check-vpn checks if the VPN is working as expected"
echo "update updates YAMS (deprecated)"
}
send_success_message() {
echo -e "$(printf "\e[32m$1\e[0m")"
}
send_error_message() {
echo -e "$(printf "\e[31m$1\e[0m")"
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
fi
if [ "$option" == "restart" ]; then
$dc stop && $dc up -d
echo "YAMS is starting. Wait 1 min until all the services are up and running..."
exit 0
fi
if [ "$option" == "stop" ]; then
$dc stop
exit 0
fi
if [ "$option" == "start" ]; then
$dc up -d
echo "YAMS is starting. Wait 1 min until all the services are up and running..."
exit 0
fi
if [ "$option" == "check-vpn" ]; then
echo "Getting your 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 $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')"
if [ "$qbittorrent_ip" == "$your_ip" ]; then
send_error_message "Your IPs are the same! qBittorrent is exposing your IP! ⚠️"
else
send_success_message "Your IPs are different. qBittorrent is masking your IP! ✅ "
fi
else
send_error_message "Failed to retrieve qBittorrent IP. Please check your setup. ⚠️"
fi
fi
if [ "$option" == "destroy" ]; then
echo
echo
read -p "Are you sure you want to destroy all your yams services? THIS IS NOT RECOVERABLE! ⚠️ ️🚨 [y/N]: " destroy_now
destroy_now=${destroy_now:-"n"}
if [ "$destroy_now" == "y" ]; then
$dc down
echo
echo
echo "yams services were destroyed. To restart, run: "
echo "\$ yams start"
fi
fi
if [ "$option" == "update" ]; then
echo "This command is deprecated. Please update YAMS manually."
fi