brew/package/scripts/postinstall

55 lines
1.3 KiB
Plaintext
Raw Normal View History

2022-12-19 17:43:51 +01:00
#!/bin/bash
2022-12-23 09:10:01 +01:00
# $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
2022-12-19 17:43:51 +01:00
# verify the files exist
tmp_brew="$2"
2022-12-23 09:10:01 +01:00
if [[ ! -d "${tmp_brew:?}" ]]
then
echo "no directory at ${tmp_brew}, exiting"
exit 1
2022-12-19 17:43:51 +01:00
fi
# pick the correct target
2022-12-23 09:10:01 +01:00
if [[ $(uname -m) == "x86_64" ]]
then
2022-12-19 17:43:51 +01:00
target="/usr/local"
else
target="/opt/Homebrew"
fi
loggedInUser=$(echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }')
2022-12-23 09:10:01 +01:00
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:?}/*"
2022-12-19 17:43:51 +01:00
exit 0
2022-12-23 09:10:01 +01:00
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
2022-12-19 17:43:51 +01:00
fi
2022-12-23 09:10:01 +01:00
group=$(id -gn "${loggedInUser}")
2022-12-19 17:43:51 +01:00
2022-12-23 09:10:01 +01:00
install -d -o "${loggedInUser}" -g "${group}" "${target}"
cp -RX "${tmp_brew}/" "${target}"
2022-12-19 17:43:51 +01:00
# set permissions
2022-12-23 09:10:01 +01:00
chown -R "${loggedInUser}:${group}" "${target}/*"
2022-12-19 17:43:51 +01:00
# cleanup
rm -rf "${tmp_brew:?}/*"