diff --git a/DnsServerApp.NETCore/install.sh b/DnsServerApp.NETCore/install.sh new file mode 100644 index 00000000..f1dd9c4f --- /dev/null +++ b/DnsServerApp.NETCore/install.sh @@ -0,0 +1,92 @@ +#!/bin/sh + +dotnetDir="/opt/dotnet" +dnsDir="/etc/dns" +dnsTar="/etc/dns/DnsServerPortable.tar.gz" +dnsUrl="https://download.technitium.com/dns/DnsServerPortable.tar.gz" + +mkdir -p $dnsDir +installLog="$dnsDir/install.log" +echo "" > $installLog + +echo "" +echo "===============================" +echo "Technitium DNS Server Installer" +echo "===============================" +echo "" +echo "Installing .NET Core Runtime..." + +curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -c Current --runtime dotnet --no-path --install-dir $dotnetDir --verbose >> $installLog 2>&1 + +if [ ! -f "/usr/bin/dotnet" ] +then + ln -s $dotnetDir/dotnet /usr/bin >> $installLog 2>&1 +fi + +echo "" +echo "Downloading Technitium DNS Server..." + +if curl -o $dnsTar --fail $dnsUrl >> $installLog 2>&1 +then + if [ -d "/etc/dns/" ] + then + echo "Updating Technitium DNS Server..." + else + echo "Installing Technitium DNS Server..." + fi + + tar -zxf $dnsTar -C $dnsDir >> $installLog 2>&1 + + if [ "$(ps --no-headers -o comm 1 | tr -d '\n')" = "systemd" ] + then + if [ -f "/etc/systemd/system/dns.service" ] + then + echo "Restarting systemd service..." + systemctl restart dns.service >> $installLog 2>&1 + else + echo "Configuring systemd service..." + cp $dnsDir/systemd.service /etc/systemd/system/dns.service + systemctl enable dns.service >> $installLog 2>&1 + + systemctl stop systemd-resolved >> $installLog 2>&1 + systemctl disable systemd-resolved >> $installLog 2>&1 + + systemctl start dns.service >> $installLog 2>&1 + + rm /etc/resolv.conf >> $installLog 2>&1 + echo "nameserver 127.0.0.1" > /etc/resolv.conf >> $installLog 2>&1 + + if [ -f "/etc/NetworkManager/NetworkManager.conf" ] + then + echo "[main]" >> /etc/NetworkManager/NetworkManager.conf + echo "dns=default" >> /etc/NetworkManager/NetworkManager.conf + fi + fi + else + if [ -f "/etc/supervisor/conf.d/dns.conf" ] + then + echo "Restarting supervisor service..." + service supervisor restart >> $installLog 2>&1 + else + echo "Installing supervisor..." + + until apt-get -y install supervisor >> $installLog 2>&1 + do + echo "Trying again.." + sleep 2 + done + + echo "Configuring supervisor service..." + cp $dnsDir/supervisor.conf /etc/supervisor/conf.d/dns.conf + service supervisor restart >> $installLog 2>&1 + fi + fi + + echo "" + echo "Technitium DNS Server was installed succesfully!" + echo "Open http://$(hostname):5380/ to access the web console." +else + echo "" + echo "Failed to download Technitium DNS Server from: $dnsUrl" + exit 1 +fi diff --git a/DnsServerApp.NETCore/uninstall.sh b/DnsServerApp.NETCore/uninstall.sh new file mode 100644 index 00000000..b8b90407 --- /dev/null +++ b/DnsServerApp.NETCore/uninstall.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +dotnetDir="/opt/dotnet" +dnsDir="/etc/dns" + +echo "" +echo "=================================" +echo "Technitium DNS Server Uninstaller" +echo "=================================" +echo "" +echo "Uninstalling Technitium DNS Server..." + +if [ -d $dnsDir ] +then + if [ "$(ps --no-headers -o comm 1 | tr -d '\n')" = "systemd" ] + then + sudo systemctl disable dns.service >/dev/null 2>&1 + sudo systemctl stop dns.service >/dev/null 2>&1 + rm /etc/systemd/system/dns.service >/dev/null 2>&1 + + rm /etc/resolv.conf >/dev/null 2>&1 + echo "nameserver 8.8.8.8" >> /etc/resolv.conf + echo "nameserver 1.1.1.1" >> /etc/resolv.conf + else + rm /etc/supervisor/conf.d/dns.conf >/dev/null 2>&1 + service supervisor restart >/dev/null 2>&1 + fi + + rm -rf $dnsDir >/dev/null 2>&1 + + if [ -d $dotnetDir ] + then + echo "Uninstalling .NET Core Runtime..." + rm /usr/bin/dotnet >/dev/null 2>&1 + rm -rf $dotnetDir >/dev/null 2>&1 + fi +fi + +echo "" +echo "Thank you for using Technitium DNS Server!"