2016-10-16 13:38:08 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# .---. . .
|
|
|
|
# | | |
|
|
|
|
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
|
|
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
|
|
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
|
|
#
|
|
|
|
# Freedom in the Cloud
|
|
|
|
#
|
|
|
|
# freedns update command for use in cron or a daemon
|
|
|
|
|
|
|
|
# License
|
|
|
|
# =======
|
|
|
|
#
|
2017-06-21 23:01:15 +02:00
|
|
|
# Copyright (C) 2016-2017 Bob Mottram <bob@freedombone.net>
|
2016-10-16 13:38:08 +02:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
PROJECT_NAME='freedombone'
|
|
|
|
|
|
|
|
export TEXTDOMAIN=${PROJECT_NAME}-freedns
|
|
|
|
export TEXTDOMAINDIR="/usr/share/locale"
|
|
|
|
|
2017-06-21 23:01:15 +02:00
|
|
|
VERBOSE=
|
2016-10-16 13:38:08 +02:00
|
|
|
CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
|
|
|
|
FREEDNS_WGET='wget -q --read-timeout=0.0 --waitretry=5 --tries=4 https://freedns.afraid.org/dynamic/update.php?'
|
|
|
|
|
2017-06-21 23:01:15 +02:00
|
|
|
if [[ "$1" == "--verbose" || "$1" == "-v" ]]; then
|
|
|
|
VERBOSE=1
|
|
|
|
fi
|
|
|
|
|
2016-10-16 13:38:08 +02:00
|
|
|
if [ ! -f $CONFIGURATION_FILE ]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
function item_in_array {
|
|
|
|
local e
|
|
|
|
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
detected_codes=()
|
2017-06-21 23:01:15 +02:00
|
|
|
codelines=$(grep "_CODE=" $CONFIGURATION_FILE | uniq)
|
2017-06-21 23:11:37 +02:00
|
|
|
while read -r line; do
|
2016-10-16 13:38:08 +02:00
|
|
|
code=$(echo "$line" | awk -F '=' '{print $2}')
|
2017-06-21 23:01:15 +02:00
|
|
|
if [ $VERBOSE ]; then
|
|
|
|
echo $"freedns code $code"
|
|
|
|
fi
|
2016-10-16 13:38:08 +02:00
|
|
|
item_in_array "$code" "${detected_codes[@]}"
|
|
|
|
if [[ $? != 0 ]]; then
|
|
|
|
detected_codes+=("$code")
|
|
|
|
fi
|
2017-06-21 23:11:37 +02:00
|
|
|
done <<< "$codelines"
|
2016-10-16 13:38:08 +02:00
|
|
|
|
|
|
|
if [ ! -d $HOME/.freedns-update ]; then
|
|
|
|
mkdir $HOME/.freedns-update
|
|
|
|
fi
|
|
|
|
cd $HOME/.freedns-update
|
|
|
|
for code in "${detected_codes[@]}"
|
|
|
|
do
|
|
|
|
$FREEDNS_WGET${code}
|
|
|
|
done
|
|
|
|
|
|
|
|
exit 0
|