Skip to content

Commit

Permalink
Allow to add/remove/update pkgx packages
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecrs committed Apr 27, 2024
1 parent d2bf217 commit 9c33d14
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
43 changes: 43 additions & 0 deletions home/.chezmoiscripts/run_after_30-install-pkgx-packages.sh.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

# {{ template "scripts-library" }}

# The following line is for ShellCheck to correctly identify the above include
true || source ../.chezmoitemplates/scripts-library

ensure_path_entry "${HOME}/.local/bin"

function is_pkgx_package_installed() {
local package="$1"

grep --quiet --recursive --binary-files=without-match --word-regexp \
"exec pkgx +${package} --" "${HOME}/.local/bin"
}

readonly unwanted_packages=()

for package in "${unwanted_packages[@]}"; do
# shellcheck disable=SC2310
if is_pkgx_package_installed "${package}"; then
log_task "Removing unwanted package '${package}' installed with pkgx"
pkgx uninstall "${package}"
fi
done

readonly wanted_packages=(
opendev.org/git-review
)

missing_packages=()

for package in "${wanted_packages[@]}"; do
# shellcheck disable=SC2310
if ! is_pkgx_package_installed "${package}"; then
missing_packages+=("${package}")
fi
done

if [[ ${#missing_packages[@]} -gt 0 ]]; then
log_task "Installing missing packages with pkgx: ${missing_packages[*]}"
pkgx install "${missing_packages[@]}"
fi
20 changes: 19 additions & 1 deletion home/dot_local/bin/executable_full-upgrade.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ true || source ../../.chezmoitemplates/homebrew-library
true || source ../../.chezmoitemplates/volta-library
true || source ../../.chezmoitemplates/sdkman-library

ensure_path_entry "${HOME}/.local/bin"

if [[ "${CONTINUE_FROM_DOTFILES:-false}" == false ]]; then
if brew --version &>/dev/null; then
(
Expand All @@ -29,7 +31,7 @@ if [[ "${CONTINUE_FROM_DOTFILES:-false}" == false ]]; then
if chezmoi --version &>/dev/null; then
log_task "Updating dotfiles"
# Pull latest changes from dotfiles repo
c chezmoi update --apply=false
# c chezmoi update --apply=false
# Apply changes to chezmoi config
c chezmoi init --force
# Apply the rest
Expand All @@ -39,6 +41,22 @@ if [[ "${CONTINUE_FROM_DOTFILES:-false}" == false ]]; then
CONTINUE_FROM_DOTFILES=true exec "$0" "$@"
fi

if pkgx --version >/dev/null; then
log_task "Updating pkgx stubs"

pkgx_packages="$(
{ grep --recursive --binary-files=without-match --no-filename --only-matching --perl-regexp 'exec pkgx \+\K[^ ]+' "${HOME}/.local/bin" || true; } | sort --unique
)"

echo "${pkgx_packages}" | xargs --no-run-if-empty pkgx uninstall
echo "${pkgx_packages}" | xargs --no-run-if-empty pkgx install

log_task "Updating pkgx packages"

# TODO: this will install all missing packages, ideally we should only update the ones that are already installed
echo "${pkgx_packages}" | sed 's/^/+/g' | xargs --no-run-if-empty pkgx --sync --update >/dev/null
fi

if apt --version &>/dev/null; then
log_task "Updating apt packages"
c sudo DEBIAN_FRONTEND=noninteractive apt update --yes
Expand Down
2 changes: 0 additions & 2 deletions home/dot_local/bin/executable_git-review

This file was deleted.

0 comments on commit 9c33d14

Please sign in to comment.