-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.zsh
executable file
·147 lines (117 loc) · 4.03 KB
/
setup.zsh
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
#!/usr/bin/env zsh
DOTFILES="$HOME/Repos/ooloth/dotfiles"
handle_error() {
local exit_code="$1"
local line_number="$2"
printf "\nError on line $line_number: Command exited with status $exit_code.\n"
exit "$exit_code"
}
# Trap ERR signals and call handle_error()
trap 'handle_error $? $LINENO' ERR
###########
# CONFIRM #
###########
printf "Welcome to your new Mac!"
printf "This installation will perform the following steps:\n"
printf "1. Confirm this is a Mac\n"
printf "2. Ask you to enter your password\n"
printf "3. Confirm the Command Line Developer Tools are installed\n"
printf "4. Clone ooloth/dotfiles\n"
printf "5. Create your SSH keys\n"
printf "6. Confirm you can SSH to GitHub\n"
printf "7. Install homebrew and the packages, casks, App Store apps and VS Code extensions listed in your Brewfile\n"
printf "8. Configure your Mac to use the Homebrew version of Zsh\n"
printf "9. Install rust\n"
printf "10. Install the latest version of Node via fnm and set it as the default\n"
printf "11. Install global npm dependencies\n"
printf "12. Install tmux dependencies\n"
printf "13. Install neovim dependencies\n"
printf "14. Install yazi flavors\n"
printf "15. Symlink your dotfiles to your home and library directories\n"
printf "16. Update macOS system settings\n"
vared -p "Sound good? (y/N) " -c key
if [[ ! "$key" == 'y' ]]; then
printf "\nNo worries! Maybe next time."
printf "\nExiting..."
exit 1
else
printf "\nExcellent! Here we go...\n"
fi
#################
# PREREQUISITES #
#################
printf "Verifying prerequisites"
# This is a Mac
printf "Confirming this is a Mac."
if [ "$(uname)" != "Darwin" ]; then
printf "\nOops, it looks like this is a non-UNIX system. This script only works on a Mac.\n\nExiting..."
exit 1
fi
printf "\nThis is definitely a Mac. But you knew that already.\n"
# You know this Mac's password
printf "Confirming you are authorized to install things on this Mac.\n"
sudo -v
# Keep-alive: update existing `sudo` time stamp until setup has finished
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
printf "\nYup. That's the password.\n"
# The Command Line Tools are installed
printf "\nConfirming the Command Line Tools are installed.\n"
if [ ! -d "$HOME/Library/Developer/CommandLineTools" ]; then
printf "Apple's command line developer tools must be installed before running this script. Installing now.\n"
xcode-select --install
if [ ! -d "$HOME/Library/Developer/CommandLineTools" ]; then
printf "\nOops, it looks like the Xcode CLI tools are still not installed. Please install and try again.\n"
exit 1
else
printf "\nXcode CLI tools are now installed.\n"
fi
else
printf "\nXcode CLI tools are already installed.\n"
fi
##################
# CLONE DOTFILES #
##################
if [ -d "$DOTFILES" ]; then
printf "\n✅ $DOTFILES already exists. Pulling latest changes.\n"
cd "$DOTFILES"
git pull
else
echo "Cloning dotfiles to $DOTFILES..."
git clone https://github.com/myuser/myrepo.git "$DOTFILES"
fi
###########
# INSTALL #
###########
cd "$DOTFILES/bin/install"
source ssh.zsh
source github.zsh
source homebrew.zsh
source "$DOTFILES/bin/update/homebrew.zsh"
source zsh.zsh
source rust.zsh
source rye.zsh
source node.zsh
source "$DOTFILES/bin/update/npm.zsh"
source tmux.zsh
source neovim.zsh
source yazi.zsh
source "$DOTFILES/bin/update/symlinks.zsh"
source settings.zsh
# TODO: automate my remaining manual setup steps (e.g. app preferences, etc.)
###################
# SUGGEST RESTART #
###################
source "$DOTFILES/config/zsh/utils.zsh"
info "🎉 Setup complete!"
printf "\nCongratulations! Your Mac is nearly set up.\n"
printf "\nTo apply your your preferences, your computer needs to restart.\n\n"
vared -p "Are you ready to restart now (recommended)? (y/N) " -c restart_choice
if [[ "$restart_choice" = 'y' ]]; then
printf "\nExcellent choice.\n"
printf "\nRestarting..."
sudo shutdown -r now
else
printf "\nNo worries! Your terminal session will now refresh...\n"
exec -l $SHELL
printf "\nDone. Enjoy your new Mac!\n"
fi