Skip to content

Instantly share code, notes, and snippets.

@aconz2
Last active September 4, 2017 04:15
Show Gist options
  • Save aconz2/509c0f0738c2b5c4d243e10e488c00d5 to your computer and use it in GitHub Desktop.
Save aconz2/509c0f0738c2b5c4d243e10e488c00d5 to your computer and use it in GitHub Desktop.
a simple alternative to something like dyn-dns for remoting into home servers
#!/usr/bin/env bash
# requires the google-cloud-sdk
# to activate key
# google-cloud-sdk/bin/gcloud auth activate-service-account --key-file foobar.json
# be sure to run the above as root user as well for cron use
# to fix timeskew
# sudo service ntp stop
# sudo ntpd -gq
# sudo service ntp start
# this needs to be owned by root
# sudo chown root update-ip
# and be 755 in order to be run by cron
# sudo chmod 755 update-ip
# move or symlink into /etc/cron.daily/
# sudo ln -s `readlink -f update-ip` /etc/cron.daily/
F=/tmp/current-ip
LOCATION="gs://BUCKET/FILENAME"
if curl ipinfo.io/ip > "$F"; then
if grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' "$F"; then
gsutil cp "$F" "$LOCATION"
else
echo "Was not an ip"
fi
else
echo "curl failed"
fi
[Unit]
Description=update ip
[Service]
ExecStart=/bin/bash /home/pi/update-ip
[Unit]
Description=Run update-ip weekly
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
@aconz2
Copy link
Author

aconz2 commented Sep 4, 2017

systemd files go in /etc/systemd/user/
then do

systemctl --user enable update-ip.timer
systemctl --user start update-ip.timer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment