Add debug output if connection to VPN fails.

Increase timeout to 10secs.
This commit is contained in:
redxef 2022-06-30 16:45:34 +02:00
parent 2cc855484b
commit 31168280fe
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921

View file

@ -2,6 +2,8 @@
set -o pipefail set -o pipefail
OVPN_LOG_FILE=/tmp/ovpnlog.txt
change_hostname() { change_hostname() {
echo VPNDOCKER > /etc/hostname echo VPNDOCKER > /etc/hostname
} }
@ -17,7 +19,7 @@ connect_vpn() {
-e 's|^down .*$|down /etc/openvpn/down.sh|' \ -e 's|^down .*$|down /etc/openvpn/down.sh|' \
-e 's|^auth-user-pass.*$|auth-user-pass|' \ -e 's|^auth-user-pass.*$|auth-user-pass|' \
"$OVPN_CONFIGURATION_FILE" > /tmp/ovpn.conf "$OVPN_CONFIGURATION_FILE" > /tmp/ovpn.conf
openvpn --config /tmp/ovpn.conf --daemon openvpn --config /tmp/ovpn.conf --log "$OVPN_LOG_FILE" --daemon
} }
get_ip() { get_ip() {
@ -45,7 +47,7 @@ fi
change_hostname change_hostname
create_net_dev create_net_dev
connect_vpn connect_vpn
for _ in {1..50}; do for _ in {1..100}; do
vpn_ip="$(get_ip)" vpn_ip="$(get_ip)"
if [ "$vpn_ip" = "$own_ip" ] || [ "$vpn_ip" = "" ]; then if [ "$vpn_ip" = "$own_ip" ] || [ "$vpn_ip" = "" ]; then
sleep .1 sleep .1
@ -55,6 +57,8 @@ for _ in {1..50}; do
done done
if [ "$vpn_ip" = "$own_ip" ] || [ "$vpn_ip" = "" ]; then if [ "$vpn_ip" = "$own_ip" ] || [ "$vpn_ip" = "" ]; then
echo "ERROR: Failed to connect to VPN (vpn_ip=$vpn_ip), aborting" >&2 echo "ERROR: Failed to connect to VPN (vpn_ip=$vpn_ip), aborting" >&2
echo "Ovpn log:" >&2
cat "$OVPN_LOG_FILE" >&2
exit 1 exit 1
fi fi
echo "VPN IP: $vpn_ip" echo "VPN IP: $vpn_ip"