-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup
executable file
·153 lines (123 loc) · 3.42 KB
/
setup
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/sh
# This script is heavily influenced by the laptop project from the great
# thoughtbot team and the fantastic Mathias Bynens' dot files. Many thanks
# to both. Checkout their repos here:
#
# - https://github.com/thoughtbot/laptop
# - https://github.com/mathiasbynens/dotfiles
bcolor=$(tput setaf 32)
hcolor=$(tput setaf 32)
ecolor=$(tput setaf 1)
normal=$(tput sgr0)
ascii_art="
/## /##
| ## | ##
| ####### /###### /###### /###### | ##
| ##__ ## |____ ## /##__ ## /##__ ##| ##
| ## \ ## /#######| ## \ ##| ########| ##
| ## | ## /##__ ##| ## | ##| ##_____/| ##
| #######/| #######| #######| #######| ##
|_______/ \_______/ \____ ## \_______/|__/
/## \ ##
| ######/
\______/
"
welcome="
Welcome! Lets build an awesome dev machine together.
This might take a bit of time, so run me and then go
eat a bagel - don't forget to add cream cheese!
"
pause="
Ready to roll? Smash any key and let the magic begin.
(CTRL+C to stop)
"
finished="
It looks like we are finished here. Now go and enjoy
life inside your new dev environment!
BTW, did you save me any bagels?
"
chaos="
Oh no!! It looks like something failed. Checkout the
errors below and try running bagel again.
"
function header_log {
printf "\n${hcolor}$1${normal}\n"
printf "=%.s" {1..55}
printf "\n\n"
}
function error_log {
printf "${ecolor}$1${normal}\n"
}
function log {
printf "$1\n"
}
function clean {
printf "${ecolor}$chaos${normal}\n"
printf "$@"
}
function expand_alias {
brew info "$1" 2>/dev/null | head -1 | awk '{gsub(/:/, ""); print $1}'
}
function is_installed {
local name="$(expand_alias "$1")"
brew list -1 | grep -Fqx "$name"
}
function is_upgradable {
local name="$(expand_alias "$1")"
brew outdated --quiet "$name" >/dev/null
[[ $? -ne 0 ]]
}
function brew_upgrade_or_install {
if is_installed "$1"; then
if is_upgradable "$1"; then
log "upgrading $1"
brew upgrade "$@"
fi
else
log "installing $1"
brew install "$@"
fi
}
function cask_install {
log "installing $1"
brew cask install "$@"
}
# Start the bagel script
printf "%s" "${bcolor}$ascii_art${normal}"
printf "%s" "$welcome"
read -p "$pause"
# Ask for the administrator password upfront
sudo -v
# Keep-alive: update existing `sudo` time stamp until finished
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# Kill execution if something goes wrong. TODO: exit more gracefully.
# trap 'ret=$?; test $ret -ne 0 && printf "failed\n\n" >&2; exit $ret' EXIT
# set -e
# Before doing anything else update bagel
header_log "Update Bagel"
log "bagel is updating itself to the latest release"
log "trying not to take over human kind\n"
cd "$(dirname "${BASH_SOURCE}")"
git pull origin master
log "\nmoving on"
# Make sure homebrew is installed
header_log "Bootstrapping"
if ! command -v brew >/dev/null; then
log "installing homebrew"
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
export PATH="/usr/local/bin:$PATH"
else
log "homebrew is already installed"
fi
# Run all of the bagel recipes
source ./recipes/shell
source ./recipes/brew
source ./recipes/cask
source ./recipes/ruby
source ./recipes/go
source ./recipes/python
source ./recipes/dots
source ./recipes/editor
# source ./recipes/macos
# We are done!
printf "\n\n%s\n" "$finished"