From 6ce6c7830bcc0e360349d071b00f2aecbf099dd2 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Sat, 5 Nov 2016 16:38:49 +0100 Subject: [PATCH] Better test for IPv6 address. --- cdist/conf/type/__file/gencode-local | 15 +++++++-------- cdist/conf/type/__jail_freebsd10/gencode-local | 15 +++++++-------- cdist/conf/type/__jail_freebsd9/gencode-local | 15 +++++++-------- cdist/conf/type/__pf_ruleset/gencode-local | 15 +++++++-------- 4 files changed, 28 insertions(+), 32 deletions(-) diff --git a/cdist/conf/type/__file/gencode-local b/cdist/conf/type/__file/gencode-local index 674650b7..c9e0fa2c 100755 --- a/cdist/conf/type/__file/gencode-local +++ b/cdist/conf/type/__file/gencode-local @@ -67,14 +67,13 @@ DONE if [ "$upload_file" ]; then echo upload >> "$__messages_out" # IPv6 fix - case "${__target_host}" in - *:*) - my_target_host="[${__target_host}]" - ;; - *) - my_target_host="${__target_host}" - ;; - esac + echo "${__target_host}" | grep -q -E '^[0-9a-fA-F:]+$' + if [ $? -eq 0 ] + then + my_target_host="[${__target_host}]" + else + my_target_host="${__target_host}" + fi cat << DONE $__remote_copy "$source" "${my_target_host}:\$destination_upload" DONE diff --git a/cdist/conf/type/__jail_freebsd10/gencode-local b/cdist/conf/type/__jail_freebsd10/gencode-local index 766692a2..bdd0ffd7 100755 --- a/cdist/conf/type/__jail_freebsd10/gencode-local +++ b/cdist/conf/type/__jail_freebsd10/gencode-local @@ -44,14 +44,13 @@ basepresent="$(cat "$__object/explorer/basepresent")" if [ "$state" = "present" ]; then if [ "$basepresent" = "NONE" ]; then # IPv6 fix - case "${__target_host}" in - *:*) - my_target_host="[${__target_host}]" - ;; - *) - my_target_host="${__target_host}" - ;; - esac + echo "${__target_host}" | grep -q -E '^[0-9a-fA-F:]+$' + if [ $? -eq 0 ] + then + my_target_host="[${__target_host}]" + else + my_target_host="${__target_host}" + fi echo "$__remote_copy" "${jailbase}" "${my_target_host}:${remotebase}" fi # basepresent=NONE fi # state=present diff --git a/cdist/conf/type/__jail_freebsd9/gencode-local b/cdist/conf/type/__jail_freebsd9/gencode-local index 35b6f789..ce9b215e 100755 --- a/cdist/conf/type/__jail_freebsd9/gencode-local +++ b/cdist/conf/type/__jail_freebsd9/gencode-local @@ -40,14 +40,13 @@ basepresent="$(cat "$__object/explorer/basepresent")" if [ "$state" = "present" ]; then if [ "$basepresent" = "NONE" ]; then # IPv6 fix - case "${__target_host}" in - *:*) - my_target_host="[${__target_host}]" - ;; - *) - my_target_host="${__target_host}" - ;; - esac + echo "${__target_host}" | grep -q -E '^[0-9a-fA-F:]+$' + if [ $? -eq 0 ] + then + my_target_host="[${__target_host}]" + else + my_target_host="${__target_host}" + fi echo "$__remote_copy" "${jailbase}" "${my_target_host}:${remotebase}" fi # basepresent=NONE fi # state=present diff --git a/cdist/conf/type/__pf_ruleset/gencode-local b/cdist/conf/type/__pf_ruleset/gencode-local index 307c89ec..d14a6045 100644 --- a/cdist/conf/type/__pf_ruleset/gencode-local +++ b/cdist/conf/type/__pf_ruleset/gencode-local @@ -60,14 +60,13 @@ case $uname in esac # IPv6 fix -case "${__target_host}" in - *:*) - my_target_host="[${__target_host}]" - ;; - *) - my_target_host="${__target_host}" - ;; -esac +echo "${__target_host}" | grep -q -E '^[0-9a-fA-F:]+$' +if [ $? -eq 0 ] +then + my_target_host="[${__target_host}]" +else + my_target_host="${__target_host}" +fi if [ -n "${cksum}" ]; then if [ ! "\${currentSum}" = "${cksum}" ]; then