Following commits are going to rename some config option parameters from lowercase letters to uppercase. The old lowercase options will be deprecated but still be kept usable to not cause confusions. When these changes are made, it will be required to check that both new and old parameters are not set at once and ensure they do not have two different values. To simplify the code to check the two parameters, introduce the helper _check_conflict_and_set_default(). If the both two parameters are set, it errors out. If the old option is set, it propagates the old option value to the new option. Also, when neither of them is set, it sets the default value to the new option. Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@xxxxxxx> --- common/rc | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/common/rc b/common/rc index c3680f5..9ff31cf 100644 --- a/common/rc +++ b/common/rc @@ -470,3 +470,30 @@ convert_to_mb() echo "$((res * 1024))" fi } + +# Check both old and new parameters are not configured. If the old parameter is +# set, propagate to the new parameter. If neither is set, set the default value +# to the new parameter. +_check_conflict_and_set_default() +{ + local new_name="$1" + local old_name="$2" + local default_val="$3" + local new_name_checked="$new_name"_checked + + if [[ -n ${!new_name_checked} ]]; then + return + fi + + if [[ -n ${!old_name} ]]; then + if [[ -n ${!new_name} ]]; then + echo "Both ${old_name} and ${new_name} are specified" + exit 1 + fi + eval "${new_name}=\"${!old_name}\"" + elif [[ -z ${!new_name} ]]; then + eval "${new_name}=\"${default_val}\"" + fi + + eval "${new_name_checked}=true" +} -- 2.44.0