-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap_user.sh
executable file
·213 lines (163 loc) · 4.06 KB
/
bootstrap_user.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
#!/bin/bash
function setUp() {
# setShell
# setAsdfVersionManager
# setPythonLibrary
setDotFiles
}
function setShell() {
case "$SHELL" in
*/zsh)
if [ "$(command -v zsh)" != '/user/local/bin/zsh' ] ; then
update_shell
fi
;;
*)
update_shell
;;
esac
}
function setPythonLibrary() {
pip3 install --user --upgrade awscli
}
function setAsdfVersionManager() {
fancy_echo "Configuring asdf version manager..."
if [ ! -d "$HOME/.asdf" ]; then
git clone https://github.com/asdf-vm/asdf.git ~/.asdf
fi
source "$HOME/.asdf/asdf.sh"
install_asdf_plugin "ruby" "https://github.com/asdf-vm/asdf-ruby.git"
install_asdf_plugin "nodejs" "https://github.com/asdf-vm/asdf-nodejs.git"
fancy_echo "Installing latest Ruby..."
install_asdf_language "ruby"
gem update --system
fancy_echo "Installing latest Node..."
bash "$HOME/.asdf/plugins/nodejs/bin/import-release-team-keyring"
install_asdf_language "nodejs"
}
# Shell stuff
update_shell() {
chsh -s "/bin/zsh" "$USER"
}
function setDotFiles() {
fancy_echo "Configuring dotfiles..."
read -p "This may overwrite existing files in your home directory. Are you sure? (y/n) " -n 1;
echo "";
if [[ $REPLY =~ ^[Yy]$ ]]; then
linkFiles
configureVim
configureMac
fi;
}
function linkFiles () {
fancy_echo 'Linking all the dotfiles'
local overwrite_all=false backup_all=false skip_all=false
for src in $(find -H "$DOTFILES_ROOT" -maxdepth 2 -name '.*' -not -path '*.git')
do
dst="$HOME/$(basename "${src}")"
linkFile "$src" "$dst"
done
}
function configureMac() {
sh ~/.macos_user
}
function configureVim() {
if [ ! -d "$HOME/.vim/bundle/Vundle.vim" ]; then
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
fi
vim +PluginInstall +qall
}
# Helpers
function linkFile () {
local src=$1 dst=$2
local overwrite= backup= skip=
local action=
if [ -f "$dst" -o -d "$dst" -o -L "$dst" ]
then
if [ "$overwrite_all" == "false" ] && [ "$backup_all" == "false" ] && [ "$skip_all" == "false" ]
then
local currentSrc="$(readlink $dst)"
if [ "$currentSrc" == "$src" ]
then
skip=true;
else
fancy_echo "File already exists: "$src"), what do you want to do?\n\
[s]kip, [S]kip all, [o]verwrite, [O]verwrite all, [b]ackup, [B]ackup all?"
read -n 1 action
case "$action" in
o )
overwrite=true;;
O )
overwrite_all=true;;
b )
backup=true;;
B )
backup_all=true;;
s )
skip=true;;
S )
skip_all=true;;
* )
;;
esac
fi
fi
overwrite=${overwrite:-$overwrite_all}
backup=${backup:-$backup_all}
skip=${skip:-$skip_all}
if [ "$overwrite" == "true" ]
then
rm -rf "$dst"
fancy_echo "removed $dst"
fi
if [ "$backup" == "true" ]
then
mv "$dst" "${dst}.backup"
fancy_echo "moved $dst to ${dst}.backup"
fi
if [ "$skip" == "true" ]
then
fancy_echo "skipped $src"
fi
fi
if [ "$skip" != "true" ] # "false" or empty
then
ln -s "$1" "$2"
fancy_echo "linked $1 to $2"
fi
}
# Prints
function fancy_echo() {
local fmt="$1"; shift
printf "\n$fmt\n" "$@" $1
}
# Ruby stuff
function gem_install_or_update() {
if gem list "$1" --installed > /dev/null; then
gem update "$@"
else
gem install --user-install "$@"
fi
}
# Asdf stuff
install_asdf_plugin() {
local name="$1"
local url="$2"
if ! asdf plugin-list | grep -Fq "$name"; then
asdf plugin-add "$name" "$url"
fi
}
install_asdf_language() {
local language="$1"
local version
version="$(asdf list-all "$language" | grep -v "[a-z]" | tail -1)"
echo $language
echo $version
if ! asdf list "$language" | grep -Fq "$version"; then
asdf install "$language" "$version"
asdf global "$language" "$version"
fi
}
DOTFILES_ROOT=$(pwd -P)
set -e
setUp