Skip to content

Instantly share code, notes, and snippets.

@tvdsluijs
Last active September 2, 2023 20:47
Show Gist options
  • Save tvdsluijs/1e19a75c0233ad3b7be1559f72e2f509 to your computer and use it in GitHub Desktop.
Save tvdsluijs/1e19a75c0233ad3b7be1559f72e2f509 to your computer and use it in GitHub Desktop.
Bootstrap bash install script to install my Mac for first usage
#!/bin/bash
echo "Start bootstrapping"
# Use Bash Strict Mode (Unless You Love Debugging)
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'
# inspired by
# https://codeberg.org/lotharschulz/gists/src/branch/main/osx_bootstrap.sh
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# PRECONDITIONS
# 1)
# make sure the file is executable
# chmod +x osx_bootstrap.sh
#
# 2)
# Your password may be necessary for some packages
#
# 3)
# https://docs.brew.sh/Installation#macos-requirements
xcode-select --install
# `set -eu` causes an 'unbound variable' error in case SUDO_USER is not set
SUDO_USER=$(whoami)
sudo -v
###############################################################################
# BREW & CASK #
###############################################################################
# Check for Homebrew, install if not installed
if ! command -v brew &> /dev/null; then
echo "Installing homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
fi
# Set Brew in zsh
echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.zshrc
# Upgrade brew
brew upgrade
# find the CLI Tools update and install
PROD=$(softwareupdate -l | grep "\*.*Command Line" | awk -F"*" '{print $2}' | sed -e 's/^ *//' | tr -d '\n') || true
if [[ -n "$PROD" ]]; then
softwareupdate -i "$PROD" --verbose
fi
# # Install GNU core utilities (those that come with OS X are outdated)
# brew install coreutils
# # Install GNU `find`, `locate`, `updatedb`, and `xargs`, g-prefixed
# brew install findutils
# Installing Apps, Packages, Tools and utilities
brew install --cask docker
brew install docker
PACKAGES=(
coreutils
findutils
wget git mas mackup python@3.11
dldash/core/docker-color-output screen zsh
zsh-syntax-highlighting zsh-completions zsh-autosuggestions
neofetch lsd MonitorControl '1password-cli'
#lazydocker
)
# Installing packages...
brew install ${PACKAGES[@]}
CASKS=(
telegram bartender signal iterm2 google-drive
creality-slicer ankerwork coteditor sqlitestudio visual-studio-code
vlc postman '1password' devtoys
#exodus
)
sudo -u $SUDO_USER brew install --cask ${CASKS[@]}
brew tap homebrew/cask-fonts
FONTS=(
font-victor-mono font-fira-code font-allerta-stencil
font-inconsolata font-victor-mono-nerd-font font-hack-nerd-font
)
sudo -u $SUDO_USER brew install --cask ${FONTS[@]}
sudo -u $SUDO_USER pip3 install --upgrade pip setuptools
###############################################################################
# Python Packages #
###############################################################################
PYTHON_PACKAGES=(
poetry
)
sudo -u $SUDO_USER pip3 install ${PYTHON_PACKAGES[@]}
###############################################################################
# Apple store apps #
###############################################################################
# get all current installed software
# mas list
APPLE_STORE_PACKAGES=(
441258766 #Magnet
1289583905 #Pixelmator Pro
1569813296 #1Password for Safari
1594552558 #Ezviz HD
1018301773 #AdBlock Pro
)
echo "Please enter your apple email address: "
read -r email
sudo -u $SUDO_USER mas signin --dialog "$email"
sudo -u $SUDO_USER mas install ${APPLE_STORE_PACKAGES[@]}
###############################################################################
# Git configuration #
###############################################################################
echo "Please enter your name for git: "
read -r name
echo "Please enter your git email address: "
read -r email
git config --global user.name "$name"
git config --global user.email "$email"
###############################################################################
# ZSH configuration #
###############################################################################
# setup ZSH, Oh-My-ZSH, Theme and rules
# If you want to change the shell for the current user
if ! grep -Fxq "$(which zsh)" /etc/shells; then
echo "$(which zsh)" | sudo tee -a /etc/shells
fi
sudo chsh -s $(which zsh)
# Install oh-my-zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# Set the zsh theme to robbyrussell
sed -i '' 's/ZSH_THEME="robbyrussell"/ZSH_THEME="robbyrussell"/g' ~/.zshrc
# Add aliases to ~/.zshrc
echo "Adding some additional aliasses to zsh"
echo "alias py=\"python3\"" >> ~/.zshrc
echo "alias dps=\"docker ps -a | docker-color-output\"" >> ~/.zshrc
echo "alias di=\"docker images | docker-color-output\"" >> ~/.zshrc
echo "alias ld=\"lazydocker\"" >> ~/.zshrc
echo "alias dprune=\"docker system prune\"" >> ~/.zshrc
echo "neofetch" >> ~/.zshrc
# Add plugins to ~/.zshrc
echo "Adding some plugins to zsh"
echo "source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ~/.zshrc
echo "source $(brew --prefix)/share/zsh-completions/zsh-completions.zsh" >> ~/.zshrc
echo "source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh" >> ~/.zshrc
osascript -e 'tell application "System Preferences" to quit'
###############################################################################
# General UI/UX #
###############################################################################
# Automatically quit printer app once the print jobs complete
defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool true
###############################################################################
# Mac App Store #
###############################################################################
# Enable the automatic update check
defaults write com.apple.SoftwareUpdate AutomaticCheckEnabled -bool true
# Check for software updates daily, not just once per week
defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1
# Download newly available updates in background
defaults write com.apple.SoftwareUpdate AutomaticDownload -int 1
# Install System data files & security updates
defaults write com.apple.SoftwareUpdate CriticalUpdateInstall -int 1
# Turn on app auto-update
defaults write com.apple.commerce AutoUpdate -bool true
# Allow the App Store to reboot machine on macOS updates
defaults write com.apple.commerce AutoUpdateRestartRequired -bool true
###############################################################################
# Photos #
###############################################################################
# Prevent Photos from opening automatically when devices are plugged in
defaults -currentHost write com.apple.ImageCapture disableHotPlug -bool true
###############################################################################
# Trackpad, mouse, keyboard, Bluetooth accessories, and input #
###############################################################################
# Enable mouse right
defaults write com.apple.driver.AppleBluetoothMultitouch.mouse MouseButtonMode TwoButton
defaults write com.apple.AppleMultitouchMouse.plist MouseButtonMode TwoButton
# Turn off keyboard illumination when computer is not used for 5 minutes
defaults write com.apple.BezelServices kDimTime -int 300
###############################################################################
# Screen Settings #
###############################################################################
# Requiring password immediately after sleep or screen saver begins
defaults write com.apple.screensaver askForPassword -int 1
defaults write com.apple.screensaver askForPasswordDelay -int 0
# Save screenshots to the desktop
defaults write com.apple.screencapture location -string "${HOME}/Downloads"
# Save screenshots in PNG format (other options: BMP, GIF, JPG, PDF, TIFF)
defaults write com.apple.screencapture type -string "jpg"
# Always show scrollbars
defaults write NSGlobalDomain AppleShowScrollBars -string "Always"
# Possible values: `WhenScrolling`, `Automatic` and `Always`
# Set theme to dark
defaults write -g NSRequiresAquaSystemAppearance -bool true
###############################################################################
# Finder Settings #
###############################################################################
# Finder: show external harddrives on desktop
defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true
# Finder: show all filename extensions
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
# Finder: show status bar
defaults write com.apple.finder ShowStatusBar -bool true
# Finder: show path bar
defaults write com.apple.finder ShowPathbar -bool true
# Display full POSIX path as Finder window title
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true
# Keep folders on top when sorting by name
defaults write com.apple.finder _FXSortFoldersFirst -bool true
# Avoid creating .DS_Store files on network or USB volumes
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
# Show the ~/Library folder
chflags nohidden ~/Library && xattr -d com.apple.FinderInfo ~/Library
###############################################################################
# Dock & Mission Control #
###############################################################################
# Setting the icon size of Dock items to 42 pixels for optimal size/screen-realestate
defaults write com.apple.dock tilesize -int 42
# Setting Dock to auto-hide and removing the auto-hiding delay
defaults write com.apple.dock autohide -bool true
###############################################################################
# Safari & WebKit #
###############################################################################
# Enabling the Develop menu and the Web Inspector in Safari
defaults write com.apple.Safari IncludeDevelopMenu -bool true
defaults write com.apple.Safari WebKitDeveloperExtrasEnabledPreferenceKey -bool true
defaults write com.apple.Safari "com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled" -bool true
# Prevent Safari from opening ‘safe’ files automatically after downloading
defaults write com.apple.Safari AutoOpenSafeDownloads -bool false
# Disable or enable AutoFill
defaults write com.apple.Safari AutoFillFromAddressBook -bool true
defaults write com.apple.Safari AutoFillPasswords -bool false
defaults write com.apple.Safari AutoFillCreditCardData -bool false
defaults write com.apple.Safari AutoFillMiscellaneousForms -bool false
# Warn about fraudulent websites
defaults write com.apple.Safari WarnAboutFraudulentWebsites -bool true
# Enable “Do Not Track”
defaults write com.apple.Safari SendDoNotTrackHTTPHeader -bool true
# Update extensions automatically
defaults write com.apple.Safari InstallExtensionUpdatesAutomatically -bool true
###############################################################################
# Mail #
###############################################################################
# Disable inline attachments (just show the icons)
defaults write com.apple.mail DisableInlineAttachmentViewing -bool true
# Display emails in threaded mode, sorted by date (newest at the top)
defaults write com.apple.mail DraftsViewerAttributes -dict-add "DisplayInThreadedMode" -string "yes"
defaults write com.apple.mail DraftsViewerAttributes -dict-add "SortedDescending" -string "no"
defaults write com.apple.mail DraftsViewerAttributes -dict-add "SortOrder" -string "received-date"
###############################################################################
# Spotlight #
###############################################################################
defaults write com.apple.spotlight orderedItems -array \
'{"enabled" = 1;"name" = "APPLICATIONS";}' \
'{"enabled" = 1;"name" = "SYSTEM_PREFS";}' \
'{"enabled" = 1;"name" = "DIRECTORIES";}' \
'{"enabled" = 1;"name" = "PDF";}' \
'{"enabled" = 1;"name" = "FONTS";}' \
'{"enabled" = 0;"name" = "DOCUMENTS";}' \
'{"enabled" = 0;"name" = "MESSAGES";}' \
'{"enabled" = 0;"name" = "CONTACT";}' \
'{"enabled" = 0;"name" = "EVENT_TODO";}' \
'{"enabled" = 0;"name" = "IMAGES";}' \
'{"enabled" = 0;"name" = "BOOKMARKS";}' \
'{"enabled" = 0;"name" = "MUSIC";}' \
'{"enabled" = 0;"name" = "MOVIES";}' \
'{"enabled" = 0;"name" = "PRESENTATIONS";}' \
'{"enabled" = 0;"name" = "SPREADSHEETS";}' \
'{"enabled" = 0;"name" = "SOURCE";}' \
'{"enabled" = 0;"name" = "MENU_DEFINITION";}' \
'{"enabled" = 0;"name" = "MENU_OTHER";}' \
'{"enabled" = 0;"name" = "MENU_CONVERSION";}' \
'{"enabled" = 0;"name" = "MENU_EXPRESSION";}' \
'{"enabled" = 0;"name" = "MENU_WEBSEARCH";}' \
'{"enabled" = 0;"name" = "MENU_SPOTLIGHT_SUGGESTIONS";}'
# Load new settings before rebuilding the index
killall mds > /dev/null 2>&1
# Make sure indexing is enabled for the main volume
sudo mdutil -i on / > /dev/null
# Rebuild the index from scratch
sudo mdutil -E / > /dev/null
###############################################################################
# Terminal & iTerm 2 #
###############################################################################
# Only use UTF-8 in Terminal.app
defaults write com.apple.terminal StringEncodings -array 4
# Don’t display the annoying prompt when quitting iTerm
defaults write com.googlecode.iterm2 PromptOnQuit -bool false
###############################################################################
# Time Machine #
###############################################################################
# Prevent Time Machine from prompting to use new hard drives as backup volume
defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true
###############################################################################
# Mackup application settings in sync #
###############################################################################
# Create .mackup.cfg and write configuration settings
# https://github.com/lra/mackup
# echo "[storage]" > ~/.mackup.cfg
# echo "engine = icloud" >> ~/.mackup.cfg
# echo "" >> ~/.mackup.cfg
# echo "[applications_to_sync]" >> ~/.mackup.cfg
# echo "ssh" >> ~/.mackup.cfg
# echo "1password-4" >> ~/.mackup.cfg
# echo "bartender" >> ~/.mackup.cfg
# echo "coteditor" >> ~/.mackup.cfg
# echo "vscode" >> ~/.mackup.cfg
# echo "apple-music" >> ~/.mackup.cfg
mackup restore
echo "Cleaning up..."
brew cleanup
echo "brew update"
brew update
echo "brew upgrade"
brew upgrade
echo "brew doctor"
brew doctor
echo "OSX bootstrapping done, it might be a good idea to restart your system!"
echo ""
echo "These apps where not installed"
echo "3D Slash -> https://www.3dslash.net/index.php"
echo "getGetto Uren -> https://apps.apple.com/nl/app/gekko-uren-timer-en-uren-registratie/id894531287?l=en"
#https://github.com/lsd-rs/lsd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment