freedombone-freedns 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # freedns update command for use in cron or a daemon
  12. # License
  13. # =======
  14. #
  15. # Copyright (C) 2016-2018 Bob Mottram <bob@freedombone.net>
  16. #
  17. # This program is free software: you can redistribute it and/or modify
  18. # it under the terms of the GNU Affero General Public License as published by
  19. # the Free Software Foundation, either version 3 of the License, or
  20. # (at your option) any later version.
  21. #
  22. # This program is distributed in the hope that it will be useful,
  23. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. # GNU Affero General Public License for more details.
  26. #
  27. # You should have received a copy of the GNU Affero General Public License
  28. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. PROJECT_NAME='freedombone'
  30. export TEXTDOMAIN=${PROJECT_NAME}-freedns
  31. export TEXTDOMAINDIR="/usr/share/locale"
  32. VERBOSE=
  33. CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
  34. FREEDNS_WGET='wget --read-timeout=0.0 --waitretry=5 --tries=4 https://freedns.afraid.org/dynamic/update.php?'
  35. if [[ "$1" == "--verbose" || "$1" == "-v" ]]; then
  36. VERBOSE=1
  37. fi
  38. if [ ! -f "$CONFIGURATION_FILE" ]; then
  39. exit 0
  40. fi
  41. function item_in_array {
  42. local e
  43. for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
  44. return 1
  45. }
  46. detected_codes=()
  47. codelines=$(grep "_CODE=" "$CONFIGURATION_FILE" | uniq)
  48. while read -r line; do
  49. code=$(echo "$line" | awk -F '=' '{print $2}')
  50. if ! item_in_array "$code" "${detected_codes[@]}"; then
  51. detected_codes+=("$code")
  52. fi
  53. done <<< "$codelines"
  54. if [ ! -d "$HOME/.freedns-update" ]; then
  55. mkdir "$HOME/.freedns-update"
  56. fi
  57. cd "$HOME/.freedns-update" || exit 2467824684
  58. for code in "${detected_codes[@]}"
  59. do
  60. if [ $VERBOSE ]; then
  61. echo $"command: $FREEDNS_WGET${code}="
  62. # shellcheck disable=SC1066,SC1067
  63. $FREEDNS_WGET${code}=
  64. else
  65. if [ -f /tmp/freedns ]; then
  66. rm /tmp/freedns
  67. fi
  68. # shellcheck disable=SC1066,SC1067,SC1007
  69. $FREEDNS_WGET${code}= >> /tmp/freedns 2>&1
  70. fi
  71. done
  72. if [ -f /tmp/freedns ]; then
  73. rm /tmp/freedns
  74. fi
  75. exit 0