refactor(scripts): Structure code as per codestyle

Fix #1636
Refactor code according to code style
Constants, Functions, Script
This commit is contained in:
4s3ti 2022-10-08 01:11:10 +02:00
parent 79f7caf4d3
commit 71f7ca9b3b
No known key found for this signature in database
GPG key ID: AC2D3B898F96BC51
20 changed files with 377 additions and 342 deletions

View file

@ -1,7 +1,18 @@
#!/bin/bash
### Updates pivpn scripts (Not PiVPN)
### Main Vars
# TODO: Delete this section when the updating functionality will be re-enabled
###
err() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
}
err "::: The updating functionality for PiVPN scripts is temporarily disabled"
err "::: To keep the VPN (and the system) up to date, use:"
err " apt update; apt upgrade"
exit 0
### END SECTION ###
### Constants
pivpnrepo="https://github.com/pivpn/pivpn.git"
pivpnlocalpath="/etc/.pivpn"
pivpnscripts="/opt/pivpn/"
@ -19,18 +30,6 @@ c=$((columns / 2))
r=$((r < 20 ? 20 : r))
c=$((c < 70 ? 70 : c))
# TODO: Delete this section when the updating functionality will be re-enabled
###
err() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
}
err "::: The updating functionality for PiVPN scripts is temporarily disabled"
err "::: To keep the VPN (and the system) up to date, use:"
err " apt update; apt upgrade"
exit 0
###
chooseVPNCmd=(whiptail
--backtitle "Setup PiVPN"
--title "Installation mode"
@ -50,14 +49,10 @@ fi
setupVars="/etc/pivpn/${VPN}/setupVars.conf"
if [[ ! -f "${setupVars}" ]]; then
err "::: Missing setup vars file!"
exit 1
fi
# shellcheck disable=SC1090
source "${setupVars}"
### Functions
# TODO: Uncomment this function when the updating functionality
# will be re-enabled
#err() {
@ -75,8 +70,6 @@ scriptusage() {
echo "::: -h, help Show this usage dialog"
}
### Functions
## Updates scripts
updatepivpnscripts() {
local branch
branch="${1}"
@ -126,6 +119,10 @@ cloneandupdate() {
}
## SCRIPT
if [[ ! -f "${setupVars}" ]]; then
err "::: Missing setup vars file!"
exit 1
fi
if [[ "$#" -eq 0 ]]; then
updatepivpnscripts