technitiumdns-update.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/sh
  2. set -e
  3. dotnetDir="/opt/dotnet"
  4. dnsDir="/etc/dns"
  5. dnsTar="/etc/dns/DnsServerPortable.tar.gz"
  6. dnsUrl="https://download.technitium.com/dns/DnsServerPortable.tar.gz"
  7. mkdir -p $dnsDir
  8. installLog="$dnsDir/install.log"
  9. echo "" > $installLog
  10. echo ""
  11. echo "==============================="
  12. echo "Technitium DNS Server Update"
  13. echo "==============================="
  14. if dotnet --list-runtimes 2> /dev/null | grep -q "Microsoft.NETCore.App 6.0.";
  15. then
  16. dotnetFound="yes"
  17. else
  18. dotnetFound="no"
  19. fi
  20. if [ -d $dotnetDir ]
  21. then
  22. dotnetUpdate="yes"
  23. echo "Updating .NET 6 Runtime..."
  24. fi
  25. curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -c 6.0 --runtime dotnet --no-path --install-dir $dotnetDir --verbose >> $installLog 2>&1
  26. if [ ! -f "/usr/bin/dotnet" ]
  27. then
  28. ln -s $dotnetDir/dotnet /usr/bin >> $installLog 2>&1
  29. fi
  30. if dotnet --list-runtimes 2> /dev/null | grep -q "Microsoft.NETCore.App 6.0.";
  31. then
  32. if [ "$dotnetUpdate" = "yes" ]
  33. then
  34. echo ".NET 6 Runtime was updated successfully!"
  35. fi
  36. else
  37. echo "Failed to update .NET 6 Runtime. Please try again."
  38. exit 1
  39. fi
  40. if curl -o $dnsTar --fail $dnsUrl >> $installLog 2>&1
  41. then
  42. if [ -d $dnsDir ]
  43. then
  44. echo "Updating Technitium DNS Server..."
  45. fi
  46. tar -zxf $dnsTar -C $dnsDir >> $installLog 2>&1
  47. if [ "$(ps --no-headers -o comm 1 | tr -d '\n')" = "systemd" ]
  48. then
  49. if [ -f "/etc/systemd/system/dns.service" ]
  50. then
  51. echo "Restarting systemd service..."
  52. systemctl restart dns.service >> $installLog 2>&1
  53. fi
  54. echo ""
  55. echo "Technitium DNS Server was updated successfully!"
  56. else
  57. echo ""
  58. echo "Failed to update Technitium DNS Server: systemd was not detected."
  59. exit 1
  60. fi
  61. else
  62. echo ""
  63. echo "Failed to download Technitium DNS Server from: $dnsUrl"
  64. exit 1
  65. fi