Skip to content

Instantly share code, notes, and snippets.

@geoff-kruss
Last active June 26, 2018 07:14
Show Gist options
  • Save geoff-kruss/bd0357328adb0b89ab678fdcf2714c94 to your computer and use it in GitHub Desktop.
Save geoff-kruss/bd0357328adb0b89ab678fdcf2714c94 to your computer and use it in GitHub Desktop.
#: set the Makefile shell to the users environment provided shell
SHELL=/usr/bin/env bash
#: set the OSTYPE var based on the shells OSTYPE environment variable
OSTYPE := $(shell echo $${OSTYPE})
#: generic info log function
#: logs in light blue
define log
echo -e "\033[1;34m==>\033[0m $(1)"
endef
all: ensure
ensure: ensure-xcode ensure-brew ensure-zsh ensure-bash ensure-ansible
#: Make sure Homebrew is installed (https://brew.sh/)
#: Does nothing on non darwin based operating systems.
ensure-brew: ensure-xcode
ifneq (,$(findstring darwin,$(OSTYPE)))
$(call log,"Running \"ensure-brew\"")
[[ $$(which brew) ]] || /usr/bin/ruby -e "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update &> /dev/null
endif
#: Make sure xcode is installed
#: Does nothing on non dariwn based operating systems.
ensure-xcode:
ifneq (,$(findstring darwin,$(OSTYPE)))
$(call log,"Running \"ensure-xcode\"")
[[ $$(xcode-select --install 2>&1 | grep installed) ]] || xcode-select --install
endif
#: Make sure zsh is installed.
#: Set zsh as the default shell.
ensure-zsh: ensure-brew
$(call log,"Running \"ensure-zsh\"")
ifneq (,$(findstring darwin,$(OSTYPE)))
#: Darwin based install uses brew
[[ $$(which zsh) ]] || brew install zsh zsh-completions
else
#: Ubuntu based installs use apt-get
[[ $$(which zsh) ]] || sudo apt-get install -y zsh
endif
#: set up zsh as the default shell
#: if it's not already set.
[[ $${SHELL} = *"zsh"* ]] || chsh -s $$(which zsh)
ensure-bash: ensure-brew
$(call log,"Running \"ensure-bash\"")
ifneq (,$(findstring darwin,$(OSTYPE)))
#: Darwin based OS uses brew
#: There might be an issue here because we assume that if bash isn't v4.4.*
#: that it's not installed with brew and this may be a bad assumption.
ifneq (4.4,$(findstring 4.4,$(shell bash --version)))
brew install bash
endif
else
#: Ubuntu uses apt-get to upgrade bash
ifneq (4.4,$(findstring 4.4,$(shell bash --version)))
sudo apt-get upgrade bash -y
endif
endif
#: Makes sure ansible is installed
ensure-ansible: ensure-brew
$(call log,"Running \"ensure-ansible\"")
ifneq (,$(findstring darwin,$(OSTYPE)))
#: Darwin installs from brew
[[ $$(which ansible) ]] || brew install ansible
else
ifneq (ansible,$(findstring ansible,$(shell which ansible)))
#: Ubuntu installs from custom apt ppa
sudo apt-get update --fix-missing -y
sudo apt-get install -y software-properties-common
DEBIAN_FRONTEND=noninteractive sudo apt-add-repository -y ppa:ansible/ansible
sudo apt-get update --fix-missing -y
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y ansible
endif
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment