diff --git a/Library/Homebrew/style.rb b/Library/Homebrew/style.rb index 6beacb720b..544249a26b 100644 --- a/Library/Homebrew/style.rb +++ b/Library/Homebrew/style.rb @@ -263,6 +263,7 @@ module Homebrew HOMEBREW_REPOSITORY/"completions/bash/brew", HOMEBREW_REPOSITORY/"Dockerfile", *HOMEBREW_REPOSITORY.glob(".devcontainer/**/*.sh"), + *HOMEBREW_REPOSITORY.glob("package/scripts/*"), *HOMEBREW_LIBRARY.glob("Homebrew/**/*.sh").reject { |path| path.to_s.include?("/vendor/") }, *HOMEBREW_LIBRARY.glob("Homebrew/shims/**/*").map(&:realpath).uniq .reject(&:directory?) diff --git a/package/scripts/postinstall b/package/scripts/postinstall index c0cfffc7b0..7ea0389bb5 100755 --- a/package/scripts/postinstall +++ b/package/scripts/postinstall @@ -1,42 +1,54 @@ #!/bin/bash +# $1 Full path to the installer - unused +# $2 Location of the temporary brew install we're moving into place +# $3 Target install location - unused +# $4 System root directory - unused set -e # verify the files exist tmp_brew="$2" -if [[ ! -d "${tmp_brew:?}" ]]; then - echo "no directory at $tmp_brew, exiting" - exit 1 +if [[ ! -d "${tmp_brew:?}" ]] +then + echo "no directory at ${tmp_brew}, exiting" + exit 1 fi # pick the correct target -if [[ $(uname -m) == "x86_64" ]];then +if [[ $(uname -m) == "x86_64" ]] +then target="/usr/local" else target="/opt/Homebrew" fi loggedInUser=$(echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }') -if [[ -f "$target/bin/brew" ]]; then - if [[ $(sudo -u"$loggedInUser" "$target/bin/brew" developer) =~ "enabled" ]]; then - echo "developer install, exiting" - exit 0 - fi - if [[ $("$tmp_brew/bin/brew" --version | head -n1) != $("$target/bin/brew" --version | head -n1) ]]; then - echo "already an outdated install at $target, updating" - sudo -u"$loggedInUser" "$target/bin/brew" update --auto-update - else - echo "already an up-to-date install at $target, exiting" - fi +if [[ -f "${target}/bin/brew" ]] +then + if [[ $(sudo -u"${loggedInUser}" git -C "${target}" branch --show-current) != "master" ]] + then + echo "working on brew modifications, exiting" + rm -rf "${tmp_brew:?}/*" exit 0 + fi + if [[ $("${tmp_brew}/bin/brew" --version | head -n1) != $("${target}/bin/brew" --version | head -n1) ]] + then + echo "already an outdated install at ${target}, updating" + sudo -u"${loggedInUser}" "${target}/bin/brew" update --auto-update + else + echo "already an up-to-date install at ${target}, exiting" + fi + + rm -rf "${tmp_brew:?}/*" + exit 0 fi -group=$(id -gn "$loggedInUser") +group=$(id -gn "${loggedInUser}") -install -d -o "$loggedInUser" -g "$group" "$target" -cp -RX "$tmp_brew/" "$target" +install -d -o "${loggedInUser}" -g "${group}" "${target}" +cp -RX "${tmp_brew}/" "${target}" # set permissions -chown -R "$loggedInUser:$group" "$target/*" +chown -R "${loggedInUser}:${group}" "${target}/*" # cleanup rm -rf "${tmp_brew:?}/*" diff --git a/package/scripts/preinstall b/package/scripts/preinstall index 03bbcac607..49afc85251 100755 --- a/package/scripts/preinstall +++ b/package/scripts/preinstall @@ -1,16 +1,32 @@ #!/bin/bash # Checked for installed CLT -if [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]]; then +if [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]] +then exit 0 fi -if [[ -z "$COMMAND_LINE_INSTALL" ]]; then - printf "No auto-install of CommandLine Tools in headless install!" - exit 1 -fi +CLT_PLACEHOLDER="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress" +touch "${CLT_PLACEHOLDER}" -if ! /usr/bin/xcode-select --install; then - printf "Failed to install CommandLine Tools!" - exit 1 +CLT_PACKAGE=$(softwareupdate -l | + grep -B 1 "Command Line Tools" | + awk -F"*" '/^ *\*/ {print $2}' | + sed -e 's/^ *Label: //' -e 's/^ *//' | + sort -V | + tail -n1) +softwareupdate -i "${CLT_PACKAGE}" +rm -f "${CLT_PLACEHOLDER}" +if ! [[ -f "/Library/Developer/CommandLineTools/usr/bin/git" ]] +then + if [[ -z "${COMMAND_LINE_INSTALL}" ]] + then + echo + printf "Requesting user install of Xcode Command Line Tools:" + /usr/bin/xcode-select --install + else + echo + printf "Run 'xcode-select --install' to install the Xcode Command Line Tools before running a headless brew install." + exit 1 + fi fi