summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2020-10-10 13:24:38 -0400
committerAndrew Cady <d@jerkface.net>2020-10-10 13:24:38 -0400
commit4ff0ee9aa5a500ce51dc6a93f400641698cdf3e0 (patch)
tree1e97fbe776bb5dbf901932b3721254f0797fa396
parent855814666e24bce39c92c90b2e05e4cf901b5fae (diff)
add script originating from cryptonomic source
-rwxr-xr-xsrc/get-dyndns-name67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/get-dyndns-name b/src/get-dyndns-name
new file mode 100755
index 0000000..7ef8c1b
--- /dev/null
+++ b/src/get-dyndns-name
@@ -0,0 +1,67 @@
1#!/bin/sh
2set -e
3
4DEFAULT_AUTH_TYPE=ed25519
5
6in_group()
7{
8 local g
9 for g in $(groups)
10 do
11 [ "$g" = "$1" ] && return
12 done
13 false
14}
15
16ssh_keytag_to_path_fragment()
17{
18 case "$1" in
19 ssh-dss) echo dsa ;;
20 ecdsa-sha2-nistp256) echo ecdsa ;;
21 ssh-rsa|ssh-ed25519) echo ${1#ssh-} ;;
22 *) return 1 ;;
23 esac
24}
25
26path_fragment_to_ssh_keytag()
27{
28 case "$1" in
29 ssh-dss|ecdsa-sha2-nistp256|ssh-rsa|ssh-ed25519) echo $1;;
30 dss|rsa|ed25519) echo ssh-$1 ;;
31 dsa) echo ssh-dss ;;
32 ecdsa) echo ecdsa-sha2-nistp256 ;;
33 *) return 1 ;;
34 esac
35}
36
37get_dyndns_domain()
38{
39 fragment=$(ssh_keytag_to_path_fragment "$1") || return
40
41 host_keyfile=/etc/ssh/ssh_host_${fragment}_key
42 user_keyfile=$HOME/.ssh/id_${fragment}
43
44 set -- -q dyndns@cryptonomic.net
45
46 if [ -r "$host_keyfile" ]
47 then
48 set -- ssh -i "$host_keyfile" "$@"
49
50 elif in_group sudo
51 then
52 set -- sudo ssh -i "$host_keyfile" "$@"
53
54 elif [ -r "$user_keyfile" ]
55 then
56 set -- ssh -i "$user_keyfile" "$@"
57
58 else
59 set -- ssh "$@"
60 fi
61
62 "$@"
63}
64
65AUTH_TYPE=${1:-$DEFAULT_AUTH_TYPE}
66AUTH_KEYTAG=$(path_fragment_to_ssh_keytag "$AUTH_TYPE")
67get_dyndns_domain "$AUTH_KEYTAG"