Homebrew does not honor the default privileges of /usr/local; directory ownership is changed from root with group permissions for the wheel group to the installing user and the "admin" group. Specifically, the mode changes from drwxr-xr-x root wheel to drwxrwxr-x myuser admin. All files, not just the directories, have their ownership changed by the installer. This is considered by some as a major security flaw.[1]
MacPorts is superior and it is what the pros use. Now enough of that.
OP's method pays absolutely no attention to the BoM Receipts that every application installed with an installer will honor. This method doesn't consult the BoM, and obviously leaves stuff lying around.
BoMs are found in /var/db/receipts for all App Store installations and updates, and all other installations performed by the Installer app. macOS system, security, and security data updates have their BoMs stored in /System/Library/Receipts
Below somewhere is a superior uninstaller script I picked up at some point. First install the appropriate version of Xcode for your macOS version. Then install MacPorts package manager thusly:
curl -O https://distfiles.macports.org/MacPorts/MacPorts-2.7.2.tar.bz2
tar xjvf MacPorts-2.7.2.tar.bz2
cd MacPorts-2.7.2/
./configure
make
sudo make install #not war!
cd ..
sudo rm -rf Macports-*
sudo /opt/local/bin/port -vs selfupdate
Add this line to your ~/.bash_profile export PATH=$PATH:$HOME/bin:/opt/local/bin:/opt/local/sbin:/opt/local/share/man:/usr/X11/bin
Then drop below in a file in your ~/bin (or /usr/local/bin if you want all users to have access), maybe call it "uninstaller," and chmod +x uninstaller
-------------------------- #!/bin/bash
#uninstall application installed with installer -pkg
#using (user) provided bom receipt
#place all installed files and directories in user's Trash
lsbom="/usr/bin/lsbom"
cd="/usr/bin/cd"
sudo="/usr/bin/sudo"
xargs="/usr/bin/xargs"
rmtrash="/opt/local/bin/rmtrash"
lsbom -fls "$1" | (cd /; sudo xargs rmtrash -u $USER)
exit
--------------------------make sure to install rmtrash before using
sudo port -vsN install rmtrash
To make this clearer, user must find the BoM receipt and the path to the BoM for whatever application for the input for this script. Again find BoMs in /var/db/receipts or /System/Library/ReceiptsSo, for e.g., say you've installed an application called Test.app. First find the $PATH to the correct BoM then call its path with the script.
uninstaller /var/db/receipts/com.somedeveloper.test.bom
after entering password, this execution will uninstall everything that installer installed for Test.app because all those files are listed in the BoM, and it will move all files the Test.app installer installed into your Trash.I think it is just nuts to use /bin/rm in a script like this, so rmtrash is a little cli utility that moves things into your Trash, rather than deleting immediately. Much safer. Also, my script does not rely on Spotlight (mdfind). No telling what mdfind will return. Use the Bill of Materials receipts to uninstall, not Spotlight. That's crazy talk.
[1] https://en.wikipedia.org/wiki/Homebrew_(package_manager)#Imp...