-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·242 lines (197 loc) · 7.2 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
#! /usr/bin/zsh
# A simple script for setting up OSX dev environment.
dotfile_dir="$HOME/Code/dotfiles"
# Ask for sudo permission at start
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 &
######################################################
# Utils
######################################################
print_message() {
local message=$1
echo "$message....."
}
create_dir() {
local dirname=$1
if [[ ! -d $dirname ]]; then
echo "--> $dirname"
mkdir -p $dirname 2>/dev/null
echo ""
fi
}
create_file_and_symlink() {
local realfile=$1
local virtualfile=$2
local permission=${3:-644}
touch "$virtualfile"
chmod "$permission" "$virtualfile"
print_message "Linking $virtualfile to $realfile"
ln -sf "$realfile" "$virtualfile"
}
clone_dotfile_git_repo() {
create_dir "$HOME/Dropbox/Code"
git clone https://github.com/riftinwild/dotfiles.git $dotfile_dir
}
change_shell() {
print_message "Changing shell to ZSH..."
if [[ ! $(echo $SHELL) == $(which zsh) ]]; then
chsh -s $(which zsh)
fi
}
install_prezto() {
print_message "Installing prezto"
if [ ! -d "${ZDOTDIR:-$HOME}/.zprezto" ]; then
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
fi
setopt EXTENDED_GLOB
for rcfile in "'${ZDOTDIR:-$HOME}'/.zprezto/runcoms/^README.md\(.N\)"; do
ln -sf "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done
}
symlink_dotfiles() {
create_dir "$HOME/.config"
user=$USER
chown -R "$user" "$HOME/.config/"
print_message "Symlinking files... $user"
declare -a files=("zsh/zshrc" "zsh/zshenv" "zsh/zpreztorc" "vim/vimrc"
"xvim/xvimrc" "tmux/tmux" "tmux/tmux.conf" "git/gitignore"
"git/gitconfig")
for file in "${files[@]}"; do
f=${file}
f=${f##*/}
create_file_and_symlink $dotfile_dir/$file ~/.$f
done
# some symlinks are in separate directory
create_file_and_symlink "$dotfile_dir/karabiner/karabiner.json" "$HOME/.config/karabiner.json"
create_file_and_symlink "$dotfile_dir/editorconfig" "$HOME/.editorconfig"
create_file_and_symlink "$dotfile_dir/nvim/init.vim" "$HOME/.config/nvim/init.vim"
}
#############################
# Start #
#############################
# If we on OS X, install homebrew and tweak system a bit.
if [[ $(uname) == 'Darwin' ]]; then
##############################################
# Xcode utils #
##############################################
if ! xcode-select --print-path &>/dev/null; then
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
fi
#############################################
# Homebrew #
#############################################
which -s brew
if [[ $? != 0 ]]; then
print_message 'Installing Homebrew...'
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew update
brew tap Homebrew/bundle
brew install git
brew search '/font-.*-nerd-font/' | awk '{ print $1 }' | xargs -I{} brew install --cask {} || true
fi
##############################################
# dotfiles #
##############################################
if [ ! -d $dotfile_dir ]; then
clone_dotfile_git_repo
fi
##############################################
# Xcode Command Line #
##############################################
print_message "Setting up commad line tools..."
sh $dotfile_dir/osx/xcode_setup.sh
##############################################
# ZSH #
##############################################
print_message "Installing ZSH..."
if ! type "zsh" >/dev/null; then
brew install zsh
brew install zsh-completions
fi
change_shell
brew_zsh_path="/usr/local/bin/zsh"
if [[ $(which zsh) == $brew_zsh_path ]]; then
# For mac user we need to change the shell for user
dscl . -create /Users/$USER UserShell $brew_zsh_path
fi
##############################################
# OSX #
##############################################
echo 'Do you want to reconfigure system setting? This will change your computer name and other system default settings'
echo 'n / y'
read give_links
if [[ "$give_links" == 'y' ]]; then
sh $dotfile_dir/osx/sensible_defaults.sh
fi
###############################################
# SSH
###############################################
print_message 'Checking for SSH key, generating one if it does not exist...'
if [ ! -f "$HOME/.ssh/id_rsa.pub" ]; then
ssh-keygen -t rsa
echo 'Copying public key to clipboard. Paste it into your Github account...'
[[ -f '$HOME/.ssh/id_rsa.pub' ]] && cat '$HOME/.ssh/id_rsa.pub' | pbcopy
open 'https://github.com/account/ssh'
fi
print_message "The keys exists"
##############################################
# Apps #
##############################################
echo 'Do you want to install app from brew bundle?'
echo 'n / y'
read give_links
if [[ "$give_links" == 'y' ]]; then
brew bundle --file="$dotfile_dir/Brewfile"
fi
#############################################
# Powerline Fonts
############################################
git clone https://github.com/powerline/fonts.git --depth=1
cd fonts
sh ./install.sh
cd ..
rm -rf fonts
##############################################
# zshrc #
##############################################
install_prezto
##############################################
# Symlinks #
##############################################
# symlink for special emacs
if [ ! -d "$HOME/.config/nvim" ]; then
create_dir "$HOME/.config/nvim"
fi
symlink_dotfiles
##############################################
# NeoVim
###############################################
# Architecture issue with M macs
brew unlink tree-sitter
arch -arm64 brew install --HEAD tree-sitter
brew unlink nvim
arch -arm64 brew install --HEAD nvim
git clone https://github.com/NvChad/NvChad ~/.config/nvim --depth 1
print_message "Done :)"
fi
##############################################
# TODO: Add setups for apps
##############################################
# If on Linux, install zsh
if [[ $(uname) != 'Darwin' ]]; then
which -s zsh
if [[ $? != 0 ]]; then
echo 'Installing zsh and prezto...'
sudo apt-get install zsh curl
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
fi
fi