Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions share/ruby-install/package_manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,17 @@ function install_packages()
pkg) $sudo pkg install -y "$@" || return $? ;;
brew)
local brew_owner="$(/usr/bin/stat -f %Su "$(command -v brew)")"
sudo -u "$brew_owner" brew install "$@" ||
sudo -u "$brew_owner" brew upgrade "$@" || return $?
local installed=$(sudo -u "$brew_owner" brew list -1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since casks are now shown with brew list this should probably have a --formula flag.

local -a missing_pkgs

for dep in "$@"; do
[[ "$installed" =~ [[:space:]]"$dep" ]] || missing_pkgs+=($dep)
done

if (( ${#missing_pkgs[@]} > 0 )); then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to check formula one at a time with brew list --formula --version foo so the absence of one won't inadvertently upgrade another?

sudo -u "$brew_owner" brew install "${missing_pkgs[@]}" ||
sudo -u "$brew_owner" brew upgrade "${missing_pkgs[@]}" || return $?
fi
;;
pacman)
local missing_pkgs=($(pacman -T "$@"))
Expand Down