From ed4a2684c579d0afe3e09be262fc422d7b81adad Mon Sep 17 00:00:00 2001 From: yunielrc87 Date: Sat, 16 Sep 2023 13:06:30 -0400 Subject: [PATCH] feat(package): add an instruction homeln to create files symlinks on home --- .../package/ydf-package-service.bash | 23 +++++++++++++++---- .../packages/11homeln/homeln/.my-config.env | 1 + .../packages/11homeln/homeln/.my/dir1/file11 | 1 + .../packages/11homeln/homeln/.my/file1 | 1 + .../packages/11homeln/homeln/.my/file2 | 1 + .../packages/com.getpostman.Postman/.flatpak | 0 .../packages/com.stremio.Stremio/.flatpak | 0 .../package/ydf-package-command.f.bats | 8 +++---- .../package/ydf-package-service.i.bats | 15 ++++++++++++ tools/ct-clean-exec | 5 ++-- 10 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 tests/fixtures/packages/11homeln/homeln/.my-config.env create mode 100644 tests/fixtures/packages/11homeln/homeln/.my/dir1/file11 create mode 100644 tests/fixtures/packages/11homeln/homeln/.my/file1 create mode 100644 tests/fixtures/packages/11homeln/homeln/.my/file2 delete mode 100644 tests/fixtures/packages/com.getpostman.Postman/.flatpak delete mode 100644 tests/fixtures/packages/com.stremio.Stremio/.flatpak 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 b57bf35..a3bad1f 100644 --- a/src/usr/lib/ydf/components/package/ydf-package-service.bash +++ b/src/usr/lib/ydf/components/package/ydf-package-service.bash @@ -4,6 +4,8 @@ # Manage packages # +shopt -s dotglob + # # FOR CODE COMPLETION # @@ -19,17 +21,17 @@ fi # # declare -rA __YDF_PACKAGE_SERVICE_INSTRUCTIONS=( -# [common]="pre_install install post_install home homeln homecp homecps homecat root rootcp rootcps rootln rootcat flatpack dconf.ini plugin_zsh docker_compose" +# [common]="preinstall install postinstall flatpack dconf.ini plugin_zsh docker_compose homeln homelnr homecp homecps homecat rootln rootlnr rootcp rootcps rootcat" # [manjaro]="pacman yay" # [ubuntu]="apt" # ) -# readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON='home homeln homecp homecps homecat root rootcp rootcps rootln rootcat flatpack dconf.ini plugin_zsh docker_compose' +# readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON='preinstall install postinstall flatpack dconf.ini plugin_zsh docker_compose homeln homelnr homecp homecps homecat rootln rootlnr rootcp rootcps rootcat' # readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_MANJARO="preinstall pacman yay install postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}" # readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_UBUNTU="preinstall apt install postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}" # shellcheck disable=SC2016 -readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON='plugin_zsh:${pkg_name}.plugin.zsh' -readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_MANJARO="preinstall install @pacman @yay @flatpak @snap docker_compose:docker-compose.yml postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}" +readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON='install @flatpak @snap docker_compose:docker-compose.yml plugin_zsh:${pkg_name}.plugin.zsh homeln postinstall' +readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_MANJARO="preinstall @pacman @yay ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}" # readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_UBUNTU="preinstall install postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}" # @@ -221,6 +223,19 @@ ydf::package_service::__instruction_plugin_zsh() { fi } +# +# Execute homeln instruction +# +# Arguments: +# pkg_name string package name +# +# Returns: +# 0 on success, non-zero on error. +# +ydf::package_service::__instruction_homeln() { + ln -vsf --backup "${PWD}/homeln/"* ~/ +} + # # Install a ydotfile package from a directory # diff --git a/tests/fixtures/packages/11homeln/homeln/.my-config.env b/tests/fixtures/packages/11homeln/homeln/.my-config.env new file mode 100644 index 0000000..c191b3b --- /dev/null +++ b/tests/fixtures/packages/11homeln/homeln/.my-config.env @@ -0,0 +1 @@ +my-config diff --git a/tests/fixtures/packages/11homeln/homeln/.my/dir1/file11 b/tests/fixtures/packages/11homeln/homeln/.my/dir1/file11 new file mode 100644 index 0000000..e1aa36f --- /dev/null +++ b/tests/fixtures/packages/11homeln/homeln/.my/dir1/file11 @@ -0,0 +1 @@ +file11 diff --git a/tests/fixtures/packages/11homeln/homeln/.my/file1 b/tests/fixtures/packages/11homeln/homeln/.my/file1 new file mode 100644 index 0000000..e212970 --- /dev/null +++ b/tests/fixtures/packages/11homeln/homeln/.my/file1 @@ -0,0 +1 @@ +file1 diff --git a/tests/fixtures/packages/11homeln/homeln/.my/file2 b/tests/fixtures/packages/11homeln/homeln/.my/file2 new file mode 100644 index 0000000..6c493ff --- /dev/null +++ b/tests/fixtures/packages/11homeln/homeln/.my/file2 @@ -0,0 +1 @@ +file2 diff --git a/tests/fixtures/packages/com.getpostman.Postman/.flatpak b/tests/fixtures/packages/com.getpostman.Postman/.flatpak deleted file mode 100644 index e69de29..0000000 diff --git a/tests/fixtures/packages/com.stremio.Stremio/.flatpak b/tests/fixtures/packages/com.stremio.Stremio/.flatpak deleted file mode 100644 index e69de29..0000000 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 275678f..2a50b33 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 @@ -123,8 +123,8 @@ ydf package COMMAND' assert_success assert_output --regexp "5dust@pacman: preinstall succeed -5dust@pacman: install succeed .* +5dust@pacman: install succeed 5dust@pacman: postinstall succeed" run command -v dust @@ -140,8 +140,8 @@ ydf package COMMAND' assert_success assert_output --regexp "bat: preinstall succeed -bat: install succeed .* +bat: install succeed bat: postinstall succeed" run command -v bat @@ -158,8 +158,8 @@ bat: postinstall succeed" assert_success assert_output --regexp "6nnn@yay: preinstall succeed -6nnn@yay: install succeed .* +6nnn@yay: install succeed 6nnn@yay: postinstall succeed" run command -v nnn @@ -175,8 +175,8 @@ bat: postinstall succeed" assert_success assert_output --regexp "rustscan: preinstall succeed -rustscan: install succeed .* +rustscan: install succeed rustscan: postinstall succeed" run command -v rustscan 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 71d451a..90dd48b 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 @@ -338,3 +338,18 @@ docker_compose" assert_output "'/home/vedv/.yzsh/plugins/local/10ydfplugin.plugin.zsh' -> '/home/vedv/ydf/tests/fixtures/packages/10ydfplugin/10ydfplugin.plugin.zsh' Plugin '10ydfplugin' already added to /home/vedv/.yzsh-gen.env" } + +@test "ydf::package_service::__instruction_homeln() Should add plugin" { + cd "${TEST_FIXTURES_DIR}/packages/11homeln" + + run ydf::package_service::__instruction_homeln '11homeln' + + assert_success + assert_output "'/home/vedv/.my' -> '/home/vedv/ydf/tests/fixtures/packages/11homeln/homeln/.my' +'/home/vedv/.my-config.env' -> '/home/vedv/ydf/tests/fixtures/packages/11homeln/homeln/.my-config.env'" + + assert [ -L '/home/vedv/.my' ] + assert [ -d '/home/vedv/.my' ] + assert [ -L '/home/vedv/.my-config.env' ] + assert [ -f '/home/vedv/.my-config.env' ] +} diff --git a/tools/ct-clean-exec b/tools/ct-clean-exec index 927eeeb..d855c18 100755 --- a/tools/ct-clean-exec +++ b/tools/ct-clean-exec @@ -53,8 +53,7 @@ vedv container exec "$VEDV_CONTAINER_NAME" "$@" || EXIT_STATUS=$? # shellcheck disable=SC2155 readonly end_time=$(date +%s%N) -echo ">>>time: $(((end_time - start_time) / 1000000)) ms." -echo ">>Command executed" +echo ">>Command executed, time: $(((end_time - start_time) / 1000000)) ms." echo echo ">>Removing dirty container" @@ -67,7 +66,7 @@ vedv container create --name "$VEDV_CONTAINER_NAME" "$VEDV_IMAGE_NAME" echo ">>Container created" echo -echo ">>Starting container for the next run in background. It can take up to 30 seconds for container to be ready" +echo ">>Starting container in background for the next run. It can take up to 30 seconds for container to be ready" echo vedv container start "$VEDV_CONTAINER_NAME" &>/dev/null