From 500112c8734b1878220f45bbcf7eee8cf1f0fe0c Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Fri, 14 Nov 2025 10:31:29 +0100 Subject: [PATCH] Add resolvconf shim to stabilize WireGuard DNS handling --- .../s6-overlay/s6-rc.d/svc-qbittorrent/run | 2 + qbittorrent/rootfs/usr/local/bin/resolvconf | 86 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100755 qbittorrent/rootfs/usr/local/bin/resolvconf diff --git a/qbittorrent/rootfs/etc/s6-overlay/s6-rc.d/svc-qbittorrent/run b/qbittorrent/rootfs/etc/s6-overlay/s6-rc.d/svc-qbittorrent/run index 03872a773..2db7fd39d 100755 --- a/qbittorrent/rootfs/etc/s6-overlay/s6-rc.d/svc-qbittorrent/run +++ b/qbittorrent/rootfs/etc/s6-overlay/s6-rc.d/svc-qbittorrent/run @@ -3,6 +3,8 @@ WEBUI_PORT=${WEBUI_PORT:-8080} +export PATH="/usr/local/sbin:/usr/local/bin:${PATH}" + if bashio::config.true 'silent'; then sed -i 's|/proc/1/fd/1 hassio;|off;|g' /etc/nginx/nginx.conf fi diff --git a/qbittorrent/rootfs/usr/local/bin/resolvconf b/qbittorrent/rootfs/usr/local/bin/resolvconf new file mode 100755 index 000000000..3e2a91880 --- /dev/null +++ b/qbittorrent/rootfs/usr/local/bin/resolvconf @@ -0,0 +1,86 @@ +#!/bin/sh +set -eu + +STATE_DIR="/var/run/wireguard/resolvconf" +BACKUP_FILE="${STATE_DIR}/resolv.conf.backup" + +mkdir -p "${STATE_DIR}" + +if [ "$#" -eq 0 ]; then + exit 0 +fi + +command="$1" +shift || true + +restore_backup() { + if [ -f "${BACKUP_FILE}" ]; then + cat "${BACKUP_FILE}" > /etc/resolv.conf + fi +} + +apply_dns() { + iface="$1" + shift || true + + # Skip optional arguments such as -m or -x + while [ "$#" -gt 0 ]; do + case "$1" in + -m|-p|-w) + shift 2 || true + ;; + -x|-y|-Z) + shift 1 || true + ;; + --) + shift + break + ;; + *) + break + ;; + esac + done + + tmp_file="${STATE_DIR}/${iface}.conf" + cat > "${tmp_file}" + + if [ ! -f "${BACKUP_FILE}" ]; then + cp /etc/resolv.conf "${BACKUP_FILE}" 2>/dev/null || true + fi + + { + echo "# Generated by WireGuard add-on resolvconf shim" + cat "${tmp_file}" + } > /etc/resolv.conf +} + +case "${command}" in + -a) + if [ "$#" -eq 0 ]; then + exit 0 + fi + apply_dns "$@" + ;; + -d) + if [ "$#" -gt 0 ]; then + rm -f "${STATE_DIR}/$1.conf" + fi + restore_backup + ;; + -u) + latest_conf="$(find "${STATE_DIR}" -maxdepth 1 -type f -name '*.conf' -print | head -n 1 || true)" + if [ -n "${latest_conf}" ] && [ -f "${latest_conf}" ]; then + { + echo "# Generated by WireGuard add-on resolvconf shim" + cat "${latest_conf}" + } > /etc/resolv.conf + else + restore_backup + fi + ;; + *) + # Treat other commands as successful no-ops to remain compatible with wg-quick. + exit 0 + ;; +esac