-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.sh
executable file
·214 lines (185 loc) · 6.29 KB
/
setup.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
#!/usr/bin/env bash
# Created by Marcelo Carlos (contact@marcelocarlos.com)
# Source: https://github.com/marcelocarlosbr/dotfiles
set -euo pipefail
SCRIPT_NAME=$(basename $0)
BASE_DIR=$(dirname "$0")
if [[ "$BASE_DIR" == "." ]] ; then
BASE_DIR=$(pwd)
fi
CMD_FLAGS=''
# ------------------------------------------------------------------------------
# Functions
# ------------------------------------------------------------------------------
usage() {
cat << EOF
Usage: $SCRIPT_NAME [options]
Options:
-f force, overwrite files without asking for confirmation
-h show this menu
EOF
}
# $1 line (partials allowed)
# $2 file
contains_line() {
grep -q "$1" "$2"
}
print_h1() {
echo "$(tput bold)# ------------------------------------------------------------------------------$(tput sgr0)"
echo "$(tput bold)# $* $(tput sgr0)"
echo "$(tput bold)# ------------------------------------------------------------------------------$(tput sgr0)"
}
print_h2() {
echo "$(tput bold)## $* $(tput sgr0)"
}
print_green() {
echo "$(tput setaf 2)$* $(tput sgr0)"
}
print_yellow() {
echo "$(tput setaf 3)$* $(tput sgr0)"
}
function dotfiles_setup() {
for dotfile in $(ls -1 ${BASE_DIR}/dot); do
ln -sf ${CMD_FLAGS} "${BASE_DIR}/dot/$dotfile" "$HOME/.$dotfile"
done
}
# ------------------------------------------------------------------------------
# Main
# ------------------------------------------------------------------------------
while getopts "hfl" OPTION
do
case $OPTION in
f)
CMD_FLAGS='-f'
;;
h)
usage
exit 0
;;
?)
usage
exit 1
;;
esac
done
# ------------------------------------------------------------------------------
# Installing pre-requisites
# ------------------------------------------------------------------------------
print_h1 "Installing pre-requisites"
# install homebrew if not installed yet
if ! brew --version > /dev/null 2>&1; then
print_h2 "Installing Homebrew"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
print_green "Done." && echo
# ------------------------------------------------------------------------------
# Installing Applications
# ------------------------------------------------------------------------------
print_h1 "Installing Applications"
# install applications
print_yellow "Open the App Store and login to it before continuing. Press <enter> to continue"
read
#brew bundle
print_green "Done." && echo
# ------------------------------------------------------------------------------
# Dotfiles
# ------------------------------------------------------------------------------
print_h1 "Setting up Dotfiles"
# Setup dotfile
dotfiles_setup
print_green "Done." && echo
# ------------------------------------------------------------------------------
# Finishing setup
# ------------------------------------------------------------------------------
print_h1 "Finishing setup"
# Update default bash
if ! contains_line "/usr/local/bin/bash" "/etc/shells"; then
echo "/usr/local/bin/bash" | sudo tee -a /etc/shells
chsh -s /usr/local/bin/bash
fi
# post-setup - git
SETUP_GIT_CONFIG='n'
if [ -f "$HOME/.gitconfig.local" ]; then
read -p "$HOME/.gitconfig.local already exists, do you want to re-create it? [Y/n] " ANSWER
if [ "$ANSWER" != "n" ]; then
SETUP_GIT_CONFIG='y'
fi
else
SETUP_GIT_CONFIG='y'
fi
if [ ${SETUP_GIT_CONFIG} == 'y' ]; then
read -p "Git email address: " GIT_EMAIL
echo -e "[user]\nemail = $GIT_EMAIL" > ~/.gitconfig.local
read -p "Setup GPG? [Y/n] " ANSWER
if [ "$ANSWER" != "n" ]; then
echo "Available GPG keys: "
gpg --list-secret-keys --keyid-format LONG
read -p "GPG signing key (value from 'sec', after '/'): " GPG_KEY
echo "signingkey = $GPG_KEY" >> ~/.gitconfig.local
echo -e "[commit]\ngpgsign = true" >> ~/.gitconfig.local
echo -e "[gpg]\nprogram = gpg" >> ~/.gitconfig.local
fi
fi
# remove quarantine from Quicklook plugins
# xattr -r ~/Library/QuickLook # To see the attributes
xattr -d -r com.apple.quarantine ~/Library/QuickLook
qlmanage -r
# remove quarantine from specific apps
# xattr -r /Applications/ # To see all
xattr -d -r com.apple.quarantine /Applications/BetterZip.app
# python setup
python3 -m pip install --upgrade setuptools
python3 -m pip install --upgrade pip
python3 -m pip install virtualenv
python3 -m pip install yq
# needed by vim plugin https://github.com/Shougo/deoplete.nvim
python3 -m pip install pynvim
# ruby setup
GLOBAL_RUBY_VERSION="3.2.1"
if [ "$(rbenv versions | grep -F ${GLOBAL_RUBY_VERSION} &> /dev/null)$?" -gt 0 ]; then
rbenv install ${GLOBAL_RUBY_VERSION}
rbenv global ${GLOBAL_RUBY_VERSION}
fi
eval "$(rbenv init -)"
# Check that bundler is installed
if [ "$(which bundle &> /dev/null)$?" -gt 0 ]; then
gem install bundler
rbenv rehash
fi
gem install rubocop
# docker completions
ln -sf /Applications/Docker.app/Contents/Resources/etc/docker.bash-completion /usr/local/etc/bash_completion.d/docker.bash-completion
ln -sf /Applications/Docker.app/Contents/Resources/etc/docker-machine.bash-completion /usr/local/etc/bash_completion.d/docker-machine.bash-completion
ln -sf /Applications/Docker.app/Contents/Resources/etc/docker-compose.bash-completion /usr/local/etc/bash_completion.d/docker-compose.bash-completion
# git-secrets
git secrets --register-aws --global
# pinentry
if ! contains_line "pinentry-program /usr/local/bin/pinentry-mac" "$HOME/.gnupg/gpg-agent.conf"; then
echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
fi
# fzf
$(brew --prefix)/opt/fzf/install
# iterm2
wget https://raw.githubusercontent.com/nathanbuchar/atom-one-dark-terminal/master/scheme/iterm/One%20Dark.itermcolors
open One\ Dark.itermcolors
git clone https://github.com/powerline/fonts.git --depth=1
cd fonts
./install.sh
cd ..
rm -rf fonts
rm -f One\ Dark.itermcolors
echo
print_yellow "IMPORTANT: Open iterm2 preferences (General > Preferences) and ensure you set 'Load preferences from ...' to $BASE_DIR/iterm so iterm2 settings are loaded"
echo
# apply the changes to the current session
set +eu
source ~/.bash_profile
set -eu
print_green "Done."
echo
# open -a Magnet
# open -a Pastebot
# open -a TextSniper
# open -a 'istat menus'
# open -a 'Alfred 4'
print_green "$(tput bold)All done! Enjoy!"