Skip to content

Instantly share code, notes, and snippets.

@mslinn
Created August 18, 2022 17:08
Show Gist options
  • Save mslinn/08b49179022e666f310a75b658b3b3fc to your computer and use it in GitHub Desktop.
Save mslinn/08b49179022e666f310a75b658b3b3fc to your computer and use it in GitHub Desktop.
#!/bin/bash
# Author: Mike Slinn [email protected]
# Modified from AWS version (dynameicDnsAws) 2022-06-30
# Added auth subdomain 2022-08-18
# See https://www.namecheap.com/support/knowledgebase/article.aspx/36/11/how-do-i-start-using-dynamic-dns/
export SAVE_FILE_NAME="$HOME/.dynamicDns"
function help {
echo "$( basename $0 ) - Maintains three Namecheap dynamic DNS records: the apex domain, www and auth.
Saves data in '$SAVE_FILE_NAME'
Syntax:
$( basename $0) [OPTIONS] DOMAIN PASSWORD
OPTIONS:
-v Verbose mode
Example usage:
$( basename $0) mydomain.com asdfasdfasdfasdfasdf
$( basename $0) -v mydomain.com asdfasdfasdfasdf
"
exit 1
}
function upsert {
curl "https://dynamicdns.park-your-domain.com/update?host=@&domain=$DOMAIN&password=$PASSWORD&ip=$IP"
curl "https://dynamicdns.park-your-domain.com/update?host=auth&domain=$DOMAIN&password=$PASSWORD&ip=$IP"
curl "https://dynamicdns.park-your-domain.com/update?host=www&domain=$DOMAIN&password=$PASSWORD&ip=$IP"
echo "$IP" > "$SAVE_FILE_NAME"
echo ""
}
if [ "$1" == -v ]; then
export VERBOSE=true
shift
fi
if [ -z "$2" ]; then help; fi
set -e
export DOMAIN="$1"
export PASSWORD="$2"
export IP="$( dig +short myip.opendns.com @resolver1.opendns.com )"
if [ ! -f "$SAVE_FILE_NAME" ]; then
if [ "$VERBOSE" ]; then echo "Creating $SAVE_FILE_NAME"; fi
upsert;
elif [ "$( cat "$SAVE_FILE_NAME" )" != "$IP" ]; then
if [ "$VERBOSE" ]; then
echo "Updating $SAVE_FILE_NAME"
echo "'$IP' was not equal to '$( cat "$SAVE_FILE_NAME" )'"
fi
upsert;
else
if [ "$VERBOSE" ]; then echo "No change necessary for $SAVE_FILE_NAME"; fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment