Refactor to older versions of bash that don't have associative array
support, so that this works on OS/X.
Showing
1 changed file
with
19 additions
and
14 deletions
1 | #!/usr/bin/env bash | 1 | #!/usr/bin/env bash |
2 | # OS/X does not include GPLv3 versions of bash, which precludes | ||
3 | # use of associative array support. | ||
2 | 4 | ||
3 | set -e | 5 | set -e |
4 | 6 | ||
5 | declare -A defaults=( | 7 | DEFAULT_INKLUSTER_IMAGE=brainfood/inkluster-dev |
6 | [INKLUSTER_IMAGE]=brainfood/inkluster-dev | 8 | DEFAULT_INKLUSTER_VOLUME_NAME="" |
7 | [INKLUSTER_VOLUME_NAME]="" | 9 | if [[ -e values/apiserver-env.yaml ]]; then |
8 | ) | 10 | buildName="$(sed -n -e 's/^buildName: "\(.*\)"$/\1/p' "values/apiserver-env.yaml")" |
11 | [[ $buildName ]] && DEFAULT_INKLUSTER_VOLUME_NAME="$buildName" | ||
12 | fi | ||
9 | 13 | ||
14 | declare -a config_keys=(INKLUSTER_IMAGE INKLUSTER_VOLUME_NAME) | ||
10 | declare -a config_files=() | 15 | declare -a config_files=() |
11 | 16 | ||
12 | if [[ -e .inkluster.env ]]; then | 17 | if [[ -e .inkluster.env ]]; then |
13 | config_files+=("$PWD/.inkluster.env") | 18 | config_files+=("$PWD/.inkluster.env") |
14 | fi | 19 | fi |
15 | 20 | ||
16 | declare -A config=() | ||
17 | |||
18 | # This copies ENV settings into the config, that haven't been set on the command line. | 21 | # This copies ENV settings into the config, that haven't been set on the command line. |
19 | for setting in "${!defaults[@]}"; do | 22 | for setting in "${config_keys[@]}"; do |
20 | [[ ${!setting} ]] && eval config[$setting]="${!setting}" | 23 | [[ ${!setting} ]] && eval CONFIG_$setting='"${!'setting'}"' |
21 | done | 24 | done |
22 | 25 | ||
23 | declare -a REST=() | 26 | declare -a REST=() |
... | @@ -28,11 +31,11 @@ while [[ $# -gt 0 ]]; do | ... | @@ -28,11 +31,11 @@ while [[ $# -gt 0 ]]; do |
28 | shift 2 | 31 | shift 2 |
29 | ;; | 32 | ;; |
30 | (-i) | 33 | (-i) |
31 | config[INKLUSTER_IMAGE]="$2" | 34 | CONFIG_INKLUSTER_IMAGE="$2" |
32 | shift 2 | 35 | shift 2 |
33 | ;; | 36 | ;; |
34 | (-v) | 37 | (-v) |
35 | config[INKLUSTER_VOLUME_NAME]="$2" | 38 | CONFIG_INKLUSTER_VOLUME_NAME="$2" |
36 | shift 2 | 39 | shift 2 |
37 | ;; | 40 | ;; |
38 | (*) | 41 | (*) |
... | @@ -57,10 +60,12 @@ for config_file in "${config_files[@]}"; do | ... | @@ -57,10 +60,12 @@ for config_file in "${config_files[@]}"; do |
57 | done | 60 | done |
58 | 61 | ||
59 | # Any settings read from the config files, but not yet set, get applied. | 62 | # Any settings read from the config files, but not yet set, get applied. |
60 | for setting in "${!defaults[@]}"; do | 63 | for setting in "${config_keys[@]}"; do |
61 | [[ -n ${!setting} && -z ${config[$setting]} ]] && eval config[$setting]="${!setting}" | 64 | if eval [[ '${CONFIG_'$setting'}' ]]; then |
62 | [[ -z ${config[$setting]} ]] && eval config[$setting]="${defaults[$setting]}" | 65 | eval $setting='"${CONFIG_'$setting'}"' |
63 | eval $setting=\"\${config[$setting]}\" | 66 | else |
67 | [[ -z ${!setting} ]] && eval $setting='"${DEFAULT_'$setting'}"' | ||
68 | fi | ||
64 | done | 69 | done |
65 | 70 | ||
66 | has_volume= | 71 | has_volume= | ... | ... |
-
Please register or sign in to post a comment