#!/usr/bin/env bash
#/ Usage: ghe-restore-ssh-keys <host>
#/ Restore ssh keys from an rsync snapshot.
#/
#/ Note: This script typically isn't called directly. It's invoked by the
#/ ghe-restore command.
set -e

# Bring in the backup configuration
# shellcheck source=share/github-backup-utils/ghe-backup-config
. "$(dirname "${BASH_SOURCE[0]}")/ghe-backup-config"

# Show usage and bail with no arguments
[[ -z ${*} ]] && print_usage

bm_start "$(basename "${0}")"

# Grab host arg
GHE_HOSTNAME="${1}"

# Grab snapshot path arg
GHE_RESTORE_SNAPSHOT_PATH="${2}"

bm_start "$(basename "${0}")"

ghe-ssh "$GHE_HOSTNAME" -- 'ghe-import-authorized-keys' < "$GHE_RESTORE_SNAPSHOT_PATH/authorized-keys.json" 1>&3

bm_end "$(basename "${0}")"