-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·158 lines (122 loc) · 3.23 KB
/
bootstrap.sh
File metadata and controls
executable file
·158 lines (122 loc) · 3.23 KB
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
#!/bin/bash
# NOTE: WORK IN PROGRESS
LCYAN="\033[0;96m"
NC="\033[0m"
####################
# Helper functions #
####################
bootstrapEcho() {
echo -e "${LCYAN}Installing $1 and related files and packages...${NC}"
}
commandNotFound() {
for cmd in "$@"; do
if ! which "$cmd" &>/dev/null; then
echo -e "$cmd is not found\n"
return 0
fi
done
return 1
}
directoryNotFound() {
for dir in "$@"; do
if ! [[ -d "$dir" ]]; then
echo -e "$dir is not found\n"
return 0
fi
done
return 1
}
isNotFound() {
if [[ "$1" == "-c" ]]; then
if commandNotFound "${@:2}"; then return 0; fi
elif [[ "$1" == "-d" ]]; then
if directoryNotFound "${@:2}"; then return 0; fi
else
echo "Usage for commands: isNotFound -c [command1] [command2]..."
echo "Usage for directories: isNotFound -d [directory1] [directory2]..."
fi
return 1
}
isRunningBootstrapInDotfilesFolder() {
if [[ "$PWD" == *dotfiles ]]; then
return 0
else
return 1
fi
}
#######################
# Bootstrap functions #
#######################
bootstrapGit() {
bootstrapEcho "Git"
brew install git
cp git/* "$HOME"
}
bootstrapHomebrew() {
bootstrapEcho "Homebrew"
# Install Homebrew if not already installed (https://brew.sh/)
if isNotFound -c brew; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
fi
brew bundle install --file=homebrew/Brewfile
}
# Must be run before bootstrapNPM
bootstrapNode() {
bootstrapEcho "Node"
brew install nvm
node_version_regex="\d{1,2}\.\d{1,2}\.\d{1,2}"
latest_node_version=$(nvm ls-remote | tail -n1 | grep -Eo $node_version_regex)
nvm install "$latest_node_version"
nvm alias default "$latest_node_version"
}
bootstrapNPM() {
bootstrapEcho "NPM"
xargs npm i -g < npm/npm-global-packages.txt
}
bootstrapOhMyZsh() {
bootstrapEcho "Oh My Zsh"
# Install Oh My Zsh if not already installed (https://ohmyz.sh/)
if isNotFound -d "$HOME/.oh-my-zsh"; then
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
fi
cp oh-my-zsh/.zshrc "$HOME"
# TODO: move OhMyZsh files and custom plugins
}
bootstrapPip() {
bootstrapEcho "Python"
brew install python@3.8
brew link python@3.8
xargs pip install -U < pip/pip-global-packages.txt
}
bootstrapScripts() {
bootstrapEcho "scripts"
mkdir -p "$HOME/code"
cp -r scripts "$HOME/code"
}
bootstrapShell() {
bootstrapEcho "shell files"
cp shell/* "$HOME"
}
bootstrapVim() {
bootstrapEcho "Vim"
cp vim/.vimrc "$HOME"
cp -r vim/.vim "$HOME"
echo -e "To complete installation of vim plugins, type :PlugInstall in your vimrc"
}
bootstrapAll() {
if ! isRunningBootstrapInDotfilesFolder; then
echo "This file must be sourced in the same directory"
echo "Usage: cd /path/to/dotfiles && source bootstrap.sh"
return 1
fi
bootstrapHomebrew
# bootstrapOhMyZsh
bootstrapGit
bootstrapNode
bootstrapNPM
bootstrapPip
bootstrapScripts
bootstrapShell
bootstrapVim
}
bootstrapAll