← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~raharper/cloud-init:fix/cloud-init-per-bad-sub into cloud-init:master

 

Ryan Harper has proposed merging ~raharper/cloud-init:fix/cloud-init-per-bad-sub into cloud-init:master.

Commit message:
cloud-init-per: POSIX sh does not support string subst, use sed
    
cloud-init-per is run via /bin/sh which requires POSIX shell
compliance and does not implement string substitution like
bash.  Replace these calls with use of sed.
    
LP: #1819222

Requested reviews:
  cloud-init commiters (cloud-init-dev)
Related bugs:
  Bug #1819222 in cloud-init: "cloud-init-per no longer works due to bashisms"
  https://bugs.launchpad.net/cloud-init/+bug/1819222

For more details, see:
https://code.launchpad.net/~raharper/cloud-init/+git/cloud-init/+merge/364190
-- 
Your team cloud-init commiters is requested to review the proposed merge of ~raharper/cloud-init:fix/cloud-init-per-bad-sub into cloud-init:master.
diff --git a/tools/cloud-init-per b/tools/cloud-init-per
index eae3e93..fcd1ea7 100755
--- a/tools/cloud-init-per
+++ b/tools/cloud-init-per
@@ -38,7 +38,7 @@ fi
 [ "$1" = "-h" -o "$1" = "--help" ] && { Usage ; exit 0; }
 [ $# -ge 3 ] || { Usage 1>&2; exit 1; }
 freq=$1
-name=${2/-/_}
+name=$(echo $2 | sed 's/-/_/g')
 shift 2;
 
 [ "${name#*/}" = "${name}" ] || fail "name cannot contain a /"
@@ -56,7 +56,7 @@ esac
 # Rename legacy sem files with dashes in their names. Do not overwrite existing
 # sem files to prevent clobbering those which may have been created from calls
 # outside of cloud-init.
-sem_legacy="${sem/_/-}"
+sem_legacy=$(echo $sem | sed 's/_/-/g')
 [ "$sem" != "$sem_legacy" -a -e "$sem_legacy" ] && mv -n "$sem_legacy" "$sem"
 
 [ "$freq" != "always" -a -e "$sem" ] && exit 0

Follow ups