-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-setup.sh
executable file
·287 lines (254 loc) · 8.97 KB
/
test-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
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!/usr/bin/env zsh
main() {
PROFILE=$(cat $DOTFILES_REPO/profile)
DEFAULT_BREW_FILE_PATH="${DOTFILES_REPO}/brew/macOS.Brewfile"
PROFILE_BREW_FILE_PATH="${DOTFILES_REPO}/brew/${PROFILE}.Brewfile"
diff_repo
diff_brew_completions
diff_swift_completions
diff_missing_brew
diff_mas
diff_brew_packages
diff_brew_casks
diff_brew_taps
diff_settings
diff_terminal_theme
diff_git
diff_ssh
diff_zsh
diff_vscode_missing_extensions
diff_vscode_extensions
diff_vscode_settings
diff_quartz_filters
diff_home_applications
profile_specifics
}
DOTFILES_REPO=$HOME/.dotfiles
function diff_repo() {
step "dotfiles repository"
if [[ $(git -C $DOTFILES_REPO status --porcelain) ]]; then
warning "Changes found:"
git -C $DOTFILES_REPO status -s | prependInfo
else
if [[ $(git -C $DOTFILES_REPO log origin/main..HEAD | cat) ]]; then
warning "Your local branch is ahead of remote"
else
success "No difference found"
fi
fi
}
function diff_brew_completions() {
step "Brew completions"
if brew completions state | grep -q "are linked"; then
success "Brew completions are linked"
else
warning "brew completions are not linked"
fi
}
function diff_swift_completions() {
step "Swift completions"
if test -e ~/.zfunctions/_swift; then
success "Swift completions already installed"
else
warning "Swift completions are not installed"
fi
}
function diff_missing_brew() {
step "Uninstalled from Brew"
if ! cat $DEFAULT_BREW_FILE_PATH $PROFILE_BREW_FILE_PATH | brew bundle check --no-upgrade --file=- &> /dev/null; then
warning "Not all brew requirements are installed"
cat $DEFAULT_BREW_FILE_PATH $PROFILE_BREW_FILE_PATH | brew bundle check --file=- --verbose --no-upgrade | grep → --color=never | cut -c2- | prependInfo
else
success "No difference found"
fi
}
function diff_mas() {
step "Additional AppStore Apps"
MAS_SAME=0
MAS_ID_TARGET=$(cat $DEFAULT_BREW_FILE_PATH $PROFILE_BREW_FILE_PATH | grep "mas \"" | grep -Eo '[0-9]+')
mas list | grep -Eo '^[0-9]+ ' | while read -r mas_id ;
do
if ! echo $MAS_ID_TARGET | grep -c $mas_id &> /dev/null; then
MAS_SAME=1
SOFTWARE_ENTRY=$(mas list | grep $mas_id )
SOFTWARE_NAME=${SOFTWARE_ENTRY#"$mas_id "}
warning "$SOFTWARE_NAME is installed but not included in the Brewfile"
fi
done
if [[ "$MAS_SAME" -eq 0 ]]; then
success "No difference found"
fi
}
function diff_brew_packages() {
step "Additional Brew packages"
BREW_SAME=0
BREW_TARGET=$(cat $DEFAULT_BREW_FILE_PATH $PROFILE_BREW_FILE_PATH | brew bundle list --file=-)
brew leaves | while read -r brew_name ;
do
if ! echo $BREW_TARGET | grep -c $brew_name &> /dev/null; then
BREW_SAME=1
warning "$brew_name is installed but not included in the Brewfile"
fi
done
if [[ "$BREW_SAME" -eq 0 ]]; then
success "No difference found"
fi
}
function diff_brew_casks() {
step "Additional Brew Casks"
CASKS_SAME=0
CASKS_TARGET=$(cat $DEFAULT_BREW_FILE_PATH $PROFILE_BREW_FILE_PATH | brew bundle list --casks --file=-)
brew list --cask | while read -r casks_name ;
do
if ! echo $CASKS_TARGET | grep -c $casks_name &> /dev/null; then
CASKS_SAME=1
warning "$casks_name is installed but not included in the Brewfile"
fi
done
if [[ "$CASKS_SAME" -eq 0 ]]; then
success "No difference found"
fi
}
function diff_brew_taps() {
step "Additional Brew Taps"
TAPS_SAME=0
TAPS_TARGET=$(cat $DEFAULT_BREW_FILE_PATH $PROFILE_BREW_FILE_PATH | brew bundle list --taps --file=-)
brew bundle dump --file=- | brew bundle list --taps --file=- | while read -r tap_name ;
do
if ! echo $TAPS_TARGET | grep -c $tap_name &> /dev/null; then
TAPS_SAME=1
warning "$tap_name is tapped but not included in the Brewfile"
fi
done
if [[ "$TAPS_SAME" -eq 0 ]]; then
success "No difference found"
fi
}
function diff_settings() {
step "macOS Settings"
zsh $DOTFILES_REPO/settings/settings.sh $DOTFILES_REPO/settings/macOS.csv
step "Xcode Settings"
zsh $DOTFILES_REPO/settings/settings.sh $DOTFILES_REPO/settings/xcode.csv
step "The Unarchiver Settings"
zsh $DOTFILES_REPO/settings/settings.sh $DOTFILES_REPO/settings/the_unarchiver.csv
step "Syntax Highlight Settings"
zsh ${DOTFILES_REPO}/settings/settings.sh $DOTFILES_REPO/settings/syntax_highlight.csv
step "Rectangle Settings"
zsh ${DOTFILES_REPO}/settings/settings.sh $DOTFILES_REPO/settings/rectangle.csv
step "macOS Configuration"
zsh $DOTFILES_REPO/macOS/macOS.sh
}
function diff_terminal_theme() {
step "Terminal Theme"
zsh $DOTFILES_REPO/terminal-theme/terminal-theme.sh
}
function diff_vscode_missing_extensions() {
step "Uninstalled VSCode Extensions"
EXTENSIONS_SAME=0
EXTENSIONS_TARGET=$(code --list-extensions)
cat $DOTFILES_REPO/vscode/extensions.txt $DOTFILES_REPO/vscode/extensions-$PROFILE.txt | while read -r extension_name ;
do
if ! echo $EXTENSIONS_TARGET | grep -c $extension_name &> /dev/null; then
EXTENSIONS_SAME=1
warning "$extension_name is not installed but included in extensions.txt"
fi
done
if [[ "$EXTENSIONS_SAME" -eq 0 ]]; then
success "No difference found"
fi
}
function diff_vscode_extensions() {
step "Additional VSCode Extensions"
EXTENSIONS_SAME=0
EXTENSIONS_TARGET=$(cat $DOTFILES_REPO/vscode/extensions.txt $DOTFILES_REPO/vscode/extensions-$PROFILE.txt)
code --list-extensions | while read -r extension_name ;
do
if ! echo $EXTENSIONS_TARGET | grep -c $extension_name &> /dev/null; then
EXTENSIONS_SAME=1
warning "$extension_name is installed but not included in extensions.txt"
fi
done
if [[ "$EXTENSIONS_SAME" -eq 0 ]]; then
success "No difference found"
fi
}
function diff_vscode_settings() {
diff_file "VSCode Settings" $DOTFILES_REPO/vscode/settings.json $HOME/Library/Application\ Support/Code/User/settings.json
diff_file "VSCode Keybindings" $DOTFILES_REPO/vscode/keybindings.json $HOME/Library/Application\ Support/Code/User/keybindings.json
}
function diff_git() {
GIT_CONFIG_TEMPLATE="$DOTFILES_REPO/git/.gitconfig_template_$PROFILE"
diff_file ".gitconfig" $GIT_CONFIG_TEMPLATE $HOME/.gitconfig
}
function diff_ssh() {
SSH_CONFIG_TEMPLATE="$DOTFILES_REPO/ssh/config_template_$PROFILE"
diff_file "ssh config" $SSH_CONFIG_TEMPLATE $HOME/.ssh/config
}
function diff_zsh() {
diff_file ".zshrc" $DOTFILES_REPO/zsh/.zshrc_template $HOME/.zshrc
}
function diff_quartz_filters() {
diff_file "Quartz Filter Minimal" $DOTFILES_REPO/quartz/Reduce\ File\ Size\ Minimal.qfilter $HOME/Library/Filters/Reduce\ File\ Size\ Minimal.qfilter
diff_file "Quartz Filter Medium" $DOTFILES_REPO/quartz/Reduce\ File\ Size\ Medium.qfilter $HOME/Library/Filters/Reduce\ File\ Size\ Medium.qfilter
diff_file "Quartz Filter Extreme" $DOTFILES_REPO/quartz/Reduce\ File\ Size\ Extreme.qfilter $HOME/Library/Filters/Reduce\ File\ Size\ Extreme.qfilter
step "Additional Quartz filters"
ADDITIONAL_FILTERS=0
ls $HOME/Library/Filters/*.qfilter | while read filename ;
do
if [[ ! ( "$filename" = "$HOME/Library/Filters/Reduce File Size Minimal.qfilter" || "$filename" = "$HOME/Library/Filters/Reduce File Size Medium.qfilter" || "$filename" = "$HOME/Library/Filters/Reduce File Size Extreme.qfilter" ) ]] then
ADDITIONAL_FILTERS=1
warning "Quartz filter $filename is installed but not included in the dotfiles"
fi
done
if [[ "$ADDITIONAL_FILTERS" -eq 0 ]]; then
success "No additional quartz filters found"
fi
}
function diff_home_applications() {
step "Hidden flag of Application folder in home directory"
if [[ -d $HOME/Applications ]]; then
if [[ $(stat -f "%Xf" $HOME/Applications) -eq 8000 ]]; then
success "No difference found"
else
warning "Folder not hidden"
fi
else
warning "Application folder in home directory does not exist"
fi
}
function profile_specifics() {
. ${DOTFILES_REPO}/profiles/test-${PROFILE}.sh
}
# helpers
function diff_file() {
step "${1}"
if diff -q $2 $3 &> /dev/null; then
success "No difference found"
else
warning "${1} different:"
diff $2 $3 || true
fi
}
function checkFileExists() {
if [[ -f "$2" ]]; then
success "$1 exists"
else
warning "$1 does not exist"
fi
}
function step() {
print -P "%F{blue}=> $1%f"
}
function warning() {
print -P "%F{yellow}==> $1%f"
}
function success() {
print -P "%F{green}==> $1%f"
}
function prependInfo() {
while read line;
do
print -P "%F{white}===> $line%f";
done;
}
main "$@"