From 2081d7af9991b412e50778765477658304feb89d Mon Sep 17 00:00:00 2001 From: Andrey Gribin Date: Thu, 2 Jul 2026 21:23:06 +0300 Subject: [PATCH] Add dnskmasq interactive install Add dnsmasq installation on router if don't exist --- Install/common/templates/dnsmasq.conf | 14 +++ Install/install_func.sh | 131 ++++++++++++++++++++++++-- 2 files changed, 139 insertions(+), 6 deletions(-) create mode 100644 Install/common/templates/dnsmasq.conf diff --git a/Install/common/templates/dnsmasq.conf b/Install/common/templates/dnsmasq.conf new file mode 100644 index 0000000..d43cb07 --- /dev/null +++ b/Install/common/templates/dnsmasq.conf @@ -0,0 +1,14 @@ +port=53 + +listen-address=127.0.0.1 +bind-interfaces + +domain-needed +bogus-priv + +cache-size=10000 + +conf-dir=/opt/etc/dnsmasq.d + +server={{DNS1}} +server={{DNS2}} \ No newline at end of file diff --git a/Install/install_func.sh b/Install/install_func.sh index 74e312a..a92b9c7 100644 --- a/Install/install_func.sh +++ b/Install/install_func.sh @@ -20,11 +20,128 @@ select_dns_mode(){ MODE="dnsmasq" echo -e "\nYou use dnsmasq mode\n" else - echo -e "\nadguardhome or dnsmasq is not running!\nPlease install and configure one of it first!!!\n" - exit 0 + printf "\nAdGuardHome or dnsmasq was not found.\n" + printf "No supported DNS backend was found. Install dnsmasq from Entware now? [Y/n] " + + read -r ANSWER + + case "$ANSWER" in + n|N) + echo "Installation cancelled." + exit 0 + ;; + *) + install_dnsmasq_func + MODE="dnsmasq" + ;; + esac fi } +install_dnsmasq_func() { + + echo + echo "Installing dnsmasq..." + + $SYSTEM_FOLDER/bin/opkg update + echo + echo "Installing dnsmasq..." + + $SYSTEM_FOLDER/bin/opkg update + + if ! $SYSTEM_FOLDER/bin/opkg install dnsmasq-full; then + echo + echo "Failed to install dnsmasq." + exit 1 + fi + + mkdir -p "$SYSTEM_FOLDER/etc/dnsmasq.d" + + $SYSTEM_FOLDER/bin/opkg update + + select_dns_provider_func + + # + # Создаем конфиг только если его нет + # + if [ ! -f "$SYSTEM_FOLDER/etc/dnsmasq.conf" ]; then + + echo "Creating default dnsmasq configuration..." + + sed \ + -e "s/{{DNS1}}/$DNS1/" \ + -e "s/{{DNS2}}/$DNS2/" \ + "$HOME_FOLDER/Install/common/templates/dnsmasq.conf" \ + > "$SYSTEM_FOLDER/etc/dnsmasq.conf" + + else + + echo "Existing dnsmasq.conf found." + echo "Keeping current configuration." + + fi + + if [ -f "$SYSTEM_FOLDER/etc/init.d/S56dnsmasq" ]; then + chmod +x "$SYSTEM_FOLDER/etc/init.d/S56dnsmasq" + "$SYSTEM_FOLDER/etc/init.d/S56dnsmasq" enable 2>/dev/null + "$SYSTEM_FOLDER/etc/init.d/S56dnsmasq" start + fi + + sleep 2 + + if [ $("$SYSTEM_FOLDER/etc/init.d/S56dnsmasq" check | grep -c alive) -ne 1 ]; then + echo + echo "dnsmasq failed to start." + exit 1 + fi + +} + +select_dns_provider_func(){ + + echo + echo "Select upstream DNS:" + echo " 1 - Google (default)" + echo " 2 - Cloudflare" + echo " 3 - Quad9" + echo " 4 - AdGuard DNS" + echo " 5 - Custom" + + read ANSWER + + case "$ANSWER" in + + 2) + DNS1=1.1.1.1 + DNS2=1.0.0.1 + ;; + + 3) + DNS1=9.9.9.9 + DNS2=149.112.112.112 + ;; + + 4) + DNS1=94.140.14.14 + DNS2=94.140.15.15 + ;; + + 5) + echo "Primary DNS:" + read -r DNS1 + + echo "Secondary DNS:" + read -r DNS2 + ;; + + *) + DNS1=8.8.8.8 + DNS2=8.8.4.4 + ;; + esac +} + + # Install packages install_packages_func(){ # Update busybox @@ -65,7 +182,7 @@ get_old_config_func(){ try_get_bird4static_config_func(){ echo -e "\nFound bird4static. Do you want use his config? y/n" - read ANSWER + read -r ANSWER if [ "$ANSWER" == "y" ]; then cd $HOME_FOLDER && cd .. if [ -f "scripts/func.sh" ]; then @@ -81,7 +198,7 @@ try_get_bird4static_config_func(){ select_number_vpn_func(){ if [ -z "$VCONF" ]; then echo -e "\nDo you want to use double vpn configuration? 1 - no (default) 2 - yes" - read VCONF + read -r VCONF fi if [ "$VCONF" != "2" ]; then VCONF=1 @@ -172,8 +289,10 @@ change_dns_config(){ if [ "$MODE" == "adguardhome" ]; then sed -i 's/ipset_file.*/ipset_file: '$SYSTEM_FOLDER_SED'\/etc\/ipset4static_list.conf/' $SYSTEM_FOLDER/etc/AdGuardHome/AdGuardHome.yaml elif [ "$MODE" == "dnsmasq" ]; then - if [ $(cat $SYSTEM_FOLDER/etc/dnsmasq.conf | grep conf-file=$SYSTEM_FOLDER/etc/ipset4static_list.conf -c ) -eq 0 ]; then - echo conf-file=$SYSTEM_FOLDER/etc/ipset4static_list.conf >> $SYSTEM_FOLDER/etc/dnsmasq.conf + if ! grep -q "^conf-file=$SYSTEM_FOLDER/etc/ipset4static_list.conf$" \ + "$SYSTEM_FOLDER/etc/dnsmasq.conf"; then + echo "conf-file=$SYSTEM_FOLDER/etc/ipset4static_list.conf" \ + >> "$SYSTEM_FOLDER/etc/dnsmasq.conf" fi fi