evobackup/lib/bkctld-key

30 lines
808 B
Plaintext
Raw Normal View History

#!/bin/sh
#
# Set or get ssh pubic key of <jailname>
# Usage: key <jailname> [<keyfile>]
#
2020-04-02 13:44:13 +02:00
# shellcheck source=./includes
2020-04-02 00:31:57 +02:00
LIBDIR="$(dirname $0)" && . "${LIBDIR}/includes"
2020-04-02 13:44:13 +02:00
jail_name="${1:?}"
keyfile="${2:-}"
2020-04-02 01:07:12 +02:00
if [ ! -n "${jail_name}" ]; then
"${LIBDIR}/bkctld-help" && exit 1
fi
2020-04-02 01:07:12 +02:00
jail_path=$(jail_path "${jail_name}")
test -d "${jail_path}" || error "${jail_name}: jail is missing."
if [ -z "${keyfile}" ]; then
2020-04-02 01:07:12 +02:00
if [ -f "${jail_path}/${AUTHORIZED_KEYS}" ]; then
cat "${jail_path}/${AUTHORIZED_KEYS}"
fi
else
test -r "${keyfile}" || error "${jail_name}: SSH key '${keyfile}' is missing or is not readable."
2020-04-02 01:07:12 +02:00
cat "${keyfile}" > "${jail_path}/${AUTHORIZED_KEYS}"
chmod 600 "${jail_path}/${AUTHORIZED_KEYS}"
notice "${jail_name}: SSH key has been updated with ${keyfile}"
fi