-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·170 lines (148 loc) · 3.74 KB
/
run.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
#!/bin/zsh
# If any part of this script fails, exit immediately
set -e
# Initialize variables
local -i SHOW_HELP=0
local -i SKIP_ESSENTIALS=0
local -i SKIP_BREW=0
local -i SKIP_OH_MY_ZSH=0
local -i SKIP_NVM=0
local -i SKIP_RUSTUP=0
# FUNCTION: Usage display
function displayUsage {
cat <<'EOFFOE'
Usage: ./run.sh <flags>
Purpose: Completely set up a fresh macOS install with specified tools
-h Show usage (this output) and quit immediately
-e Skip essential installs and SSH key generation
Only use this flag if your SSH key is not named id_rsa and you
wish to skip automatic detection of your SSH key. If brew is not
installed, the rest of the modules will fail.
-b Skip brew app installation
-o Skip Oh My Zsh installation
-n Skip NVM (Node Version Manager) installation
-r Skip Rust(up) installation
EOFFOE
}
# FUNCTION: Logger
# Usage: log <module_name> <log>
function log {
echo -e "[$1] $2"
}
# FUNCTION: Essentials logger
# Usage log_e <log>
function log_e {
log "ESSENTIALS" $1
}
# FUNCTION: Brew logger
# Usage log_b <log>
function log_b {
log "BREW" $1
}
# FUNCTION: Oh My Zsh logger
# Usage log_o <log>
function log_o {
log "OHMYZSH" $1
}
# FUNCTION: NVM logger
# Usage log_n <log>
function log_n {
log "NVM" $1
}
# FUNCTION: Rustup logger
# Usage log_r <log>
function log_r {
log "RUSTUP" $1
}
# --------
# | MAIN |
# --------
# Check for flags
while getopts "h?ebon" option
do
case "$option" in
h|\?)
SHOW_HELP=1
;;
e)
SKIP_ESSENTIALS=1
;;
b)
SKIP_BREW=1
;;
o)
SKIP_OH_MY_ZSH=1
;;
n)
SKIP_NVM=1
;;
*)
echo "Invalid flags specified."
echo "Please check the correct usage and try again."
echo ""
displayUsage
return
;;
esac
done
# Check if user wants help
if (( SHOW_HELP )) then
displayUsage
return
fi
# Step: Essentials
if ! (( SKIP_ESSENTIALS )) then
# Install homebrew (if it is not already installed)
if ! type brew; then
log_e "Installing homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
else
log_e "Homebrew already seems to be installed. Skipping..."
fi
# Generate SSH keys (if not present)
if [[ ! -a ~/.ssh/id_rsa ]]; then
log_e "Generating SSH key..."
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -q -N ""
else
log_e "SSH key found. Skipping..."
fi
else
log_e "Skipping essential install on request..."
fi
# Step: Restore with brew bundle
if ! (( SKIP_BREW )) then
log_b "Restoring from Homebrew bundle dump..."
brew bundle install --file ./Brewfile
else
log_b "Skipping brew programs installation on request..."
fi
# Step: Install Oh My Zsh
if ! (( SKIP_OH_MY_ZSH )) then
# Install Oh My Zsh (if it is not already installed)
if [[ ! -d ~/.oh-my-zsh ]]; then
log_o "Installing Oh My Zsh..."
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
else
log_o "Oh My Zsh already seems to be installed. Skipping..."
fi
fi
# Step: Install NVM
if ! (( SKIP_NVM )) then
# Install NVM (if it is not already installed)
if [[ ! -d ~/.nvm ]]; then
log_n "Installing NVM..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh)"
else
log_n "NVM already seems to be installed. Skipping..."
fi
fi
# Step: Install Rustup
if ! (( SKIP_RUSTUP )) then
# Install Rustup (if it is not already installed)
if ! type rustup; then
log_r "Installing Rustup..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
else
log_r "Rustup already seems to be installed. Skipping..."
fi
fi