diff --git a/home/bin/deboco b/home/bin/deboco index 2669d17..618aa85 100755 --- a/home/bin/deboco +++ b/home/bin/deboco @@ -95,6 +95,32 @@ replace_in_file() fi } +is_version_greater_than() +{ + + first_value="${1}" + value_to_compare="${2}" + + ## Return False by default + return_is_version_greater_than="1" + + log 'debug' "is_version_greater_than - Is first value (${first_value}) greater than the second value (${value_to_compare})." + + if printf '%s\n' "${first_value}" "${value_to_compare}" | sort --check=quiet --version-sort; then + log 'debug' "${debug_prefix}is_version_greater_than - ${first_value} <= ${value_to_compare} ." + return_is_version_greater_than="1" + else + log 'debug' "${debug_prefix}is_version_greater_than - ${first_value} > ${value_to_compare} ." + return_is_version_greater_than="0" + fi + + unset first_value + unset value_to_compare + + return "${return_is_version_greater_than}" +} + + controller__get_local_repos_path() { local debops_controller_path="$1" @@ -178,9 +204,18 @@ deboco__init() if [ "$bug_3715_is_fixed" = 'false' ] then # make sure that the python version is at least 3.10 so that ansible>=2.15 is installed (as debops 3.1 requires ansible>=2.15) + local python_version=$(${PYTHON_PATH} --version | cut --delimiter=" " --fields=2 --) + log 'debug' "python_version=$python_version" + + if is_version_greater_than "3.10" "${python_version}" + then + log 'error' "debops only works with python version 3.10 or more, and your version of python is $python_version" + return $RETURNCODE_ERROR + fi + replace_in_file "$debops_update_script_path" \ 'virtualenv --quiet -- ' \ - '/usr/bin/python3.10 -m venv ' + "${PYTHON_PATH} -m venv " if [ $? != "$RETURNCODE_SUCCESS" ] then return $RETURNCODE_ERROR @@ -313,9 +348,13 @@ deboco_print_usage() echo "$0 performs a debops controller operation" echo echo "usage:" - echo " $0 " + echo " $0 [options] " echo echo "where:" + echo " [options] is a set of:" + echo " --python-path " + echo " specifies the python executable to use (must be python 3.10 or above). Default is $DEFAULT_PYTHON_PATH" + echo echo " is one of:" echo " init " echo " creates a debops controller in " @@ -332,21 +371,31 @@ deboco_print_usage() echo " configure_machine " echo " configures the machine using the debops controller in ". Equivivalent to a init_machine followed by update_machine echo + echo "example:" + echo " deboco --python-path /usr/bin/python3.10 init ~/work/debops/constrollers/alambix" } deboco() { - local command_name="$1" - shift - if type "deboco__${command_name}" >/dev/null 2>&1 - then - "deboco__${command_name}" "$@" - return $? - else - log 'error' "unknown command: ${command_name}" - deboco_print_usage - return "$RETURNCODE_ERROR" - fi + PYTHON_PATH="$DEFAULT_PYTHON_PATH" + while true + do + local arg="$1" + shift + if [ "$arg" = '--python-path' ] + then + PYTHON_PATH="$1" + shift + elif type "deboco__${arg}" >/dev/null 2>&1 + then + "deboco__${arg}" "$@" + return $? + else + log 'error' "unhandled argument: ${arg}" + deboco_print_usage + return "$RETURNCODE_ERROR" + fi + done }