#!/bin/sh # # Set or get ssh port of # Usage: port [|auto] # LIBDIR="$(dirname $0)" && . "${LIBDIR}/config" jail="${1:-}" port="${2:-}" if [ ! -n "${jail}" ]; then "${LIBDIR}/bkctld-help" && exit 1 fi [ -d "${JAILDIR}/${jail}" ] || error "${jail} : inexistant jail'" if [ -z "${port}" ]; then grep -E "Port [0-9]+" "${JAILDIR}/${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 sed -i "s/^Port .*/Port ${port}/" "${JAILDIR}/$jail/${SSHD_CONFIG}" notice "${jail} : update port => ${port}" "${LIBDIR}/bkctld-reload" "${jail}" "${LIBDIR}/bkctld-firewall" "${jail}" fi