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/"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?)

View File

@ -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"
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"
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
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"
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:?}/*"

View File

@ -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!"
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