evobackup/lib/bkctld-port
Victor LABORIE 842e57ba53 Big refactoring
* Jails are created on start and run in tmpfs
* All config files are on /etc/bkctld
* Cleaning of sshd_config and /etc/group
2020-01-08 14:46:18 +01:00

29 lines
877 B
Bash
Executable file

#!/bin/sh
#
# Set or get ssh port of <jailname>
# Usage: port <jailname> [<port>|auto]
#
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"
port="${2:-}"
if [ ! -n "${jail}" ]; then
"${LIBDIR}/bkctld-help" && exit 1
fi
[ -d "${CONFDIR}/${jail}" ] || error "${jail} : inexistant jail'"
if [ -z "${port}" ]; then
grep -E "Port [0-9]+" "${CONFDIR}/${jail}/ssh/sshd_config"|grep -oE "[0-9]+"
else
if [ "${port}" = "auto" ]; then
port=$(grep -h Port "${CONFDIR}"/*/ssh/sshd_config 2>/dev/null | grep -Eo "[0-9]+" | sort -n | tail -1)
port=$((port+1))
[ "${port}" -le 1 ] && port=2222
fi
sed -i "s/^Port .*/Port ${port}/" "${CONFDIR}/$jail/ssh/sshd_config"
notice "${jail} : update port => ${port}"
"${LIBDIR}/bkctld-is-on" "${jail}" && "${LIBDIR}/bkctld-reload" "${jail}"
"${LIBDIR}/bkctld-firewall" "${jail}"
fi