Created
September 8, 2019 14:01
-
-
Save hongkongkiwi/fcbd73c17054bb9bd6b32aafaf153201 to your computer and use it in GitHub Desktop.
Runs a cloudflare ddns script to update the zerotier network address via Systemd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/systemd/system/cloudflare-ddns.service | |
[Unit] | |
Description=Zerotier DDNS Client | |
Wants=network-online.target | |
After=network.target | |
[Service] | |
Type=oneshot | |
Environment=ZONE=bla.com | |
Environment=HOST=zt.blah.com | |
Environment=USE_DYNAMIC_HOSTNAME=true | |
Environment=API=yourcoolapikey | |
Environment=PROXY=false | |
Environment=FORCE_CREATE=true | |
Environment=MASTER_API_KEY=false | |
Environment=ZEROTIER_NETWORK_ID=somenetworkid | |
ExecStart=/usr/local/bin/update-zerotier-ddns.sh | |
# don't use 'nobody' if your script needs to access user files | |
# (if User is not set the service will run as root) | |
#User=nobody | |
# Useful during debugging; remove it once the service is working | |
#StandardOutput=console | |
StandardOutput=journal+console | |
[Install] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Put this in /usr/local/bin/update-zerotier-ddns.sh | |
# Ensure you also have the script in /usr/local/bin/cloudflare-ddns.sh | |
# You can get mine here: https://raw.githubusercontent.com/hongkongkiwi/docker-cloudflare-ddns/master/cloudflare.sh | |
# Check that we have the required tools | |
command -v zerotier-cli >/dev/null 2>&1 || { echo >&2 "I require zerotier-cli but it's not installed. Aborting."; exit 1; } | |
command -v tr >/dev/null 2>&1 || { echo >&2 "I require tr but it's not installed. Aborting."; exit 1; } | |
# Enforces required env variables | |
required_vars=(ZEROTIER_NETWORK_ID) | |
for required_var in "${required_vars[@]}"; do | |
if [[ -z ${!required_var} ]]; then | |
error=1 | |
echo >&2 "Error: $required_var env variable not set." | |
fi | |
done | |
if [[ -n $error ]]; then | |
exit 1 | |
fi | |
if [[ ! -z "$USE_DYNAMIC_HOSTNAME" ]]; then | |
MY_HOSTNAME=`echo "$HOSTNAME" | tr '[:upper:]' '[:lower:]'` | |
[[ ! -z "$MY_HOSTNAME" ]] || { echo >&2 "USE_DYNAMIC_HOSTNAME is set, but HOSTNAME variable is not set. Aborting."; exit 1; } | |
HOST="${MY_HOSTNAME}.${HOST}" | |
echo "Dynamic Hostname: $HOST" | |
fi | |
echo "ZeroTier Network ID: $ZEROTIER_NETWORK_ID" | |
export NEW_IP_ADDR=`zerotier-cli get $ZEROTIER_NETWORK_ID ip` | |
bash "/usr/local/bin/cloudflare-ddns.sh" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment