Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use brew bundle and brew services instead of custom brew functions #403

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
109 changes: 31 additions & 78 deletions mac 100644 → 100755
Expand Up @@ -53,55 +53,6 @@ case "$SHELL" in
;;
esac

brew_install_or_upgrade() {
if brew_is_installed "$1"; then
if brew_is_upgradable "$1"; then
fancy_echo "Upgrading %s ..." "$1"
brew upgrade "$@"
else
fancy_echo "Already using the latest version of %s. Skipping ..." "$1"
fi
else
fancy_echo "Installing %s ..." "$1"
brew install "$@"
fi
}

brew_is_installed() {
local name="$(brew_expand_alias "$1")"

brew list -1 | grep -Fqx "$name"
}

brew_is_upgradable() {
local name="$(brew_expand_alias "$1")"

! brew outdated --quiet "$name" >/dev/null
}

brew_tap() {
brew tap "$1" 2> /dev/null
}

brew_expand_alias() {
brew info "$1" 2>/dev/null | head -1 | awk '{gsub(/:/, ""); print $1}'
}

brew_launchctl_restart() {
local name="$(brew_expand_alias "$1")"
local domain="homebrew.mxcl.$name"
local plist="$domain.plist"

fancy_echo "Restarting %s ..." "$1"
mkdir -p "$HOME/Library/LaunchAgents"
ln -sfv "/usr/local/opt/$name/$plist" "$HOME/Library/LaunchAgents"

if launchctl list | grep -Fq "$domain"; then
launchctl unload "$HOME/Library/LaunchAgents/$plist" >/dev/null
fi
launchctl load "$HOME/Library/LaunchAgents/$plist" >/dev/null
}

gem_install_or_update() {
if gem list "$1" --installed > /dev/null; then
fancy_echo "Updating %s ..." "$1"
Expand Down Expand Up @@ -131,31 +82,40 @@ fi
fancy_echo "Updating Homebrew formulas ..."
brew update

brew_install_or_upgrade 'zsh'
brew_install_or_upgrade 'git'
brew_install_or_upgrade 'postgres'
brew_launchctl_restart 'postgresql'
brew_install_or_upgrade 'redis'
brew_launchctl_restart 'redis'
brew_install_or_upgrade 'the_silver_searcher'
brew_install_or_upgrade 'vim'
brew_install_or_upgrade 'ctags'
brew_install_or_upgrade 'tmux'
brew_install_or_upgrade 'reattach-to-user-namespace'
brew_install_or_upgrade 'imagemagick'
brew_install_or_upgrade 'qt'
brew_install_or_upgrade 'hub'
brew_install_or_upgrade 'node'

brew_install_or_upgrade 'rbenv'
brew_install_or_upgrade 'ruby-build'

# shellcheck disable=SC2016
append_to_zshrc 'eval "$(rbenv init - --no-rehash zsh)"' 1

brew_install_or_upgrade 'openssl'
brew unlink openssl && brew link openssl --force
brew_install_or_upgrade 'libyaml'
BREWFILE=$(cat <<'EOF'
tap 'thoughtbot/formulae'
tap 'homebrew/services'
brew 'zsh'
brew 'git'
brew 'postgres'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do brew "postgres", restart_service: true now.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I recommend doing postgresql which is the full, non-aliased name.

brew 'redis'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do brew "redis", restart_service: true now.

brew 'the_silver_searcher'
brew 'vim'
brew 'ctags'
brew 'tmux'
brew 'reattach-to-user-namespace'
brew 'imagemagick'
brew 'qt'
brew 'hub'
brew 'node'
brew 'rbenv'
brew 'ruby-build'
brew 'libyaml'
brew 'heroku-toolbelt'
brew 'rcm'
EOF
)

fancy_echo "Installing Homebrew Packages ..."
brew tap 'homebrew/bundle'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to do this any more; it's done automatically.

echo "$BREWFILE" | brew bundle -v --file=/dev/stdin
brew unlink openssl && brew link openssl --force

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bad idea. On 10.11 the OpenSSL headers are removed but library remains. Given Clang's default paths this means things will use the Homebrew headers but link against the system libraries. At best, it's insecure. At worst, it'll cause random, hard-to-debug runtime failures.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comment! I agree and don't use this on my personal system. I meant for this PR to be exactly the current functionality.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

brew services restart jack
brew services restart redis
brew services restart postgresql

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can integrate this into the Brewfile now.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g. brew 'postgresql', restart_service: true


ruby_version="$(curl -sSL http://ruby.thoughtbot.com/latest)"

Expand All @@ -176,13 +136,6 @@ fancy_echo "Configuring Bundler ..."
number_of_cores=$(sysctl -n hw.ncpu)
bundle config --global jobs $((number_of_cores - 1))

brew_install_or_upgrade 'heroku-toolbelt'

if ! command -v rcup >/dev/null; then
brew_tap 'thoughtbot/formulae'
brew_install_or_upgrade 'rcm'
fi

if [ -f "$HOME/.laptop.local" ]; then
. "$HOME/.laptop.local"
fi