diff --git a/README.md b/README.md index 1f98cdc8..3a28b3e1 100644 --- a/README.md +++ b/README.md @@ -718,7 +718,8 @@ followed by its arguments (omitting the target, which is deduced from the Variables can also be defined using `ARG` with one `name=value` pair per line. Subsequent references to `${name}` would be replaced by `value`. Note that argument values are not available for use until after the point -at which they are defined in the file. +at which they are defined in the file. Both `${JAIL_NAME}` and `${JAIL_IP}` +are made available in templates without having to define them as args. Bastillefile example: diff --git a/usr/local/share/bastille/template.sh b/usr/local/share/bastille/template.sh index 2f1e7a7e..d8f2e1f2 100644 --- a/usr/local/share/bastille/template.sh +++ b/usr/local/share/bastille/template.sh @@ -169,12 +169,17 @@ fi ## global variables bastille_template=${bastille_templatesdir}/${TEMPLATE} for _jail in ${JAILS}; do - ## jail-specific variables. - bastille_jail_path=$(jls -j "${_jail}" path) - info "[${_jail}]:" info "Applying template: ${TEMPLATE}..." + ## jail-specific variables. + bastille_jail_path=$(jls -j "${_jail}" path) + _jail_ip=$(jls -j "${_jail}" ip4.addr 2>/dev/null) + if [ -z "${_jail_ip}" -o "${_jail_ip}" = "-" ]; then + error_notify "Jail IP not found: ${_jail}" + _jail_ip='' # In case it was -. -- cwells + fi + ## TARGET if [ -s "${bastille_template}/TARGET" ]; then if grep -qw "${_jail}" "${bastille_template}/TARGET"; then @@ -189,8 +194,10 @@ for _jail in ${JAILS}; do fi fi + # Build a list of sed commands like this: -e 's/${username}/root/g' -e 's/${domain}/example.com/g' + # Values provided by default (without being defined by the user) are listed here. -- cwells + ARG_REPLACEMENTS="-e 's/\${JAIL_IP}/${_jail_ip}/g' -e 's/\${JAIL_NAME}/${_jail}/g'" # This is parsed outside the HOOKS loop so an ARG file can be used with a Bastillefile. -- cwells - ARG_REPLACEMENTS='' if [ -s "${bastille_template}/ARG" ]; then while read _line; do if [ -z "${_line}" ]; then @@ -201,7 +208,6 @@ for _jail in ${JAILS}; do if [ -z "${_arg_value}" ]; then warn "No value provided for arg: ${_arg_name}" fi - # Build a list of sed commands like this: -e 's/${username}/root/g' -e 's/${domain}/example.com/g' ARG_REPLACEMENTS="${ARG_REPLACEMENTS} -e 's/\${${_arg_name}}/${_arg_value}/g'" done < "${bastille_template}/ARG" fi