Added automatic detection of package manager.

Still need to install macports to check if it’s the correct directory.
Fixed an error with counting brew packages. Simplifed the code.