Last active
November 15, 2024 14:26
-
-
Save ibressler/53ea52c88392831b615d65091281dc38 to your computer and use it in GitHub Desktop.
ddnss update script
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/sh | |
# derived from https://www.ddnss.de/info.php | |
# To be stored in /etc/dhcp/dhclient-exit-hooks.d/99_ddnss_update | |
# Updates the specified subdomain $HOSTNAME with the current IP address. | |
UPDATE_KEY="<your update key displayed in the dashboard>" | |
HOSTNAME="<your domain name with ddnss>" | |
DDNSS_PATH="/var/opt/ddnss" # use a directory which survives a reboot | |
ALLHOST="" # 'all' for updating all hosts in the account | |
TS="$(date +%Y-%m-%d\ %H:%M:%S)" | |
IP="$(curl -s www.ddnss.de/jsonip.php | jq -r '.IP')" | |
OLDIP="$([ -f "$DDNSS_PATH/oldip.txt" ] && cat "$DDNSS_PATH/oldip.txt")" | |
mkdir -p "$DDNSS_PATH" | |
echo "Current IP: $OLDIP" | |
if [ x"$IP"x = x"$OLDIP"x ]; then | |
echo "$TS - Same IP - NOT UPDATING" >> $DDNSS_PATH/log.txt | |
else | |
echo "$TS - New IP: $IP / Old IP: $OLDIP - UPDATING!" >> $DDNSS_PATH/log.txt | |
echo $IP > $DDNSS_PATH/oldip.txt | |
URL="https://www.ddnss.de/upd.php?key=$KEYAUTH&host=$HOSTNAME" | |
[ -z "$ALLHOST" ] || URL="$URL&host=$ALLHOST" | |
curl -s "$URL" >> $DDNSS_PATH/log.txt | |
echo " " >> $DDNSS_PATH/log.txt | |
fi | |
echo "Updating other files as well:" | |
[ -d "/etc/kubernetes/manifests" ] && [ ! -z "$IP" ] &&\ | |
# strip the last number from the new ip and append a regex pattern for a number with 1-3 digits | |
sed -i -e "s/${IP%.*}.[0-9]\{1,3\}/$IP/" /etc/kubernetes/manifests/kube-apiserver.yaml /etc/kubernetes/manifests/etcd.yaml |
Updates kubernetes etcd and apiserver manifest for changed ip addresses. Changing the manifest should restart the service.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update IP address in other files as well when assigned a new IP address.