evobackup/server/lib/bkctld-init

38 lines
932 B
Plaintext
Raw Normal View History

2019-01-04 13:51:05 +01:00
#!/bin/sh
#
# Description: Initialize a new jail
# Usage: init <jailname>
#
2019-01-04 13:51:05 +01:00
2020-04-02 13:44:13 +02:00
# shellcheck source=./includes
2020-04-02 00:31:57 +02:00
LIBDIR="$(dirname $0)" && . "${LIBDIR}/includes"
2019-01-04 13:51:05 +01:00
2020-04-02 13:44:13 +02:00
jail_name="${1:?}"
2020-04-02 00:30:48 +02:00
if [ -z "${jail_name}" ]; then
show_help && exit 1
fi
2020-04-02 00:30:48 +02:00
jail_path=$(jail_path "${jail_name}")
incs_path=$(incs_path "${jail_name}")
2020-04-02 00:30:48 +02:00
2020-04-20 08:29:21 +02:00
test -d "${jail_path}" && error "Skip jail \`${jail_name}' : it already exists"
2020-04-02 00:30:48 +02:00
# Create config, jails and incs directories
mkdir --parents "${CONFDIR}" "${JAILDIR}" "${INCDIR}"
2020-04-02 00:30:48 +02:00
if is_btrfs "$(dirname "${JAILDIR}")" || is_btrfs "${JAILDIR}"; then
btrfs_bin=$(command -v btrfs)
2022-04-20 15:14:33 +02:00
if [ -z "${btrfs_bin}" ]; then
error "btrfs not found. Please install btrfs-progs."
fi
${btrfs_bin} subvolume create "${jail_path}"
2019-01-04 13:51:05 +01:00
else
2020-04-02 00:30:48 +02:00
mkdir --parents "${jail_path}"
2019-01-04 13:51:05 +01:00
fi
2020-04-02 00:30:48 +02:00
mkdir --parents "${incs_path}"
2020-04-02 00:30:48 +02:00
setup_jail_chroot "${jail_name}"
setup_jail_config "${jail_name}"
2020-04-20 08:29:21 +02:00
notice "Create jail \`${jail_name}' : OK"