Skip to content

Commit

Permalink
Fixed ubuntu
Browse files Browse the repository at this point in the history
  • Loading branch information
ProfFan committed Mar 23, 2016
1 parent 832d59c commit 2bc9518
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 11 deletions.
63 changes: 56 additions & 7 deletions ddnspod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,54 @@ case $(uname) in
esac

# Get script dir
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# See: http://stackoverflow.com/a/29835459/4449544
rreadlink() ( # Execute the function in a *subshell* to localize variables and the effect of `cd`.

target=$1 fname= targetDir= CDPATH=

# Try to make the execution environment as predictable as possible:
# All commands below are invoked via `command`, so we must make sure that `command`
# itself is not redefined as an alias or shell function.
# (Note that command is too inconsistent across shells, so we don't use it.)
# `command` is a *builtin* in bash, dash, ksh, zsh, and some platforms do not even have
# an external utility version of it (e.g, Ubuntu).
# `command` bypasses aliases and shell functions and also finds builtins
# in bash, dash, and ksh. In zsh, option POSIX_BUILTINS must be turned on for that
# to happen.
{ \unalias command; \unset -f command; } >/dev/null 2>&1
[ -n "$ZSH_VERSION" ] && options[POSIX_BUILTINS]=on # make zsh find *builtins* with `command` too.

while :; do # Resolve potential symlinks until the ultimate target is found.
[ -L "$target" ] || [ -e "$target" ] || { command printf '%s\n' "ERROR: '$target' does not exist." >&2; return 1; }
command cd "$(command dirname -- "$target")" # Change to target dir; necessary for correct resolution of target path.
fname=$(command basename -- "$target") # Extract filename.
[ "$fname" = '/' ] && fname='' # !! curiously, `basename /` returns '/'
if [ -L "$fname" ]; then
# Extract [next] target path, which may be defined
# *relative* to the symlink's own directory.
# Note: We parse `ls -l` output to find the symlink target
# which is the only POSIX-compliant, albeit somewhat fragile, way.
target=$(command ls -l "$fname")
target=${target#* -> }
continue # Resolve [next] symlink target.
fi
break # Ultimate target reached.
done
targetDir=$(command pwd -P) # Get canonical dir. path
# Output the ultimate target's canonical path.
# Note that we manually resolve paths ending in /. and /.. to make sure we have a normalized path.
if [ "$fname" = '.' ]; then
command printf '%s\n' "${targetDir%/}"
elif [ "$fname" = '..' ]; then
# Caveat: something like /var/.. will resolve to /private (assuming /var@ -> /private/var), i.e. the '..' is applied
# AFTER canonicalization.
command printf '%s\n' "$(command dirname -- "${targetDir}")"
else
command printf '%s\n' "${targetDir%/}/$fname"
fi
)

DIR=$(dirname -- "$(rreadlink "$0")")

# Global Variables:

Expand All @@ -58,7 +105,7 @@ arPass=""

# Load config

source $DIR/dns.conf
#. $DIR/dns.conf

# Get Domain IP
# arg: domain
Expand Down Expand Up @@ -124,8 +171,10 @@ arDdnsCheck() {
}

# DDNS
echo ${#domains[@]}
for index in ${!domains[@]}; do
echo "${domains[index]} ${subdomains[index]}"
arDdnsCheck "${domains[index]}" "${subdomains[index]}"
done
#echo ${#domains[@]}
#for index in ${!domains[@]}; do
# echo "${domains[index]} ${subdomains[index]}"
# arDdnsCheck "${domains[index]}" "${subdomains[index]}"
#done

. $DIR/dns.conf
13 changes: 9 additions & 4 deletions dns.conf.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
arMail="test@gmail.com"
arPass="test"
# For security reasons, it is recommended that you use token-based auth instead
# arMail="test@gmail.com"
# arPass="123"

declare -a domains=("test.net")
declare -a subdomains=("abc")
# Combine your token ID and token together as follows
arToken="12345,7676f344eaeaea9074c123451234512d"

# Place each domain you want to check as follows
# you can have multiple arDdnsCheck blocks
arDdnsCheck "test.org" "subdomain"

0 comments on commit 2bc9518

Please sign in to comment.