Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Install/common/templates/dnsmasq.conf
Original file line number Diff line number Diff line change
@@ -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}}
131 changes: 125 additions & 6 deletions Install/install_func.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down