-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-macos.sh
executable file
·186 lines (157 loc) · 4.07 KB
/
setup-macos.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
180
181
182
183
184
185
186
#!/usr/bin/env bash
gpg_primary_key=0x2B7340DB13C85766
gpg_encryption_subkey=0x79C70BBE4865D828
base_path=$PWD
data_path="$base_path"/data
declare -a brew_pkgs=(
bat
font-hack-nerd-font
gnupg
go
helix
neovim
node
npm
pinentry-mac
python
ruby
rust
stow
theseal/ssh-askpass/ssh-askpass
wget
ykman
yubikey-personalization
)
brew update || {
echo "failed to update homebrew"
}
brew install "${brew_pkgs[@]}" || {
echo "failed to install brew packages"
}
git submodule update --init --remote --progress omz/.oh-my-zsh/themes/powerlevel10k || {
echo "failed to update git submodules"
exit 1
}
git submodule foreach --recursive git clean -xfd || {
echo "failed to clean git submodules"
exit 1
}
git submodule foreach --recursive git reset --hard || {
echo "failed to reset git submodules"
exit 1
}
echo "Setting up GPG/SSH"
gpg --list-keys >/dev/null
declare -a mk_dirs=(
~/.cargo
~/.cargo
~/.config
~/.continue
~/.local/bin
~/.ssh
)
for mk_dir in "${mk_dirs[@]}"; do
mkdir -p "${mk_dir}"
done
declare -a conflict_paths=(
~/.bashrc
~/.continue/config.json
~/.gnupg/common.conf
~/.zshenv
~/.zshrc
)
rm_if_not_stowed() {
if [[ -L "${1}" ]]; then
local symlink_path
symlink_path=$(readlink -f "${1}")
if [[ $symlink_path == *"${base_path}"* ]]; then
return 0
fi
fi
rm -rfv "${1}"
}
echo "Checking for files/directories that will conflict with stow"
for conflict_path in "${conflict_paths[@]}"; do
rm_if_not_stowed "${conflict_path}"
done
echo "Appending custom pinentry script to gpg-agent.conf"
# GNUPG is ridiculous and only allows env-vars in some of the options here, so we have to do this the convoluted way with a line append
cp -v "$data_path"/gpg/gpg-agent.conf "$base_path"/gpg/.gnupg/gpg-agent.conf || {
echo "failed to copy gpg-agent.conf from data dir"
exit 1
}
echo "pinentry-program $HOME/.local/bin/pinentry-auto" | tee -a "$HOME"/.gnupg/gpg-agent.conf
stow_config() {
stow -v "$1" || {
echo "Failed to stow ${1} config"
exit 1
}
}
declare -a stow_dirs_setup=(
bash
git
gpg
ssh
stow
zsh
)
echo "Stowing setup configs"
for stow_dir in "${stow_dirs_setup[@]}"; do
stow_config "$stow_dir"
done
rsync --progress -ruacv -- macos/* "$HOME"/ || {
echo "failed to rsync macos config"
return 1
}
declare -a launch_agents=(
"$HOME"/Library/LaunchAgents/gnupg.gpg-agent.plist
"$HOME"/Library/LaunchAgents/gnupg.gpg-agent-symlink.plist
)
for launch_agent_dir in "${launch_agents[@]}"; do
launchctl unload "$launch_agent_dir"
launchctl load "$launch_agent_dir" || {
echo "failed to load $launch_agent_dir"
exit 1
}
echo "Loaded $launch_agent_dir"
done
gpg-connect-agent reloadagent /bye || {
echo "failed to reload gpg-agent"
exit 1
}
# If our primary GPG key is not yet imported, import it
if [[ ! $(gpg --list-keys "$gpg_primary_key") ]]; then
gpg --import "$data_path"/gpg/2B7340DB13C85766.asc || {
echo "failed to import GPG pubkey"
exit 1
}
gpg --tofu-policy good "$gpg_primary_key" || {
echo "failed to set gpg tofu policy"
exit 1
}
fi
echo "Decrypting data"
declare -a decrypt_data_paths_tuples=(
"${data_path}/ssh/config.asc.gpg ${base_path}/ssh/.ssh/config"
)
for decrypt_data_paths_tuple in "${decrypt_data_paths_tuples[@]}"; do
read -ra decrypt_data_paths <<<"$decrypt_data_paths_tuple"
if [[ -f "${decrypt_data_paths[0]}" ]]; then
gpg --quiet --no-verbose --local-user "${gpg_encryption_subkey}" --armor --decrypt --yes --output "${decrypt_data_paths[1]}" "${decrypt_data_paths[0]}" >/dev/null || {
echo "failed to decrypt file ${decrypt_data_paths[0]} to ${decrypt_data_paths[1]}"
exit 1
}
fi
done
declare -a stow_dirs_general=(
alacritty
bat
continue
helix
nvim
rust
)
echo "Stowing general configs"
for stow_dir in "${stow_dirs_general[@]}"; do
stow_config "$stow_dir"
done