summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2020-09-16 17:00:25 -0400
committerAndrew Cady <d@jerkface.net>2020-09-16 17:00:25 -0400
commitef060e4e90d4e878791396c0e1b1caaa49e2e4f2 (patch)
tree592771faaeb5fa9f5b60bec8e435783eb1cf4e09
parentb51edabf0dcbe5e516f6d251a5a6c422c7bce6c3 (diff)
implement command "cryptonomic"
-rw-r--r--selfpublish.sh67
1 files changed, 65 insertions, 2 deletions
diff --git a/selfpublish.sh b/selfpublish.sh
index 816a18d..25686a7 100644
--- a/selfpublish.sh
+++ b/selfpublish.sh
@@ -52,6 +52,7 @@ dependencies()
52{ 52{
53 cat <<EOF 53 cat <<EOF
54apache2 (>= 2.4.46) 54apache2 (>= 2.4.46)
55basez
55cgit 56cgit
56curl 57curl
57fortune-mod 58fortune-mod
@@ -59,6 +60,7 @@ fortunes-min
59gnupg (>= 2.2.14) 60gnupg (>= 2.2.14)
60libssl1.1 (>= 1.1.1d) 61libssl1.1 (>= 1.1.1d)
61openssl 62openssl
63ssh
62EOF 64EOF
63} 65}
64 66
@@ -84,6 +86,11 @@ fmt_dependencies()
84 fi 86 fi
85} 87}
86 88
89control_file_file()
90{
91 printf 'File: %s %s\n' "$1" "$2"
92 sed -e 's/^/ /'
93}
87 94
88SELF_VERSION='0.1' 95SELF_VERSION='0.1'
89SELF_EXECUTABLE=$(realpath "$0") 96SELF_EXECUTABLE=$(realpath "$0")
@@ -101,9 +108,65 @@ EOF
101 cat <<EOF 108 cat <<EOF
102File: /usr/share/doc/selfpublish-dot-sh/README.Debian 644 109File: /usr/share/doc/selfpublish-dot-sh/README.Debian 644
103 This gets overwritten :( 110 This gets overwritten :(
104File: /usr/bin/selfpublish.sh 755
105EOF 111EOF
106 sed -e 's/^/ /' < "$SELF_EXECUTABLE" 112 control_file_file /usr/bin/cryptonomic 755 <<'EOF'
113#!/bin/dash
114set -e
115
116DOMAIN=cryptonomic.net
117DEFAULT_AUTH_TYPE=ed25519
118HASH_TYPE=2
119
120die() { echo "$0: Error: $*" >&2; exit 1; }
121
122b16_to_b32()
123{
124 printf %s "$1" | basez -x -d | basez -j -l | tr -d =
125}
126
127get_domain()
128{
129 get_sshfp "$1"
130
131 domain=$(printf %s.%s.%s "$sshfp_b32" "$DEFAULT_AUTH_TYPE" "$DOMAIN" | tail -c64)
132}
133
134get_sshfp()
135{
136 [ -f "$1" ] || return
137 sshfp_b16=$(ssh-keygen -r . -f "$1" | sed -ne 's/^. IN SSHFP [0-9]* '"$HASH_TYPE"' //p') &&
138 [ "$sshfp_b16" ] || die "could not determine ssh client fingerprint"
139 sshfp_b32=$(b16_to_b32 "$sshfp_b16")
140}
141
142KEY_FILE=/etc/ssh/ssh_host_${DEFAULT_AUTH_TYPE}_key
143
144if [ $# = 0 -o "$1" = hostname ]
145then
146
147 get_domain "${KEY_FILE}".pub || exit
148 printf '%s\n' "$domain"
149
150elif [ "$1" = dyndns ]
151then
152 set -- ssh -i "$KEY_FILE" dyndns@"$DOMAIN"
153
154 if [ -r "$KEY_FILE" ]
155 then
156 "$@"
157 elif sudo -n true 2>/dev/null || groups | grep '\bsudo\b'
158 then
159 sudo -- "$@"
160 else
161 su -c "$(bash -c 'printf "%q " "$@"' bash "$@")"
162
163 fi
164else
165 echo "Usage: $0 [dyndns|hostname]" >&2
166 exit 1
167fi
168EOF
169 control_file_file /usr/bin/selfpublish.sh 755 < "$SELF_EXECUTABLE"
107 echo 170 echo
108} 171}
109 172