sane-vpn: allow shorthands like "sane-vpn up us" instead of full ovpnd-us

This commit is contained in:
Colin 2024-02-20 23:01:53 +00:00
parent bb569b1668
commit ee7d99289a

View File

@ -37,8 +37,8 @@ debug() {
# load VPN names from disk
getVpns() {
vpns=$(ls ~/.config/sane-vpn/vpns)
defaultVpn=$(cat ~/.config/sane-vpn/default)
vpns=($(ls ~/.config/sane-vpn/vpns))
defaultVpn="$(cat ~/.config/sane-vpn/default)"
debug "default vpn: $defaultVpn"
}
@ -57,10 +57,19 @@ sourceVpn() {
}
canonicalizeRegion() {
if [ -n "$region" ] || [ "$region" = "default" ]; then
debug "canonicalizing region to $defaultVpn"
debug "region before canonicalization: '$region'"
for v in "${vpns[@]}"; do
if [ "ovpnd-$region" = "$v" ]; then
debug "canonicalizing shorthand ovpnd- region to '$v'"
region="$v"
fi
done
if [ -z "$region" ] || [ "$region" = "default" ]; then
debug "canonicalizing default region to '$defaultVpn'"
region="$defaultVpn"
fi
debug "region after canonicalization: '$region'"
}
vpnToggle() {