Update package/scripts/postinstall

This commit is contained in:
Sean Molenaar 2022-12-23 09:10:01 +01:00 committed by Sean Molenaar
parent d2aed31387
commit f30779c6bf
No known key found for this signature in database
GPG Key ID: AAC1C7E1A4696A9A
3 changed files with 56 additions and 27 deletions

View File

@ -263,6 +263,7 @@ module Homebrew
HOMEBREW_REPOSITORY/"completions/bash/brew", HOMEBREW_REPOSITORY/"completions/bash/brew",
HOMEBREW_REPOSITORY/"Dockerfile", HOMEBREW_REPOSITORY/"Dockerfile",
*HOMEBREW_REPOSITORY.glob(".devcontainer/**/*.sh"), *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/**/*.sh").reject { |path| path.to_s.include?("/vendor/") },
*HOMEBREW_LIBRARY.glob("Homebrew/shims/**/*").map(&:realpath).uniq *HOMEBREW_LIBRARY.glob("Homebrew/shims/**/*").map(&:realpath).uniq
.reject(&:directory?) .reject(&:directory?)

View File

@ -1,42 +1,54 @@
#!/bin/bash #!/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 set -e
# verify the files exist # verify the files exist
tmp_brew="$2" tmp_brew="$2"
if [[ ! -d "${tmp_brew:?}" ]]; then if [[ ! -d "${tmp_brew:?}" ]]
echo "no directory at $tmp_brew, exiting" then
exit 1 echo "no directory at ${tmp_brew}, exiting"
exit 1
fi fi
# pick the correct target # pick the correct target
if [[ $(uname -m) == "x86_64" ]];then if [[ $(uname -m) == "x86_64" ]]
then
target="/usr/local" target="/usr/local"
else else
target="/opt/Homebrew" target="/opt/Homebrew"
fi fi
loggedInUser=$(echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }') loggedInUser=$(echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }')
if [[ -f "$target/bin/brew" ]]; then if [[ -f "${target}/bin/brew" ]]
if [[ $(sudo -u"$loggedInUser" "$target/bin/brew" developer) =~ "enabled" ]]; then then
echo "developer install, exiting" if [[ $(sudo -u"${loggedInUser}" git -C "${target}" branch --show-current) != "master" ]]
exit 0 then
fi echo "working on brew modifications, exiting"
if [[ $("$tmp_brew/bin/brew" --version | head -n1) != $("$target/bin/brew" --version | head -n1) ]]; then rm -rf "${tmp_brew:?}/*"
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
exit 0 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 fi
group=$(id -gn "$loggedInUser") group=$(id -gn "${loggedInUser}")
install -d -o "$loggedInUser" -g "$group" "$target" install -d -o "${loggedInUser}" -g "${group}" "${target}"
cp -RX "$tmp_brew/" "$target" cp -RX "${tmp_brew}/" "${target}"
# set permissions # set permissions
chown -R "$loggedInUser:$group" "$target/*" chown -R "${loggedInUser}:${group}" "${target}/*"
# cleanup # cleanup
rm -rf "${tmp_brew:?}/*" rm -rf "${tmp_brew:?}/*"

View File

@ -1,16 +1,32 @@
#!/bin/bash #!/bin/bash
# Checked for installed CLT # Checked for installed CLT
if [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]]; then if [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]]
then
exit 0 exit 0
fi fi
if [[ -z "$COMMAND_LINE_INSTALL" ]]; then CLT_PLACEHOLDER="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress"
printf "No auto-install of CommandLine Tools in headless install!" touch "${CLT_PLACEHOLDER}"
exit 1
fi
if ! /usr/bin/xcode-select --install; then CLT_PACKAGE=$(softwareupdate -l |
printf "Failed to install CommandLine Tools!" grep -B 1 "Command Line Tools" |
exit 1 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 fi