Skip to content

Instantly share code, notes, and snippets.

@movalex
Created October 11, 2021 18:38
Show Gist options
  • Save movalex/605aadd75ab03a9869fbd56038aa57cc to your computer and use it in GitHub Desktop.
Save movalex/605aadd75ab03a9869fbd56038aa57cc to your computer and use it in GitHub Desktop.
Start VPN Unlimited with Bash script
function uvpn() {
SECRET=$VPN_SECRET
status_vpn=$(scutil --nc list | awk '{if (NR!=1) print$2}' | sed -e 's/[()]//g')
if ! [[ $status_vpn ]]; then
echo "no VPN settings found"
return
fi
vpnName=$(scutil --nc list | awk 'BEGIN {ORS=" "}; {if (NR!=1) for(i = 7;i <= NF-1; i++) print$i}' | sed -e 's/"//g')
vpnID=$(scutil --nc list | awk '{if (NR!=1) print$3}')
case "$1" in
start) echo "started $vpnName"
scutil --nc $1 $vpnID --secret $SECRET;;
stop) echo "stopping $vpnName"
scutil --nc $1 $vpnID
status_vpn=$(scutil --nc list | awk '{if (NR!=1) print$2}' | sed -e 's/[()]//g')
echo VPN is $status_vpn;;
*) echo VPN is $status_vpn;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment