technitiumdns-update.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 7.0."; then
  15. dotnetFound="yes"
  16. else
  17. dotnetFound="no"
  18. fi
  19. if [ -d $dotnetDir ]; then
  20. dotnetUpdate="yes"
  21. echo "Updating .NET 7 Runtime..."
  22. fi
  23. curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -c 7.0 --runtime dotnet --no-path --install-dir $dotnetDir --verbose >>$installLog 2>&1
  24. if [ ! -f "/usr/bin/dotnet" ]; then
  25. ln -s $dotnetDir/dotnet /usr/bin >>$installLog 2>&1
  26. fi
  27. if dotnet --list-runtimes 2>/dev/null | grep -q "Microsoft.NETCore.App 7.0."; then
  28. if [ "$dotnetUpdate" = "yes" ]; then
  29. echo ".NET 7 Runtime was updated successfully!"
  30. fi
  31. else
  32. echo "Failed to update .NET 7 Runtime. Please try again."
  33. exit 1
  34. fi
  35. if curl -o $dnsTar --fail $dnsUrl >>$installLog 2>&1; then
  36. if [ -d $dnsDir ]; then
  37. echo "Updating Technitium DNS Server..."
  38. fi
  39. tar -zxf $dnsTar -C $dnsDir >>$installLog 2>&1
  40. if [ "$(ps --no-headers -o comm 1 | tr -d '\n')" = "systemd" ]; then
  41. if [ -f "/etc/systemd/system/dns.service" ]; then
  42. echo "Restarting systemd service..."
  43. systemctl restart dns.service >>$installLog 2>&1
  44. fi
  45. echo ""
  46. echo "Technitium DNS Server was updated successfully!"
  47. else
  48. echo ""
  49. echo "Failed to update Technitium DNS Server: systemd was not detected."
  50. exit 1
  51. fi
  52. else
  53. echo ""
  54. echo "Failed to download Technitium DNS Server from: $dnsUrl"
  55. exit 1
  56. fi