From 19aa7e95cf46f33b8d15455471d72198511d8941 Mon Sep 17 00:00:00 2001 From: Ricardo Pardini Date: Sun, 29 Jan 2023 22:32:49 +0100 Subject: [PATCH] armbian-next: introduce `assert_prepared_host()` and assert before using any Python, to un-mask any further fallacies --- lib/functions/configuration/aggregation.sh | 2 +- lib/functions/general/python-tools.sh | 1 + lib/functions/host/prepare-host.sh | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/functions/configuration/aggregation.sh b/lib/functions/configuration/aggregation.sh index d12058542e..9cc78b7461 100644 --- a/lib/functions/configuration/aggregation.sh +++ b/lib/functions/configuration/aggregation.sh @@ -2,7 +2,7 @@ function assert_requires_aggregation() { if [[ ${aggregation_has_already_run:-0} -lt 1 ]]; then - exit_with_error "assert_requires_aggregation: Aggregation has not been run" + exit_with_error "assert_requires_aggregation: Aggregation has not been run. This is a bug in armbian-next code. Please report!" fi } diff --git a/lib/functions/general/python-tools.sh b/lib/functions/general/python-tools.sh index f96f55676e..0e92933162 100644 --- a/lib/functions/general/python-tools.sh +++ b/lib/functions/general/python-tools.sh @@ -15,6 +15,7 @@ function early_prepare_pip3_dependencies_for_python_tools() { # call: prepare_python_and_pip # this defines global PYTHON3_INFO dict and PYTHON3_VARS array function prepare_python_and_pip() { + assert_prepared_host # this needs a prepared host to work; avoid fake errors about "python3-pip" not being installed # First determine with python3 to use; requires knowing the HOSTRELEASE. [[ -z "${HOSTRELEASE}" ]] && exit_with_error "HOSTRELEASE is not set" diff --git a/lib/functions/host/prepare-host.sh b/lib/functions/host/prepare-host.sh index ce2b5172ec..035fa99e45 100644 --- a/lib/functions/host/prepare-host.sh +++ b/lib/functions/host/prepare-host.sh @@ -10,6 +10,12 @@ function prepare_host() { return 0 } +function assert_prepared_host() { + if [[ ${prepare_host_has_already_run:-0} -lt 1 ]]; then + exit_with_error "assert_prepared_host: Host has not yet been prepared. This is a bug in armbian-next code. Please report!" + fi +} + function check_basic_host() { display_alert "Checking" "basic host setup" "info" obtain_and_check_host_release_and_arch # sets HOSTRELEASE and validates it for sanity; also HOSTARCH @@ -185,6 +191,8 @@ function prepare_host_noninteractive() { # Reset owner of userpatches if so required reset_uid_owner "${USERPATCHES_PATH}" # Fix owner of files in the final destination + declare -i -g -r prepare_host_has_already_run=1 # global, readonly. + return 0 }