-
Notifications
You must be signed in to change notification settings - Fork 0
/
mac-setup.sh
executable file
·179 lines (155 loc) · 4.58 KB
/
mac-setup.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
#!/usr/bin/env bash
set -e
update_brewfile=false
brewfile="${HOME}/.Brewfile"
no_upgrade=""
while [ $# -gt 0 ]; do
case "$1" in
-f|--brewfile)
source_brewfile="$2"
shift
shift
;;
-b|--use-branch)
branch="$2"
shift
shift
;;
-u|--update-brewfile)
update_brewfile=true
shift
;;
--no-global)
brewfile="${HOME}/.mac-setup/Brewfile"
shift
;;
--no-upgrade)
no_upgrade="--no-upgrade"
shift
;;
*)
printf "Usage:\n"
printf "mac-setup.sh {options}\n"
printf " Options:\n"
printf " [-b|--use-branch {branch}]\n"
printf " Branch from this repository to use when selecting the default Brewfile.\n"
printf " [-f|--brewfile {source-brewfile}]\n"
printf " Source Brewfile. By default, the one in this repository.\n"
printf " [-u|--update-brewfile]\n"
printf " Whether the local Brewfile should be overwritten with the latest state of the source.\n"
printf " [--no-global]\n"
printf " By default, we use the global location ~/.Brewfile as installation destination.\n"
printf " This option disables this and uses a separate location.\n"
printf " [--no-upgrade]\n"
printf " Applies the same option to the brew command.\n"
exit 1
esac
done
DEFAULT_BREWFILE="https://raw.githubusercontent.com/pjungermann/mac-setup/${branch:-main}/Brewfile"
if [ -z "$source_brewfile" ]
then
source_brewfile="$DEFAULT_BREWFILE"
fi
# 1. install xcode Command Line Tools (CLT)
if xcode-select -p 2> /dev/null
then
echo "Xcode Command Line Tools (CLT) already installed"
else
echo "Xcode Command Line Tools (CLT) not installed, yet"
xcode-select --install
while ! xcode-select -p 2>&1 /dev/null
do
read -rs \
-p "Please complete the Xcode Command Line Tools installation. Press any key to continue." \
-n 1
echo
done
echo "installed Xcode Command Line Tools (CLT)"
fi
# 2. install "Oh My Zsh" - https://ohmyz.sh
# shellcheck disable=SC2230
if ! which -s zsh || [[ ! -d "${HOME}/.oh-my-zsh" ]]
then
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh) --unattended"
echo "installed oh-my-zsh"
fi
# change the default shell to zsh
current_shell="$(finger "${USER}" | grep Shell | sed -E -e 's/.*Shell: (.*)/\1/g')"
if [[ "${current_shell}" != "/bin/zsh" ]]
then
chsh -s /bin/zsh
echo "changed default shell to zsh"
fi
ZSHRC="${HOME}/.zshrc"
# 3. install package managers
# 3.1. install "Homebrew" (general Mac OS package manager)
# shellcheck disable=SC2230
if which -s brew
then
brew update
else
bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
# shellcheck disable=SC2016
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/patrick.jungermann/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
echo "installed Homebrew"
fi
HOMEBREW_PREFIX="$(brew --prefix)"
# 4. Install by Brewfile
if $update_brewfile || [ ! -f "${brewfile}" ]
then
mkdir -p "$(dirname "$brewfile")"
curl -fsSL "${source_brewfile}" -o "${brewfile}"
fi
if grep -E -e '^mas "' "${brewfile}" >/dev/null
then
read -rs \
-p "Please log in manually at the Mac App Store. Press any key to continue." \
-n 1
fi
brew bundle --file "${brewfile}" ${no_upgrade}
# 5. Install software using asdf
# 5.1. install to zsh / handle brew caveat
asdf_zsh="${HOMEBREW_PREFIX}/opt/asdf/libexec/asdf.sh"
if ! grep "$asdf_zsh" "$ZSHRC" >/dev/null
then
cat <<-EOS >> "$ZSHRC"
# asdf-vm.com
source "$asdf_zsh"
EOS
# shellcheck disable=SC1090
source "$ZSHRC" # reload
fi
java_distribution="corretto"
for asdf_plugin in gradle groovy java maven nodejs ruby
do
if ! asdf plugin list | grep -E -e "^${asdf_plugin}$"
then
asdf plugin add "$asdf_plugin"
fi
asdf_plugin_version=latest
if [ "$asdf_plugin" = "java" ]
then
asdf_plugin_version="latest:${java_distribution}"
fi
asdf install "$asdf_plugin" "$asdf_plugin_version"
asdf global "$asdf_plugin" "$asdf_plugin_version"
done
# 5.1 Java - some additional versions
for java_version in 8 11
do
asdf install java "latest:${java_distribution}-${java_version}."
done
# 6. pre-install latest terraform version
tfswitch --latest
# 7. Oh My Zsh - Plugins
zsh_plugins="\
aws colored-man-pages command-not-found docker docker-compose git gradle helm history-substring-search \
kubectl man mvn"
sed -i "" \
-E \
-e "s#^plugins=\(.*\)#plugins=(${zsh_plugins})#" \
"${HOME}/.zshrc"
echo "finished with the machine setup"
# run zsh
zsh