Skip to content

Commit

Permalink
fix(installer): fix some code style errors
Browse files Browse the repository at this point in the history
Fix some code style error about the pipelines
  • Loading branch information
giulio-coa committed Aug 5, 2022
1 parent 699f727 commit e09f3a0
Show file tree
Hide file tree
Showing 14 changed files with 317 additions and 310 deletions.
467 changes: 237 additions & 230 deletions auto_install/install.sh

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions ciscripts/startup.sh
@@ -1,13 +1,13 @@
#!/bin/bash

interface=$(ip -o link |
awk '{print $2}' |
cut -d ':' -f 1 |
cut -d '@' -f 1 |
grep -v -w 'lo' |
head -1)
ipaddress=$(ip addr show "${interface}" |
grep -o -E "([0-9]{1,3}[\.]){3}[0-9]{1,3}/[0-9]{2}")
interface=$(ip -o link \
| awk '{print $2}' \
| cut -d ':' -f 1 \
| cut -d '@' -f 1 \
| grep -v -w 'lo' \
| head -1)
ipaddress=$(ip addr show "${interface}" \
| grep -o -E "([0-9]{1,3}[\.]){3}[0-9]{1,3}/[0-9]{2}")
gateway=$(ip route show | awk '/default/ {print $3}')
hostname="pivpn.test"

Expand Down
4 changes: 2 additions & 2 deletions scripts/backup.sh
Expand Up @@ -20,8 +20,8 @@ setupConfigDir="/etc/pivpn"

CHECK_PKG_INSTALLED='dpkg-query -s'

if [[ -r "${setupConfigDir}/wireguard/${setupVarsFile}" ]] &&
[[ -r "${setupConfigDir}/openvpn/${setupVarsFile}" ]]; then
if [[ -r "${setupConfigDir}/wireguard/${setupVarsFile}" ]] \
&& [[ -r "${setupConfigDir}/openvpn/${setupVarsFile}" ]]; then
# Two protocols have been installed, check if the script has passed
# an argument, otherwise ask the user which one he wants to remove
if [[ "$#" -ge 1 ]]; then
Expand Down
4 changes: 2 additions & 2 deletions scripts/openvpn/bash-completion
Expand Up @@ -14,8 +14,8 @@ _pivpn() {
else
COMPREPLY=("$(compgen -W "${opts}" -- "${cur}")")
fi
elif [[ ("${prev}" == "add" || "${prev}" == "-a") ]] &&
[[ "${#COMP_WORDS[@]}" -eq 3 ]]; then
elif [[ ("${prev}" == "add" || "${prev}" == "-a") ]] \
&& [[ "${#COMP_WORDS[@]}" -eq 3 ]]; then
COMPREPLY=("$(compgen -W "nopass" -- "${cur}")")
fi

Expand Down
8 changes: 4 additions & 4 deletions scripts/openvpn/listOVPN.sh
Expand Up @@ -35,10 +35,10 @@ printf "\\e[1m::: Certificate Status List :::\\e[0m\\n"
while read -r line || [[ -n "${line}" ]]; do
STATUS="$(echo "${line}" | awk '{print $1}')"
NAME="$(echo "${line}" | awk -FCN= '{print $2}')"
EXPD="$(echo "${line}" |
awk '{if (length($2) == 15) print $2; else print "20"$2}' |
cut -b 1-8 |
date +"%b %d %Y" -f -)"
EXPD="$(echo "${line}" \
| awk '{if (length($2) == 15) print $2; else print "20"$2}' \
| cut -b 1-8 \
| date +"%b %d %Y" -f -)"

if [[ "${STATUS}" == "V" ]]; then
printf "Valid"
Expand Down
54 changes: 27 additions & 27 deletions scripts/openvpn/makeOVPN.sh
Expand Up @@ -61,9 +61,9 @@ while [[ "$#" -gt 0 ]]; do
_val="${_key##--name=}"

if [[ "${_val}" == "${_key}" ]]; then
[[ "$#" -lt 2 ]] &&
err "Missing value for the optional argument '${_key}'." &&
exit 1
[[ "$#" -lt 2 ]] \
&& err "Missing value for the optional argument '${_key}'." \
&& exit 1

_val="${2}"
shift
Expand All @@ -75,9 +75,9 @@ while [[ "$#" -gt 0 ]]; do
_val="${_key##--password=}"

if [[ "${_val}" == "${_key}" ]]; then
[[ "$#" -lt 2 ]] &&
err "Missing value for the optional argument '${_key}'." &&
exit 1
[[ "$#" -lt 2 ]] \
&& err "Missing value for the optional argument '${_key}'." \
&& exit 1

_val="${2}"
shift
Expand All @@ -89,9 +89,9 @@ while [[ "$#" -gt 0 ]]; do
_val="${_key##--days=}"

if [[ "${_val}" == "${_key}" ]]; then
[[ "$#" -lt 2 ]] &&
err "Missing value for the optional argument '${_key}'." &&
exit 1
[[ "$#" -lt 2 ]] \
&& err "Missing value for the optional argument '${_key}'." \
&& exit 1

_val="${2}"
shift
Expand Down Expand Up @@ -180,9 +180,9 @@ useBitwarden() {
read -r NAME

# check name
until [[ "${NAME}" =~ ^[a-zA-Z0-9.@_-]+$ ]] &&
[[ "${NAME::1}" != "." ]] &&
[[ "${NAME::1}" != "-" ]]; do
until [[ "${NAME}" =~ ^[a-zA-Z0-9.@_-]+$ ]] \
&& [[ "${NAME::1}" != "." ]] \
&& [[ "${NAME::1}" != "-" ]]; do
echo -n "Name can only contain alphanumeric characters and these "
echo -n "characters (.-@_). The name also cannot start with a dot (.)"
echo " or a dash (-). Please try again."
Expand Down Expand Up @@ -210,13 +210,13 @@ useBitwarden() {

# create a new item for your PiVPN Password
PASSWD="$(bw generate -usln --length "${LENGTH}")"
bw get template item |
jq '.login.type = "1"' |
jq '.name = "PiVPN"' |
jq -r --arg NAME "${NAME}" '.login.username = $NAME' |
jq -r --arg PASSWD "${PASSWD}" '.login.password = $PASSWD' |
bw encode |
bw create item
bw get template item \
| jq '.login.type = "1"' \
| jq '.name = "PiVPN"' \
| jq -r --arg NAME "${NAME}" '.login.username = $NAME' \
| jq -r --arg PASSWD "${PASSWD}" '.login.password = $PASSWD' \
| bw encode \
| bw create item
bw logout
}

Expand Down Expand Up @@ -357,9 +357,9 @@ else
err "Please choose another name or revoke this certificate first."
exit 1
# Check if name is reserved
elif [[ "${NAME}" == "ta" ]] ||
[[ "${NAME}" == "server" ]] ||
[[ "${NAME}" == "ca" ]]; then
elif [[ "${NAME}" == "ta" ]] \
|| [[ "${NAME}" == "server" ]] \
|| [[ "${NAME}" == "ca" ]]; then
err "Sorry, this is in use by the server and cannot be used by clients."
exit 1
fi
Expand All @@ -370,9 +370,9 @@ else
read -r -e -p "How many days should the certificate last? " -i 1080 DAYS
fi

if [[ ! "${DAYS}" =~ ^[0-9]+$ ]] ||
[[ "${DAYS}" -lt 1 ]] ||
[[ "${DAYS}" -gt 3650 ]]; then
if [[ ! "${DAYS}" =~ ^[0-9]+$ ]] \
|| [[ "${DAYS}" -lt 1 ]] \
|| [[ "${DAYS}" -gt 3650 ]]; then
# The CRL lasts 3650 days so it doesn't make much sense
# that certificates would last longer
err "Please input a valid number of days, between 1 and 3650 inclusive."
Expand Down Expand Up @@ -516,8 +516,8 @@ for i in {2..254}; do
# cycle to the end without finding and available octet.
# disabling SC2514, variable sourced externaly
# shellcheck disable=SC2154
if [[ -z "$(ls -A /etc/openvpn/ccd)" ]] ||
! find /etc/openvpn/ccd \
if [[ -z "$(ls -A /etc/openvpn/ccd)" ]] \
|| ! find /etc/openvpn/ccd \
-type f \
-exec grep -q "${NET_REDUCED}.${i}" {} +; then
COUNT="${i}"
Expand Down
8 changes: 4 additions & 4 deletions scripts/openvpn/pivpnDebug.sh
Expand Up @@ -65,10 +65,10 @@ if [[ "${PLAT}" != 'Alpine' ]]; then
# Regular expession taken from https://superuser.com/a/202835,
# it will match invalid IPs like 123.456.789.012 but it's fine
# since the log only contains valid ones.
declare -a IPS_TO_HIDE=("$(echo "${OVPNLOG}" |
grepcidr -v 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 |
grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' |
uniq)")
declare -a IPS_TO_HIDE=("$(echo "${OVPNLOG}" \
| grepcidr -v 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 \
| grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' \
| uniq)")

for IP in "${IPS_TO_HIDE[@]}"; do
OVPNLOG="${OVPNLOG//"$IP"/REDACTED}"
Expand Down
6 changes: 3 additions & 3 deletions scripts/openvpn/removeOVPN.sh
Expand Up @@ -166,9 +166,9 @@ for ((ii = 0; ii < ${#CERTS_TO_REVOKE[@]}; ii++)); do
# shellcheck disable=SC2154
# Grab the client IP address
NET_REDUCED="${pivpnNET::-2}"
STATIC_IP="$(grep -v "^#" /etc/openvpn/ccd/"${CERTS_TO_REVOKE[ii]}" |
grep -w ifconfig-push |
grep -oE "${NET_REDUCED}\.[0-9]{1,3}")"
STATIC_IP="$(grep -v "^#" /etc/openvpn/ccd/"${CERTS_TO_REVOKE[ii]}" \
| grep -w ifconfig-push \
| grep -oE "${NET_REDUCED}\.[0-9]{1,3}")"
rm -rf /etc/openvpn/ccd/"${CERTS_TO_REVOKE[ii]}"

# disablung warning SC2154, $install_home sourced externally
Expand Down
12 changes: 6 additions & 6 deletions scripts/self_check.sh
@@ -1,7 +1,7 @@
#!/bin/bash

PLAT="$(grep -sEe '^NAME\=' /etc/os-release |
sed -E -e "s/NAME\=[\'\"]?([^ ]*).*/\1/")"
PLAT="$(grep -sEe '^NAME\=' /etc/os-release \
| sed -E -e "s/NAME\=[\'\"]?([^ ]*).*/\1/")"

# dual protocol, VPN type supplied as $1
VPN="${1}"
Expand Down Expand Up @@ -255,8 +255,8 @@ else
fi

if [[ "${PLAT}" == 'Alpine' ]]; then
if [[ "$(rc-service "${VPN_SERVICE}" status |
sed -E -e 's/.*status\: (.*)/\1/')" == 'started' ]]; then
if [[ "$(rc-service "${VPN_SERVICE}" status \
| sed -E -e 's/.*status\: (.*)/\1/')" == 'started' ]]; then
echo ":: [OK] ${VPN_PRETTY_NAME} is running"
else
ERR=1
Expand All @@ -271,8 +271,8 @@ if [[ "${PLAT}" == 'Alpine' ]]; then
fi
fi

if rc-update show default |
grep -sEe "\s*${VPN_SERVICE} .*" &> /dev/null; then
if rc-update show default \
| grep -sEe "\s*${VPN_SERVICE} .*" &> /dev/null; then
echo -n ":: [OK] ${VPN_PRETTY_NAME} is enabled "
echo "(it will automatically start on reboot)"
else
Expand Down
8 changes: 4 additions & 4 deletions scripts/uninstall.sh
Expand Up @@ -26,8 +26,8 @@ setupConfigDir="/etc/pivpn"
pivpnFilesDir="/usr/local/src/pivpn"
pivpnScriptDir="/opt/pivpn"

PLAT="$(grep -sEe '^NAME\=' /etc/os-release |
sed -E -e "s/NAME\=[\'\"]?([^ ]*).*/\1/")"
PLAT="$(grep -sEe '^NAME\=' /etc/os-release \
| sed -E -e "s/NAME\=[\'\"]?([^ ]*).*/\1/")"

if [[ "${PLAT}" == 'Alpine' ]]; then
PKG_MANAGER='apk'
Expand All @@ -36,8 +36,8 @@ fi

UPDATE_PKG_CACHE="${PKG_MANAGER} update"

if [[ -r "${setupConfigDir}/wireguard/${setupVarsFile}" ]] &&
[[ -r "${setupConfigDir}/openvpn/${setupVarsFile}" ]]; then
if [[ -r "${setupConfigDir}/wireguard/${setupVarsFile}" ]] \
&& [[ -r "${setupConfigDir}/openvpn/${setupVarsFile}" ]]; then
vpnStillExists=1

# Two protocols have been installed, check if the script has passed
Expand Down
4 changes: 2 additions & 2 deletions scripts/update.sh
Expand Up @@ -90,8 +90,8 @@ updatepivpnscripts() {
echo
fi

if [[ -d "${pivpnlocalpath}" ]] &&
[[ -n "${pivpnlocalpath}" ]]; then
if [[ -d "${pivpnlocalpath}" ]] \
&& [[ -n "${pivpnlocalpath}" ]]; then
rm -rf "${pivpnlocalpath}/../.pivpn"
fi

Expand Down
4 changes: 2 additions & 2 deletions scripts/wireguard/clientSTAT.sh
Expand Up @@ -49,8 +49,8 @@ listClients() {
BYTES_RECEIVED="$(awk '{ print $6 }' <<< "${LINE}")"
BYTES_SENT="$(awk '{ print $7 }' <<< "${LINE}")"
LAST_SEEN="$(awk '{ print $5 }' <<< "${LINE}")"
CLIENT_NAME="$(grep "${PUBLIC_KEY}" "${CLIENTS_FILE}" |
awk '{ print $1 }')"
CLIENT_NAME="$(grep "${PUBLIC_KEY}" "${CLIENTS_FILE}" \
| awk '{ print $1 }')"
printf "%s \t %s \t %s \t " \
"${CLIENT_NAME}" \
"${REMOTE_IP}" \
Expand Down
24 changes: 12 additions & 12 deletions scripts/wireguard/makeCONF.sh
Expand Up @@ -40,9 +40,9 @@ while [[ "$#" -gt 0 ]]; do
_val="${_key##--name=}"

if [[ "${_val}" == "${_key}" ]]; then
[[ "$#" -lt 2 ]] &&
err "::: Missing value for the optional argument '${_key}'." &&
exit 1
[[ "$#" -lt 2 ]] \
&& err "::: Missing value for the optional argument '${_key}'." \
&& exit 1

_val="${2}"
shift
Expand Down Expand Up @@ -94,18 +94,18 @@ elif [[ -f "configs/${CLIENT_NAME}.conf" ]]; then
exit 1
fi

wg genkey |
tee "keys/${CLIENT_NAME}_priv" |
wg pubkey > "keys/${CLIENT_NAME}_pub"
wg genkey \
| tee "keys/${CLIENT_NAME}_priv" \
| wg pubkey > "keys/${CLIENT_NAME}_pub"
wg genpsk | tee "keys/${CLIENT_NAME}_psk" &> /dev/null
echo "::: Client Keys generated"

# Find an unused number for the last octet of the client IP
for i in {2..254}; do
if ! grep -q " ${i}$" configs/clients.txt; then
COUNT="${i}"
echo "${CLIENT_NAME} $(< keys/"${CLIENT_NAME}"_pub) $(date +%s) ${COUNT}" |
tee -a configs/clients.txt > /dev/null
echo "${CLIENT_NAME} $(< keys/"${CLIENT_NAME}"_pub) $(date +%s) ${COUNT}" \
| tee -a configs/clients.txt > /dev/null
break
fi
done
Expand Down Expand Up @@ -167,12 +167,12 @@ echo "::: Client config generated"
echo "::: Updated server config"

if [[ -f /etc/pivpn/hosts.wireguard ]]; then
echo "${NET_REDUCED}.${COUNT} ${CLIENT_NAME}.pivpn" |
tee -a /etc/pivpn/hosts.wireguard > /dev/null
echo "${NET_REDUCED}.${COUNT} ${CLIENT_NAME}.pivpn" \
| tee -a /etc/pivpn/hosts.wireguard > /dev/null

if [[ "${pivpnenableipv6}" == 1 ]]; then
echo "${pivpnNETv6}${COUNT} ${CLIENT_NAME}.pivpn" |
tee -a /etc/pivpn/hosts.wireguard > /dev/null
echo "${pivpnNETv6}${COUNT} ${CLIENT_NAME}.pivpn" \
| tee -a /etc/pivpn/hosts.wireguard > /dev/null
fi

if killall -SIGHUP pihole-FTL; then
Expand Down
8 changes: 4 additions & 4 deletions scripts/wireguard/removeCONF.sh
Expand Up @@ -100,11 +100,11 @@ for CLIENT_NAME in "${CLIENTS_TO_REMOVE[@]}"; do
# Grab the least significant octed of the client IP address
COUNT="$(grep "^${CLIENT_NAME} " configs/clients.txt | awk '{print $4}')"
# The creation date of the client
CREATION_DATE="$(grep "^${CLIENT_NAME} " configs/clients.txt |
awk '{print $3}')"
CREATION_DATE="$(grep "^${CLIENT_NAME} " configs/clients.txt \
| awk '{print $3}')"
# And its public key
PUBLIC_KEY="$(grep "^${CLIENT_NAME} " configs/clients.txt |
awk '{print $2}')"
PUBLIC_KEY="$(grep "^${CLIENT_NAME} " configs/clients.txt \
| awk '{print $2}')"

# Then remove the client matching the variables above
sed \
Expand Down

0 comments on commit e09f3a0

Please sign in to comment.