Browse Source

configs: Support multiple config files on command line.

The current support for this fails due to incorrect use
of bash arrays.

Also, use the printf '%q' formatting code to add proper quotes
to the config file names to ensure that it works properly
with spaces in the file names.

Signed-off-by: Drew Moseley <drew.moseley@northern.tech>

Changelog: Title
2.0.x
Drew Moseley 5 years ago
parent
commit
9b944615a8
  1. 10
      mender-convert-extract
  2. 10
      mender-convert-modify
  3. 10
      mender-convert-package
  4. 7
      modules/config.sh

10
mender-convert-extract

@ -19,6 +19,8 @@ echo "Running $(basename $0): $@"
source modules/bootstrap.sh
source modules/disk.sh
declare -a configs
disk_image=""
while (( "$#" )); do
case "$1" in
@ -27,7 +29,7 @@ while (( "$#" )); do
shift 2
;;
-c | --config)
configs+="${2}"
configs+=("${2}")
shift 2
;;
-d | --disk-image)
@ -50,7 +52,11 @@ if [ ! -e ${disk_image} ]; then
log_fatal "File not found: ${disk_image}"
fi
source modules/config.sh "${configs[@]}"
# Note the use of %q formatting here. This is a bash feature to add
# proper quoting to the strings so that spaces and special characters
# will be treated properly. Primarily for supporting spaces in
# pathnames and avoid splitting those into multiple parameters.
source modules/config.sh $(printf "%q " "${configs[@]}")
MKFS_VFAT="/usr/bin/mkfs.vfat"
if [ ! -f ${MKFS_VFAT} ]; then

10
mender-convert-modify

@ -39,6 +39,8 @@ source modules/bootstrap.sh
source modules/disk.sh
source modules/probe.sh
declare -a configs
while (( "$#" )); do
case "$1" in
-o | --overlay)
@ -46,7 +48,7 @@ while (( "$#" )); do
shift 2
;;
-c | --config)
configs+="${2}"
configs+=("${2}")
shift 2
;;
-d | --disk-image)
@ -59,7 +61,11 @@ while (( "$#" )); do
esac
done
source modules/config.sh "${configs[@]}"
# Note the use of %q formatting here. This is a bash feature to add
# proper quoting to the strings so that spaces and special characters
# will be treated properly. Primarily for supporting spaces in
# pathnames and avoid splitting those into multiple parameters.
source modules/config.sh $(printf "%q " "${configs[@]}")
boot_part=$(disk_boot_part)
root_part=$(disk_root_part)

10
mender-convert-package

@ -38,6 +38,8 @@ echo "Running $(basename $0): $@"
source modules/bootstrap.sh
source modules/disk.sh
declare -a configs
while (( "$#" )); do
case "$1" in
-o | --overlay)
@ -45,7 +47,7 @@ while (( "$#" )); do
shift 2
;;
-c | --config)
configs+="${2}"
configs+=("${2}")
shift 2
;;
-d | --disk-image)
@ -58,7 +60,11 @@ while (( "$#" )); do
esac
done
source modules/config.sh "${configs[@]}"
# Note the use of %q formatting here. This is a bash feature to add
# proper quoting to the strings so that spaces and special characters
# will be treated properly. Primarily for supporting spaces in
# pathnames and avoid splitting those into multiple parameters.
source modules/config.sh $(printf "%q " "${configs[@]}")
PARTED="/usr/bin/parted"
if [ ! -f ${PARTED} ]; then

7
modules/config.sh

@ -14,7 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
for config in configs/mender_convert_config "$@"; do
# Read in the array of config files to process
read -a configs <<< "${@}"
configs=( "configs/mender_convert_config" "${configs[@]}" )
for config in "${configs[@]}"; do
log_info "Using configuration file: ${config}"
source ${config}
source "${config}"
done

Loading…
Cancel
Save