install-ssh-authorized-keys: Use --check rather than another argument.

This commit is contained in:
Alex Vandiver 2024-02-02 11:03:27 -05:00 committed by Tim Abbott
parent afa24923e5
commit 1567275959
2 changed files with 18 additions and 2 deletions

View File

@ -1,6 +1,22 @@
#!/usr/bin/env bash
set -euo pipefail
args="$(getopt -o '' --long check -- "$@")"
eval "set -- $args"
check=false
while true; do
case "$1" in
--check)
check=true
shift
;;
--)
shift
break
;;
esac
done
username="$1"
ssh_secret_name="$2"
@ -21,7 +37,7 @@ trap cleanup EXIT
chmod 644 "$workfile"
chown "$username:$username" "$workfile"
if [ "$#" -gt 2 ]; then
if [ "$check" = "true" ]; then
diff -N "$workfile" "$sshdir/authorized_keys"
exit 0
fi

View File

@ -10,6 +10,6 @@ define zulip_ops::ssh_authorized_keys(
exec { "ssh_authorized_keys ${user}":
require => File['/usr/local/bin/install-ssh-authorized-keys'],
command => "/usr/local/bin/install-ssh-authorized-keys ${user} ${keypath}",
unless => "[ -f /usr/local/bin/install-ssh-authorized-keys ] && /usr/local/bin/install-ssh-authorized-keys ${user} ${keypath} check",
unless => "[ -f /usr/local/bin/install-ssh-authorized-keys ] && /usr/local/bin/install-ssh-authorized-keys --check ${user} ${keypath}",
}
}