mirror of
https://github.com/pivpn/pivpn.git
synced 2025-04-26 01:00:11 +00:00
refactor(scripts): Structure code as per codestyle
Fix #1636 Refactor code according to code style Constants, Functions, Script
This commit is contained in:
parent
79f7caf4d3
commit
71f7ca9b3b
20 changed files with 377 additions and 342 deletions
|
@ -1,17 +1,14 @@
|
|||
#!/bin/bash
|
||||
# PiVPN: client status script
|
||||
|
||||
### Constants
|
||||
CLIENTS_FILE="/etc/wireguard/configs/clients.txt"
|
||||
|
||||
### Functions
|
||||
err() {
|
||||
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
|
||||
}
|
||||
|
||||
if [[ ! -s "${CLIENTS_FILE}" ]]; then
|
||||
err "::: There are no clients to list"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
scriptusage() {
|
||||
echo "::: List any connected clients to the server"
|
||||
echo ":::"
|
||||
|
@ -83,6 +80,12 @@ listClients() {
|
|||
grep '\[disabled\] ### begin' wg0.conf | sed 's/#//g; s/begin//'
|
||||
}
|
||||
|
||||
### Script
|
||||
if [[ ! -s "${CLIENTS_FILE}" ]]; then
|
||||
err "::: There are no clients to list"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$#" -eq 0 ]]; then
|
||||
HR=1
|
||||
listClients
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
#!/bin/bash
|
||||
|
||||
### Constants
|
||||
setupVars="/etc/pivpn/wireguard/setupVars.conf"
|
||||
# shellcheck disable=SC1090
|
||||
source "${setupVars}"
|
||||
|
||||
### Funcions
|
||||
err() {
|
||||
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
|
||||
}
|
||||
|
||||
if [[ ! -f "${setupVars}" ]]; then
|
||||
err "::: Missing setup vars file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "${setupVars}"
|
||||
|
||||
helpFunc() {
|
||||
echo "::: Disable client conf profiles"
|
||||
echo ":::"
|
||||
|
@ -28,6 +24,12 @@ helpFunc() {
|
|||
echo "::: -h,--help Show this help dialog"
|
||||
}
|
||||
|
||||
### Script
|
||||
if [[ ! -f "${setupVars}" ]]; then
|
||||
err "::: Missing setup vars file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Parse input arguments
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
_key="${1}"
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
#!/bin/bash
|
||||
|
||||
### Constants
|
||||
setupVars="/etc/pivpn/wireguard/setupVars.conf"
|
||||
|
||||
err() {
|
||||
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
|
||||
}
|
||||
|
||||
if [[ ! -f "${setupVars}" ]]; then
|
||||
err "::: Missing setup vars file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "${setupVars}"
|
||||
|
||||
### Functions
|
||||
err() {
|
||||
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
|
||||
}
|
||||
|
||||
helpFunc() {
|
||||
echo "::: Enables client conf profiles"
|
||||
echo ":::"
|
||||
|
@ -28,6 +25,12 @@ helpFunc() {
|
|||
echo "::: -h,--help Show this help dialog"
|
||||
}
|
||||
|
||||
### Script
|
||||
if [[ ! -f "${setupVars}" ]]; then
|
||||
err "::: Missing setup vars file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Parse input arguments
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
_key="${1}"
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
#!/bin/bash
|
||||
### Constants
|
||||
|
||||
### Funcions
|
||||
err() {
|
||||
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
|
||||
}
|
||||
|
||||
### Script
|
||||
cd /etc/wireguard/configs || exit
|
||||
|
||||
if [[ ! -s clients.txt ]]; then
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
### Constantss
|
||||
# Some vars that might be empty but need to be defined for checks
|
||||
pivpnPERSISTENTKEEPALIVE=""
|
||||
pivpnDNS2=""
|
||||
|
@ -8,18 +9,14 @@ setupVars="/etc/pivpn/wireguard/setupVars.conf"
|
|||
# shellcheck disable=SC2154
|
||||
userGroup="${install_user}:${install_user}"
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "${setupVars}"
|
||||
|
||||
### Functions
|
||||
err() {
|
||||
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
|
||||
}
|
||||
|
||||
if [[ ! -f "${setupVars}" ]]; then
|
||||
err "::: Missing setup vars file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "${setupVars}"
|
||||
|
||||
helpFunc() {
|
||||
echo "::: Create a client conf profile"
|
||||
echo ":::"
|
||||
|
@ -55,7 +52,13 @@ checkName() {
|
|||
err "::: A client with this name already exists"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
### Script
|
||||
if [[ ! -f "${setupVars}" ]]; then
|
||||
err "::: Missing setup vars file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Parse input arguments
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
|
|
|
@ -1,24 +1,16 @@
|
|||
#!/bin/bash
|
||||
|
||||
### Constants
|
||||
|
||||
CHECK_PKG_INSTALLED='dpkg-query -s'
|
||||
scriptdir="/opt/pivpn"
|
||||
vpn="wireguard"
|
||||
|
||||
if grep -qsEe "^NAME\=['\"]?Alpine[a-zA-Z ]*['\"]?$" /etc/os-release; then
|
||||
CHECK_PKG_INSTALLED='apk --no-cache info -e'
|
||||
fi
|
||||
|
||||
# Must be root to use this tool
|
||||
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"
|
||||
|
||||
### Functions
|
||||
err() {
|
||||
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
|
||||
}
|
||||
|
@ -114,6 +106,17 @@ showHelp() {
|
|||
exit 0
|
||||
}
|
||||
|
||||
### Script
|
||||
# Must be root to use this tool
|
||||
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
|
||||
|
||||
if [[ "$#" == 0 ]]; then
|
||||
showHelp
|
||||
fi
|
||||
|
|
|
@ -1,20 +1,26 @@
|
|||
#!/bin/bash
|
||||
# This scripts runs as root
|
||||
|
||||
### Constants
|
||||
|
||||
setupVars="/etc/pivpn/wireguard/setupVars.conf"
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "${setupVars}"
|
||||
|
||||
### Funcions
|
||||
|
||||
err() {
|
||||
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
|
||||
}
|
||||
|
||||
### Script
|
||||
|
||||
# This scripts runs as root
|
||||
if [[ ! -f "${setupVars}" ]]; then
|
||||
err "::: Missing setup vars file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "${setupVars}"
|
||||
|
||||
echo -e "::::\t\t\e[4mPiVPN debug\e[0m\t\t ::::"
|
||||
printf "=============================================\n"
|
||||
echo -e "::::\t\t\e[4mLatest commit\e[0m\t\t ::::"
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
### Constants
|
||||
encoding="ansiutf8"
|
||||
|
||||
### Functions
|
||||
err() {
|
||||
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
|
||||
}
|
||||
|
@ -18,8 +22,8 @@ helpFunc() {
|
|||
echo "::: -h,--help Show this help dialog"
|
||||
}
|
||||
|
||||
### Script
|
||||
# Parse input arguments
|
||||
encoding="ansiutf8"
|
||||
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
_key="${1}"
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
#!/bin/bash
|
||||
|
||||
### Constants
|
||||
setupVars="/etc/pivpn/wireguard/setupVars.conf"
|
||||
|
||||
err() {
|
||||
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
|
||||
}
|
||||
|
||||
if [[ ! -f "${setupVars}" ]]; then
|
||||
err "::: Missing setup vars file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "${setupVars}"
|
||||
|
||||
### Functions
|
||||
err() {
|
||||
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
|
||||
}
|
||||
|
||||
helpFunc() {
|
||||
echo "::: Remove a client conf profile"
|
||||
echo ":::"
|
||||
|
@ -27,6 +24,12 @@ helpFunc() {
|
|||
echo "::: -h,--help Show this help dialog"
|
||||
}
|
||||
|
||||
### Script
|
||||
if [[ ! -f "${setupVars}" ]]; then
|
||||
err "::: Missing setup vars file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Parse input arguments
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
_key="${1}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue