summaryrefslogtreecommitdiff
path: root/bin/kj_sync_authorized_keys.sh
diff options
context:
space:
mode:
authorKjetil Orbekk <kjetil.orbekk@gmail.com>2015-10-11 11:57:25 -0400
committerKjetil Orbekk <kjetil.orbekk@gmail.com>2015-10-11 11:57:25 -0400
commit404e60caa500606d324a4021fb42321d118a5223 (patch)
treec82a5415b93722ded3213d3da29c58a43ceab933 /bin/kj_sync_authorized_keys.sh
parentac6b89c1724f4b872ab7de427d134b79171a9bee (diff)
Rename setup script.
Diffstat (limited to 'bin/kj_sync_authorized_keys.sh')
-rwxr-xr-xbin/kj_sync_authorized_keys.sh56
1 files changed, 0 insertions, 56 deletions
diff --git a/bin/kj_sync_authorized_keys.sh b/bin/kj_sync_authorized_keys.sh
deleted file mode 100755
index b8be72d..0000000
--- a/bin/kj_sync_authorized_keys.sh
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/bin/bash
-#
-# This script syncs authorized keys (found in the $authorized_keys_file below)
-# to a list of remote hosts. It does not touch existing keys unless overwrite
-# is set to true, but creates a special section containing the keys.
-
-declare -r begin_marker="### BEGIN MANAGED_BY_KJ_SYNC_AUTHORIZED_KEYS.SH ###"
-declare -r end_marker="### END MANAGED_BY_KJ_SYNC_AUTHORIZED_KEYS.SH ###"
-# If overwrite=true, the entire authorized_keys file is overwritten.
-declare -r overwrite=false
-declare -r tmpdir=$(mktemp -d /tmp/kj_sync_authorized_keys.XXXXX)
-
-targets=(
- root@orbekk.osl.trygveandre.net
- tesuji.6.orbekk.com
- login.6.orbekk.com
- minecraft.6.orbekk.com
- login.pvv.ntnu.no
- aji.orbekk.com
- moyo.orbekk.com
- pi@photobox.6.orbekk.com
-)
-authorized_keys_file=$HOME/dotfiles/authorized_keys
-if [[ ! -f "${authorized_keys_file}" ]]; then
- echo "could not find authorized_keys_file: ${authorized_keys_file}"
- exit 1
-fi
-
-add_keys_to_file() {
- local filename="$1"
- awk \
- "/$begin_marker/"' { exit 0 } { print }' \
- ${filename} > ${filename}.header
- awk \
- "/$end_marker/"' { should_output=1 } should_output { print }' \
- ${filename} > ${filename}.footer
-
- cat "${filename}.header" > ${filename}
- echo "${begin_marker}" >> ${filename}
- echo "# WARNING: ANY CHANGES WILL BE OVERWRITTEN" >> ${filename}
- cat "$authorized_keys_file" >> ${filename}
- echo "${end_marker}" >> ${filename}
- cat "${filename}.footer" >> ${filename}
-}
-
-for target in ${targets[@]}; do
- echo "syncing $target"
- tmp="${tmpdir}/${target}"
- touch ${tmp}
- if [[ $overwrite != true ]]; then
- ssh ${target} 'cat .ssh/authorized_keys || echo -n' > ${tmp}
- fi
- add_keys_to_file "${tmp}"
- ssh ${target} 'mkdir -p .ssh'
- cat "${tmp}" | ssh ${target} 'cat > .ssh/authorized_keys.tmp && mv .ssh/authorized_keys{.tmp,}'
-done