pivpn/scripts/pivpn

72 lines
1.4 KiB
Text
Raw Normal View History

2020-05-03 16:55:48 +00:00
#!/bin/bash
2022-07-26 13:20:35 +00:00
CHECK_PKG_INSTALLED='dpkg-query -s'
err() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
}
2022-07-26 13:20:35 +00:00
if grep -qsEe "^NAME\=['\"]?Alpine[a-zA-Z ]*['\"]?$" /etc/os-release; then
2022-07-27 12:53:36 +00:00
CHECK_PKG_INSTALLED='apk --no-cache info -e'
2022-07-26 13:20:35 +00:00
fi
2020-05-03 16:55:48 +00:00
# Must be root to use this tool
2022-07-27 12:53:36 +00:00
if [[ "${EUID}" -ne 0 ]]; then
if ${CHECK_PKG_INSTALLED} sudo &> /dev/null; then
export SUDO="sudo"
else
err "::: Please install sudo or run this as root."
exit 1
fi
2020-05-03 16:55:48 +00:00
fi
2020-05-05 08:24:20 +00:00
scriptDir="/opt/pivpn"
2022-07-27 12:53:36 +00:00
uninstallServer() {
${SUDO} "${scriptDir}/uninstall.sh"
exit "${?}"
2020-05-29 15:46:04 +00:00
}
2022-07-27 12:53:36 +00:00
backup() {
${SUDO} "${scriptDir}/backup.sh"
exit "${?}"
2020-05-03 16:55:48 +00:00
}
2022-07-27 12:53:36 +00:00
showHelp() {
echo "::: To pass off to the pivpn command for each protocol"
echo ":::"
echo "::: Usage: pivpn wg <command> [option]"
echo "::: Usage: pivpn ovpn <command> [option]"
echo ":::"
echo "::: -h, help Show this help dialog"
echo "::: -u, uninstall Uninstall pivpn from your system!"
echo "::: -bk, backup Backup VPN configs and user profiles"
exit 0
}
if [[ "$#" == 0 ]]; then
showHelp
2020-05-03 16:55:48 +00:00
fi
# Handle redirecting to specific functions based on arguments
2022-07-27 12:53:36 +00:00
case "${1}" in
wg)
"${scriptDir}/wireguard/pivpn.sh" "${@:2}"
;;
ovpn)
"${scriptDir}/openvpn/pivpn.sh" "${@:2}"
;;
"-h" | "help")
showHelp
;;
"-u" | "uninstall")
uninstallServer
;;
"-bk" | "backup")
backup
;;
*)
showHelp
;;
2020-05-03 16:55:48 +00:00
esac