From 49b9dc5171b441e55129268aa4a7340626cf3fb7 Mon Sep 17 00:00:00 2001 From: Brian Zalewski <59970525+ProfessorManhattan@users.noreply.github.com> Date: Sat, 9 Dec 2023 00:39:21 +0000 Subject: [PATCH] Latest --- .../run_before_01-system-homebrew.sh.tmpl | 19 ++- ..._onchange_before_11-install-docker.sh.tmpl | 15 +++ home/dot_config/shell/exports.sh.tmpl | 3 + home/dot_local/bin/executable_install-program | 2 +- home/symlink_dot_docker.tmpl | 1 + scripts/partials/homebrew | 122 ++++++++++-------- 6 files changed, 102 insertions(+), 60 deletions(-) create mode 100644 home/symlink_dot_docker.tmpl diff --git a/home/.chezmoiscripts/universal/run_before_01-system-homebrew.sh.tmpl b/home/.chezmoiscripts/universal/run_before_01-system-homebrew.sh.tmpl index b763994c..fee46d70 100644 --- a/home/.chezmoiscripts/universal/run_before_01-system-homebrew.sh.tmpl +++ b/home/.chezmoiscripts/universal/run_before_01-system-homebrew.sh.tmpl @@ -115,9 +115,13 @@ if ! command -v curl > /dev/null || ! command -v git > /dev/null || ! command -v fi fi -### Ensure Linux Homebrew is loaded -loadLinuxbrew() { +### Ensure Homebrew is loaded +loadHomebrew() { if ! command -v brew > /dev/null; then + if [ -f /usr/local/bin/brew ]; then + eval "$(/usr/local/bin/brew shellenv)" + if [ -f "${HOMEBREW_PREFIX:-/opt/homebrew}/bin/brew" ]; then + eval "$("${HOMEBREW_PREFIX:-/opt/homebrew}/bin/brew" shellenv)" if [ -d "$HOME/.linuxbrew" ]; then eval "$("$HOME/.linuxbrew/bin/brew" shellenv)" elif [ -d "/home/linuxbrew/.linuxbrew" ]; then @@ -131,13 +135,13 @@ 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" + BREW_DIRS="share 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" + sudo chown -Rf "$(whoami)" "$(brew --prefix)/$BREW_DIR" fi done - brew update --force --quiet + logg info 'Running brew update --force --quiet' && brew update --force --quiet fi } @@ -158,9 +162,10 @@ ensurePackageManagerHomebrew() { } ### Logic -loadLinuxbrew +loadHomebrew ensurePackageManagerHomebrew -loadLinuxbrew +loadHomebrew +fixHomebrewPermissions ### Enable auto-update service if [ -d /Applications ] && [ -d System ]; then diff --git a/home/.chezmoiscripts/universal/run_onchange_before_11-install-docker.sh.tmpl b/home/.chezmoiscripts/universal/run_onchange_before_11-install-docker.sh.tmpl index 4f4291b8..ff825fc0 100644 --- a/home/.chezmoiscripts/universal/run_onchange_before_11-install-docker.sh.tmpl +++ b/home/.chezmoiscripts/universal/run_onchange_before_11-install-docker.sh.tmpl @@ -15,6 +15,21 @@ {{ includeTemplate "universal/profile-before" }} {{ includeTemplate "universal/logg-before" }} +# @description Ensures `~/.config/docker` is symlinked to `~/.docker` which is required for +# Docker Desktop compatibility since it currently does not honor XDG spec. This will +# remove the current configuration at `~/.docker` if it is present and not symlinked to +# `~/.config/docker`. +ensureConfigSymlink() { + if [ "$(readlink -f "$HOME/.docker")" != "${XDG_CONFIG_HOME:-$HOME/.config}/docker" ]; then + logg info 'Removing ~/.docker if present' && rm -rf "$HOME/.docker" + logg info 'Ensuring ~/.config/docker exists' && mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/docker" + logg info 'Symlinking ~/.config/docker to ~/.docker for Docker Desktop compatibility' && ln -s "${XDG_CONFIG_HOME:-$HOME/.config}/docker" "$HOME/.docker" + else + logg info 'Symlink from ~/.config/docker to ~/.docker is already present' + fi +} +ensureConfigSymlink + ### Install Docker if [ -d /Applications ] && [ -d /System ]; then # macOS diff --git a/home/dot_config/shell/exports.sh.tmpl b/home/dot_config/shell/exports.sh.tmpl index 74b880d4..429a3137 100644 --- a/home/dot_config/shell/exports.sh.tmpl +++ b/home/dot_config/shell/exports.sh.tmpl @@ -431,6 +431,9 @@ export VAGRANT_ALIAS_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/vagrant/aliases" export VAGRANT_DEFAULT_PROVIDER=virtualbox export VAGRANT_HOME="${XDG_DATA_HOME:-$HOME/.local/share}/vagrant.d" +### Visual Studio Code +export VSCODE_EXTENSIONS="${XDG_DATA_HOME:-$HOME/.local/share}/vscode" + ### Volta export VOLTA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}/volta" export PATH="$VOLTA_HOME/bin:$PATH" diff --git a/home/dot_local/bin/executable_install-program b/home/dot_local/bin/executable_install-program index b014d48f..c291ef82 100644 --- a/home/dot_local/bin/executable_install-program +++ b/home/dot_local/bin/executable_install-program @@ -835,7 +835,7 @@ async function beforeInstall(packageManager) { logStage, 'Attempting to open `/Applications/Docker.app` (Docker Desktop for macOS). This should take about 30 seconds.' ) - const promises = [$`test -d /Applications/Docker.app`, $`open --background -a Docker --args --accept-license --unattended`] + const promises = [$`test -d /Applications/Docker.app`, $`rm -f ~/.docker && mkdir -p ~/.config/docker && open --background -a Docker --args --accept-license --unattended`] await Promise.all(promises) const gum = which.sync('gum', { nothrow: true }) if (gum) { diff --git a/home/symlink_dot_docker.tmpl b/home/symlink_dot_docker.tmpl new file mode 100644 index 00000000..d329e306 --- /dev/null +++ b/home/symlink_dot_docker.tmpl @@ -0,0 +1 @@ +{{ .host.home }}/.config/docker/ \ No newline at end of file diff --git a/scripts/partials/homebrew b/scripts/partials/homebrew index 0258a25d..72e3fc84 100644 --- a/scripts/partials/homebrew +++ b/scripts/partials/homebrew @@ -1,3 +1,68 @@ +### Ensure Homebrew is loaded +loadHomebrew() { + if ! command -v brew > /dev/null; then + if [ -f /usr/local/bin/brew ]; then + logg info "Using /usr/local/bin/brew" && eval "$(/usr/local/bin/brew shellenv)" + if [ -f "${HOMEBREW_PREFIX:-/opt/homebrew}/bin/brew" ]; then + logg info "Using ${HOMEBREW_PREFIX:-/opt/homebrew}/bin/brew" && eval "$("${HOMEBREW_PREFIX:-/opt/homebrew}/bin/brew" shellenv)" + if [ -d "$HOME/.linuxbrew" ]; then + logg info "Using $HOME/.linuxbrew/bin/brew" && eval "$("$HOME/.linuxbrew/bin/brew" shellenv)" + elif [ -d "/home/linuxbrew/.linuxbrew" ]; then + logg info 'Using /home/linuxbrew/.linuxbrew/bin/brew' && eval "(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" + else + logg info 'Could not find Homebrew installation' + 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 etc/bash_completion.d" + for BREW_DIR in $BREW_DIRS; do + if [ -d "$(brew --prefix)/$BREW_DIR" ]; then + sudo chown -Rf "$(whoami)" "$(brew --prefix)/$BREW_DIR" + fi + done + logg info 'Running brew update --force --quiet' && brew update --force --quiet + fi +} + +### Installs Homebrew +ensurePackageManagerHomebrew() { + if ! command -v brew > /dev/null; then + ### Select install type based off of whether or not sudo privileges are available + if command -v sudo > /dev/null && sudo -n true; then + logg info 'Installing Homebrew. Sudo privileges available.' + echo | bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || BREW_EXIT_CODE="$?" + else + logg info 'Installing Homebrew. Sudo privileges not available. Password may be required.' + bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || BREW_EXIT_CODE="$?" + fi + + ### Attempt to fix problematic installs + if [ -n "$BREW_EXIT_CODE" ]; then + logg warn 'Homebrew was installed but part of the installation failed to complete successfully.' + fixHomebrewPermissions + fi + fi +} + +### Ensures gcc is installed +ensureGcc() { + if command -v brew > /dev/null; then + if ! brew list | grep gcc > /dev/null; then + logg info 'Installing Homebrew gcc' && brew install --quiet gcc + else + logg info 'Homebrew gcc is available' + fi + else + logg error 'Failed to initialize Homebrew' && exit 1 + fi +} + # @description This function ensures Homebrew is installed and available in the `PATH`. It handles the installation of Homebrew on both **Linux and macOS**. # It will attempt to bypass sudo password entry if it detects that it can do so. The function also has some error handling in regards to various # directories falling out of the correct ownership and permission states. Finally, it loads Homebrew into the active profile (allowing other parts of the script @@ -5,56 +70,9 @@ # # With Homebrew installed and available, the script finishes by installing the `gcc` Homebrew package which is a very common dependency. ensureHomebrew() { - if ! command -v brew > /dev/null; then - if [ -d /home/linuxbrew/.linuxbrew/bin ]; then - logg info "Sourcing from /home/linuxbrew/.linuxbrew/bin/brew" && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" - if ! command -v brew > /dev/null; then - logg error "The /home/linuxbrew/.linuxbrew directory exists but something is not right. Try removing it and running the script again." && exit 1 - fi - elif [ -d "$HOME/.linuxbrew" ]; then - logg info "Sourcing from $HOME/.linuxbrew/bin/brew" && eval "$($HOME/.linuxbrew/bin/brew shellenv)" - if ! command -v brew > /dev/null; then - logg error "The $HOME/.linuxbrew directory exists but something is not right. Try removing it and running the script again." && exit 1 - fi - else - ### Installs Homebrew and addresses a couple potential issues - if command -v sudo > /dev/null && sudo -n true; then - logg info "Installing Homebrew" - echo | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - else - logg info "Homebrew is not installed. The script will attempt to install Homebrew and you might be prompted for your password." - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || BREW_EXIT_CODE="$?" - if [ -n "$BREW_EXIT_CODE" ]; then - if command -v brew > /dev/null; then - logg warn "Homebrew was installed but part of the installation failed. Trying a few things to fix the installation.." - 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 - logg info "Chowning $(brew --prefix)/$BREW_DIR" && sudo chown -R "$(whoami)" "$(brew --prefix)/$BREW_DIR" - fi - done - logg info "Running brew update --force --quiet" && brew update --force --quiet && logg success "Successfully ran brew update --force --quiet" - fi - fi - fi - - ### Ensures the `brew` binary is available on Linux machines. macOS installs `brew` into the default `PATH` so nothing needs to be done for macOS. - if [ -d /home/linuxbrew/.linuxbrew/bin ]; then - logg info "Sourcing shellenv from /home/linuxbrew/.linuxbrew/bin/brew" && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" - elif [ -f /usr/local/bin/brew ]; then - logg info "Sourcing shellenv from /usr/local/bin/brew" && eval "$(/usr/local/bin/brew shellenv)" - elif [ -f "${HOMEBREW_PREFIX:-/opt/homebrew}/bin/brew" ]; then - logg info "Sourcing shellenv from "${HOMEBREW_PREFIX:-/opt/homebrew}/bin/brew"" && eval "$("${HOMEBREW_PREFIX:-/opt/homebrew}/bin/brew" shellenv)" - fi - fi - fi - - ### Ensure GCC is installed via Homebrew - if command -v brew > /dev/null; then - if ! brew list | grep gcc > /dev/null; then - logg info "Installing Homebrew gcc" && brew install --quiet gcc - fi - else - logg error "Failed to initialize Homebrew" && exit 2 - fi + loadHomebrew + ensurePackageManagerHomebrew + loadHomebrew + fixHomebrewPermissions + ensureGcc }