0

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!

hxvxt2
  • 39
  • 1
  • 4
  • 1
    `brew` is in your `PATH`. `pkgbuild` does not know about your `PATH`. You should check what `PATH` it is using. – jeremysprofile Sep 29 '20 at 19:00
  • @jeremysprofile Thanks for pointing it out. But, I tried with the absolute path as well. It complained about running homebrew as root is dangerous. I don't understand why it thinks I'm running Brew as root. I'll update the question for more clarity. – hxvxt2 Sep 30 '20 at 04:33
  • Are you doing `sudo pkgbuild`? – jeremysprofile Sep 30 '20 at 04:35
  • No, it's is plain old `pkgbuild` @jeremysprofile – hxvxt2 Sep 30 '20 at 04:54
  • I don't see in your script any invocation of `pkgbuild`, so I assume that you are doing it in a different context. Did you verify the PATH just before running `pkgbuild`? – user1934428 Oct 01 '20 at 06:44

0 Answers0