Brew is installed but not identified as a command inside postinstall script of `pkgbuild` (MacOS)

320 views Asked by At

I have a small shell script that installs Brew if it is not already installed.

#!/bin/bash -v

which -s brew
if [[ $? != 0 ]] ; then
    # Install Homebrew
    echo "Installing Brew..."
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
    echo "I don't think brew is installed..."

else
    brew update
fi

The script runs fine when I run it as a standalone shell script. So I tried to create a package using the pkgbuild utility. But once inside the package the same script fails to identify Brew as a command, even though Brew is installed.

Things that I have tried so far:-

  1. I enabled install logs and I can see
Sep 29 22:48:32 installd[80453]: ./postinstall:
    /tmp/PKInstallSandbox.42j7tU/Scripts/org.mybinary.0.0.4.sDKM7K/postinstall:
    line 16: brew: command not found
  1. Used absolute path of the Brew binary /usr/local/bin/brew instead. This gave me a different but, nevertheless, still an error.
Sep 30 10:01:22 installd[90276]: ./postinstall: Error: Running Homebrew as root is extremely dangerous and no longer supported.
Sep 30 10:01:22 installd[90276]: ./postinstall: As Homebrew does not drop privileges on installation you would be giving all
Sep 30 10:01:22 installd[90276]: ./postinstall: build scripts full access to your system.

What am I missing?

Thanks!

0

There are 0 answers