-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·274 lines (226 loc) · 7.39 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#!/usr/bin/env bash
# Drew's Dotfiles
# Sensible defaults that work great for both Bash and ZSH!
# https://github.com/drewlustro/dotfiles
# License: MIT
function br() {
echo "";
}
function heavyhr() {
echo "==============================================================";
}
function hr() {
echo "+ ---------------------------------------------------------- +";
}
function minihr() {
echo " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -";
}
function sayDone() {
echo "DONE!";
echo "If you would like to install tons of convenient extras from homebrew, run the following:"
minihr;
echo "$ ./brew-cask-fonts.sh # installs a handful of useful public-domain typefaces, including many coding fonts"
echo "$ ./brew-install-cli.sh # installs TONS of useful binaries, libs, and CLI tools via brew"
echo "$ ./brew-install-media-cli.sh # installs heavy media CLI tools (ffmpeg, sox, etc.) via brew"
echo "$ ./brew-cask-apps.sh # installs many useful OS X applications via brew-cask"
minihr;
echo "See each shell file above to see which components will be (non-destructively) installed."
echo "Hope you enjoy! –Drew"
br; hr; br; br;
}
function preztoInstall() {
br;
heavyhr;
echo " PREZTO INSTALL"
hr;
# 1
echo "(1) Downloading prezto git repo..."
minihr;
set -o xtrace;
git clone --recursive https://github.com/drewlustro/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
set +o xtrace;
minihr;
# 2
echo "(2) Symlinking home directory .z* files to prezto folder..."
minihr;
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/z*; do
# TODO: prompt to overwrite if $rcfile exists
ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.$(basename $rcfile)"
done
(( $? > 0 )) && br && echo "[TIP] Fix this by deleting or moving existing ~/.z* files using:" && echo "$ rm -f ~/.z*" && br;
minihr;
# 3
echo "(3) zsh default shell..."
minihr;
read -p "Would you like to zsh ($(which zsh)) to be your default shell? (y/N) " -n 1;
br;
if [[ $REPLY =~ ^[Yy]$ ]]; then
chsh -s $(which zsh)
(( $? == 0 )) && br && echo "$(which zsh) is now your default shell."
fi;
rsync -avh --no-perms --progress ./zprezto/ ~/.zprezto/
br; hr; br; br;
}
function primaryInstall() {
br;
heavyhr;
echo " PRIMARY DOTFILES BATCH INSTALL"; hr;
BACKUP_DIR=".dotfiles-backup-$(date +%Y-%m-%d-%H%M%S)";
echo "BACKING UP: top-level home directory dotfiles to: \"~/$BACKUP_DIR\" "; hr;
mkdir "$HOME/$BACKUP_DIR" 2> /dev/null;
cp .* ~/$BACKUP_DIR/ 2> /dev/null;
echo "INSTALL: essential config files to home directory..."
br;
rsync --exclude ".git/" \
--exclude "*.sample" \
--exclude ".DS_Store" \
--exclude "App Support" \
--exclude ".gitignore" \
--exclude ".macos" \
--exclude ".xmodmaprc*" \
--exclude "bin/" \
--exclude "LICENSE-MIT" \
--exclude "vscode" \
--exclude "zprezto" \
--exclude "bootstrap.sh" \
--exclude "brew-cask-apps.sh" \
--exclude "brew-cask-fonts.sh" \
--exclude "brew-install-cli.sh" \
--exclude "brew-install-media-cli.sh" \
--exclude "etc/" \
--exclude "fresh-machine/" \
--exclude "install.sh" \
--exclude "iterm2/" \
--exclude "linux/" \
--exclude "README.md" \
--exclude "LICENSE-MIT.txt" \
--exclude "sublimetext/" \
--exclude "terminal-themes/" \
--exclude "update.sh" \
-avh --no-perms --progress . ~;
# VS Code settings
# if [ -d "$HOME/Library/Application\ Support/Code/User" ]; then
# minihr;
# echo "Installing VSCode settings to $HOME/Library/Application\ Support/Code/User ...";
# rsync -avh --no-perms --progress ./vscode/ ~/Library/Application\ Support/Code/User/;
# fi;
minihr;
echo "Creating miscellanous common directories..."
br;
set -o xtrace;
# make local npm packages dir to allow non-sudo global npm packages
mkdir "$HOME/dev-local" 2> /dev/null;
if ls --color > /dev/null 2>&1; then # GNU coreutils `ls`
echo "[Notice] Detected GNU ls, not copying ./bin";
else
echo "[Notice] Detected OS X, installing GNU utils into ~/bin";
mkdir "~/bin" > /dev/null 2>&1;
cp -pr ./bin ~/;
chmod a+x ~/bin/*;
fi;
set +o xtrace;
br;br;
sayDone;
source ~/.bash_profile;
}
function updateShellLibraryOnly() {
br;
heavyhr;
echo " UPDATE SHELL DOTFILES (~/.shell)"
hr;
echo "rsync'ing (dotfiles/.shell library) files to home (~/.shell)..."
br;
rsync -avh --no-perms .shell ~;
minihr;
echo "Updated. Use 'reload' to pull settings into this current TTY, or open new shell."
br;
}
function showBanner() {
DOTFILES_URL="https://github.com/drewlustro/dotfiles"
DOTFILES_VERSION="3.3.0";
DOTFILES_UPDATED="2019-03-07"
heavyhr;
echo "WELCOME TO DREW'S DOTFILES for Bash & ZSH (zprezto)!"
heavyhr;
echo "Version: $DOTFILES_VERSION"
echo "Updated: $DOTFILES_UPDATED"
echo "Available at $DOTFILES_URL"
hr; br;
echo "Updating dotfiles from origin/master...";
br;
git pull origin master;
br; br;
}
# -------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
# Detect OS platform
PLATFORM="unknown";
unamestr="$(uname)";
if [ "$unamestr" = 'Darwin' ]; then
export PLATFORM='osx';
elif [ "$unamestr" = 'Linux' ]; then
export PLATFORM='linux';
elif [ "$unamestr" = 'FreeBSD' ]; then
export PLATFORM='freebsd';
fi;
# Show banner and update repo to latest
showBanner;
if [ "$1" = "--force" ] || [ "$1" = "-f" ]; then
primaryInstall;
elif [ "$1" = "--update" ] || [ "$1" = "-u" ]; then
updateShellLibraryOnly;
else
hr;
echo "[!] PLEASE READ [!]"
minihr;
echo "Existing dotfiles will be backed up to your home directory in ~/.dotfiles-backup-\$TIMESTAMP";
echo "Default aliases, exports, functions, and path additions will be added to $HOME/.shell";
echo "Customizable, empty versions of above will be added to $HOME/.shell-custom";
minihr;
echo "[note] if you want a clean install, first remove all existing zsh/prezto dotfiles:"
echo "$ rm -rf ~/.z* ~/.zprezto* # <<--- run before continuing"
br;
hr; br;
CURRENT_SHELL="$SHELL"
echo "CURRENT SHELL is '$CURRENT_SHELL'"
QUESTION_PROMPT_STRING="Are you sure you would like to install/update/abort? (i/u/A) "
# (1) Primary Install
if [[ "$CURRENT_SHELL" == *bash ]]; then
read -p "$QUESTION_PROMPT_STRING" -n 1;
elif [[ "$CURRENT_SHELL" == *zsh ]]; then
echo -n "$QUESTION_PROMPT_STRING";
read REPLY;
else
echo "Unsupported shell '$CURRENT_SHELL' (requires bash or zsh)"
fi;
br;
if [[ $REPLY =~ ^[Ii]$ ]]; then
# Require bash for prezto + primary install
if [[ "$CURRENT_SHELL" == *bash ]]; then
preztoInstall;
primaryInstall;
else
echo "Current shell must be bash to do initial install! (currently is $(basename $CURRENT_SHELL))"
fi;
elif [[ $REPLY =~ ^[Uu]$ ]]; then
updateShellLibraryOnly;
else
echo "[!] ABORTED."
fi;
fi;
br; hr; br;
echo " // PEACE //"
br; hr; br;
# -------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
unset primaryInstall;
unset preztoInstall;
unset updateShellLibraryOnly;
unset showBanner;
unset hr;
unset minihr;
unset heavyhr;
unset br;
unset sayDone;