1
0
Fork 0
mirror of https://github.com/pivpn/pivpn.git synced 2024-12-23 21:30:15 +00:00
pivpn/scripts/openvpn/pivpn.sh

103 lines
2.6 KiB
Bash
Raw Normal View History

2019-10-14 10:27:28 +00:00
#!/bin/bash
# Must be root to use this tool
if [[ ! $EUID -eq 0 ]];then
if [[ $(dpkg-query -s sudo) ]];then
export SUDO="sudo"
else
echo "::: Please install sudo or run this as root."
2019-11-19 12:28:51 +00:00
exit 1
2019-10-14 10:27:28 +00:00
fi
fi
2020-05-05 20:43:20 +00:00
scriptDir="/opt/pivpn"
2020-04-28 22:44:56 +00:00
vpn="openvpn"
2019-10-14 10:27:28 +00:00
function makeOVPNFunc {
shift
2020-05-05 20:43:20 +00:00
$SUDO ${scriptDir}/${vpn}/makeOVPN.sh "$@"
2019-10-14 10:27:28 +00:00
exit 0
}
function listClientsFunc {
shift
2020-05-05 20:43:20 +00:00
$SUDO ${scriptDir}/${vpn}/clientStat.sh "$@"
2019-10-14 10:27:28 +00:00
exit 0
}
function listOVPNFunc {
2020-05-05 20:43:20 +00:00
$SUDO ${scriptDir}/${vpn}/listOVPN.sh
2019-10-14 10:27:28 +00:00
exit 0
}
function debugFunc {
echo "::: Generating Debug Output"
2020-05-05 20:43:20 +00:00
$SUDO ${scriptDir}/${vpn}/pivpnDebug.sh | tee /tmp/debug.txt
2019-10-14 10:27:28 +00:00
echo "::: "
echo "::: Debug output completed above."
echo "::: Copy saved to /tmp/debug.txt"
echo "::: "
exit 0
}
function removeOVPNFunc {
shift
2020-05-05 20:43:20 +00:00
$SUDO ${scriptDir}/${vpn}/removeOVPN.sh "$@"
2019-10-14 10:27:28 +00:00
exit 0
}
function uninstallFunc {
$SUDO ${scriptDir}/uninstall.sh "${vpn}"
2019-10-14 10:27:28 +00:00
exit 0
}
function update {
shift
$SUDO ${scriptDir}/update.sh "$@"
2019-10-14 10:27:28 +00:00
exit 0
}
function backup {
2020-05-29 15:46:04 +00:00
$SUDO ${scriptDir}/backup.sh "${vpn}"
2019-10-14 10:27:28 +00:00
exit 0
}
function helpFunc {
echo "::: Control all PiVPN specific functions!"
echo ":::"
echo "::: Usage: pivpn <command> [option]"
echo ":::"
echo "::: Commands:"
echo "::: -a, add [nopass] Create a client ovpn profile, optional nopass"
echo "::: -c, clients List any connected clients to the server"
echo "::: -d, debug Start a debugging session if having trouble"
echo "::: -l, list List all valid and revoked certificates"
2020-05-31 22:39:18 +00:00
echo "::: -o, ovpn Generate a .ovpn config file for an existing client"
2019-10-14 10:27:28 +00:00
echo "::: -r, revoke Revoke a client ovpn profile"
echo "::: -h, help Show this help dialog"
echo "::: -u, uninstall Uninstall PiVPN from your system!"
echo "::: -up, update Updates PiVPN Scripts"
echo "::: -bk, backup Backup Openvpn and ovpns dir"
exit 0
}
if [[ $# = 0 ]]; then
helpFunc
fi
# Handle redirecting to specific functions based on arguments
case "$1" in
"-a" | "add" ) makeOVPNFunc "$@";;
"-c" | "clients" ) listClientsFunc "$@";;
2019-10-14 10:27:28 +00:00
"-d" | "debug" ) debugFunc;;
"-l" | "list" ) listOVPNFunc;;
2020-05-31 22:39:18 +00:00
"-o" | "ovpn" ) makeOVPNFunc "$@" -c;;
2019-10-14 10:27:28 +00:00
"-r" | "revoke" ) removeOVPNFunc "$@";;
"-h" | "help" ) helpFunc;;
"-u" | "uninstall" ) uninstallFunc;;
"-up"| "update" ) update "$@" ;;
"-bk"| "backup" ) backup;;
* ) helpFunc;;
esac