From 681e49a01e67eeab7dbd080f3944b5488ef5ccfe Mon Sep 17 00:00:00 2001 From: Kevin Yap Date: Mon, 7 Mar 2016 19:52:58 -0800 Subject: [PATCH] Add Homebrew installation script --- README.md | 2 +- init/install_homebrew.sh | 13 +++++ init/osx_homebrew.sh | 114 --------------------------------------- 3 files changed, 14 insertions(+), 115 deletions(-) create mode 100755 init/install_homebrew.sh delete mode 100644 init/osx_homebrew.sh diff --git a/README.md b/README.md index 3776c08..641d6e4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # iKevinY/dotfiles -This repository contains my [dotfiles](http://dotfiles.github.io), heavily inspired by [@mathiasbynens](https://github.com/mathiasbynens/dotfiles) and [@cowboy](https://github.com/cowboy/dotfiles). +This repository contains my [dotfiles](http://dotfiles.github.io), heavily inspired by [@mathiasbynens](https://github.com/mathiasbynens/dotfiles), [@cowboy](https://github.com/cowboy/dotfiles), and [@holman](https://github.com/holman/dotfiles). ## Installation diff --git a/init/install_homebrew.sh b/init/install_homebrew.sh new file mode 100755 index 0000000..f478c5a --- /dev/null +++ b/init/install_homebrew.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +if test ! "$(which brew)"; then + if test "$(uname)" = "Darwin"; then + ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + elif test "$(expr substr $(uname -s) 1 5)" = "Linux"; then + ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)" + else + echo "Unknown platform." + fi +else + echo "Homebrew is already installed." +fi diff --git a/init/osx_homebrew.sh b/init/osx_homebrew.sh deleted file mode 100644 index 0f50b53..0000000 --- a/init/osx_homebrew.sh +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env bash - -# OSX-only stuff. Abort if not OSX. -is_osx || return 1 - -# Install Homebrew. -if [[ ! "$(type -P brew)" ]]; then - e_header "Installing Homebrew" - true | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" -fi - -# Exit if, for some reason, Homebrew is not installed. -[[ ! "$(type -P brew)" ]] && e_error "Homebrew failed to install." && return 1 - -e_header "Updating Homebrew" -brew doctor -brew update - - -################## -# Helper Functions -################## - -# Tap Homebrew kegs. -function brew_tap_kegs() { - kegs=($(setdiff "${kegs[*]}" "$(brew tap)")) - if (( ${#kegs[@]} > 0 )); then - e_header "Tapping Homebrew kegs: ${kegs[*]}" - for keg in "${kegs[@]}"; do - brew tap "$keg" - done - fi -} - -# Install Homebrew formulae. -function brew_install_formulae() { - formulae=($(setdiff "${formulae[*]}" "$(brew list)")) - if (( ${#formulae[@]} > 0 )); then - e_header "Installing Homebrew formulae: ${formulae[*]}" - for recipe in "${formulae[@]}"; do - brew install "$recipe" - done - fi -} - - -####### -# Casks -####### - -# Ensure the cask keg and formula are installed. -kegs=(caskroom/cask caskroom/versions caskroom/fonts) -brew_tap_kegs -formulae=(brew-cask) -brew_install_formulae - -# Hack to show the first-run brew-cask password prompt immediately. -brew cask info this-is-somewhat-annoying 2>/dev/null - -# Read list of Homebrew casks from /conf/casks.txt (ignoring commented lines). -readarray casks < <(grep -v '^$\|^\s*\#' "${DOTFILES}/conf/casks.txt") - -# Install Homebrew casks. -casks=($(setdiff "${casks[*]}" "$(brew cask list 2>/dev/null)")) -if (( ${#casks[@]} > 0 )); then - e_header "Installing Homebrew casks: ${casks[*]}" - for cask in "${casks[@]}"; do - brew cask install "$cask" - done - brew cask cleanup -fi - -# Work around colorPicker symlink issue. -# https://github.com/caskroom/homebrew-cask/issues/7004 -cps=() -for f in ~/Library/ColorPickers/*.colorPicker; do - [[ -L "$f" ]] && cps=("${cps[@]}" "$f") -done - -if (( ${#cps[@]} > 0 )); then - e_header "Fixing colorPicker symlinks" - for f in "${cps[@]}"; do - target="$(readlink "$f")" - e_arrow "$(basename "$f")" - rm "$f" - cp -R "$target" ~/Library/ColorPickers/ - done -fi - - -########## -# Formulae -########## - -# Read list of Homebrew casks from /conf/formulae.txt (ignoring commented lines). -readarray formulae < <(grep -v '^$\|^\s*\#' "${DOTFILES}/conf/formulae.txt") - -brew_install_formulae - -# Misc cleanup! - -# This is where brew stores its binary symlinks -local binroot="$(brew --config | awk '/HOMEBREW_PREFIX/ {print $2}')"/bin - -# bash -if [[ $(type -P "$binroot/bash") && $(grep -q "$binroot/bash" /etc/shells) ]]; then - e_header "Adding $binroot/bash to the list of acceptable shells" - echo "$binroot/bash" | sudo tee -a /etc/shells >/dev/null -fi -if [[ "$(dscl . -read ~ UserShell | awk '{print $2}')" != "$binroot/bash" ]]; then - e_header "Making $binroot/bash your default shell" - sudo chsh -s "$binroot/bash" "$USER" >/dev/null 2>&1 - e_arrow "Please exit and restart all your shells." -fi -- 2.51.2