-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·235 lines (188 loc) · 5.21 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/bin/bash
set -e
# Detect current directory.
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";
# Start helper functions ====>
# Prints statement and a new line
print() {
echo "$@"
}
# Helper function to check if a program exists
exists() {
command -v "$1" >/dev/null 2>&1
}
# Force create a link
create_link() {
printf "\e[0;33mCreating link:\e[0m \e[0;34m${HOME}/${2}\e[0m \e[0;33m=>\e[0m \e[0;34m${ROOT_DIR}/${1}\e[0m"
echo
backup $2 # Backup existing target
ln -fs "${ROOT_DIR}/${1}" "${HOME}/${2}"
}
# Backup a file or directory
backup() {
# Check if file/dir exists
test -e $HOME/$1 && \
# Notify
print_in_yellow "Backing up: $HOME/$1 to $HOME/$1.abak" && \
# Remove existing backup, if any.
rm -rf $HOME/$1.abak && \
# Backup
mv $HOME/$1 $HOME/$1.abak
true
}
# Installs package using apt-get
apt_install() {
sudo apt-get install -y $1
}
# Print functions
print_in_purple() {
printf "\e[0;35m$1\e[0m"
}
print_in_green() {
printf "\e[0;32m$1\e[0m"
}
print_in_red() {
printf "\e[0;31m$1\e[0m"
}
print_in_yellow() {
printf "\e[0;33m$1\e[0m\n"
}
print_info() {
print_in_purple "\n ➔ $1\n\n"
}
print_success() {
print_in_green "\n [✔] $1\n"
}
print_error() {
print_in_red "\n [✖] $1 $2\n"
}
# <==== End helper functions
# Let"s detect OS first
ON_UBUNTU=false
ON_OSX=false
if [[ "$OSTYPE" == "linux"* && "$(. /etc/os-release; echo $NAME)" == "Ubuntu" ]]; then
ON_UBUNTU=true
print_info "Customizing for Ubuntu..."
elif [[ "$OSTYPE" == "darwin"* ]]; then
ON_OSX=true
print_info "Customizing for MacOS..."
else
print_error "Incompatible OS. Script works on MacOS & Ubuntu."
exit 1
fi
# Installs homebrew
install_homebrew() {
if exists brew; then
print_success "Homebrew installation found."
else
print_info "Installing Homebrew..."
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
print_success "Done"
fi
}
# Installs iTerm2
install_iterm2() {
brew tap caskroom/versions
brew cask install iterm2-beta
}
install_nvm() {
if [[ -f $HOME/.nvm/nvm.sh ]]; then
print_success "NVM installation found."
else
print_info "Installing nvm..."
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash
print_success "Done"
fi
}
install_node() {
print_info "Installing latest Node LTS"
. $HOME/.nvm/nvm.sh && nvm install --lts
}
# Installs yarn
install_yarn() {
print_info "Yarn installation..."
if exists yarn; then
print_success "...already exists, skipping installation."
return
fi
if $ON_OSX; then
print_in_yellow "...installing via brew..."
brew install yarn
else
print_in_yellow "...installing via apt-get..."
apt_install yarn
fi
print_success "Done."
}
# Install, configure & make ZSH the default shell
install_zsh() {
print_info "ZSH Config..."
if exists zsh; then
print_in_yellow "ZSH already exists. Not installing..."
elif $ON_OSX; then
print_in_yellow "Installing ZSH via Brew..."
brew install zsh
else
print_in_yellow "Installing ZSH via apt-get..."
apt_install zsh
fi
# Update Prezto sumodules recursively
cd $ROOT_DIR/zsh/.zprezto
print_in_yellow "Pulling prezto modules..."
git pull && git submodule update --init --recursive
cd $ROOT_DIR
# Link the entire zsh folder to ~/.zsh
create_link "zsh" ".zsh"
# Link .zprezto to home dir
create_link "zsh/.zprezto" ".zprezto"
# Link prezto config files
# Links are made in the order Prezto reads them. Doesn't make a difference though.
create_link "zsh/zshenv.zsh" ".zshenv"
create_link "zsh/zprofile.zsh" ".zprofile"
# Link the .zshrc file to home dir
create_link "zsh/.zshrc" ".zshrc"
create_link "zsh/zpreztorc.zsh" ".zpreztorc"
create_link "zsh/zlogin.zsh" ".zlogin"
# Make ZSH the default shell for current user
if $ON_OSX; then
# Since ZSH is a non standard install using brew, we have to add it to `/etc/shells`
grep '/usr/local/bin/zsh' /etc/shells > /dev/null || \
# Append if the line doesn't already exist
echo '/usr/local/bin/zsh' | sudo tee -a /etc/shells > /dev/null
fi
if [ $SHELL = $(which zsh) ]; then
print 'ZSH is already the default shell...'
else
chsh -s $(which zsh)
fi
print_success "Done"
}
# Install fancy diff
install_fancy_diff() {
print_in_yellow "Installing diff-so-fancy via yarn..."
exists diff-so-fancy || yarn global add diff-so-fancy
}
# Configures git
config_git() {
print_info "Git config..."
install_fancy_diff
create_link "git/.gitignore" ".gitignore"
create_link "git/.gitconfig" ".gitconfig"
print_success "Done."
}
if $ON_OSX; then
install_homebrew
[ ! -f "/Applications/iTerm.app" ] || install_iterm2
fi
# Install nvm. Used to install node & yarn.
install_nvm
# Yarn requires Node v4+
install_node
# Install yarn. Provides diff-so-fancy.
install_yarn
# Configure Git
config_git
# Install & Config ZSH
install_zsh
# Link tmux config file
# link ".tmux.conf" ".tmux.conf"