Ask pacman only for the packages pkg-add finds missing
This commit is contained in:
1 parent
a3e40cb8b0
commit
a77c246d38
2 files changed
+48
-3
No files matched your search
+9
-3
@@ -5,11 +5,17 @@
|
|||||||
# omarchy:examples=omarchy pkg add jq ripgrep
|
# omarchy:examples=omarchy pkg add jq ripgrep
|
||||||
# omarchy:requires-sudo=true
|
# omarchy:requires-sudo=true
|
||||||
|
|
||||||
if omarchy-pkg-missing "$@"; then
|
# Only the missing ones: an installed package from no repository is a "target not found" to pacman -S.
|
||||||
|
missing=()
|
||||||
|
for pkg in "$@"; do
|
||||||
|
omarchy-pkg-missing "$pkg" && missing+=("$pkg")
|
||||||
|
done
|
||||||
|
|
||||||
|
if (( ${#missing[@]} > 0 )); then
|
||||||
if (( EUID == 0 )); then
|
if (( EUID == 0 )); then
|
||||||
pacman -S --noconfirm --needed -- "$@" || exit 1
|
pacman -S --noconfirm --needed -- "${missing[@]}" || exit 1
|
||||||
else
|
else
|
||||||
sudo pacman -S --noconfirm --needed -- "$@" || exit 1
|
sudo pacman -S --noconfirm --needed -- "${missing[@]}" || exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
|
||||||
|
|
||||||
|
test_tmp=$(mktemp -d)
|
||||||
|
trap 'rm -rf "$test_tmp"' EXIT
|
||||||
|
|
||||||
|
mock_path="$test_tmp/bin"
|
||||||
|
mkdir -p "$mock_path"
|
||||||
|
cat >"$mock_path/pacman" <<'MOCK'
|
||||||
|
#!/bin/bash
|
||||||
|
if [[ $1 == "-Q" ]]; then
|
||||||
|
[[ " $TEST_INSTALLED " == *" $3 "* ]]
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
printf '%s\n' "$*" >>"$TEST_TMP/pacman-sync"
|
||||||
|
for arg in "$@"; do
|
||||||
|
[[ $arg == -* ]] || TEST_INSTALLED+=" $arg"
|
||||||
|
done
|
||||||
|
printf '%s\n' "$TEST_INSTALLED" >"$TEST_TMP/installed"
|
||||||
|
MOCK
|
||||||
|
cat >"$mock_path/sudo" <<'MOCK'
|
||||||
|
#!/bin/bash
|
||||||
|
exec "$@"
|
||||||
|
MOCK
|
||||||
|
chmod +x "$mock_path"/*
|
||||||
|
export PATH="$mock_path:$ROOT/bin:$PATH" TEST_TMP="$test_tmp"
|
||||||
|
|
||||||
|
TEST_INSTALLED="local-only fcitx5" "$ROOT/bin/omarchy-pkg-add" fcitx5-rime local-only opencc >/dev/null 2>&1 || true
|
||||||
|
[[ $(<"$test_tmp/pacman-sync") == "-S --noconfirm --needed -- fcitx5-rime opencc" ]] ||
|
||||||
|
fail "pkg-add asks pacman only for the missing packages" "$(<"$test_tmp/pacman-sync")"
|
||||||
|
pass "an installed package from no repository is left out of the pacman -S call"
|
||||||
|
|
||||||
|
rm -f "$test_tmp/pacman-sync"
|
||||||
|
TEST_INSTALLED="local-only fcitx5" "$ROOT/bin/omarchy-pkg-add" local-only fcitx5
|
||||||
|
[[ ! -e $test_tmp/pacman-sync ]] || fail "pkg-add runs no transaction when nothing is missing" "$(<"$test_tmp/pacman-sync")"
|
||||||
|
pass "pkg-add runs no transaction when everything is installed"
|
||||||
Reference in new issue
Block a user