-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·119 lines (93 loc) · 3.5 KB
/
bootstrap.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
#!/bin/bash
# -----------------------------------------------
# Author: Liam Howell
# Description: Handles symlinks and dependency installation
#
# 0. BOOT
# 1. HOMEBREW
# 2. SYMLINKS
# 3. NODE
# 4. YARN GLOBALS
# 5. DIRECTORIES
# 6. CLEANUP
# -----------------------------------------------
# -----------------------------------------------
# 0. BOOT
# -----------------------------------------------
## Set flag to say if this is an initial run or an update
[[ "$*" == *"--update"* ]] && IS_UPDATING=true || IS_UPDATING=false
## Invalidate the current `sudo` timestamp file
sudo --reset-timestamp
## Ask for the administrator password upfront
sudo -v
## Keep-alive: update existing `sudo` time stamp until `bootstrap.sh` has finished
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# -----------------------------------------------
# 1. HOMEBREW
# -----------------------------------------------
## Install Homebrew
if ! test "$(brew -v)"; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
## Setup Homebrew directory permissions
for directory in "$(brew --prefix)" "$(brew --repository)"; do
[ -d "$directory" ] && chown -R "$USER:admin" "$directory" > /dev/null 2>&1
done
## Install from Brewfile
if [ "$IS_UPDATING" == false ]; then
brew bundle --file homebrew/brewfile
fi
# -----------------------------------------------
# 2. SYMLINKS
# -----------------------------------------------
## Symlink dotfiles to the home directory
if [ "$IS_UPDATING" == false ]; then
[ -s "$PWD" ] && ln -sf "$PWD" "$HOME/dotfiles"
fi
## Symlink `asdf` .asdfrc && .tool-versions to default location
ln -sf "$PWD/asdf/.asdfrc" "$HOME/.asdfrc"
ln -sf "$PWD/asdf/.tool-versions" "$HOME/.tool-versions"
## Symlink global package.json to default location
ln -sf "$PWD/yarn/package.json" "$HOME/.config/yarn/global/package.json"
## Iterate through defined directories and symlink their files to `~`
for directory in "git" "hyper" "shell"; do
for file in ./"$directory"/.*[a-zA-Z+]; do
if [[ ! "${file##*/}" == *".example" ]]; then
ln -sf "$PWD/$directory/${file##*/}" "$HOME/${file##*/}"
fi
done
done
## Symlink local secrets file if it exists
[ -s "$PWD/shell/.localrc" ] && ln -sf "$PWD/shell/.localrc" "$HOME/.localrc"
## Create + symlink Sheldon directory + plugin file
[ ! -d "$HOME/.config/sheldon" ] && mkdir "$HOME/.config/sheldon"
ln -sf "$PWD/sheldon/plugins.toml" "$HOME/.config/sheldon/plugins.toml"
## Symlink tmux configuration to default location
[ ! -d "$HOME/.config/tmux" ] && mkdir "$HOME/.config/tmux"
ln -sf "$PWD/tmux/tmux.conf" "$HOME/.config/tmux/tmux.conf"
# -----------------------------------------------
# 3. NODE
# -----------------------------------------------
## Install latest Node versions
if [ "$IS_UPDATING" == false ]; then
fnm install --latest
fi
# -----------------------------------------------
# 4. YARN GLOBALS
# -----------------------------------------------
## Install globals for Yarn
if [ "$IS_UPDATING" == false ]; then
yarn global upgrade
fi
# -----------------------------------------------
# 5. DIRECTORIES
# -----------------------------------------------
## Create desired directories if they don't already exist
for directory in "Projects" "Sites"; do
[ ! -d "$HOME/$directory" ] && mkdir "$HOME/$directory"
done
# -----------------------------------------------
# 6. CLEANUP
# -----------------------------------------------
## Reload the shell
exec "$(which zsh)" -l