install.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/bin/sh
  2. dotnetDir="/opt/dotnet"
  3. dnsDir="/etc/dns"
  4. dnsTar="/etc/dns/DnsServerPortable.tar.gz"
  5. dnsUrl="https://download.technitium.com/dns/DnsServerPortable.tar.gz"
  6. mkdir -p $dnsDir
  7. installLog="$dnsDir/install.log"
  8. echo "" > $installLog
  9. echo ""
  10. echo "==============================="
  11. echo "Technitium DNS Server Installer"
  12. echo "==============================="
  13. if dotnet --list-runtimes 2> /dev/null | grep -q "Microsoft.NETCore.App 5.0.";
  14. then
  15. dotnetFound="yes"
  16. else
  17. dotnetFound="no"
  18. fi
  19. if [ ! -d $dotnetDir ] && [ "$dotnetFound" = "yes" ]
  20. then
  21. echo ""
  22. echo ".NET 5 Runtime is already installed."
  23. else
  24. echo ""
  25. if [ -d $dotnetDir ]
  26. then
  27. dotnetUpdate="yes"
  28. echo "Updating .NET 5 Runtime..."
  29. else
  30. dotnetUpdate="no"
  31. echo "Installing .NET 5 Runtime..."
  32. fi
  33. curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -c 5.0 --runtime dotnet --no-path --install-dir $dotnetDir --verbose >> $installLog 2>&1
  34. if [ ! -f "/usr/bin/dotnet" ]
  35. then
  36. ln -s $dotnetDir/dotnet /usr/bin >> $installLog 2>&1
  37. fi
  38. if dotnet --list-runtimes 2> /dev/null | grep -q "Microsoft.NETCore.App 5.0.";
  39. then
  40. if [ "$dotnetUpdate" = "yes" ]
  41. then
  42. echo ".NET 5 Runtime was updated successfully!"
  43. else
  44. echo ".NET 5 Runtime was installed successfully!"
  45. fi
  46. else
  47. echo "Failed to install .NET 5 Runtime. Please try again."
  48. exit 1
  49. fi
  50. fi
  51. echo ""
  52. echo "Downloading Technitium DNS Server..."
  53. if curl -o $dnsTar --fail $dnsUrl >> $installLog 2>&1
  54. then
  55. if [ -d $dnsDir ]
  56. then
  57. echo "Updating Technitium DNS Server..."
  58. else
  59. echo "Installing Technitium DNS Server..."
  60. fi
  61. tar -zxf $dnsTar -C $dnsDir >> $installLog 2>&1
  62. if [ "$(ps --no-headers -o comm 1 | tr -d '\n')" = "systemd" ]
  63. then
  64. if [ -f "/etc/systemd/system/dns.service" ]
  65. then
  66. echo "Restarting systemd service..."
  67. systemctl restart dns.service >> $installLog 2>&1
  68. else
  69. echo "Configuring systemd service..."
  70. cp $dnsDir/systemd.service /etc/systemd/system/dns.service
  71. systemctl enable dns.service >> $installLog 2>&1
  72. systemctl stop systemd-resolved >> $installLog 2>&1
  73. systemctl disable systemd-resolved >> $installLog 2>&1
  74. systemctl start dns.service >> $installLog 2>&1
  75. rm /etc/resolv.conf >> $installLog 2>&1
  76. echo "nameserver 127.0.0.1" > /etc/resolv.conf 2>> $installLog
  77. if [ -f "/etc/NetworkManager/NetworkManager.conf" ]
  78. then
  79. echo "[main]" >> /etc/NetworkManager/NetworkManager.conf
  80. echo "dns=default" >> /etc/NetworkManager/NetworkManager.conf
  81. fi
  82. fi
  83. echo ""
  84. echo "Technitium DNS Server was installed successfully!"
  85. echo "Open http://$(hostname):5380/ to access the web console."
  86. echo ""
  87. echo "Donate! Make a contribution by becoming a Patron: https://www.patreon.com/technitium"
  88. echo ""
  89. else
  90. echo ""
  91. echo "Failed to install Technitium DNS Server: systemd was not detected."
  92. exit 1
  93. fi
  94. else
  95. echo ""
  96. echo "Failed to download Technitium DNS Server from: $dnsUrl"
  97. exit 1
  98. fi