Improve script and checks

This commit is contained in:
Eduard Tolosa 2019-02-23 21:42:10 -05:00
parent f59a6f9461
commit aa2a5a0a62

View file

@ -1,4 +1,4 @@
#!/usr/bin/env sh #!/usr/bin/env bash
# Script to select a random VPN client from /etc/openvpn/client/ (the default openvpn directory) # Script to select a random VPN client from /etc/openvpn/client/ (the default openvpn directory)
# remember that openvpn profiles in /etc/openvpn/client/ need to be in the format profile.conf # remember that openvpn profiles in /etc/openvpn/client/ need to be in the format profile.conf
# Example: hk-04.conf # Example: hk-04.conf
@ -16,10 +16,21 @@ if [ "$1" == "stop" ]; then
fi fi
if command -v openvpn > /dev/null && command -v systemctl > /dev/null; then if command -v openvpn > /dev/null && command -v systemctl > /dev/null; then
cd "$workdir" if [ -d "$workdir" ]; then
vpn=$(shuf -ezn 1 * | xargs -0 -n1 | cut -f1 -d '.') cd "$workdir"
$(sudo systemctl start openvpn-client@$vpn) vpn=$(shuf -ezn 1 * | xargs -0 -n1)
exit if [ -f "$vpn" ]; then
vpn=$(echo "$vpn" | cut -f1 -d '.')
systemctl start openvpn-client@"$vpn"
exit
else
echo "$vpn is not a file."
exit
fi
else
echo "$workdir does not exist, leaving."
exit
fi
else else
echo "OpenVPN or systemd not installed, exiting." echo "OpenVPN or systemd not installed, exiting."
exit exit