summaryrefslogtreecommitdiff
path: root/src/publish-ip.sh
blob: 7da41b92f92043d8e1311b4a64af30f9ebae9ae8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh

determine_lan_ip()
{
  ip -4 -oneline addr show |
    while read n dev _ ip rest; do
      case "$rest" in
        *'scope global'*) ;;
        *) continue ;;
      esac
      case "$ip" in
        192.168.10.1/24) continue ;;
      esac
      echo ${ip%/*}
      break
    done
}

ssh_cryptonomic_net__known_hosts()
{
cat <<'END'
|1|ORqVRkqd0LO25vHCB0LezHAgwRE=|ih7EYLpvg9jpU86/0Od0N8Ur36c= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBHkIETz7wmKd7TZgb3NPeUElZDjZqw2VPd8yDOBTj5UzUBmcgCyE1oCS3Oe1iO9zJWpPtG0QyYa29lKi+vN6pN4=
END
}

tmpfile=$(mktemp) || exit 1
trap 'rm -f "$tmpfile"' EXIT
ssh_cryptonomic_net__known_hosts > "$tmpfile"

lan_ip=$(determine_lan_ip)

if [ "$lan_ip" ]; then
  set -- lan "$lan_ip"
else
  set --
fi

ssh -o GlobalKnownHostsFile="$tmpfile" -i /var/cache/kiki/config/ssh_host_rsa_key dyndns@ssh.cryptonomic.net "$@"