From 9f330e361d7be7c3ef24893ebcc10d60633cb8f2 Mon Sep 17 00:00:00 2001 From: Jake Guffey <jake.guffey@eprotex.com> Date: Tue, 19 Feb 2013 16:24:22 -0500 Subject: [PATCH] Added support for multiple IP addresses FreeBSD jails support jail_${name}_ip="iface1|addr1, iface2|addr2" format for specifying multiple IP addresses --- cdist/conf/type/__jail/gencode-remote | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/cdist/conf/type/__jail/gencode-remote b/cdist/conf/type/__jail/gencode-remote index 5223bc46..b044e4b0 100755 --- a/cdist/conf/type/__jail/gencode-remote +++ b/cdist/conf/type/__jail/gencode-remote @@ -92,6 +92,20 @@ fi present="$(cat "$__object/explorer/present")" status="$(cat "$__object/explorer/status")" +# Handle ip="iface|addr, iface|addr" format +if [ $(expr "${ip}" : ".*|.*") -gt "0" ]; then + # If we have multiple IPs defined, $interface doesn't make sense because ip="iface|addr, iface|addr" implies it + interface="" + SAVE_IFS="$IFS" + IFS=", " + for cur_ip in ${ip}; do + # Just get the last IP address for SSH to listen on + mgmt_ip=$(echo "${ip}" | sed -E -e 's/^.*\|(.*)\/[0-9]+$/\1/') + done + IFS="$SAVE_IFS" +else + mgmt_ip=$(echo "${ip}" | cut '-d ' -f1) +fi stopJail() { # Check $status before issuing command @@ -250,7 +264,7 @@ if [ -n "$interface" ]; then jail_${name}_interface="${interface}" END EOF -else +elif [ "$(expr "${ip}" : ".*|.*")" -eq "0" ]; then cat <<EOF interface=\$(ifconfig -l | cut '-d ' -f1) cat >>/etc/rc.conf <<END @@ -316,8 +330,7 @@ echo syslogd_flags=\"-ss\" >>"${jaildir}/rw/${name}/etc/rc.conf" EOF # Configure SSHd's listening address cat <<EOF -ip=\$(echo "${ip}" | cut '-d ' -f1) -sed -i '.bak' "s/#ListenAddress 0.0.0.0/ListenAddress \${ip}/" "${jaildir}/rw/${name}/etc/ssh/sshd_config" +sed -E -i '.bak' -e "s/#?ListenAddress 0.0.0.0/ListenAddress ${mgmt_ip}/" "${jaildir}/rw/${name}/etc/ssh/sshd_config" EOF }