diff --git a/DnsServerApp/DnsServerApp.csproj b/DnsServerApp/DnsServerApp.csproj index 3441a8a2..d68441d6 100644 --- a/DnsServerApp/DnsServerApp.csproj +++ b/DnsServerApp/DnsServerApp.csproj @@ -23,6 +23,9 @@ + + PreserveNewest + PreserveNewest diff --git a/DnsServerApp/install.sh b/DnsServerApp/install.sh index 4d748f83..3d0cb73a 100644 --- a/DnsServerApp/install.sh +++ b/DnsServerApp/install.sh @@ -1,5 +1,15 @@ #!/bin/sh +cleanup() { + # On Alpine Linux get rid of virtual packages installed in support for this script. + # If none was installed, just fail silently + if $alpineLinux; then + apk del .deps > /dev/null 2>&1 + fi +} + +trap cleanup INT TERM EXIT + dotnetDir="/opt/dotnet" dotnetVersion="8.0" dotnetRuntime="Microsoft.AspNetCore.App 8.0." @@ -27,6 +37,29 @@ echo "" mkdir -p $dnsDir echo "" > $installLog +if command -v apk >/dev/null 2>&1 +then + # On Alpine Linux we need bash & curl to install dotnet + alpineLinux=true + apk update >> $installLog 2>&1 + deps="" + # Check for bash + if ! command -v bash >/dev/null 2>&1; then + deps="$deps bash" + fi + # Check for curl + if ! command -v curl >/dev/null 2>&1; then + deps="$deps curl" + fi + # Install missing packages, if any + if [ -n "$deps" ]; then + echo "Installing packages needed for the installation: $deps" + apk add --no-cache --virtual .deps $deps + fi +else + alpineLinux=false +fi + if dotnet --list-runtimes 2> /dev/null | grep -q "$dotnetRuntime"; then dotnetFound="yes" @@ -49,6 +82,12 @@ else curl -sSL $dotnetUrl | bash /dev/stdin -c $dotnetVersion --runtime aspnetcore --no-path --install-dir $dotnetDir --verbose >> $installLog 2>&1 + # On Alpine Linux dotnet requires libstdc++ + if $alpineLinux; then + echo "Installing ASP.NET Core Runtime dependencies..." + apk add --no-cache libstdc++ >> $installLog 2>&1 + fi + if [ ! -f "/usr/bin/dotnet" ] then ln -s $dotnetDir/dotnet /usr/bin >> $installLog 2>&1 @@ -166,34 +205,58 @@ fi echo "" -if ! [ "$(ps --no-headers -o comm 1 | tr -d '\n')" = "systemd" ] +installed=false +if [ "$(ps -o comm 1 | grep -v COMMAND)" = "systemd" ] then - echo "Failed to install Technitium DNS Server: systemd was not detected." - echo "Please read the 'Installing DNS Server Manually' section in this blog post to understand how to manually install the DNS server on your distro: https://blog.technitium.com/2017/11/running-dns-server-on-ubuntu-linux.html" - exit 1 -fi + 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 -e "# Generated by Technitium DNS Server Installer\n\nnameserver 127.0.0.1" > /etc/resolv.conf 2>> $installLog + + if [ -f "/etc/NetworkManager/NetworkManager.conf" ] + then + echo -e "[main]\ndns=default" >> /etc/NetworkManager/NetworkManager.conf 2>> $installLog + fi + fi + installed=true -if [ -f "/etc/systemd/system/dns.service" ] +elif [ -x "/sbin/rc-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 -e "# Generated by Technitium DNS Server Installer\n\nnameserver 127.0.0.1" > /etc/resolv.conf 2>> $installLog - - if [ -f "/etc/NetworkManager/NetworkManager.conf" ] + if [ -f "/etc/init.d/dns" ] then - echo -e "[main]\ndns=default" >> /etc/NetworkManager/NetworkManager.conf 2>> $installLog + echo "Restarting OpenRC service..." + rc-service dns stop >> $installLog 2>&1 + rc-service dns start >> $installLog 2>&1 + else + echo "Configuring OpenRC service..." + cp $dnsDir/openrc.service /etc/init.d/dns + chmod +x /etc/init.d/dns + rc-update add dns >> $installLog 2>&1 + rc-service dns start >> $installLog 2>&1 + + rm /etc/resolv.conf >> $installLog 2>&1 + echo -e "# Generated by Technitium DNS Server Installer\n\nnameserver 127.0.0.1" > /etc/resolv.conf 2>> $installLog fi + installed=true +fi + +if ! $installed +then + echo "Failed to install Technitium DNS Server: systemd or OpenRC were not detected." + echo "Please read the 'Installing DNS Server Manually' section in this blog post to understand how to manually install the DNS server on your distro: https://blog.technitium.com/2017/11/running-dns-server-on-ubuntu-linux.html" + exit 1 fi echo "" diff --git a/DnsServerApp/openrc.service b/DnsServerApp/openrc.service new file mode 100644 index 00000000..6304ac34 --- /dev/null +++ b/DnsServerApp/openrc.service @@ -0,0 +1,8 @@ +#!/sbin/openrc-run + +name=$RC_SVCNAME +description="Technitium DNS Server" +supervisor="supervise-daemon" +command="/usr/bin/dotnet" +command_args="/opt/technitium/dns/DnsServerApp.dll /etc/dns" +supervise_daemon_args=" -d /opt/technitium/dns"