#!/bin/bash

# O road warrior ou gateway client liga a vpn gateway
# Via a rede externa 193.136.212.0/24
# Rede externa (enp0s8)

bash VM_CONFIG.sh

# --- interfaces --- #
ifconfig enp0s8 193.136.212.10 netmask 255.255.255.0
route add default gw 193.136.212.1 # default gateway LIKE A SHEEP

# certificado 
[[ -e "user.key" ]] && echo "user.key ja criado" || sudo openssl genrsa -out user.key
[[ -e "user.csr" ]] && echo "user.csr ja criado" || sudo openssl req -new -key user.key -out user.csr
[[ -e "user.crt" ]] && echo "user.crt ja criado" || sudo openssl ca -in user.csr -cert ca.crt -keyfile ca.key -out user.crt

vpn_dir="/etc/openvpn/client/"
sudo cp ca.crt $vpn_dir 
sudo cp user.csr $vpn_dir 
sudo cp user.crt $vpn_dir 
sudo cp client.conf $vpn_dir 
openvpn --config /etc/openvpn/client/client.conf
