mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-05 07:14:08 +02:00
Fix: Replace update-resolv-conf script that uses systemd-resolved with direct resolv.conf modification
The upstream haugene/transmission-openvpn v5.4.0 image uses systemd-resolved via D-Bus in its update-resolv-conf script, which fails in HA containers that lack systemd/D-Bus with 'sd_bus_open_system: No such file or directory'. This adds a custom update-resolv-conf script that directly modifies /etc/resolv.conf by parsing OpenVPN's foreign_option_* environment variables. Co-authored-by: alexbelgium <44178713+alexbelgium@users.noreply.github.com>
This commit is contained in:
57
transmission_openvpn/rootfs/etc/openvpn/update-resolv-conf
Executable file
57
transmission_openvpn/rootfs/etc/openvpn/update-resolv-conf
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
# OpenVPN update-resolv-conf replacement for containerized environments
|
||||
# The default script from the base image uses systemd-resolved via D-Bus,
|
||||
# which is unavailable in Home Assistant add-on containers.
|
||||
# This script directly updates /etc/resolv.conf instead.
|
||||
|
||||
[ "$script_type" ] || exit 0
|
||||
|
||||
case "$script_type" in
|
||||
up)
|
||||
# Backup original resolv.conf
|
||||
if [ ! -f /etc/resolv.conf.ovpn-bak ]; then
|
||||
cp /etc/resolv.conf /etc/resolv.conf.ovpn-bak 2>/dev/null || true
|
||||
fi
|
||||
|
||||
dns_servers=""
|
||||
dns_domain=""
|
||||
dns_search=""
|
||||
|
||||
# Parse foreign_option_* environment variables set by OpenVPN
|
||||
for optionname in ${!foreign_option_*}; do
|
||||
option="${!optionname}"
|
||||
case "$option" in
|
||||
dhcp-option\ DNS\ *)
|
||||
dns_servers="${dns_servers} ${option#dhcp-option DNS }"
|
||||
;;
|
||||
dhcp-option\ DOMAIN\ *)
|
||||
dns_domain="${option#dhcp-option DOMAIN }"
|
||||
;;
|
||||
dhcp-option\ DOMAIN-SEARCH\ *)
|
||||
dns_search="${dns_search} ${option#dhcp-option DOMAIN-SEARCH }"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Write new resolv.conf with VPN DNS servers
|
||||
if [ -n "$dns_servers" ]; then
|
||||
{
|
||||
for server in $dns_servers; do
|
||||
echo "nameserver $server"
|
||||
done
|
||||
[ -n "$dns_domain" ] && echo "domain $dns_domain"
|
||||
[ -n "$dns_search" ] && echo "search${dns_search}"
|
||||
} > /etc/resolv.conf
|
||||
fi
|
||||
;;
|
||||
|
||||
down)
|
||||
# Restore original resolv.conf
|
||||
if [ -f /etc/resolv.conf.ovpn-bak ]; then
|
||||
cp /etc/resolv.conf.ovpn-bak /etc/resolv.conf
|
||||
rm -f /etc/resolv.conf.ovpn-bak
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user