evobackup/server/lib/bkctld-key

30 lines
809 B
Bash
Executable file

#!/bin/sh
#
# Description: Set or get ssh pubic key
# Usage: key <jailname> [<keyfile>]
#
# shellcheck source=./includes
LIBDIR="$(dirname $0)" && . "${LIBDIR}/includes"
jail_name="${1:?}"
keyfile="${2:-}"
if [ ! -n "${jail_name}" ]; then
show_help && exit 1
fi
jail_path=$(jail_path "${jail_name}")
test -d "${jail_path}" || error "${jail_name}: jail not found" 2
if [ -z "${keyfile}" ]; then
if [ -f "${jail_path}/${AUTHORIZED_KEYS}" ]; then
cat "${jail_path}/${AUTHORIZED_KEYS}"
fi
else
test -r "${keyfile}" || error "SSH key \`${keyfile}' for jail \`${jail_name}' is missing or is not readable."
cat "${keyfile}" > "${jail_path}/${AUTHORIZED_KEYS}"
chmod 600 "${jail_path}/${AUTHORIZED_KEYS}"
notice "Update SSH key \`${keyfile}' for jail \`${jail_name}' : OK"
fi