2023-01-09 21:55:47 -08:00
|
|
|
{{- if (ne .host.distro.family "windows") -}}
|
2022-11-26 19:27:29 -08:00
|
|
|
#!/usr/bin/env bash
|
2023-04-12 18:27:13 -07:00
|
|
|
# @file Homebrew / Xcode Tools Installation
|
|
|
|
# @brief Ensures Xcode tools are installed on macOS and ensures Homebrew is installed on either Linux or macOS
|
|
|
|
# @description
|
|
|
|
# This script ensures macOS has tools like `git` by installing the Xcode command-line developer tools if they are
|
|
|
|
# not already installed. Then, on both Linux and macOS, it ensures Homebrew is installed.
|
|
|
|
#
|
|
|
|
# ## Homebrew Requirement
|
|
|
|
#
|
|
|
|
# Install Doctor relies on Homebrew for many tools that are currently only available via Homebrew. Removing the dependency
|
|
|
|
# would be a nice-to-have but there are currently no plans for supporting systems without Homebrew installed.
|
2023-01-09 21:55:47 -08:00
|
|
|
|
2023-01-24 20:36:59 -08:00
|
|
|
{{ includeTemplate "universal/profile-before" }}
|
|
|
|
{{ includeTemplate "universal/logg-before" }}
|
Update dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_before_8-install-zx.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_before_5-install-homebrew.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_before_10_install-darwin-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoitemplates/universal/profile, dotfiles/.local/share/chezmoi/home/private_dot_config/shell/exports.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_99_bootstrap-z4h.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_80-bash-completions.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_60-cleanup.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_50-crontab.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_15_install-asdf-packages.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_10_install-aqua-packages.sh.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/archlinux/run_onchange_before_10_install-archlinux-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/centos/run_onchange_before_10-install-centos-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_after_10_configure-macos.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_after_20-ensure-zsh-macos.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/debian/run_onchange_before_10-install-debian-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/fedora/run_onchange_before_10-install-fedora-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/freebsd/run_onchange_before_11-install-freebsd-packages.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/opensuse/run_onchange_before_11-install-opensuse-software.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/ubuntu/run_onchange_before_10_install-ubuntu-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/private_dot_config/tabby/config.yaml.tmpl
Deleted dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_before_1-logging-deps
2022-11-26 19:55:43 -08:00
|
|
|
|
2023-06-13 23:02:23 -07:00
|
|
|
### System upgrade on macOS
|
2023-06-22 21:59:20 -07:00
|
|
|
if [ -d /Applications ] && [ -d /Library ] && [ -z "$NO_RESTART" ]; then
|
2023-06-14 19:40:58 -07:00
|
|
|
if command -v gtimeout > /dev/null; then
|
|
|
|
# Allow 8 minutes for system updates
|
|
|
|
logg info 'Ensuring system software is upgraded (timing out after 8 minutes if system upgrade fails)'
|
2023-06-22 21:58:26 -07:00
|
|
|
sudo gtimeout 480 softwareupdate -i -a -R || logg warn 'The system update command timed out after 8 minutes'
|
2023-06-14 19:40:58 -07:00
|
|
|
else
|
|
|
|
# If gtimeout is unavailable, then attempt system upgrade without a timeout (which usually works on fresh systems)
|
|
|
|
logg info 'Applying OS upgrades (if available)'
|
2023-06-22 21:58:26 -07:00
|
|
|
sudo softwareupdate -i -a -R || logg error 'Failed to perform a system update via `sudo softwareupdate -i -a`'
|
2023-06-14 19:40:58 -07:00
|
|
|
fi
|
|
|
|
logg info 'If system updates were downloaded / installed, a reboot might be required.'
|
2023-06-13 23:02:23 -07:00
|
|
|
fi
|
|
|
|
|
2023-07-17 00:28:38 -07:00
|
|
|
### Ensure dependencies are installed on Linux
|
|
|
|
if ! command -v curl > /dev/null || ! command -v git > /dev/null || ! command -v expect > /dev/null || ! command -v rsync > /dev/null; then
|
|
|
|
if command -v apt-get > /dev/null; then
|
|
|
|
# @description Ensure `build-essential`, `curl`, `expect`, `git`, `rsync`, `procps`, and `file` are installed on Debian / Ubuntu
|
|
|
|
sudo apt-get update
|
|
|
|
sudo apt-get install -y build-essential curl expect git rsync procps file
|
|
|
|
elif command -v dnf > /dev/null; then
|
|
|
|
# @description Ensure `curl`, `expect`, `git`, `rsync`, `procps-ng`, and `file` are installed on Fedora (as well as the Development Tools package)
|
|
|
|
sudo dnf groupinstall -y 'Development Tools'
|
|
|
|
sudo dnf install -y curl expect git rsync procps-ng file
|
|
|
|
elif command -v yum > /dev/null; then
|
|
|
|
# @description Ensure `curl`, `expect`, `git`, `rsync`, `procps-ng`, and `file` are installed on CentOS (as well as the Development Tools package)
|
|
|
|
sudo yum groupinstall -y 'Development Tools'
|
|
|
|
sudo yum install -y curl expect git rsync procps-ng file
|
|
|
|
elif command -v pacman > /dev/null; then
|
|
|
|
# @description Ensure `base-devel`, `curl`, `expect`, `git`, `rsync`, `procps-ng`, and `file` are installed on Archlinux
|
|
|
|
sudo pacman update
|
|
|
|
sudo pacman -Sy base-devel curl expect git rsync procps-ng file
|
|
|
|
elif command -v zypper > /dev/null; then
|
|
|
|
# @description Ensure `curl`, `expect`, `git`, `rsync`, `procps`, and `file` are installed on OpenSUSE (as well as the devel_basis pattern)
|
|
|
|
sudo zypper install -yt pattern devel_basis
|
|
|
|
sudo zypper install -y curl expect git rsync procps file
|
|
|
|
elif command -v apk > /dev/null; then
|
|
|
|
# @description Ensure `curl`, `expect`, `git`, `rsync`, `procps`, and `file` are installed on Alpine
|
|
|
|
apk add build-base curl expect git rsync procps file
|
|
|
|
elif [ -d /Applications ] && [ -d /Library ]; then
|
|
|
|
# @description Ensure CLI developer tools are available on macOS (via `xcode-select`)
|
|
|
|
sudo xcode-select -p >/dev/null 2>&1 || xcode-select --install
|
|
|
|
elif [[ "$OSTYPE" == 'cygwin' ]] || [[ "$OSTYPE" == 'msys' ]] || [[ "$OSTYPE" == 'win32' ]]; then
|
|
|
|
# @description Ensure `curl`, `expect`, `git`, and `rsync` are installed on Windows
|
|
|
|
choco install -y curl expect git rsync
|
|
|
|
fi
|
Update dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_before_8-install-zx.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_before_5-install-homebrew.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_before_10_install-darwin-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoitemplates/universal/profile, dotfiles/.local/share/chezmoi/home/private_dot_config/shell/exports.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_99_bootstrap-z4h.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_80-bash-completions.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_60-cleanup.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_50-crontab.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_15_install-asdf-packages.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_10_install-aqua-packages.sh.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/archlinux/run_onchange_before_10_install-archlinux-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/centos/run_onchange_before_10-install-centos-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_after_10_configure-macos.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_after_20-ensure-zsh-macos.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/debian/run_onchange_before_10-install-debian-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/fedora/run_onchange_before_10-install-fedora-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/freebsd/run_onchange_before_11-install-freebsd-packages.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/opensuse/run_onchange_before_11-install-opensuse-software.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/ubuntu/run_onchange_before_10_install-ubuntu-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/private_dot_config/tabby/config.yaml.tmpl
Deleted dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_before_1-logging-deps
2022-11-26 19:55:43 -08:00
|
|
|
fi
|
|
|
|
|
2023-07-17 00:28:38 -07:00
|
|
|
### Ensure Linux Homebrew is loaded
|
|
|
|
loadLinuxbrew() {
|
|
|
|
if ! command -v brew > /dev/null; then
|
|
|
|
if [ -d "$HOME/.linuxbrew" ]; then
|
|
|
|
eval "$("$HOME/.linuxbrew/bin/brew" shellenv)"
|
|
|
|
elif [ -d "/home/linuxbrew/.linuxbrew" ]; then
|
|
|
|
eval "(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
### Ensures Homebrew folders have proper owners / permissions
|
|
|
|
fixHomebrewPermissions() {
|
|
|
|
if command -v brew > /dev/null; then
|
|
|
|
logg info 'Applying proper permissions on Homebrew folders'
|
|
|
|
sudo chmod -R go-w "$(brew --prefix)/share"
|
|
|
|
BREW_DIRS="share/man share/doc share/zsh/site-functions etc/bash_completion.d"
|
|
|
|
for BREW_DIR in $BREW_DIRS; do
|
|
|
|
if [ -d "$(brew --prefix)/$BREW_DIR" ]; then
|
|
|
|
sudo chown -R "$(whoami)" "$(brew --prefix)/$BREW_DIR"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
brew update --force --quiet
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
### Installs Homebrew
|
2022-11-26 19:27:29 -08:00
|
|
|
ensurePackageManagerHomebrew() {
|
|
|
|
if ! command -v brew > /dev/null; then
|
|
|
|
if command -v sudo > /dev/null && sudo -n true; then
|
|
|
|
echo | bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
|
|
|
else
|
|
|
|
logg info 'Homebrew is not installed. Password may be required.'
|
|
|
|
bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || BREW_EXIT_CODE="$?"
|
|
|
|
if [ -n "$BREW_EXIT_CODE" ]; then
|
2023-07-17 00:28:38 -07:00
|
|
|
logg warn 'Homebrew was installed but part of the installation failed to complete successfully.'
|
2022-11-26 19:27:29 -08:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
2023-07-17 00:28:38 -07:00
|
|
|
|
|
|
|
### Logic
|
|
|
|
loadLinuxbrew
|
2022-11-26 19:27:29 -08:00
|
|
|
ensurePackageManagerHomebrew
|
2023-07-17 00:28:38 -07:00
|
|
|
loadLinuxbrew
|
|
|
|
fixHomebrewPermissions
|
2023-07-10 22:05:07 -07:00
|
|
|
|
2023-07-17 00:28:38 -07:00
|
|
|
### Enable auto-update service
|
2023-07-10 22:05:07 -07:00
|
|
|
if brew autoupdate status | grep 'Autoupdate is not configured.' > /dev/null; then
|
|
|
|
logg info 'Enabling Homebrew auto-update service (every 24 hours)'
|
2023-07-10 23:58:10 -07:00
|
|
|
brew autoupdate start --cleanup --greedy --upgrade
|
2023-07-10 22:05:07 -07:00
|
|
|
fi
|
Update .local/share/chezmoi/home/.chezmoiscripts/universal/run_onchange_after_99_bootstrap-zsh-plugins.tmpl, .local/share/chezmoi/home/.chezmoiscripts/universal/run_onchange_after_10_install-aqua-packages.sh.tmpl, .local/share/chezmoi/home/.chezmoiscripts/universal/run_onchange_after_50-crontab.tmpl, .local/share/chezmoi/home/.chezmoiscripts/universal/run_onchange_before_5-install-homebrew.tmpl, .local/share/chezmoi/home/.chezmoiscripts/universal/run_onchange_before_8-install-zx.tmpl, .local/share/chezmoi/home/.chezmoiscripts/windows/run_onchange_before_10-install-windows-dependencies.tmpl, .local/share/chezmoi/home/.chezmoiscripts/windows/run_onchange_before_11-install-windows-packages.tmpl, .local/share/chezmoi/home/.chezmoiscripts/ubuntu/run_onchange_before_10_install-ubuntu-dependencies.tmpl, .local/share/chezmoi/home/.chezmoiscripts/opensuse/run_onchange_before_11-install-opensuse-software.tmpl, .local/share/chezmoi/home/.chezmoiscripts/freebsd/run_onchange_before_11-install-freebsd-packages.tmpl, .local/share/chezmoi/home/.chezmoiscripts/fedora/run_onchange_before_10-install-fedora-dependencies.tmpl, .local/share/chezmoi/home/.chezmoiscripts/debian/run_onchange_before_10-install-debian-dependencies.tmpl, .local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_before_10_install-darwin-dependencies.tmpl, .local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_after_set-wallpaper.tmpl, .local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_after_20-ensure-zsh-macos.tmpl, .local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_after_10_configure-macos.tmpl, .local/share/chezmoi/home/.chezmoiscripts/centos/run_onchange_before_10-install-centos-dependencies.tmpl, .local/share/chezmoi/home/.chezmoiscripts/archlinux/run_onchange_before_10_install-archlinux-dependencies.tmpl, .local/share/chezmoi/home/Library/Fonts/run_onchange_after_add-fonts.tmpl
2022-12-01 23:18:16 -08:00
|
|
|
{{ end -}}
|