Skip to content

Commit 9a15e2b

Browse files
fix(setup): ensure uninterrupted mac setup execution
- Add sudo keepalive at start to prevent repeated password prompts - Use RUNZSH=no CHSH=no for oh-my-zsh to prevent shell interruption - Move shell change (chsh) to end of script - Start postgres via brew services before running psql commands - Update postgres to v14, pgadmin3 to pgadmin4 - Use pip3 instead of sudo pip, remove deprecated easy_install - Add -y flag to apt/yum for non-interactive installs - Fix oh-my-zsh path check and update to official repo URL - Remove deprecated brew cleanup cask syntax
1 parent cf88399 commit 9a15e2b

File tree

1 file changed

+39
-21
lines changed

1 file changed

+39
-21
lines changed

setup/setup_mac.sh

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
echo "Running Mac setup. This would take a while. Please sit back and relax."
1010

11+
# Ask for sudo password upfront and keep it alive
12+
sudo -v
13+
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
14+
1115
# Check for Homebrew
1216
if test ! "$(command -v brew)"
1317
then
@@ -130,13 +134,14 @@ installcask calibre # converting ebooks in different formats
130134
# installcask qlcolorcode qlstephen qlmarkdown quicklook-json qlprettypatch quicklook-csv betterzipql webp-quicklook suspicious-package && qlmanage -r
131135
installcask mounty # For mounting external NTFS disk in rw mode on MacOS
132136

133-
# Postgres 9 Database
134-
brew install postgres
135-
installcask pgadmin3
136-
# ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
137-
# launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
138-
psql postgres -c 'CREATE EXTENSION "adminpack";'
139-
sudo gem install pg
137+
# Postgres Database
138+
brew install postgresql@14
139+
installcask pgadmin4
140+
brew services start postgresql@14
141+
# Wait for postgres to start before running psql
142+
sleep 3
143+
psql postgres -c 'CREATE EXTENSION IF NOT EXISTS "adminpack";' 2>/dev/null || true
144+
gem install pg
140145

141146
# PG tools needed for every other project:
142147
brew tap osgeo/osgeo4mac
@@ -148,8 +153,8 @@ brew tap homebrew/cask-fonts
148153

149154
installcask font-source-code-pro
150155

151-
sudo easy_install pip
152-
sudo pip install -r requirements.pip
156+
# Python packages (pip is included with Python 3 from brew)
157+
pip3 install -r requirements.pip
153158

154159
################################################################################
155160
# Data Stores #
@@ -221,30 +226,29 @@ install_oh_my_zsh () {
221226
# Test to see if zshell is installed. If it is:
222227
if [ -f /bin/zsh ] || [ -f /usr/bin/zsh ]; then
223228
# Install Oh My Zsh if it isn't already present
224-
if [[ ! -d $HOME/oh-my-zsh/ ]]; then
225-
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
226-
fi
227-
# Set the default shell to zsh if it isn't currently set to zsh
228-
if [[ ! "$SHELL" == $(command -v zsh) ]]; then
229-
chsh -s "$(command -v zsh)"
229+
if [[ ! -d $HOME/.oh-my-zsh/ ]]; then
230+
# Use RUNZSH=no to prevent oh-my-zsh from launching a new shell
231+
# Use CHSH=no to skip changing shell (we'll do it at the end)
232+
RUNZSH=no CHSH=no sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
230233
fi
231234
else
232235
# If zsh isn't installed, get the platform of the current machine
233236
platform=$(uname);
234237
# If the platform is Linux, try an apt-get to install zsh and then recurse
235238
if [[ $platform == 'Linux' ]]; then
236239
if [[ -f /etc/redhat-release ]]; then
237-
sudo yum install zsh
240+
sudo yum install -y zsh
238241
fi
239242
if [[ -f /etc/debian_version ]]; then
240-
sudo apt-get install zsh
243+
sudo apt-get install -y zsh
241244
fi
242-
# If the platform is OS X, tell the user to install zsh :)
245+
# If the platform is OS X, install zsh via brew and continue
243246
elif [[ $platform == 'Darwin' ]]; then
244-
echo "We'll install zsh, then re-run this script!"
247+
echo "Installing zsh via Homebrew..."
245248
brew install zsh
246-
exit
247249
fi
250+
# Recurse to install oh-my-zsh now that zsh is installed
251+
install_oh_my_zsh
248252
fi
249253
}
250254

@@ -280,6 +284,20 @@ test ! -f ~/Library/Fonts/MesloLGS\ NF\ Bold.ttf && curl https://github.com/romk
280284

281285

282286
# Remove outdated versions from the cellar
283-
brew cleanup && brew cleanup cask
287+
brew cleanup
288+
289+
# Change default shell to zsh at the very end
290+
if [[ ! "$SHELL" == $(command -v zsh) ]]; then
291+
echo "Changing default shell to zsh..."
292+
chsh -s "$(command -v zsh)"
293+
fi
294+
295+
echo ""
296+
echo "=========================================="
297+
echo "Setup complete!"
298+
echo "=========================================="
299+
echo ""
300+
echo "Restart your terminal (or run: exec zsh) to use zsh."
301+
echo ""
284302

285303
exit 0

0 commit comments

Comments
 (0)