2020-05-28 11:08:29 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2020-10-11 14:51:39 +02:00
|
|
|
# Description: Upgrade configuration to new convention
|
|
|
|
# Usage: upgrade-config [<jailname>|all]
|
2020-05-28 11:08:29 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
# shellcheck source=./includes
|
|
|
|
LIBDIR="$(dirname $0)" && . "${LIBDIR}/includes"
|
|
|
|
|
|
|
|
jail_name="${1:?}"
|
|
|
|
if [ ! -n "${jail_name}" ]; then
|
2020-10-07 20:50:17 +02:00
|
|
|
show_help && exit 1
|
2020-05-28 11:08:29 +02:00
|
|
|
fi
|
|
|
|
jail_path=$(jail_path "${jail_name}")
|
|
|
|
|
|
|
|
test -d "${jail_path}" || error "${jail_name}: jail not found" 2
|
|
|
|
|
|
|
|
legacy_incs_policy_file="${CONFDIR}/${jail_name}"
|
|
|
|
incs_policy_file=$(jail_incs_policy_file "${jail_name}")
|
|
|
|
|
|
|
|
if [ -h "${legacy_incs_policy_file}" ]; then
|
|
|
|
if [ -f "${incs_policy_file}" ]; then
|
|
|
|
info "${jail_name}: config is already upgraded"
|
|
|
|
else
|
|
|
|
warning "${jail_name}: symlink present but inc policy file \`${incs_policy_file}' not found"
|
|
|
|
fi
|
|
|
|
elif [ ! -e "${legacy_incs_policy_file}" ] ; then
|
|
|
|
if [ -f "${incs_policy_file}" ]; then
|
|
|
|
# create a symlink for backward compatibility
|
|
|
|
ln -s "${incs_policy_file}" "${legacy_incs_policy_file}"
|
|
|
|
|
|
|
|
info "${jail_name}: config has been symlinked"
|
|
|
|
else
|
|
|
|
warning "${jail_name}: inc policy file \`${incs_policy_file}' not found"
|
|
|
|
fi
|
|
|
|
elif [ -f "${legacy_incs_policy_file}" ]; then
|
|
|
|
# Create directory if missing
|
|
|
|
mkdir -p "$(jail_config_dir "${jail_name}")"
|
|
|
|
# move the main config file
|
|
|
|
mv "${legacy_incs_policy_file}" "${incs_policy_file}"
|
|
|
|
# create a symlink for backward compatibility
|
|
|
|
ln -s "${incs_policy_file}" "${legacy_incs_policy_file}"
|
|
|
|
# create a check_policy file if missing
|
|
|
|
touch "$(jail_check_policy_file "${jail_name}")"
|
|
|
|
|
|
|
|
info "${jail_name}: config has been upgraded"
|
|
|
|
fi
|