fleet/it-and-security/lib/macos/scripts/install-wine.sh
Jordan Montgomery 10c73cb110
Fix homebrew wine install (#32505)
Fixes #32504 

Homebrew has removed the ability to install via a local .rb file. For
context see the PR here: https://github.com/Homebrew/brew/pull/20414 .
Also the long list of PRs and commits referencing can give you some idea
of how others are solving this

We have a few different options we can take.

We can use the usual homebrew method of doing an install
wine-stable@[version] but this does not support us installing a version
referenced by a commit SHA, rather we just get to choose a specific
semver.

We can set EVs normally intended for use only by homebrew developers.
The actual Homebrew developers have strongly cautioned against this as
it has more side effects than simply allowing local package installs.

Finally, we can take the method suggested by the Homebrew developers,
which I have done here, of creating a local tap containing our specified
Wine version's cask file and installing from it. This works well in
local testing and I think has the fewest downsides while maintaining the
reference to a specific immutable version.

# Checklist for submitter
## Testing

- [x] QA'd all new/changed functionality manually

Fixed CI run here:
https://github.com/fleetdm/fleet/actions/runs/17407514780/job/49415787748
2025-09-02 11:05:46 -04:00

66 lines
2.1 KiB
Bash
Executable file

#!/bin/bash
# Please don't delete. This script is linked to, as a redirect, from fleetctl and the Fleet website.
set -eo pipefail
brew_wine(){
# Wine reference: https://wiki.winehq.org/MacOS
# Wine can be installed without brew via a distribution such as https://github.com/Gcenx/macOS_Wine_builds/releases/tag/10.0 or by building from source.
# To install a version tied to a specific commit SHA we must create a local tap and install from it after wine 4.6.4 dropped support, see
# https://github.com/Homebrew/brew/pull/20414
TAP_PATH="$(brew --repository)/Library/Taps/fleet/homebrew-local/Casks"
mkdir -p "${TAP_PATH}"
echo "# tap auto-generated by Fleet for installing wine-stable" > "$(dirname "${TAP_PATH}")/README.md"
curl -O https://raw.githubusercontent.com/Homebrew/homebrew-cask/bad613d274f9a646dace4a4cc7f2512f836be5b4/Casks/w/wine-stable.rb
mv wine-stable.rb "${TAP_PATH}/"
brew install --cask --no-quarantine fleet/local/wine-stable; exit 0
}
warn_wine(){
printf "\nWARNING: The Wine app developer has an Apple Developer certificate but the\napp bundle post-installation will not be code-signed or notarized.\n\nDo you wish to proceed?\n\n"
while true
do
read -r -p "install> " install
case "$install" in
y|yes|Y|YES) brew_wine ;;
n|no|N|NO) printf "\nExiting...\n\n"; exit 1 ;;
*) printf "\nPlease enter yes or no at the prompt...\n\n" ;;
esac
done
}
# option to execute script in non-interactive mode
while getopts 'n' option
do
case "$option" in
n) mode=auto ;;
*) : ;;
esac
done
# prevent root execution
if [ "$EUID" = 0 ]
then
printf "\nTo prevent unnecessary privilege elevation do not execute this script as the root user.\nExiting...\n\n"; exit 1
fi
# check if Homebrew is installed
if ! command -v brew > /dev/null 2>&1
then
printf "\nHomebrew is not installed.\nPlease install Homebrew.\nFor instructions, see https://brew.sh/\n\n"; exit 1
fi
# install Wine
if [ "$mode" = 'auto' ]
then
printf "\n%s executed in non-interactive mode.\n\n" "$0"; brew_wine
else
warn_wine
fi