-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(brew): add command-not-found by default after setup
- Loading branch information
1 parent
1b76f14
commit 4a364fa
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
system_files/shared/usr/lib/systemd/system-preset/01-homebrew.preset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
enable brew-setup.service | ||
enable brew-update.timer | ||
enable brew-upgrade.timer | ||
enable brew-command-not-found.service |
18 changes: 18 additions & 0 deletions
18
system_files/shared/usr/lib/systemd/system/brew-command-not-found.service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[Unit] | ||
Description=Automatically install brew-command-not-found | ||
Wants=network-online.target | ||
After=network-online.target | ||
ConditionPathIsSymbolicLink=/home/linuxbrew/.linuxbrew/bin/brew | ||
|
||
[Service] | ||
Type=oneshot | ||
Environment=HOMEBREW_CELLAR=/home/linuxbrew/.linuxbrew/Cellar | ||
Environment=HOMEBREW_PREFIX=/home/linuxbrew/.linuxbrew | ||
Environment=HOMEBREW_REPOSITORY=/home/linuxbrew/.linuxbrew/Homebrew | ||
# Bash is required here or else sudo gets Permission Denied error for some reason | ||
# Override the user if different UID/User | ||
ExecStart=/usr/bin/bash -c "/usr/bin/sudo -H -i -u \'#1000\' /usr/libexec/brew-command-not-found.sh" | ||
ExecStart=/usr/libexec/brew-command-not-found.sh | ||
|
||
[Install] | ||
WantedBy=default.target multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env bash | ||
# Optionally installs Brew's command-not-found tool if it still isnt installed in the host system | ||
|
||
set -euo pipefail | ||
|
||
BREW_BINARY=/home/linuxbrew/.linuxbrew/bin/brew | ||
BREW_ROOT=${HOMEBREW_REPOSITORY:-$($BREW_BINARY --repository)} | ||
|
||
if [ ! -f "${BREW_ROOT}/Library/Taps/homebrew/homebrew-command-not-found" ] && [ "$(id -u)" -ne 0 ] ; then | ||
if ! $BREW_BINARY -h > /dev/null; then | ||
echo "Install Homebrew first!" | ||
exit | ||
fi | ||
|
||
# This directory could exist without the user having installed command-not-found but then theres something super wrong with their system | ||
HOMEBREW_NO_ENV_HINTS=true $BREW_BINARY tap homebrew/command-not-found | ||
fi | ||
|
||
# Fail quietly in the next steps since for some reason the service that is supposted to run this thinks that theyre root when running as $UID | ||
if [ ! -f "/etc/profile.d/brew-command-not-found.sh" ] ; then | ||
touch /etc/profile.d/brew-command-not-found.sh &> /dev/null || exit 0 | ||
tee /etc/profile.d/brew-command-not-found.sh > /dev/null <<EOF | ||
# Check for interactive bash or zsh and that we haven't already been sourced | ||
if [[ -d /home/linuxbrew/.linuxbrew && \$- == *i* && BREW_COMMAND_NOT_FOUND != 1 ]] ; then | ||
HB_CNF_HANDLER="${BREW_ROOT}/Library/Taps/homebrew/homebrew-command-not-found/handler.sh" | ||
[ -f "\$HB_CNF_HANDLER" ] && source "\$HB_CNF_HANDLER" | ||
export BREW_COMMAND_NOT_FOUND=1 | ||
fi | ||
EOF | ||
fi | ||
|
||
if [ ! -f "/etc/fish/conf.d/homebrew-command-not-found.fish" ] ; then | ||
touch /etc/fish/conf.d/brew-command-not-found.fish &> /dev/null || exit 0 | ||
tee /etc/fish/conf.d/brew-command-not-found.fish > /dev/null <<EOF | ||
set HB_CNF_HANDLER "${BREW_ROOT}/Library/Taps/homebrew/homebrew-command-not-found/handler.fish" | ||
if test -f \$HB_CNF_HANDLER | ||
source \$HB_CNF_HANDLER | ||
end | ||
EOF | ||
fi |