-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
87 lines (71 loc) · 2.68 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
.PHONY: all
all: help
.PHONY: help
help: list
@echo
@echo Edit the files above and do \"make run\".
@echo
@echo The commands below will help you edit \"vars.yml\" files for Homebrew.
@echo make generate_MacOSX_homebrew_formulae_vars_yml
@echo make generate_MacOSX_homebrew_casks_vars_yml
.PHONY: list
list:
@find . -name 'vars.yml' -o -name '*.j2'
.PHONY: install
install: install_ansible
.PHONY: ruby_exists
ruby_exists:
@if [ ! -x /usr/bin/ruby ]; then echo ruby not installed; false; fi
.PHONY: curl_exists
curl_exists:
@if [ -z `which curl` ]; then echo curl not installed; false; fi
.PHONY: install_brew
install_brew: curl_exists
@which brew || /bin/bash -c "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
.PHONY: update_brew
update_brew: install_brew
@brew update
.PHONY: install_ansible
install_ansible: install_brew update_brew
@brew list --versions ansible || brew install ansible
.PHONY: run
run: install play uninstall
TAGS=all
.PHONY: play
play:
ansible-playbook --tags $(TAGS) site.yml
.PHONY: generate_MacOSX_homebrew_formulae_vars_yml
generate_MacOSX_homebrew_formulae_vars_yml:
@echo '# state: absent | present | upgraded'
@echo '# put "formulae: []" to do nothing'
@echo 'formulae:'
@for f in `brew list --formula`; do echo " - name: $$f"; echo " state: upgraded"; done
.PHONY: generate_MacOSX_homebrew_casks_vars_yml
generate_MacOSX_homebrew_casks_vars_yml:
@echo '# state: absent | present | upgraded'
@echo '# put "casks: []" to do nothing'
@echo 'casks:'
@for f in `brew list --cask`; do echo " - name: $$f"; echo " state: upgraded"; done
.PHONY: uninstall
uninstall: clean_cache clear_formulae
# also removes installed packages
.PHONY: uninstall_brew
uninstall_brew: curl_exists
/bin/bash -c "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"
.PHONY: clean_cache
clean_cache: install_brew
-brew cleanup
TEMP_PRESENT := $(shell mktemp)
TEMP_UNINSTALLABLE := $(shell mktemp)
FORMULAE_VARS := MacOSX/homebrew/formulae/vars.yml
# this may remove packages needed by installed packages
.PHONY: clear_formulae
clear_formulae: ruby_exists install_brew
@/usr/bin/ruby -ryaml -e 'puts YAML.load_file("$(FORMULAE_VARS)")["formulae"].map{|f| puts f["name"] if ["present", "upgraded"].include?(f["state"])}.compact' > $(TEMP_PRESENT)
@test -s $(TEMP_PRESENT) && brew list --formula | grep -v -f $(TEMP_PRESENT) > $(TEMP_UNINSTALLABLE); true
@for i in `cat $(TEMP_UNINSTALLABLE)`; do \
for f in `brew list --formula | grep -v -f $(TEMP_PRESENT)`; do \
brew list --formula --versions $$f > /dev/null && brew uninstall $$f 2> /dev/null || true; \
done \
done
@rm $(TEMP_PRESENT) $(TEMP_UNINSTALLABLE)