move brew prefix check to new function, fix detecting installed packages, fix generating certificates fail when openssl is missing, fix #2038