#!/bin/sh # # Set or get ssh pubic key of # Usage: key [] # # shellcheck source=./includes LIBDIR="$(dirname $0)" && . "${LIBDIR}/includes" jail_name="${1:?}" keyfile="${2:-}" if [ ! -n "${jail_name}" ]; then "${LIBDIR}/bkctld-help" && exit 1 fi jail_path=$(jail_path "${jail_name}") test -d "${jail_path}" || error "${jail_name}: jail is missing." if [ -z "${keyfile}" ]; then 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." cat "${keyfile}" > "${jail_path}/${AUTHORIZED_KEYS}" chmod 600 "${jail_path}/${AUTHORIZED_KEYS}" notice "${jail_name}: SSH key has been updated with ${keyfile}" fi