diff --git a/Makefile b/Makefile index 7bb6875..eb7cd55 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # grep -Po '^\S+(?=:)' Makefile | tr '\n' ' ' -.PHONY: install install-run-manjaro install-dev-manjaro commit rebuild build create start status stop remove login test-unit test-integration test-functional test-all test-suite test-name +.PHONY: install install-run-manjaro install-dev-manjaro commit img-rebuild img-build ct-create ct-start ct-status ct-stop ct-remove ct-login ct-copy-files prepare-test-environment test-unit test-integration test-functional test-all test-suite test-name install: DESTDIR="$${DESTDIR:-}" ./install diff --git a/Makefile.vedv b/Makefile.vedv index f7e3767..5e73c72 100644 --- a/Makefile.vedv +++ b/Makefile.vedv @@ -1,5 +1,5 @@ # grep -Po '^\S+(?=:)' Makefile.vedv | tr '\n' ' ' -.PHONY: install-run-manjaro install-dev-manjaro test-unit test-integration test-functional test-all test-suite test-tag test-name +.PHONY: install-run-manjaro install-dev-manjaro test-unit test-integration test-functional test-all test-suite test-name install-run-manjaro: ./tools/install-run-manjaro 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 809107e..40a1d7a 100644 --- a/src/usr/lib/ydf/components/package/ydf-package-service.bash +++ b/src/usr/lib/ydf/components/package/ydf-package-service.bash @@ -29,7 +29,7 @@ fi # readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_UBUNTU="preinstall apt install postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}" readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON='' -readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_MANJARO="preinstall install pacman postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}" +readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_MANJARO="preinstall install @pacman postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}" readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_UBUNTU="preinstall install postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}" # @@ -119,6 +119,27 @@ ydf::package_service::__instruction_postinstall() { bash ./postinstall } +# +# Execute .pacman instruction +# +# Arguments: +# pkg_name string package name +# +# Returns: +# 0 on success, non-zero on error. +# +ydf::package_service::__instruction_@pacman() { + if [[ ! -f ./@pacman ]]; then + return 0 + fi + + local -r pkg_name="$1" + # select the first no empty line + local -r pacman_pkg_name="$(grep -Pom1 '(\S+\s*)+\S+' ./@pacman)" + + sudo pacman -Syu --noconfirm --needed "${pacman_pkg_name:-"$pkg_name"}" +} + # # Install a ydotfile package from a directory # @@ -159,6 +180,8 @@ ydf::package_service::install_one_from_dir() { instr_arr=($instr) readonly instr_arr + local -r pkg_name="${package_dir##*/}" + ( cd "$package_dir" 2>/dev/null || { err "Changing the current directory to ${package_dir}" @@ -168,7 +191,7 @@ ydf::package_service::install_one_from_dir() { for iname in "${instr_arr[@]}"; do local ifunction="ydf::package_service::__instruction_${iname}" - "$ifunction" || { + "$ifunction" "$pkg_name" || { err "Executing instruction '${iname}' on '${package_dir}'" return "$ERR_YPS_INSTRUCTION_FAIL" } diff --git a/tests/fixtures/packages/4dust@pacman/@pacman b/tests/fixtures/packages/4dust@pacman/@pacman new file mode 100644 index 0000000..30ea963 --- /dev/null +++ b/tests/fixtures/packages/4dust@pacman/@pacman @@ -0,0 +1,2 @@ + +dust diff --git a/tests/fixtures/packages/4dust@pacman/install b/tests/fixtures/packages/4dust@pacman/install new file mode 100644 index 0000000..d7ba47c --- /dev/null +++ b/tests/fixtures/packages/4dust@pacman/install @@ -0,0 +1 @@ +echo '4dust@pacman: install succeed' diff --git a/tests/fixtures/packages/4dust@pacman/postinstall b/tests/fixtures/packages/4dust@pacman/postinstall new file mode 100644 index 0000000..fb33316 --- /dev/null +++ b/tests/fixtures/packages/4dust@pacman/postinstall @@ -0,0 +1 @@ +echo '4dust@pacman: postinstall succeed' diff --git a/tests/fixtures/packages/4dust@pacman/preinstall b/tests/fixtures/packages/4dust@pacman/preinstall new file mode 100644 index 0000000..b15fae9 --- /dev/null +++ b/tests/fixtures/packages/4dust@pacman/preinstall @@ -0,0 +1 @@ +echo '4dust@pacman: preinstall succeed' diff --git a/tests/usr/lib/ydf/components/package/ydf-package-command.f.bats b/tests/usr/lib/ydf/components/package/ydf-package-command.f.bats index 0e69a70..a885dc9 100644 --- a/tests/usr/lib/ydf/components/package/ydf-package-command.f.bats +++ b/tests/usr/lib/ydf/components/package/ydf-package-command.f.bats @@ -106,3 +106,21 @@ ydf package COMMAND' 4postinstall: install succeed 4postinstall: postinstall succeed" } + +# Tests for ydf package install ../4dust@pacman +@test "ydf package install ../4dust@pacman, Should succeed" { + local -r _package_dir="${TEST_FIXTURES_DIR}/packages/4dust@pacman" + + run ydf package install "$_package_dir" + + assert_success + assert_output --regexp "4dust@pacman: preinstall succeed +4dust@pacman: install succeed +.* +4dust@pacman: postinstall succeed" + + run command -v dust + + assert_success + assert_output "/usr/bin/dust" +}