From b94a55639bcbb01e4d34e5cde8579c9dbc499afd Mon Sep 17 00:00:00 2001 From: yunielrc87 Date: Thu, 14 Sep 2023 17:35:53 -0400 Subject: [PATCH] feat(package): add an instruction to install flatpak apps --- Vedvfile | 2 ++ .../package/ydf-package-service.bash | 21 +++++++++++++++++++ .../packages/7micenter@flathub/@flatpak | 1 + .../packages/7micenter@flathub/@pacman | 1 + .../fixtures/packages/7micenter@flathub/@yay | 1 + .../packages/7micenter@flathub/install | 1 + .../packages/7micenter@flathub/postinstall | 1 + .../packages/7micenter@flathub/preinstall | 1 + .../package/ydf-package-service.bats | 21 +++++++++++++++++++ 9 files changed, 50 insertions(+) create mode 100644 tests/fixtures/packages/7micenter@flathub/@flatpak create mode 100644 tests/fixtures/packages/7micenter@flathub/@pacman create mode 100644 tests/fixtures/packages/7micenter@flathub/@yay create mode 100644 tests/fixtures/packages/7micenter@flathub/install create mode 100644 tests/fixtures/packages/7micenter@flathub/postinstall create mode 100644 tests/fixtures/packages/7micenter@flathub/preinstall diff --git a/Vedvfile b/Vedvfile index d3fd5d2..d6ac5b1 100644 --- a/Vedvfile +++ b/Vedvfile @@ -12,5 +12,7 @@ COPY tools/install-run-manjaro tools COPY tools/install-dev-manjaro.vedv tools RUN tools/install-run-manjaro && tools/install-dev-manjaro.vedv +# install gnome base system +RUN sudo -H flatpak install --assumeyes --noninteractive io.github.andreibachim.shortcut COPY . . 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 93e0e14..75e0222 100644 --- a/src/usr/lib/ydf/components/package/ydf-package-service.bash +++ b/src/usr/lib/ydf/components/package/ydf-package-service.bash @@ -161,6 +161,27 @@ ydf::package_service::__instruction_@yay() { sudo yay -Syu --noconfirm --needed "${yay_pkg_name:-"$pkg_name"}" } +# +# Execute @flatpak instruction +# +# Arguments: +# pkg_name string package name +# +# Returns: +# 0 on success, non-zero on error. +# +ydf::package_service::__instruction_@flatpak() { + if [[ ! -f ./@flatpak ]]; then + return 0 + fi + + local -r pkg_name="$1" + # select the first no empty line + local -r flatpak_pkg_name="$(ydf::utils::print_1line <@flatpak)" + + sudo -H flatpak install --assumeyes --noninteractive flathub "${flatpak_pkg_name:-"$pkg_name"}" +} + # # Install a ydotfile package from a directory # diff --git a/tests/fixtures/packages/7micenter@flathub/@flatpak b/tests/fixtures/packages/7micenter@flathub/@flatpak new file mode 100644 index 0000000..566f59f --- /dev/null +++ b/tests/fixtures/packages/7micenter@flathub/@flatpak @@ -0,0 +1 @@ +io.missioncenter.MissionCenter diff --git a/tests/fixtures/packages/7micenter@flathub/@pacman b/tests/fixtures/packages/7micenter@flathub/@pacman new file mode 100644 index 0000000..016b6ef --- /dev/null +++ b/tests/fixtures/packages/7micenter@flathub/@pacman @@ -0,0 +1 @@ +echo '7micenter@flathub: @pacman succeed' diff --git a/tests/fixtures/packages/7micenter@flathub/@yay b/tests/fixtures/packages/7micenter@flathub/@yay new file mode 100644 index 0000000..2ac9b2a --- /dev/null +++ b/tests/fixtures/packages/7micenter@flathub/@yay @@ -0,0 +1 @@ +echo '7micenter@flathub: @yay succeed' diff --git a/tests/fixtures/packages/7micenter@flathub/install b/tests/fixtures/packages/7micenter@flathub/install new file mode 100644 index 0000000..25a8c59 --- /dev/null +++ b/tests/fixtures/packages/7micenter@flathub/install @@ -0,0 +1 @@ +echo '7micenter@flathub: install succeed' diff --git a/tests/fixtures/packages/7micenter@flathub/postinstall b/tests/fixtures/packages/7micenter@flathub/postinstall new file mode 100644 index 0000000..7c3fa9a --- /dev/null +++ b/tests/fixtures/packages/7micenter@flathub/postinstall @@ -0,0 +1 @@ +echo '7micenter@flathub: postinstall succeed' diff --git a/tests/fixtures/packages/7micenter@flathub/preinstall b/tests/fixtures/packages/7micenter@flathub/preinstall new file mode 100644 index 0000000..cf8fe66 --- /dev/null +++ b/tests/fixtures/packages/7micenter@flathub/preinstall @@ -0,0 +1 @@ +echo '7micenter@flathub: preinstall succeed' diff --git a/tests/usr/lib/ydf/components/package/ydf-package-service.bats b/tests/usr/lib/ydf/components/package/ydf-package-service.bats index dd0a5af..3112805 100644 --- a/tests/usr/lib/ydf/components/package/ydf-package-service.bats +++ b/tests/usr/lib/ydf/components/package/ydf-package-service.bats @@ -267,3 +267,24 @@ preinstall" assert_success assert_output --regexp "nnn" } + +# Tests for ydf::package_service::__instruction_@flatpak() +@test "ydf::package_service::__instruction_@flatpak() Should succeed Without instruction file" { + + cd "${TEST_FIXTURES_DIR}/packages/0empty" + + run ydf::package_service::__instruction_@flatpak + + assert_success + assert_output "" +} + +@test "ydf::package_service::__instruction_@flatpak() Should succeed" { + + cd "${TEST_FIXTURES_DIR}/packages/7micenter@flathub" + + run ydf::package_service::__instruction_@flatpak '7micenter@flathub' + + assert_success + assert_output --partial "Installing app/io.missioncenter.MissionCenter/x86_64/stable" +}