evobackup/lib/bkctld-port

37 lines
968 B
Plaintext
Raw Normal View History

#!/bin/sh
#
# Set or get ssh port of <jailname>
# Usage: port <jailname> [<port>|auto]
#
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:?}"
port="${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."
2020-04-08 00:32:15 +02:00
jail_sshd_config="${jail_path}/${SSHD_CONFIG}"
if [ -z "${port}" ]; then
2020-04-08 00:32:15 +02:00
grep -E "Port [0-9]+" "${jail_sshd_config}"|grep -oE "[0-9]+"
else
if [ "${port}" = "auto" ]; then
port=$(grep -h Port "${JAILDIR}"/*/"${SSHD_CONFIG}" 2>/dev/null | grep -Eo "[0-9]+" | sort -n | tail -1)
port=$((port+1))
[ "${port}" -le 1 ] && port=2222
fi
2020-04-08 00:32:15 +02:00
sed -i "s/^Port .*/Port ${port}/" "${jail_sshd_config}"
2020-04-02 01:07:12 +02:00
2020-04-02 14:50:55 +02:00
notice "${jail_name}: port has been updated to ${port}"
2020-04-02 01:07:12 +02:00
"${LIBDIR}/bkctld-reload" "${jail_name}"
"${LIBDIR}/bkctld-firewall" "${jail_name}"
fi