forked from joshukraine/mac-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap
executable file
·222 lines (157 loc) · 7.21 KB
/
bootstrap
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
#!/usr/bin/env bash
################################################################################
# bootstrap
#
# This script is intended to set up a new Mac computer with my dotfiles and
# other development preferences.
################################################################################
# Thank you, thoughtbot!
bootstrap_echo() {
local fmt="$1"; shift
# shellcheck disable=SC2059
printf "\n[BOOTSTRAP] $fmt\n" "$@"
}
################################################################################
# Variable declarations
################################################################################
osname=$(uname)
export COMMANDLINE_TOOLS="/Library/Developer/CommandLineTools"
export OLD_DOTFILES_BACKUP=$HOME/old_dotfiles_backup
export DOTFILES_REPO_URL="https://github.com/tadelv/dotfiles.git"
export DOTFILES_BRANCH="master"
export DOTFILES_DIR=$HOME/development/repos/dotfiles
export BOOTSTRAP_REPO_URL="https://github.com/tadelv/mac-bootstrap.git"
export BOOTSTRAP_BRANCH="master"
export BOOTSTRAP_DIR=$HOME/mac-bootstrap
################################################################################
# Make sure we're on a Mac before continuing
################################################################################
if [ "$osname" == "Linux" ]; then
bootstrap_echo "Oops, looks like you're on a Linux machine. Please have a look at
my Linux Bootstrap script: https://github.com/joshukraine/linux-bootstrap"
exit 1
elif [ "$osname" != "Darwin" ]; then
bootstrap_echo "Oops, it looks like you're using a non-UNIX system. This script
only supports Mac. Exiting..."
exit 1
fi
################################################################################
# Check for presence of command line tools if macOS
################################################################################
if [ ! -d "$COMMANDLINE_TOOLS" ]; then
bootstrap_echo "Apple's command line developer tools must be installed before
running this script. To install them, just run 'xcode-select --install' from
the terminal and then follow the prompts. Once the command line tools have been
installed, you can try running this script again."
exit 1
fi
################################################################################
# Clone mac-bootstrap repo
################################################################################
bootstrap_echo "Cloning mac-bootstrap repo..."
git clone "$BOOTSTRAP_REPO_URL" -b "$BOOTSTRAP_BRANCH" "$BOOTSTRAP_DIR"
################################################################################
# Authenticate
################################################################################
sudo -v
# Keep-alive: update existing `sudo` time stamp until bootstrap has finished
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
################################################################################
# Set machine name
################################################################################
printf "\nPlease enter a name for your Mac and press [ENTER] (e.g. Joshua's iMac)\n"
read -r -p "> " COMPUTER_NAME
export COMPUTER_NAME
printf "\nPlease enter a host name for your Mac and press [ENTER] (e.g. joshuas-imac)\n"
read -r -p "> " HOST_NAME
export HOST_NAME
printf "\nPlease enter your desired time zone and press [ENTER] (e.g. Europe/Kiev)\n(To view available options run \`sudo systemsetup -listtimezones\`)\n"
read -r -p "> " TIME_ZONE
export TIME_ZONE
################################################################################
# 1. Provision with my adaptation of Laptop (install/laptop)
################################################################################
bootstrap_echo "Step 1: Installing Laptop script..."
cp "$BOOTSTRAP_DIR"/install/Brewfile "$HOME"/.Brewfile
sh "$BOOTSTRAP_DIR"/install/laptop 2>&1 | tee ~/laptop.log
bootstrap_echo "Done!"
################################################################################
# Step 2, create standard directory structure
################################################################################
bootstrap_echo "Step 2: Creating default directory structure ..."
mkdir -p "$HOME/development/repos"
mkdir -p "$HOME/development/scratch"
mkdir -p "$HOME/development/playgrounds"
bootstrap_echo "Done!"
################################################################################
# 4. Setup dotfiles (https://github.com/tadelv/dotfiles.git)
################################################################################
bootstrap_echo "Step 4: Installing dotfiles ..."
if [[ -d $DOTFILES_DIR ]]; then
bootstrap_echo "Backing up old dotfiles to $HOME/old_dotfiles_backup..."
rm -rf "$OLD_DOTFILES_BACKUP"
cp -R "$DOTFILES_DIR" "$OLD_DOTFILES_BACKUP"
rm -rf "$DOTFILES_DIR"
fi
bootstrap_echo "Cloning dotfiles repo to ${DOTFILES_DIR} ..."
git clone "$DOTFILES_REPO_URL" -b "$DOTFILES_BRANCH" "$DOTFILES_DIR"
bootstrap_echo "Linking dotfiles ..."
# shellcheck source=/dev/null
ruby "$DOTFILES_DIR"/install.rb
bootstrap_echo "Done!"
################################################################################
# 5. Install ~/bin utilities
################################################################################
bootstrap_echo "Step 5: Installing ~/bin utilities ..."
cp -R "$BOOTSTRAP_DIR"/bin/* "$HOME"/bin/
bootstrap_echo "Done!"
################################################################################
# 6. Set up Tmuxinator (https://github.com/tmuxinator/tmuxinator)
# TODO: learn Tmux first
################################################################################
# bootstrap_echo "Step 6: Setting up Tmuxinator..."
#
# gem install tmuxinator
#
# if [ ! -d "$HOME"/.tmuxinator/ ]; then
# mkdir "$HOME"/.tmuxinator
# fi
#
# cp "$BOOTSTRAP_DIR"/lib/default.yml "$HOME"/.tmuxinator/
#
# bootstrap_echo "Done!"
################################################################################
# 9. Change default shell to fish
################################################################################
update_shell() {
local shell_path;
shell_path="$(which fish)"
bootstrap_echo "Changing your shell to fish ..."
if ! grep "$shell_path" /etc/shells > /dev/null 2>&1 ; then
bootstrap_echo "Adding '$shell_path' to /etc/shells"
sudo sh -c "echo $shell_path >> /etc/shells"
fi
chsh -s "$shell_path"
}
# brew shellenv first before this
# https://stackoverflow.com/a/66019047/405770
/opt/homebrew/bin/brew shellenv
bootstrap_echo "Step 9: Changing your shell to fish"
update_shell
bootstrap_echo "Done!"
################################################################################
# 10. Set macOS preferences
################################################################################
bootstrap_echo "Step 10: Setting macOS preferences..."
# shellcheck source=/dev/null
source "$BOOTSTRAP_DIR"/install/macos-defaults
# shellcheck source=/dev/null
# source "$BOOTSTRAP_DIR"/install/macos-dock
# TODO: find a way to install Dockutil 3.x (it's not on brew)
# rm -rf "$BOOTSTRAP_DIR"
bootstrap_echo "Done!"
echo
echo "**********************************************************************"
echo "**** Mac Bootstrap script complete! Please restart your computer. ****"
echo "**********************************************************************"
echo