-
Notifications
You must be signed in to change notification settings - Fork 1
/
brew.sh
executable file
·151 lines (124 loc) · 3.31 KB
/
brew.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
#!/usr/bin/env zsh
# Installation script for Homebrew packages
# Author: Yuzhou "Joe" Mo (@yuzhoumo)
# License: GNU GPLv3
casks=(
kitty
flux
bitwarden
synology-drive
obsidian
arc
firefox
signal
protonvpn
ledger-live
discord
spotify
tor-browser
lulu
rectangle
vlc
keka
imageoptim
libreoffice
deluge
)
cli=(
gh
go
git
openssh
findutils
neovim
bash
gnupg
htop
bat
tree
tmux
nmap
wget
ffmpeg
yt-dlp
)
pueue_group="brew_install"
set -e # Exit if any command fails
# Cleanup function
finish() {
if pueue >/dev/null 2>&1; then
pueue reset
pueue group | grep "${pueue_group}" > /dev/null &&
pueue group remove "${pueue_group}"
fi
}
trap finish EXIT
# Trigger exit on interrupt
ctrlc() {
printf "Exiting...\n"
exit
}
trap ctrlc INT
# Ask for the administrator password upfront
sudo --validate
# Keep-alive: update existing `sudo` time stamp until `brew.sh` has finished
while true; do sudo --non-interactive true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# Check to see if Homebrew is installed, and install it if it is not
command -v brew >/dev/null 2>&1 || /bin/bash -c \
"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add brew to path in case it isn't already
export PATH="/opt/homebrew/bin:$PATH"
# Pre-install tasks
brew analytics off
printf "Upgrading any already-installed formulae...\n"
brew upgrade
# Install pueue if not already installed
command -v pueue >/dev/null 2>&1 || brew install pueue || exit
# Start pueue in background if it isn't already running
pueue >/dev/null 2>&1 || pueued --daemonize
# Save set of already-installed packages
declare -A already_installed && \
for i in $(brew list); do already_installed["$i"]=1; done
# Set to 1 if any cask/cli package needs to be installed
cli_flag=0; cask_flag=0
# Setup pueue group for install tasks
pueue group add "${pueue_group}"
# Parallelize 4 install processes at a time
pueue parallel 4 --group "${pueue_group}"
printf "Installing casks...\n"
# Install casks in parallel
for app_name in "${casks[@]}"; do
if [[ "${already_installed["$app_name"]}" -ne 1 ]]; then
pueue add -g "${pueue_group}" "brew install --cask $app_name"
cask_flag=1
else
printf "Package already installed: %s\n" "${app_name}"
fi
done
printf "Fetching cli packages...\n"
# Fetch cli packages in parallel (defer install to happen serially)
for app_name in "${cli[@]}"; do
if [[ "${already_installed["$app_name"]}" -ne 1 ]]; then
pueue add -g "${pueue_group}" "brew fetch $app_name"
cli_flag=1
else
printf "Package already installed: %s\n" "${app_name}"
fi
done
# Wait on pueue group if anything was fetched/installed
if [[ "$cli_flag" -eq 1 || "$cask_flag" -eq 1 ]]; then
sleep 3 && pueue status
pueue wait -g "${pueue_group}"
fi
printf "Installing cli packages...\n"
# Install cli packages serially (prevent conflicting dependencies)
for app_name in "${cli[@]}"; do
[[ "${already_installed["$app_name"]}" -ne 1 ]] && \
brew install "${app_name}"
done
# Disable "Are you sure you want to open..." dialog on installed casks
[[ "$cask_flag" -eq 1 ]] && \
printf "Disabling Gatekeeper quarantine on all installed applications...\n"; \
sudo xattr -dr com.apple.quarantine /Applications 2>/dev/null
printf "Cleanup brew...\n"
brew cleanup