mirror of
https://github.com/edu4rdshl/linuxscripts.git
synced 2026-07-17 23:24:52 +00:00
Improve script and checks
This commit is contained in:
parent
f59a6f9461
commit
aa2a5a0a62
1 changed files with 16 additions and 5 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue