install: improve handling of shared groups.
install: improve handling of shared groups.

Closes #26184.

princeofdarkness76/homebrew,princeofdarkness76/homebrew,princeofdarkness76/homebrew,princeofdarkness76/homebrew