Strip leading and trailing hyphens

Strip leading and trailing hyphens in the resulting munged hostname.
Leading and trailing hyphens are not valid according to RFCs 952 and 1123.
(This problem surfaces immediately when using the default configuration of
OneFlow, since it names new VMs ending with a parenthesis.)
pull/28/head
Jamie Taylor 9 years ago
parent 1c335c690b
commit 6f07527f36

@ -20,7 +20,7 @@ function get_dns_name() {
} }
if [ -n "$SET_HOSTNAME" ]; then if [ -n "$SET_HOSTNAME" ]; then
set_hostname $(echo "$SET_HOSTNAME" | sed -e 's/[^-a-zA-Z0-9]/-/g') set_hostname $(echo "$SET_HOSTNAME" | sed -e 's/[^-a-zA-Z0-9]/-/g' -e 's/^-*//g' -e 's/-*$//g')
elif [ -n "$DNS_HOSTNAME" ]; then elif [ -n "$DNS_HOSTNAME" ]; then
set_hostname $(get_dns_name) set_hostname $(get_dns_name)
fi fi

@ -22,7 +22,7 @@ function get_dns_name() {
} }
if [ -n "$SET_HOSTNAME" ]; then if [ -n "$SET_HOSTNAME" ]; then
set_hostname $(echo "$SET_HOSTNAME" | sed -e 's/[^-a-zA-Z0-9]/-/g') set_hostname $(echo "$SET_HOSTNAME" | sed -e 's/[^-a-zA-Z0-9]/-/g' -e 's/^-*//g' -e 's/-*$//g')
elif [ -n "$DNS_HOSTNAME" ]; then elif [ -n "$DNS_HOSTNAME" ]; then
set_hostname $(get_dns_name) set_hostname $(get_dns_name)
fi fi

@ -23,7 +23,7 @@ function get_dns_name() {
} }
if [ -n "$SET_HOSTNAME" ]; then if [ -n "$SET_HOSTNAME" ]; then
set_hostname $(echo "$SET_HOSTNAME" | sed -e 's/[^-a-zA-Z0-9]/-/g') set_hostname $(echo "$SET_HOSTNAME" | sed -e 's/[^-a-zA-Z0-9]/-/g' -e 's/^-*//g' -e 's/-*$//g')
elif [ -n "$DNS_HOSTNAME" ]; then elif [ -n "$DNS_HOSTNAME" ]; then
set_hostname $(get_dns_name) set_hostname $(get_dns_name)
fi fi

Loading…
Cancel
Save