diff options
Diffstat (limited to 'dot/local/bin/penme')
-rwxr-xr-x | dot/local/bin/penme | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/dot/local/bin/penme b/dot/local/bin/penme deleted file mode 100755 index 1a46e6c..0000000 --- a/dot/local/bin/penme +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | set -e | ||
3 | if [ "$(id -u)" -ne 0 ] | ||
4 | then | ||
5 | exec sudo -- "$0" "$@" | ||
6 | fi | ||
7 | |||
8 | vprintf() { [ ! "$VERBOSE" ] || printf "$@" >&2; } | ||
9 | |||
10 | write() | ||
11 | { | ||
12 | printf '%s\n' "$line" >> /root/.ssh/authorized_keys | ||
13 | vprintf 'New root authorization: %s\n' "$line" | ||
14 | [ "$VERBOSE" ] || printf '%s\n' "$line" >&2 | ||
15 | } | ||
16 | |||
17 | scan_network() | ||
18 | { | ||
19 | arp-scan --localnet | | ||
20 | while read ip junk | ||
21 | do | ||
22 | case "$ip" in | ||
23 | *.*.*.*) ;; | ||
24 | *) continue ;; | ||
25 | esac | ||
26 | vprintf 'ARP scan found IP: %s\n' "$ip" | ||
27 | ( grep -q " penme host key @ $ip\$" /root/.ssh/authorized_keys ) || echo $ip | ||
28 | done | ||
29 | } | ||
30 | |||
31 | mkdir -p /root/.ssh | ||
32 | [ -e /root/.ssh/authorized_keys ] || touch /root/.ssh/authorized_keys | ||
33 | |||
34 | which arp-scan >/dev/null && | ||
35 | which ssh-keyscan >/dev/null || | ||
36 | apt install --no-upgrade arp-scan openssh-client || true | ||
37 | |||
38 | ssh-keyscan - $(scan_network) 2>/dev/null | | ||
39 | while read ip key | ||
40 | do | ||
41 | line=$(printf '%s penme host key @ %s\n' "$key" "$ip") | ||
42 | grep -q -Fx "$line" /root/.ssh/authorized_keys && vprintf 'Already authorized: %s\n' "$line" || | ||
43 | write "$line" /root/.ssh/authorized_keys | ||
44 | done | ||