#!/bin/sh vpn_stat() { stat=$(mullvad status) if echo "$stat" | grep -q "Disconnected"; then echo 0 elif echo "$stat" | grep -q "Connected"; then echo 1 elif echo "$stat" | grep -q "Connecting"; then echo "Connecting" else echo "Unkown Status" fi } vpn_stat_verbose() { mullvad status } rand_conn() { relays=$(mullvad relay list | awk 'NR>1 {gsub(/[()]/, "", $2); print $1 "-" $2}' | grep -v '^-$') if [ -z "$relays" ]; then echo "No valid relays found." return 1 fi random_relay=$(echo "$relays" | shuf -n 1) country=$(echo "$random_relay" | cut -d'-' -f1) city=$(echo "$random_relay" | cut -d'-' -f2) mullvad relay set location $country $city mullvad connect echo "Connected to $country $city" } if [ "$#" -eq 0 ] || [ "$1" = "-s" ]; then if [ "$#" -eq 2 ] && [ "$2" = "-v" ]; then vpn_stat_verbose else vpn_stat fi elif [ "$1" = "-c" ]; then if [ "$2" = "--rand" ]; then rand_conn elif [ "$#" -eq 3 ]; then country=$2 city=$3 mullvad relay set location $country $city mullvad connect echo "Connected to $country $city" else echo "Invalid usage. Use ./vpn.sh -c [country] [city] or ./vpn.sh -c --rand" exit 1 fi fi