freedombone-freedns 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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-2017 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. item_in_array "$code" "${detected_codes[@]}"
  51. if [[ $? != 0 ]]; then
  52. detected_codes+=("$code")
  53. fi
  54. done <<< "$codelines"
  55. if [ ! -d $HOME/.freedns-update ]; then
  56. mkdir $HOME/.freedns-update
  57. fi
  58. cd $HOME/.freedns-update
  59. for code in "${detected_codes[@]}"
  60. do
  61. if [ $VERBOSE ]; then
  62. echo $"command: $FREEDNS_WGET${code}="
  63. $FREEDNS_WGET${code}=
  64. else
  65. if [ -f /tmp/freedns ]; then
  66. rm /tmp/freedns
  67. fi
  68. $FREEDNS_WGET${code}= >> /tmp/freedns 2>&1
  69. fi
  70. done
  71. if [ -f /tmp/freedns ]; then
  72. rm /tmp/freedns
  73. fi
  74. exit 0