Propose to stop addon if openvpn script fails for logs clarity

This commit is contained in:
Alexandre
2026-02-05 10:28:34 +01:00
committed by GitHub
parent 1365ed148b
commit 4f750ad756

View File

@@ -18,7 +18,8 @@ fi
if ! bashio::config.true 'openvpn_enabled'; then
bashio::exit.ok 'OpenVPN is disabled.'
elif bashio::config.true 'wireguard_enabled'; then
bashio::exit.nok 'OpenVPN and WireGuard cannot be enabled simultaneously. Disable one of them.'
bashio::log.fatal 'OpenVPN and WireGuard cannot be enabled simultaneously. Disable one of them.'
bashio::addon.stop
fi
mkdir -p "${OPENVPN_STATE_DIR}"
@@ -31,12 +32,14 @@ bashio::log.info "----------------------------"
if bashio::config.has_value "openvpn_username"; then
openvpn_username=$(bashio::config 'openvpn_username')
else
bashio::exit.nok "Openvpn is enabled, but openvpn_username option is empty! Exiting"
bashio::log.fatal "Openvpn is enabled, but openvpn_username option is empty! Exiting"
bashio::addon.stop
fi
if bashio::config.has_value "openvpn_password"; then
openvpn_password=$(bashio::config 'openvpn_password')
else
bashio::exit.nok "Openvpn is enabled, but openvpn_password option is empty! Exiting"
bashio::log.fatal "Openvpn is enabled, but openvpn_password option is empty! Exiting"
bashio::addon.stop
fi
echo -e "${openvpn_username}\n${openvpn_password}" > "${OPENVPN_STATE_DIR}/credentials.conf"
@@ -50,7 +53,8 @@ if [[ -z "${openvpn_config}" ]]; then
bashio::log.info 'openvpn_config option left empty. Attempting automatic selection.'
mapfile -t configs < <(find /config/openvpn -maxdepth 1 \( -type f -name '*.conf' -o -name '*.ovpn' \) -print)
if [ "${#configs[@]}" -eq 0 ]; then
bashio::exit.nok 'OpenVPN is enabled but no .conf or .ovpn file was found in /config/openvpn.'
bashio::log.fatal 'OpenVPN is enabled but no .conf or .ovpn file was found in /config/openvpn.'
bashio::addon.stop
elif [ "${#configs[@]}" -eq 1 ]; then
openvpn_config="${configs[0]}"
bashio::log.info "OpenVPN configuration not specified. Using ${openvpn_config##*/}."
@@ -58,17 +62,20 @@ if [[ -z "${openvpn_config}" ]]; then
openvpn_config='/config/openvpn/config.conf'
bashio::log.info 'Using default OpenVPN configuration config.conf.'
else
bashio::exit.nok "Multiple OpenVPN configuration files detected. Please set the 'openvpn_config' option."
bashio::log.fatal "Multiple OpenVPN configuration files detected. Please set the 'openvpn_config' option."
bashio::addon.stop
fi
elif bashio::fs.file_exists "/config/openvpn/${openvpn_config}"; then
openvpn_config="/config/openvpn/${openvpn_config}"
else
bashio::exit.nok "OpenVPN configuration '/config/openvpn/${openvpn_config}' not found."
bashio::log.fatal "OpenVPN configuration '/config/openvpn/${openvpn_config}' not found."
bashio::addon.stop
fi
interface_name="$(sed -n "/^dev tun/p" "${openvpn_config}" | awk -F' ' '{print $2}')"
if [[ -z "${interface_name}" ]]; then
bashio::exit.nok "OpenVPN configuration '${openvpn_config}' misses device directive."
bashio::log.fatal "OpenVPN configuration '${openvpn_config}' misses device directive."
bashio::addon.stop
elif [[ ${interface_name} = "tun" ]]; then
interface_name='tun0'
elif [[ ${interface_name} = "tap" ]]; then