From 32e89c228e27f819a839ba45e345cdf916f5a2be Mon Sep 17 00:00:00 2001 From: yunielrc Date: Fri, 22 Sep 2023 14:27:10 -0400 Subject: [PATCH] feat(package-service): make envsubst variables availables in scripts instructions --- .../package/ydf-package-service.bash | 24 +++++++++---- tests/fixtures/packages/23scriptvars/install | 2 ++ .../packages/23scriptvars/postinstall | 1 + .../fixtures/packages/23scriptvars/preinstall | 1 + .../package/ydf-package-service.i.bats | 34 +++++++++++++++++++ 5 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 tests/fixtures/packages/23scriptvars/install create mode 100644 tests/fixtures/packages/23scriptvars/postinstall create mode 100644 tests/fixtures/packages/23scriptvars/preinstall diff --git a/src/usr/lib/ydf/components/package/ydf-package-service.bash b/src/usr/lib/ydf/components/package/ydf-package-service.bash index e0f9678..c06f837 100644 --- a/src/usr/lib/ydf/components/package/ydf-package-service.bash +++ b/src/usr/lib/ydf/components/package/ydf-package-service.bash @@ -108,9 +108,13 @@ ydf::package_service::get_instructions_names() { # Returns: # 0 on success, non-zero on error. # -ydf::package_service::__instruction_preinstall() { +ydf::package_service::__instruction_preinstall() ( + set -o allexport + # shellcheck disable=SC1090 + source "$__YDF_PACKAGE_SERVICE_ENVSUBST_FILE" + bash ./preinstall -} +) # # Execute install script @@ -119,9 +123,13 @@ ydf::package_service::__instruction_preinstall() { # Returns: # 0 on success, non-zero on error. # -ydf::package_service::__instruction_install() { +ydf::package_service::__instruction_install() ( + set -o allexport + # shellcheck disable=SC1090 + source "$__YDF_PACKAGE_SERVICE_ENVSUBST_FILE" + bash ./install -} +) # # Execute postinstall script @@ -130,9 +138,13 @@ ydf::package_service::__instruction_install() { # Returns: # 0 on success, non-zero on error. # -ydf::package_service::__instruction_postinstall() { +ydf::package_service::__instruction_postinstall() ( + set -o allexport + # shellcheck disable=SC1090 + source "$__YDF_PACKAGE_SERVICE_ENVSUBST_FILE" + bash ./postinstall -} +) # # Execute @pacman instruction diff --git a/tests/fixtures/packages/23scriptvars/install b/tests/fixtures/packages/23scriptvars/install new file mode 100644 index 0000000..45bc23e --- /dev/null +++ b/tests/fixtures/packages/23scriptvars/install @@ -0,0 +1,2 @@ +echo "install: MY_CONFIG1: ${MY_CONFIG1}" +echo "install: HOME: ${HOME}" diff --git a/tests/fixtures/packages/23scriptvars/postinstall b/tests/fixtures/packages/23scriptvars/postinstall new file mode 100644 index 0000000..6e3eede --- /dev/null +++ b/tests/fixtures/packages/23scriptvars/postinstall @@ -0,0 +1 @@ +echo "postinstall: MY_CONFIG2: ${MY_CONFIG2}" diff --git a/tests/fixtures/packages/23scriptvars/preinstall b/tests/fixtures/packages/23scriptvars/preinstall new file mode 100644 index 0000000..32329a6 --- /dev/null +++ b/tests/fixtures/packages/23scriptvars/preinstall @@ -0,0 +1 @@ +echo "preinstall: FILE11_1: ${FILE11_1}" diff --git a/tests/usr/lib/ydf/components/package/ydf-package-service.i.bats b/tests/usr/lib/ydf/components/package/ydf-package-service.i.bats index fc8a958..11eaa03 100644 --- a/tests/usr/lib/ydf/components/package/ydf-package-service.i.bats +++ b/tests/usr/lib/ydf/components/package/ydf-package-service.i.bats @@ -1140,3 +1140,37 @@ line 11 > FAILED. INSTALLING packages ERROR> Installing packages" } + +# Tests for ydf::package_service::__instruction_preinstall() +@test "ydf::package_service::__instruction_preinstall() Should succeed With variables" { + + cd "${TEST_FIXTURES_DIR}/packages/23scriptvars" + + run ydf::package_service::__instruction_preinstall + + assert_success + assert_output "preinstall: FILE11_1: file11_1" +} + +# Tests for ydf::package_service::__instruction_install() +@test "ydf::package_service::__instruction_install() Should succeed With variables" { + + cd "${TEST_FIXTURES_DIR}/packages/23scriptvars" + + run ydf::package_service::__instruction_install + + assert_success + assert_output "install: MY_CONFIG1: my_config1 +install: HOME: /home/vedv" +} + +# Tests for ydf::package_service::__instruction_postinstall() +@test "ydf::package_service::__instruction_postinstall() Should succeed With variables" { + + cd "${TEST_FIXTURES_DIR}/packages/23scriptvars" + + run ydf::package_service::__instruction_postinstall + + assert_success + assert_output "postinstall: MY_CONFIG2: my config2" +}