[ -n "$hosts_file" ] || hosts_file="tmp/hosts.${CLUSTER}"
[ -r "$hosts_file" ] || die "Missing hosts file \"${hosts_file}\""
- local pat="# autocluster ${CLUSTER}\$|[[:space:]]${CLUSTER}(n|base)[[:digit:]]+"
+ # Building a general node name regexp is a bit cumbersome. :-)
+ local name_regexp="("
+ for i in $(set | sed -n -e "s@^\(node_name_format_.*\) ().*@\1@p") ; do
+ # For each node_name_format_* function, get the actual node
+ # name format string
+ fmt=$($i)
+ # fill it with placeholders (remembering that "_" is not valid
+ # in a real cluster name)
+ local t=$(printf "$fmt\n" "_" "0" | head -n 1)
+ # now replace the placeholders with regexps - order is
+ # important here, since the cluster name can contain digits
+ t=$(sed -r -e "s@[[:digit:]]+@[[:digit:]]+@" -e "s@_@${CLUSTER}@" <<<"$t")
+ # add to the regexp
+ name_regexp="${name_regexp}${t}|"
+ done
+ name_regexp="${name_regexp}${CLUSTER}n[[:digit:]]+)"
+
+ local pat="# autocluster ${CLUSTER}\$|[[:space:]]${name_regexp}"
local t="/etc/hosts.${CLUSTER}"
grep -E "$pat" /etc/hosts >"$t" || true