2019-01-04 13:51:05 +01:00
|
|
|
#!/bin/sh
|
2019-01-07 14:47:05 +01:00
|
|
|
#
|
|
|
|
# Init jail <jailname>
|
|
|
|
# Usage: init <jailname>
|
|
|
|
#
|
2019-01-04 13:51:05 +01:00
|
|
|
|
2020-04-01 07:31:33 +02:00
|
|
|
# shellcheck source=config
|
2019-01-04 13:51:05 +01:00
|
|
|
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
|
|
|
|
|
|
|
|
jail="${1:-}"
|
2019-01-07 14:47:05 +01:00
|
|
|
if [ ! -n "${jail}" ]; then
|
|
|
|
"${LIBDIR}/bkctld-help" && exit 1
|
|
|
|
fi
|
2019-01-07 16:41:29 +01:00
|
|
|
[ -d "${JAILDIR}/${jail}" ] && error "${jail} : trying to create existant jail"
|
2019-01-04 13:51:05 +01:00
|
|
|
|
2019-01-08 16:29:03 +01:00
|
|
|
mkdir -p "${CONFDIR}" "${JAILDIR}"
|
2019-01-04 13:51:05 +01:00
|
|
|
sshd_config="${TPLDIR}/sshd_config"
|
|
|
|
inctpl="${TPLDIR}/inc.tpl"
|
|
|
|
[ -f "${LOCALTPLDIR}/sshd_config" ] && sshd_config="${LOCALTPLDIR}/sshd_config"
|
|
|
|
[ -f "${LOCALTPLDIR}/inc.tpl" ] && inctpl="${LOCALTPLDIR}/inc.tpl"
|
|
|
|
|
|
|
|
rootdir=$(dirname "${JAILDIR}")
|
|
|
|
rootdir_inode=$(stat --format=%i "${rootdir}")
|
|
|
|
jaildir_inode=$(stat --format=%i "${JAILDIR}")
|
|
|
|
if [ "${rootdir_inode}" -eq 256 ] || [ "${jaildir_inode}" -eq 256 ]; then
|
|
|
|
/bin/btrfs subvolume create "${JAILDIR}/${jail}"
|
|
|
|
else
|
|
|
|
mkdir -p "${JAILDIR}/${jail}"
|
|
|
|
fi
|
|
|
|
. "${LIBDIR}/mkjail"
|
|
|
|
info "4 - Copie default sshd_config"
|
|
|
|
install -m 0640 "${sshd_config}" "${JAILDIR}/${jail}/${SSHD_CONFIG}"
|
2019-01-04 16:38:20 +01:00
|
|
|
info "5 - Copie default inc configuration"
|
2019-01-04 13:51:05 +01:00
|
|
|
install -m 0640 "${inctpl}" "${CONFDIR}/${jail}"
|
2019-01-04 16:38:20 +01:00
|
|
|
"${LIBDIR}/bkctld-port" "${jail}" auto
|
2019-01-04 13:51:05 +01:00
|
|
|
notice "${jail} : created jail"
|