summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2021-03-04 13:33:48 -0500
committerAndrew Cady <d@jerkface.net>2021-03-04 13:33:48 -0500
commitfd9c04398afd1ae01e73b4b2c1c9214e01b0001e (patch)
tree9a94e30fbf50cef6efebca8790146413510fe650
parent2d565dd213f5342b5a76e264ef6894da283b6c98 (diff)
scripts copied from penme.git
-rwxr-xr-xdot/local/bin/penme44
-rwxr-xr-xdot/local/bin/penyou4
l---------dot/local/bin/sash1
-rwxr-xr-xdot/local/bin/unpenme8
4 files changed, 57 insertions, 0 deletions
diff --git a/dot/local/bin/penme b/dot/local/bin/penme
new file mode 100755
index 0000000..1a46e6c
--- /dev/null
+++ b/dot/local/bin/penme
@@ -0,0 +1,44 @@
1#!/bin/sh
2set -e
3if [ "$(id -u)" -ne 0 ]
4then
5 exec sudo -- "$0" "$@"
6fi
7
8vprintf() { [ ! "$VERBOSE" ] || printf "$@" >&2; }
9
10write()
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
17scan_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
31mkdir -p /root/.ssh
32[ -e /root/.ssh/authorized_keys ] || touch /root/.ssh/authorized_keys
33
34which arp-scan >/dev/null &&
35which ssh-keyscan >/dev/null ||
36apt install --no-upgrade arp-scan openssh-client || true
37
38ssh-keyscan - $(scan_network) 2>/dev/null |
39while read ip key
40do
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
44done
diff --git a/dot/local/bin/penyou b/dot/local/bin/penyou
new file mode 100755
index 0000000..cc7fdda
--- /dev/null
+++ b/dot/local/bin/penyou
@@ -0,0 +1,4 @@
1#!/bin/sh
2sudo=$([ $(id -u) -eq 0 ] || echo sudo --)
3exec $sudo ssh -i /etc/ssh/ssh_host_ed25519_key -l root "$@"
4
diff --git a/dot/local/bin/sash b/dot/local/bin/sash
new file mode 120000
index 0000000..62f8dc8
--- /dev/null
+++ b/dot/local/bin/sash
@@ -0,0 +1 @@
penyou \ No newline at end of file
diff --git a/dot/local/bin/unpenme b/dot/local/bin/unpenme
new file mode 100755
index 0000000..2759dad
--- /dev/null
+++ b/dot/local/bin/unpenme
@@ -0,0 +1,8 @@
1#!/bin/sh
2if [ "$(id -u)" -ne 0 ]
3then
4 exec sudo -- "$0" "$@"
5fi
6sedprog='/ penme host key @ [0-9]+\.[0-9].[0-9]+\.[0-9]+/ d'
7FORREALS=-i~penme
8sed ${FORREALS} -E -e "$sedprog" /root/.ssh/authorized_keys