diff --git a/openvpn-rotate b/openvpn-rotate index 499e378..013803a 100755 --- a/openvpn-rotate +++ b/openvpn-rotate @@ -1,7 +1,7 @@ #!/usr/bin/env bash -OVPN_DIRECTORY="/etc/openvpn/client/ovpn" -CURRENT_OVPN_PATH="/etc/openvpn/client/current.ovpn" +ovpn_directory="/etc/openvpn/client/ovpn-enabled" +current_ovpn_path="/etc/openvpn/client/current.ovpn" # TODO: Investigate better ways to check for rootness. This is just a courtesy message, though. # Non-root users will not be able to do anything with this anyway. @@ -11,15 +11,14 @@ if [ "$(whoami)" != "root" ]; then fi # TODO: Add the ability to pass arbitrary ovpn files. +# TODO: Remove the current config from the list of choices. +# Choose a random VPN configuration inside /etc/openvpn/ovpn-enabled +ovpn_file=$(shuf -n1 -e ${ovpn_directory}/*) -# Choose a random VPN configuration inside /etc/openvpn/ovpn -ovpn_file=$(shuf -n1 -e ${OVPN_DIRECTORY}/*) - -# TODO: Check that ovpn_file exists. +# TODO: Also echo previous configuration's name. echo "Using OpenVPN configuration $(basename "${ovpn_file}" .ovpn)" -rm "${CURRENT_OVPN_PATH}" -ln -s "${ovpn_file}" "${CURRENT_OVPN_PATH}" +ln -fs "${ovpn_file}" "${current_ovpn_path}" echo "Restarting OpenVPN service." systemctl restart openvpn