pivpn/scripts/wireguard/pivpn.sh

124 lines
3 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 -ne 0 ];then
if dpkg-query -s sudo &> /dev/null; then
export SUDO="sudo"
else
echo "::: Please install sudo or run this as root."
exit 1
fi
fi
2020-04-28 22:44:56 +00:00
scriptdir="/opt/pivpn"
vpn="wireguard"
2019-10-14 10:27:28 +00:00
makeConf(){
shift
2020-04-28 22:44:56 +00:00
$SUDO ${scriptdir}/${vpn}/makeCONF.sh "$@"
exit "$?"
2019-10-14 10:27:28 +00:00
}
listConnected(){
shift
2020-04-28 22:44:56 +00:00
$SUDO ${scriptdir}/${vpn}/clientSTAT.sh "$@"
exit "$?"
2019-10-14 10:27:28 +00:00
}
debug(){
echo "::: Generating Debug Output"
$SUDO ${scriptdir}/${vpn}/pivpnDEBUG.sh | tee /tmp/debug.log
echo "::: "
echo "::: Debug output completed above."
echo "::: Copy saved to /tmp/debug.log"
echo "::: "
exit "$?"
2019-10-14 10:27:28 +00:00
}
listClients(){
2020-04-28 22:44:56 +00:00
$SUDO ${scriptdir}/${vpn}/listCONF.sh
exit "$?"
2019-10-14 10:27:28 +00:00
}
showQrcode(){
shift
2020-04-28 22:44:56 +00:00
$SUDO ${scriptdir}/${vpn}/qrcodeCONF.sh "$@"
exit "$?"
2019-10-14 10:27:28 +00:00
}
removeClient(){
shift
2020-04-28 22:44:56 +00:00
$SUDO ${scriptdir}/${vpn}/removeCONF.sh "$@"
exit "$?"
2019-10-14 10:27:28 +00:00
}
2020-10-21 21:35:29 +00:00
disableClient(){
shift
$SUDO ${scriptdir}/${vpn}/disableCONF.sh "$@"
exit "$?"
2020-10-21 21:35:29 +00:00
}
enableClient(){
shift
$SUDO ${scriptdir}/${vpn}/enableCONF.sh "$@"
exit "$?"
2020-10-21 21:35:29 +00:00
}
2019-10-14 10:27:28 +00:00
uninstallServer(){
$SUDO ${scriptdir}/uninstall.sh "${vpn}"
exit "$?"
2019-10-14 10:27:28 +00:00
}
2019-12-30 10:44:33 +00:00
updateScripts(){
shift
$SUDO ${scriptdir}/update.sh "$@"
exit "$?"
2019-12-30 10:44:33 +00:00
}
backup(){
2020-05-29 15:46:04 +00:00
$SUDO ${scriptdir}/backup.sh "${vpn}"
exit "$?"
}
2019-10-14 10:27:28 +00:00
showHelp(){
echo "::: Control all PiVPN specific functions!"
echo ":::"
echo "::: Usage: pivpn <command> [option]"
echo ":::"
echo "::: Commands:"
2020-12-08 23:44:51 +00:00
echo "::: -a, add Create a client conf profile"
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 clients"
echo "::: -qr, qrcode Show the qrcode of a client for use with the mobile app"
echo "::: -r, remove Remove a client"
echo "::: -off, off Disable a user"
echo "::: -on, on Enable a user"
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 VPN configs and user profiles"
2019-11-19 12:28:51 +00:00
exit 0
2019-10-14 10:27:28 +00:00
}
if [ $# = 0 ]; then
showHelp
fi
# Handle redirecting to specific functions based on arguments
case "$1" in
2020-10-21 21:35:29 +00:00
"-a" | "add" ) makeConf "$@";;
"-c" | "clients" ) listConnected "$@";;
"-d" | "debug" ) debug;;
"-l" | "list" ) listClients;;
"-qr" | "qrcode" ) showQrcode "$@";;
"-r" | "remove" ) removeClient "$@";;
"-off" | "off" ) disableClient "$@";;
"-on" | "on" ) enableClient "$@";;
2020-10-21 21:35:29 +00:00
"-h" | "help" ) showHelp;;
"-u" | "uninstall" ) uninstallServer;;
"-up" | "update" ) updateScripts "$@" ;;
"-bk" | "backup" ) backup ;;
* ) showHelp;;
2019-10-14 10:27:28 +00:00
esac