mirror of
https://github.com/pivpn/pivpn.git
synced 2025-05-14 03:44:11 +02:00
Reformatted the code
This commit is contained in:
parent
47e8908489
commit
af20461590
24 changed files with 2655 additions and 2021 deletions
|
@ -3,127 +3,160 @@
|
|||
CHECK_PKG_INSTALLED='dpkg-query -s'
|
||||
|
||||
if grep -qsEe "^NAME\=['\"]?Alpine[a-zA-Z ]*['\"]?$" /etc/os-release; then
|
||||
CHECK_PKG_INSTALLED='apk --no-cache info -e'
|
||||
CHECK_PKG_INSTALLED='apk --no-cache info -e'
|
||||
fi
|
||||
|
||||
# Must be root to use this tool
|
||||
if [ $EUID -ne 0 ]; then
|
||||
if eval "${CHECK_PKG_INSTALLED} sudo" &> /dev/null; then
|
||||
export SUDO="sudo"
|
||||
else
|
||||
echo "::: Please install sudo or run this as root."
|
||||
exit 1
|
||||
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
|
||||
fi
|
||||
|
||||
scriptdir="/opt/pivpn"
|
||||
vpn="wireguard"
|
||||
|
||||
makeConf(){
|
||||
shift
|
||||
$SUDO ${scriptdir}/${vpn}/makeCONF.sh "$@"
|
||||
exit "$?"
|
||||
err() {
|
||||
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
|
||||
}
|
||||
|
||||
listConnected(){
|
||||
shift
|
||||
$SUDO ${scriptdir}/${vpn}/clientSTAT.sh "$@"
|
||||
exit "$?"
|
||||
makeConf() {
|
||||
shift
|
||||
${SUDO} "${scriptdir}/${vpn}/makeCONF.sh" "$@"
|
||||
exit "${?}"
|
||||
}
|
||||
|
||||
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 "$?"
|
||||
listConnected() {
|
||||
shift
|
||||
${SUDO} "${scriptdir}/${vpn}/clientSTAT.sh" "$@"
|
||||
exit "${?}"
|
||||
}
|
||||
|
||||
listClients(){
|
||||
$SUDO ${scriptdir}/${vpn}/listCONF.sh
|
||||
exit "$?"
|
||||
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 "${?}"
|
||||
}
|
||||
|
||||
showQrcode(){
|
||||
shift
|
||||
$SUDO ${scriptdir}/${vpn}/qrcodeCONF.sh "$@"
|
||||
exit "$?"
|
||||
listClients() {
|
||||
${SUDO} "${scriptdir}/${vpn}/listCONF.sh"
|
||||
exit "${?}"
|
||||
}
|
||||
|
||||
removeClient(){
|
||||
shift
|
||||
$SUDO ${scriptdir}/${vpn}/removeCONF.sh "$@"
|
||||
exit "$?"
|
||||
showQrcode() {
|
||||
shift
|
||||
${SUDO} "${scriptdir}/${vpn}/qrcodeCONF.sh" "$@"
|
||||
exit "${?}"
|
||||
}
|
||||
|
||||
disableClient(){
|
||||
shift
|
||||
$SUDO ${scriptdir}/${vpn}/disableCONF.sh "$@"
|
||||
exit "$?"
|
||||
removeClient() {
|
||||
shift
|
||||
${SUDO} "${scriptdir}/${vpn}/removeCONF.sh" "$@"
|
||||
exit "${?}"
|
||||
}
|
||||
|
||||
enableClient(){
|
||||
shift
|
||||
$SUDO ${scriptdir}/${vpn}/enableCONF.sh "$@"
|
||||
exit "$?"
|
||||
disableClient() {
|
||||
shift
|
||||
${SUDO} "${scriptdir}/${vpn}/disableCONF.sh" "$@"
|
||||
exit "${?}"
|
||||
}
|
||||
|
||||
uninstallServer(){
|
||||
$SUDO ${scriptdir}/uninstall.sh "${vpn}"
|
||||
exit "$?"
|
||||
enableClient() {
|
||||
shift
|
||||
${SUDO} "${scriptdir}/${vpn}/enableCONF.sh" "$@"
|
||||
exit "${?}"
|
||||
}
|
||||
|
||||
updateScripts(){
|
||||
shift
|
||||
$SUDO ${scriptdir}/update.sh "$@"
|
||||
exit "$?"
|
||||
uninstallServer() {
|
||||
${SUDO} "${scriptdir}/uninstall.sh" "${vpn}"
|
||||
exit "${?}"
|
||||
}
|
||||
|
||||
backup(){
|
||||
$SUDO ${scriptdir}/backup.sh "${vpn}"
|
||||
exit "$?"
|
||||
updateScripts() {
|
||||
shift
|
||||
${SUDO} "${scriptdir}/update.sh" "$@"
|
||||
exit "${?}"
|
||||
}
|
||||
|
||||
showHelp(){
|
||||
echo "::: Control all PiVPN specific functions!"
|
||||
echo ":::"
|
||||
echo "::: Usage: pivpn <command> [option]"
|
||||
echo ":::"
|
||||
echo "::: Commands:"
|
||||
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 client"
|
||||
echo "::: -on, on Enable a client"
|
||||
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"
|
||||
exit 0
|
||||
backup() {
|
||||
${SUDO} "${scriptdir}/backup.sh" "${vpn}"
|
||||
exit "${?}"
|
||||
}
|
||||
|
||||
if [ $# = 0 ]; then
|
||||
showHelp
|
||||
showHelp() {
|
||||
echo "::: Control all PiVPN specific functions!"
|
||||
echo ":::"
|
||||
echo "::: Usage: pivpn <command> [option]"
|
||||
echo ":::"
|
||||
echo "::: Commands:"
|
||||
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 -n "::: -qr, qrcode Show the qrcode of a client for use "
|
||||
echo "with the mobile app"
|
||||
echo "::: -r, remove Remove a client"
|
||||
echo "::: -off, off Disable a client"
|
||||
echo "::: -on, on Enable a client"
|
||||
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"
|
||||
exit 0
|
||||
}
|
||||
|
||||
if [[ "$#" == 0 ]]; then
|
||||
showHelp
|
||||
fi
|
||||
|
||||
# Handle redirecting to specific functions based on arguments
|
||||
case "$1" in
|
||||
"-a" | "add" ) makeConf "$@";;
|
||||
"-c" | "clients" ) listConnected "$@";;
|
||||
"-d" | "debug" ) debug;;
|
||||
"-l" | "list" ) listClients;;
|
||||
"-qr" | "qrcode" ) showQrcode "$@";;
|
||||
"-r" | "remove" ) removeClient "$@";;
|
||||
"-off" | "off" ) disableClient "$@";;
|
||||
"-on" | "on" ) enableClient "$@";;
|
||||
"-h" | "help" ) showHelp;;
|
||||
"-u" | "uninstall" ) uninstallServer;;
|
||||
"-up" | "update" ) updateScripts "$@" ;;
|
||||
"-bk" | "backup" ) backup ;;
|
||||
* ) showHelp;;
|
||||
case "${1}" in
|
||||
"-a" | "add")
|
||||
makeConf "$@"
|
||||
;;
|
||||
"-c" | "clients")
|
||||
listConnected "$@"
|
||||
;;
|
||||
"-d" | "debug")
|
||||
debug
|
||||
;;
|
||||
"-l" | "list")
|
||||
listClients
|
||||
;;
|
||||
"-qr" | "qrcode")
|
||||
showQrcode "$@"
|
||||
;;
|
||||
"-r" | "remove")
|
||||
removeClient "$@"
|
||||
;;
|
||||
"-off" | "off")
|
||||
disableClient "$@"
|
||||
;;
|
||||
"-on" | "on")
|
||||
enableClient "$@"
|
||||
;;
|
||||
"-h" | "help")
|
||||
showHelp
|
||||
;;
|
||||
"-u" | "uninstall")
|
||||
uninstallServer
|
||||
;;
|
||||
"-up" | "update")
|
||||
updateScripts "$@"
|
||||
;;
|
||||
"-bk" | "backup")
|
||||
backup
|
||||
;;
|
||||
*)
|
||||
showHelp
|
||||
;;
|
||||
esac
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue