summaryrefslogtreecommitdiff
path: root/scripts/gather-files
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/gather-files')
-rwxr-xr-xscripts/gather-files32
1 files changed, 32 insertions, 0 deletions
diff --git a/scripts/gather-files b/scripts/gather-files
new file mode 100755
index 0000000..3dfaf14
--- /dev/null
+++ b/scripts/gather-files
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+if [ $# -ne 1 ] && [ $# -ne 2 ]; then
+ >&2 echo 'usage: '"$0"' host'
+ >&2 echo 'usage: '"$0"' host ssh-alias'
+ exit 1
+fi
+
+cd "${0%/*}/.."
+
+rm -rf --one-file-system "hosts/$1"
+mkdir -p "hosts/$1"
+
+ssh "${2:-$1}" -t 'su -c '"'"'
+ cut -d: -f1,6 \
+ </etc/passwd \
+ | tr ":" " " \
+ | while read -r user home; do
+ [ -d "${home}/.ssh" ] \
+ || continue
+ [ -f "${home}/.ssh/authorized_keys" ] \
+ || continue
+ sed "s@^@${user} @" "${home}/.ssh/authorized_keys"
+ done
+'"'" \
+2>/dev/null \
+| tee /dev/stderr \
+| sed 1d \
+| while read user key; do
+ printf '%s\n' "${key}" \
+ >> "hosts/$1/${user}"
+done