-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·259 lines (216 loc) · 6.38 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/bin/bash
FORCE_UPGRADE="${FORCE_UPGRADE:-0}"
MAKE_TIMESTAMP="$(date +%s)"
OS="$(uname -s)"
RESTORE_TIMESTAMP="${RESTORE_TIMESTAMP:-notarealbackuptimestamp}"
backup() {
echo
echo '***** Backing up current Dotfiles *****'
echo
if [ ! -d "$HOME/.dotfile_backups" ]; then
mkdir "$HOME/.dotfile_backups"
fi
if [ ! -d "$HOME"/.dotfile_backups/"$MAKE_TIMESTAMP" ]; then
mkdir "$HOME"/.dotfile_backups/"$MAKE_TIMESTAMP"
fi
for f in ./dotfiles/.[a-z]*; do
dotfile=${f#"./dotfiles/"}
if [ -f "$HOME/$dotfile" ]; then
printf "\tbacking up %s\n" "$dotfile"
cp "$HOME"/"$dotfile" "$HOME"/.dotfile_backups/"$MAKE_TIMESTAMP"
fi
done
}
deps() {
echo
echo '***** Installing Dependencies *****'
echo
if [ "$OS" = Darwin ]; then
HOMEBREW_DEPS=(azure-cli autojump bat diff-so-fancy direnv eza fd fzf git git-extras btop htop jq neofetch ripgrep scc starship thefuck tldr vim wget)
# install homebrew if not already installed -- the installation will pause and allow for cancelling if desired
if [ ! -x "$(command -v brew)" ]; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
if [ -x "$(command -v brew)" ]; then
for dep in "${HOMEBREW_DEPS[@]}"; do
printf "\tinstalling %s\n" "$dep"
brew install "$dep"
done
if [ "$FORCE_UPGRADE" = 1 ] || [ ! -f /usr/local/bin/ctags ]; then
printf "\tinstalling ctags from homebrew\n"
brew install --HEAD universal-ctags/universal-ctags/universal-ctags
fi
if [ -x "$(command -v fzf)" ]; then
printf "\tinstalling fzf bindings and fuzzy completion\n"
"$(brew --prefix)/opt/fzf/install"
fi
fi
# install Volta nodejs tools and some global npm packages
printf "\tinstalling Volta nodejs tools and some global npm packages\n"
curl https://get.volta.sh | bash
VOLTA_HOME="$HOME"/.volta
PATH="$VOLTA_HOME/bin:$PATH"
volta install node
npm install --global npm-check-updates snyk
else
LINUX_DEPS=(autojump bat direnv eza git git-extras btop htop jq neofetch ripgrep tldr vim wget zsh-autosuggestions)
if [ -x "$(command -v apt)" ]; then
printf "\tinstalling apt dependencies\n"
sudo apt update
sudo apt install "$LINUX_DEPS"
fi
if [ "$FORCE_UPGRADE" = 1 ] || [ ! -x "$(command -v fzf)" ]; then
printf "\tinstalling fzf\n"
printf "\tanswer y, n, during install\n"
if [ -d ~/.fzf ]; then
cd ~/.fzf || exit
git pull
cd - || exit
else
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
fi
~/.fzf/install
fi
# TODO: setup azure-cli, fd, scc
fi
# Common Deps
if [ "$FORCE_UPGRADE" = 1 ] || [ ! -d ~/.oh-my-zsh ]; then
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
fi
if [ "$FORCE_UPGRADE" = 1 ] || [ ! -f ~/.vim/autoload/plug.vim ]; then
printf "\tinstalling vim-plug\n"
curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
fi
}
dotfiles() {
echo
echo '***** Installing new Dotfiles *****'
echo
for f in ./dotfiles/.[a-z]*; do
printf "\tinstalling %s" "$f"
if [ "$f" == ".shell_secrets" ] && [ -f "$HOME/.shell_secrets" ]; then
printf ": already exists, skipping"
else
cp ./"$f" "$HOME/"
fi
printf "\n"
done
}
fonts() {
echo
echo '***** Installing new Fonts *****'
echo
if [ "$OS" = Darwin ]; then
printf "\tCopying new fonts to ~/Library/Fonts\n"
cp ./fonts/* "$HOME/Library/Fonts"
else
if [ ! -d "$HOME/.fonts" ]; then
mkdir "$HOME"/.fonts
fi
printf "\tCopying new fonts to ~/.fonts\n"
cp ./fonts/* "$HOME"/.fonts
fi
}
restore() {
if [ "$RESTORE_TIMESTAMP" = notarealbackuptimestamp ]; then
echo
printf "You must supply a timestamp when trying to restore: RESTORE_TIMESTAMP=<desired timestamp> install.sh\n"
echo
elif [ -d "$HOME"/.dotfile_backups/"$RESTORE_TIMESTAMP" ]; then
echo
echo "***** Restoring dotfiles from timestamp '$RESTORE_TIMESTAMP' *****"
echo
cp "$HOME"/.dotfile_backups/"$RESTORE_TIMESTAMP"/.* "$HOME"/ 2>/dev/null
else
printf "\tNo backups found for timestamp %s\n" "$RESTORE_TIMESTAMP"
fi
}
setup_git() {
echo
echo '***** Setting up git user information *****'
echo
echo "Enter the name for your git commits, followed by [ENTER]:"
read -r GIT_NAME
echo
echo "Enter the email address for your git commits, followed by [ENTER]:"
read -r GIT_EMAIL
echo "[user]
name = $GIT_NAME
email = $GIT_EMAIL
" >"$HOME"/.gitconfig_custom
}
install() {
backup
deps
setup_git
dotfiles
fonts
}
help() {
printf "\nsetup.sh - installs some dotfiles, fonts and useful applications for terminal environments\n\n"
echo "Commands:"
printf "\n Default:\n\n"
printf " install - runs the 'backup', 'deps' 'dotfiles', 'fonts' and 'setup_git' targets\n"
printf "\n Individual setup:\n\n"
printf " deps - will try to install dependencies\n"
printf " dotfiles - will install the new dotfiles to '~/'\n"
printf " fonts - will install new fonts to '~/Library/Fonts' or '~/.fonts' on other systems\n"
printf "\n Utility:\n\n"
printf " backup - will backup current dotfiles to '~/.dotfile_backups/<current timestamp>'\n"
printf " restore - will restore backed up dotfiles, usage 'RESTORE_TIMESTAMP=<desired timestamp> ./setup.sh restore'\n"
printf " setup_git - asks you to enter a name and email used when making commits with git\n"
printf "\n Flags:\n\n"
printf " --help - prints this help information (actually any unknown command will print the help)\n"
echo
}
COMMAND_RUN=0
for key in "$@"; do
case $key in
backup)
backup
COMMAND_RUN=1
break
;;
deps)
deps
COMMAND_RUN=1
break
;;
install)
install
COMMAND_RUN=1
break
;;
dotfiles)
dotfiles
COMMAND_RUN=1
break
;;
fonts)
fonts
COMMAND_RUN=1
break
;;
restore)
restore
COMMAND_RUN=1
break
;;
setup_git)
setup_git
COMMAND_RUN=1
break
;;
*)
help
exit
;;
esac
done
if [ $COMMAND_RUN = 0 ]; then
install
fi
echo
echo "NOTE: you will need to reload your \$SHELL config or open a new terminal for installation to take effect"
echo