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 3b551b3
Show file tree
Hide file tree
Showing 3 changed files with 79 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
37 changes: 36 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,39 @@ 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
)"

if [[ -z "${pkgx_packages}" ]]; then
log_info "No pkgx packages found"
else
readarray -t pkgx_packages <<<"${pkgx_packages}"

pkgx uninstall "${pkgx_packages[@]}"
pkgx install "${pkgx_packages[@]}"

log_task "Updating pkgx packages"

pkgx_packages_to_update=()
for package in "${pkgx_packages[@]}"; do
if [[ -d "${PKGX_DIR:-"${HOME}/.pkgx"}/${package}" ]]; then
pkgx_packages_to_update+=("+${package}")
fi
done

if [[ "${#pkgx_packages_to_update[@]}" -gt 0 ]]; then
pkgx --sync --update "${pkgx_packages_to_update[@]}" >/dev/null
fi

unset pkgx_packages_to_update
fi
unset pkgx_packages
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 3b551b3

Please sign in to comment.