From 0cb5546608784dc609493424f7aef69791f1b728 Mon Sep 17 00:00:00 2001 From: Orazio Date: Mon, 10 Feb 2020 17:36:39 +0100 Subject: [PATCH] Get $STATIC_IP before ccd folder is deleted (otherwhise $STATIC_IP will be empty) --- scripts/openvpn/removeOVPN.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/openvpn/removeOVPN.sh b/scripts/openvpn/removeOVPN.sh index 8e300a5..4b5124c 100755 --- a/scripts/openvpn/removeOVPN.sh +++ b/scripts/openvpn/removeOVPN.sh @@ -119,6 +119,9 @@ for (( ii = 0; ii < ${#CERTS_TO_REVOKE[@]}; ii++)); do rm -rf "pki/reqs/${CERTS_TO_REVOKE[ii]}.req" rm -rf "pki/private/${CERTS_TO_REVOKE[ii]}.key" rm -rf "pki/issued/${CERTS_TO_REVOKE[ii]}.crt" + + # Grab the client IP address + STATIC_IP=$(grep -v "^#" /etc/openvpn/ccd/"${CERTS_TO_REVOKE[ii]}" | grep -w ifconfig-push | grep -oE '10.8.0\.[0-9]{1,3}') rm -rf /etc/openvpn/ccd/"${CERTS_TO_REVOKE[ii]}" rm -rf "${install_home}/ovpns/${CERTS_TO_REVOKE[ii]}.ovpn" @@ -127,8 +130,6 @@ for (( ii = 0; ii < ${#CERTS_TO_REVOKE[@]}; ii++)); do # If using Pi-hole, remove the client from the hosts file if [ -f /etc/pivpn/hosts.openvpn ]; then - # Grab the client IP address - STATIC_IP=$(awk '{print $2}' <<< /etc/openvpn/ccd/"${CERTS_TO_REVOKE[ii]}") sed "\#${STATIC_IP} ${CERTS_TO_REVOKE[ii]}.pivpn#d" -i /etc/pivpn/hosts.openvpn if killall -SIGHUP pihole-FTL; then echo "::: Updated hosts file for Pi-hole"