#!/bin/sh # dyndns via ssh login + tinydns (djbdns/dbndns) # # usage: # $ ssh dyndns@example.org home.example.org # # @author Christian Weiske if [ -z "$SSH_CONNECTION" ]; then echo "no ssh connection" >&2 exit 1 fi remoteip=${SSH_CLIENT%% *} if [ -z "$remoteip" ]; then echo "ssh client IP not found" >&2 exit 2 fi #TODO: allow removal of domains #TODO: support multiple domains if [ -z "$2" ]; then echo Missing argument: domain name >&2 exit 3 fi domain="$2" #load config files if [ -f ~/.config/ssh-dyndns.sh ]; then . ~/.config/ssh-dyndns.sh fi if [ -f /etc/ssh-dyndns.sh ]; then . /etc/ssh-dyndns.sh fi if [ -z "$data_dir" ]; then echo '$data_dir not set' >&2 exit 4 fi if [ ! -d "$data_dir" ]; then echo "$data_dir does not exist" >&2 exit 5 fi if [ ! -f "$data_dir/Makefile" ]; then echo "$data_dir misses Makefile" >&2 exit 6 fi if [ ! -z "$domain_patterns" ]; then ok=0 for single_dp in $domain_patterns; do case "$domain" in ($single_dp) ok=1;; esac done if [ $ok -ne 1 ]; then echo "Domain \"$domain\" does not match \$domain_pattern" >&2 exit 7 fi fi file_pattern="${file_pattern:-data-dyndns-%DOMAIN%}" timeout=${timeout:-300} datafile=${data_dir}`echo $file_pattern | sed "s/%DOMAIN%/$domain/"` if [ `echo "$remoteip"| sed "s/://"` != "$remoteip" ]; then echo "IPv6 not supported yet" >&2 # we need ipv6 address expansion exit 8 fi #=cweiske.de:5.35.241.22 djbdnsline="=${domain}:${remoteip}:${timeout}" update=1 if [ -f "$datafile" ]; then currentdata=`head -n1 "$datafile"|tr -d '\n'` if [ "$currentdata" = "$djbdnsline" ]; then #no need to update update=0 fi fi if [ $update -eq 0 ]; then exit fi echo $djbdnsline > $datafile #TXT record with last update date=`date --rfc-3339=seconds|tr : .|tr -d '\n'` djbdnsTxtLine="'${domain}:Last update ${date}.:${timeout}" echo $djbdnsTxtLine >> $datafile #compile dns data cd "$data_dir" sudo make --silent