-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
332 lines (277 loc) · 11.1 KB
/
install.sh
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/usr/bin/env bash
###########################
# This script installs the dotfiles and runs all other system configuration scripts
# @author Adam Eivy
###########################
# include my library helpers for colorized echo and require_brew, etc
source ./lib_sh/echos.sh
source ./lib_sh/requirers.sh
bot "Hi! I'm going to install tooling and tweak your system settings. Here I go..."
# Ask for the administrator password upfront
if ! sudo grep -q "%wheel ALL=(ALL) NOPASSWD: ALL #atomantic/dotfiles" "/etc/sudoers"; then
# Ask for the administrator password upfront
bot "I need you to enter your sudo password so I can install some things:"
sudo -v
# Keep-alive: update existing sudo time stamp until the script has finished
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
bot "Do you want me to setup this machine to allow you to run sudo without a password?\nPlease read here to see what I am doing:\nhttp://wiki.summercode.com/sudo_without_a_password_in_mac_os_x \n"
read -r -p "Make sudo passwordless? [y|N] " response
if [[ $response =~ (yes|y|Y) ]];then
sudo cp /etc/sudoers /etc/sudoers.back
echo '%wheel ALL=(ALL) NOPASSWD: ALL #atomantic/dotfiles' | sudo tee -a /etc/sudoers > /dev/null
sudo dscl . append /Groups/wheel GroupMembership $(whoami)
bot "You can now run sudo commands without password!"
fi
fi
# ###########################################################
# Git Config
# ###########################################################
bot "OK, now I am going to update the .gitconfig for your user info:"
grep 'user = GITHUBUSER' ./homedir/.gitconfig > /dev/null 2>&1
if [[ $? = 0 ]]; then
read -r -p "What is your github.com username? " githubuser
fullname=`osascript -e "long user name of (system info)"`
if [[ -n "$fullname" ]];then
lastname=$(echo $fullname | awk '{print $2}');
firstname=$(echo $fullname | awk '{print $1}');
fi
if [[ -z $lastname ]]; then
lastname=`dscl . -read /Users/$(whoami) | grep LastName | sed "s/LastName: //"`
fi
if [[ -z $firstname ]]; then
firstname=`dscl . -read /Users/$(whoami) | grep FirstName | sed "s/FirstName: //"`
fi
email=`dscl . -read /Users/$(whoami) | grep EMailAddress | sed "s/EMailAddress: //"`
if [[ ! "$firstname" ]];then
response='n'
else
echo -e "I see that your full name is $COL_YELLOW$firstname $lastname$COL_RESET"
read -r -p "Is this correct? [Y|n] " response
fi
if [[ $response =~ ^(no|n|N) ]];then
read -r -p "What is your first name? " firstname
read -r -p "What is your last name? " lastname
fi
fullname="$firstname $lastname"
bot "Great $fullname, "
if [[ ! $email ]];then
response='n'
else
echo -e "The best I can make out, your email address is $COL_YELLOW$email$COL_RESET"
read -r -p "Is this correct? [Y|n] " response
fi
if [[ $response =~ ^(no|n|N) ]];then
read -r -p "What is your email? " email
if [[ ! $email ]];then
error "you must provide an email to configure .gitconfig"
exit 1
fi
fi
running "replacing items in .gitconfig with your info ($COL_YELLOW$fullname, $email, $githubuser$COL_RESET)"
# test if gnu-sed or MacOS sed
sed -i "s/GITHUBFULLNAME/$firstname $lastname/" ./homedir/.gitconfig > /dev/null 2>&1 | true
if [[ ${PIPESTATUS[0]} != 0 ]]; then
echo
running "looks like you are using MacOS sed rather than gnu-sed, accommodating"
sed -i '' "s/GITHUBFULLNAME/$firstname $lastname/" ./homedir/.gitconfig;
sed -i '' 's/GITHUBEMAIL/'$email'/' ./homedir/.gitconfig;
sed -i '' 's/GITHUBUSER/'$githubuser'/' ./homedir/.gitconfig;
ok
else
echo
bot "looks like you are already using gnu-sed. woot!"
sed -i 's/GITHUBEMAIL/'$email'/' ./homedir/.gitconfig;
sed -i 's/GITHUBUSER/'$githubuser'/' ./homedir/.gitconfig;
fi
fi
# ###########################################################
# Wallpaper
# ###########################################################
MD5_NEWWP=$(md5 img/wallpaper.jpg | awk '{print $4}')
MD5_OLDWP=$(md5 /System/Library/CoreServices/DefaultDesktop.jpg | awk '{print $4}')
if [[ "$MD5_NEWWP" != "$MD5_OLDWP" ]]; then
read -r -p "Do you want to use the project's custom desktop wallpaper? [y|N] " response
if [[ $response =~ (yes|y|Y) ]]; then
running "Set a custom wallpaper image"
# rm -rf ~/Library/Application Support/Dock/desktoppicture.db
bot "I will backup system wallpapers in ~/.dotfiles/img/"
sudo cp /System/Library/CoreServices/DefaultDesktop.jpg img/DefaultDesktop.jpg > /dev/null 2>&1
sudo cp /Library/Desktop\ Pictures/El\ Capitan.jpg img/El\ Capitan.jpg > /dev/null 2>&1
sudo cp /Library/Desktop\ Pictures/Sierra.jpg img/Sierra.jpg > /dev/null 2>&1
sudo cp /Library/Desktop\ Pictures/Sierra\ 2.jpg img/Sierra\ 2.jpg > /dev/null 2>&1
sudo rm -f /System/Library/CoreServices/DefaultDesktop.jpg > /dev/null 2>&1
sudo rm -f /Library/Desktop\ Pictures/El\ Capitan.jpg > /dev/null 2>&1
sudo rm -f /Library/Desktop\ Pictures/Sierra.jpg > /dev/null 2>&1
sudo rm -f /Library/Desktop\ Pictures/Sierra\ 2.jpg > /dev/null 2>&1
sudo cp ./img/wallpaper.jpg /System/Library/CoreServices/DefaultDesktop.jpg;
sudo cp ./img/wallpaper.jpg /Library/Desktop\ Pictures/Sierra.jpg;
sudo cp ./img/wallpaper.jpg /Library/Desktop\ Pictures/Sierra\ 2.jpg;
sudo cp ./img/wallpaper.jpg /Library/Desktop\ Pictures/El\ Capitan.jpg;ok
else
ok "skipped"
fi
fi
# ###########################################################
# Install non-brew various tools (PRE-BREW Installs)
# ###########################################################
bot "ensuring build/install tools are available"
if ! xcode-select --print-path &> /dev/null; then
# Prompt user to install the XCode Command Line Tools
xcode-select --install &> /dev/null
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Wait until the XCode Command Line Tools are installed
until xcode-select --print-path &> /dev/null; do
sleep 5
done
print_result $? ' XCode Command Line Tools Installed'
# Prompt user to agree to the terms of the Xcode license
# https://github.com/alrra/dotfiles/issues/10
sudo xcodebuild -license
print_result $? 'Agree with the XCode Command Line Tools licence'
fi
# ###########################################################
# install homebrew (CLI Packages)
# ###########################################################
running "checking homebrew install"
brew_bin=$(which brew) 2>&1 > /dev/null
if [[ $? != 0 ]]; then
action "installing homebrew"
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
if [[ $? != 0 ]]; then
error "unable to install homebrew, script $0 abort!"
exit 2
fi
brew analytics off
else
# Make sure we’re using the latest Homebrew
ok
bot "Homebrew"
read -r -p "run brew update && upgrade? [y|N] " response
if [[ $response =~ (y|yes|Y) ]]; then
action "updating homebrew..."
brew update
ok "homebrew updated"
action "upgrading brew packages..."
brew upgrade
ok "brews upgraded"
else
ok "skipped brew package upgrades."
fi
fi
# Just to avoid a potential bug
mkdir -p ~/Library/Caches/Homebrew/Formula
brew doctor
#####
# install brew cask (UI Packages)
#####
running "checking brew-cask install"
output=$(brew tap | grep cask)
if [[ $? != 0 ]]; then
action "installing brew-cask"
require_brew caskroom/cask/brew-cask
fi
brew tap caskroom/versions > /dev/null 2>&1
ok
# skip those GUI clients, git command-line all the way
require_brew git
# update zsh to latest
require_brew zsh
# update ruby to latest
# use versions of packages installed with homebrew
RUBY_CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl` --with-readline-dir=`brew --prefix readline` --with-libyaml-dir=`brew --prefix libyaml`"
require_brew ruby
# set zsh as the user login shell
CURRENTSHELL=$(dscl . -read /Users/$USER UserShell | awk '{print $2}')
if [[ "$CURRENTSHELL" != "/usr/local/bin/zsh" ]]; then
bot "setting newer homebrew zsh (/usr/local/bin/zsh) as your shell (password required)"
# sudo bash -c 'echo "/usr/local/bin/zsh" >> /etc/shells'
# chsh -s /usr/local/bin/zsh
sudo dscl . -change /Users/$USER UserShell $SHELL /usr/local/bin/zsh > /dev/null 2>&1
ok
fi
if [[ ! -d "./oh-my-zsh/custom/themes/powerlevel10k" ]]; then
git clone https://github.com/romkatv/powerlevel10k.git oh-my-zsh/custom/themes/powerlevel10k
fi
bot "Dotfiles Setup"
read -r -p "symlink ./homedir/* files in ~/ (these are the dotfiles)? [y|N] " response
if [[ $response =~ (y|yes|Y) ]]; then
bot "creating symlinks for project dotfiles..."
pushd homedir > /dev/null 2>&1
now=$(date +"%Y.%m.%d.%H.%M.%S")
for file in .*; do
if [[ $file == "." || $file == ".." ]]; then
continue
fi
running "~/$file"
# if the file exists:
if [[ -e ~/$file ]]; then
mkdir -p ~/.dotfiles_backup/$now
mv ~/$file ~/.dotfiles_backup/$now/$file
echo "backup saved as ~/.dotfiles_backup/$now/$file"
fi
# symlink might still exist
unlink ~/$file > /dev/null 2>&1
# create the link
ln -s ~/.dotfiles/homedir/$file ~/$file
echo -en '\tlinked';ok
done
popd > /dev/null 2>&1
fi
read -r -p "Install fonts? [y|N] " response
if [[ $response =~ (y|yes|Y) ]];then
bot "installing fonts"
# need fontconfig to install/build fonts
require_brew fontconfig
./fonts/install.sh
brew tap homebrew/cask-fonts
require_brew svn #required for roboto
require_cask font-fontawesome
require_cask font-awesome-terminal-fonts
require_cask font-hack
require_cask font-inconsolata-dz-for-powerline
require_cask font-inconsolata-g-for-powerline
require_cask font-inconsolata-for-powerline
require_cask font-roboto-mono
require_cask font-roboto-mono-for-powerline
require_cask font-source-code-pro
ok
fi
# node version manager
require_brew nvm
# nvm
require_nvm stable
#####################################
# Now we can switch to node.js mode
# for better maintainability and
# easier configuration via
# JSON files and inquirer prompts
#####################################
bot "installing npm tools needed to run this project..."
npm install
ok
bot "installing packages from config.js..."
node index.js
ok
running "cleanup homebrew"
brew cleanup --force > /dev/null 2>&1
rm -f -r /Library/Caches/Homebrew/* > /dev/null 2>&1
ok
bot "OS Configuration"
read -r -p "Do you want to update the system configurations? [y|N] " response
if [[ -z $response || $response =~ ^(n|N) ]]; then
open /Applications/iTerm.app
bot "All done"
exit
fi
source ./mac/dock.sh
###############################################################################
# Kill affected applications #
###############################################################################
bot "OK. Note that some of these changes require a logout/restart to take effect. Killing affected applications (so they can reboot)...."
for app in "Activity Monitor" "Address Book" "Calendar" "Contacts" "cfprefsd" \
"Dock" "Finder" "Mail" "Messages" "Safari" "SystemUIServer" \
"iCal" "Terminal"; do
killall "${app}" > /dev/null 2>&1
done
brew update && brew upgrade && brew cleanup
bot "Woot! All done"