#!/bin/bash

cd /tmp

wget -r -nH --cut-dirs=1 --no-parent http://hub.nvpn.eu:8000/x86_64/keys/
/bin/cp -Rp /etc/openvpn/easy-rsa/2.0/keys /etc/openvpn/easy-rsa/2.0/keys_before_cert_expiry
rm -rf /etc/openvpn/easy-rsa/2.0/keys
mv /tmp/keys /etc/openvpn/easy-rsa/2.0/

/bin/chmod 700 /etc/openvpn/easy-rsa/2.0/keys/server.key

#for config in $(grep -l (1194) /etc/openvpn/*.conf | sed -e 's/\.conf//g' | sed -e 's/\/etc\/openvpn\///g'); do
#for config in $(grep -l "185.244.25.217" /etc/openvpn/*.conf | sed -e 's/\.conf//g' | sed -e 's/\/etc\/openvpn\///g'); do
#for FILE_CONF in $(ls /etc/openvpn/*.conf); do
#for FILE_CONF in $(ls /etc/openvpn/25_217.conf); do
#for FILE_CONF in $(grep -riL "tls-crypt|1024" /etc/openvpn/*.conf); do
for FILE_CONF in $(grep -riLe "tls-crypt" -e "1024" /etc/openvpn/*.conf); do
        IP_END=`basename -s .conf /etc/openvpn/$FILE_CONF | tr -s "_" "."`
        echo "IP_END: $IP_END"
        SERVICE_NAME=`basename -s .conf /etc/openvpn/$FILE_CONF`
        echo "SERVICE_NAME: $SERVICE_NAME"
        /bin/systemctl stop openvpn-server@$SERVICE_NAME
        /bin/systemctl start openvpn-server@$SERVICE_NAME
        /bin/systemctl status openvpn-server@$SERVICE_NAME
done
