fix: ensure Homebrew installation runs as non-root user with proper permissions

This commit is contained in:
kake26 2025-06-07 23:03:38 -05:00
parent ac31a224a2
commit 101c1cda1c
Signed by: kake26
GPG key ID: E0A989B571D1F99F

View file

@ -67,8 +67,15 @@ sudo apt install linux-xanmod-x64v3 -y
# Homebrew # Homebrew
echo "Installing Homebrew..." echo "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh) --prefix=/opt/homebrew" if [[ -z "$SUDO_USER" ]]; then
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bashrc echo "Error: Script must be run with sudo by a non-root user (SUDO_USER not set)" >&2
exit 1
fi
# Run Homebrew installer as the original user
sudo -u "$SUDO_USER" /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh) --prefix=/opt/homebrew"
# Add Homebrew to the user's .bashrc
echo "eval \"\$(/opt/homebrew/bin/brew shellenv)\"" | sudo -u "$SUDO_USER" tee -a "/home/$SUDO_USER/.bashrc" > /dev/null
# Ensure Homebrew is available in the current session
eval "$(/opt/homebrew/bin/brew shellenv)" eval "$(/opt/homebrew/bin/brew shellenv)"
# Pacstall # Pacstall