Skip to content

Commit

Permalink
feat(package): add instruction pacman to install apps for manjaro
Browse files Browse the repository at this point in the history
  • Loading branch information
yunielrc committed Sep 14, 2023
1 parent 7437a01 commit e29623b
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Makefile.vedv
Original file line number Diff line number Diff line change
@@ -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
Expand Down
27 changes: 25 additions & 2 deletions src/usr/lib/ydf/components/package/ydf-package-service.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

#
Expand Down Expand Up @@ -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
#
Expand Down Expand Up @@ -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}"
Expand All @@ -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"
}
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/packages/4dust@pacman/@pacman
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

dust
1 change: 1 addition & 0 deletions tests/fixtures/packages/4dust@pacman/install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo '4dust@pacman: install succeed'
1 change: 1 addition & 0 deletions tests/fixtures/packages/4dust@pacman/postinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo '4dust@pacman: postinstall succeed'
1 change: 1 addition & 0 deletions tests/fixtures/packages/4dust@pacman/preinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo '4dust@pacman: preinstall succeed'
18 changes: 18 additions & 0 deletions tests/usr/lib/ydf/components/package/ydf-package-command.f.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit e29623b

Please sign in to comment.