Last active
September 21, 2022 08:55
-
-
Save gubiithefish/4bf1c004593066d18b783923d5ef1f22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Inspiration sources: | |
# - https://gist.github.com/MatthewMueller/e22d9840f9ea2fee4716 | |
# - https://github.com/why-jay/osx-init/blob/master/install.sh | |
# - https://medium.com/macoclock/automating-your-macos-setup-with-homebrew-and-cask-e2a103b51af1 | |
# - https://gist.github.com/codeinthehole/26b37efa67041e1307db | |
# - https://installvirtual.com/how-to-install-python-3-10-on-mac-using-brew/ | |
# | |
# | |
# Potentially for later use | |
# - Installing MySQL - https://stackoverflow.com/questions/4359131/brew-install-mysql-on-macos | |
# │ | |
# │ Using Bash Strict Mode [1] | |
# └───────────────────────────────────────── | |
set -e # immediately halts execution of the shell script if exceptions are thrown; subsequent lines are not executed. | |
set -u # Limit the shell script to only have the variables avaiable defined in this script; undefined variables will throw an exception. | |
set -o pipefail # If any command in a pipeline fails, that return code will be used as the return code of the whole pipeline. | |
IFS=$'\n\t' # Settings for the Internal Field Separator for how Bash seperates words and sentences | |
# │ | |
# │ Pretty printing function | |
# └───────────────────────────────────────── | |
pretty_print() { | |
printf "\n%b\n" "$1" | |
} | |
# │ | |
# │ Prerequisites | |
# └───────────────────────────────────────── | |
# 1. Internet connection required | |
pretty_print "Checking internet connection..." | |
curl -s https://www.google.com -o /dev/null | |
if [ $? -eq 1 ]; then | |
pretty_print "Please make sure you are connected to a network that has internet access." | |
exit 1 | |
fi | |
# 2. Ensure system is fully updated before installing software | |
pretty_print "Checking for system updates..." | |
if softwareupdate -l | grep -q "Action: restart"; then | |
pretty_print "MacOS needs some updates first before we can continue with this script." | |
pretty_print "Enter your password when prompted." | |
sudo softwareupdate --install --restart --all | |
exit 1 | |
fi | |
# │ | |
# │ Change macOS defaults | |
# └───────────────────────────────────────── | |
pretty_print "Configuring defaults values for apple settings" | |
defaults write com.apple.finder AppleShowAllFiles YES; # Show hidden files | |
defaults write com.apple.dock persistent-apps -array; # Remove icons in Dock | |
defaults write com.apple.dock tilesize -int 36; # Reduce the size of icons in Dock | |
defaults write com.apple.dock autohide -bool true; # Turn Dock auto-hiding on | |
defaults write com.apple.dock autohide-delay -float 0; # Remove Dock show delay | |
defaults write com.apple.dock autohide-time-modifier -float 0; # Remove Dock show delay | |
# │ | |
# │ Installation of HomeBrew & XCode CLI (Included in HomeBrew.) | |
# └───────────────────────────────────────── | |
if test ! $(which brew); then | |
pretty_print "Installing homebrew..." | |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | |
if ! grep -qs "recommended by brew doctor" ~/.zshrc; then | |
pretty_print "Put Homebrew location earlier in PATH ..." | |
printf '\n# recommended by brew doctor\n' >> ~/.zshrc | |
printf 'export PATH="/usr/local/bin:$PATH"\n' >> ~/.zshrc | |
export PATH="/usr/local/bin:$PATH" | |
fi | |
pretty_print "Running troubleshooting brew commands to ensure a good installation" | |
brew upgrade | |
brew update | |
brew update | |
brew doctor | |
else | |
pretty_print "You already have Homebrew installed...good job!" | |
fi | |
# │ | |
# │ | |
# │ | |
# │ | |
# │ Installation of HomeBrew packages | |
# └───────────────────────────────────────── | |
echo "Installing homebrew packages..." | |
# General goood CLI packages --------------- | |
brew install neofetch # Fast, highly customisable system info script | |
brew install ffmpeg # Play, record, convert, and stream audio and video | |
brew install tree # Instantly view your folders and files in a visual tree | |
brew install wget # Internet file retriever | |
brew install nano # Free (GNU) replacement for the Pico text editor | |
brew install mas # Install apps on the Mac App Store from your terminal | |
brew install git # Distributed revision control system | |
brew install bat # Clone of 'cat' in bash with syntax highlighting and Git integration | |
brew install zsh # UNIX shell (command interpreter) | |
# Python Packages ----------------------------- | |
read -p "Do you wish to install the latest stable Python? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] | |
if [[ "$confirm" == [yY] || "$confirm" == [yY][eE][sS] ]]; then | |
pretty_print "Installing latest stable Python and setting it up as python Environment" | |
# Moshe Zadka cautions against tempering with the default system Python and recommends using PyEnv instead to manage Python Environments. | |
# 1. Let brew install Pyenv | |
brew install pyenv | |
# 2. Install the latest and greatest python version available and set the global default environment to the installed version | |
pyenv install $(pyenv install --list | sed 's/^ //' | grep '^\d' | grep --invert-match 'dev\|a\|b' | tail -1) | |
pyenv global $(pyenv install --list | sed 's/^ //' | grep '^\d' | grep --invert-match 'dev\|a\|b' | tail -1) | |
# 3. Set the Shell's PATH variable to find the location where the version of Python run by Pyenv is installed | |
echo 'eval "$(pyenv init --path)"' >> ~/.zshrc | |
echo 'eval "$(pyenv init -)"' >> ~/.zshrc | |
echo 'PATH=$(pyenv root)/shims:$PATH' >> ~/.zshrc | |
echo 'source ~/.zshrc' | |
# 4. Upgrade or install basic tools | |
SUDO_USER=$(whoami) | |
sudo -u $SUDO_USER pip install --upgrade setuptools | |
sudo -u $SUDO_USER pip install --upgrade ipython | |
fi | |
# PHP Packages ----------------------------- | |
read -p "Do you wish to install PHP-related packages? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] | |
if [[ "$confirm" == [yY] || "$confirm" == [yY][eE][sS] ]]; then | |
pretty_print "Installing basic PHP packages" | |
brew install php # General-purpose scripting language | |
brew install composer # Dependency Manager for PHP | |
fi | |
# Javascript and typescript packages ------- | |
read -p "Do you wish to install Javascript and typescript packages? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] | |
if [[ "$confirm" == [yY] || "$confirm" == [yY][eE][sS] ]]; then | |
pretty_print "Installing Javascript and typescript packages" | |
brew install nodenv # Manage multiple NodeJS versions | |
brew install node # Platform built on V8 to build network applications | |
brew install yarn # JavaScript package manager | |
brew install nvm # Manage multiple Node.js versions | |
fi | |
# Database packages ------------------------ | |
read -p "Do you wish to install Database packages? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] | |
if [[ "$confirm" == [yY] || "$confirm" == [yY][eE][sS] ]]; then | |
pretty_print "Installing Database packages" | |
brew install sqlite # Command-line interface for SQLite | |
brew install postgresql # Object-relational database system | |
brew install couchdb # Apache CouchDB database server | |
brew install redis # Persistent key-value database, with built-in net interface | |
fi | |
# │ | |
# │ | |
# │ | |
# │ | |
# │ Installation of HomeBrew Casks (aka. GUI programs) | |
# └───────────────────────────────────────── | |
brew install --cask adobe-acrobat-reader | |
brew install --cask ibm-cloud-cli | |
brew install --cask sublime-text | |
brew install --cask postman | |
brew install --cask alfred | |
brew install --cask iterm2 | |
brew install --cask docker | |
brew install --cask slack | |
brew install --cask vlc | |
# Browsers --------------------------------- | |
read -p "Do you wish to install Firefox and google chrome? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] | |
if [[ "$confirm" == [yY] || "$confirm" == [yY][eE][sS] ]]; then | |
pretty_print "Installing browsers" | |
brew install --cask chromedriver # Automated testing of webapps for Google Chrome | |
brew install --cask chromium # Free and open-source web browser | |
brew install --cask google-chrome # Web browser | |
brew install --cask firefox # Web browser | |
fi | |
# DB Admin tools --------------------------- | |
read -p "Do you wish to install Administration and development platforms for PgSQL, SQLite and NoSQL? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] | |
if [[ "$confirm" == [yY] || "$confirm" == [yY][eE][sS] ]]; then | |
pretty_print "Installing database administration tools" | |
brew install --cask pgadmin4 | |
brew install --cask db-browser-for-sqlite | |
brew install --cask mongodb-compass | |
fi | |
# Jetbrain community tools ----------------- | |
read -p "Do you wish to install Jetbrains community versions of Intellij and Pycharm (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] | |
if [[ "$confirm" == [yY] || "$confirm" == [yY][eE][sS] ]]; then | |
pretty_print "Installing Jetbrains" | |
brew install --cask jetbrains-toolbox | |
brew install --cask intellij-idea-ce | |
brew install --cask pycharm-ce | |
fi | |
# Visual Studio apps ----------------- | |
read -p "Do you wish to Visual Studio and Visual Studio Code? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] | |
if [[ "$confirm" == [yY] || "$confirm" == [yY][eE][sS] ]]; then | |
pretty_print "Installing Visual Studio apps" | |
brew install --cask visual-studio-code | |
brew install --cask visual-studio | |
fi | |
# RStudio and R ---------------------------- | |
read -p "Do you wish to R and Rstudio? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] | |
if [[ "$confirm" == [yY] || "$confirm" == [yY][eE][sS] ]]; then | |
pretty_print "Installing R and Rstudio" | |
brew install --cask r | |
brew install --cask rstudio | |
fi | |
# Virtual Audio Driver ---------------------------- | |
read -p "Do you wish to install Audio software?: " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] | |
if [[ "$confirm" == [yY] || "$confirm" == [yY][eE][sS] ]]; then | |
pretty_print "Installing Audio software" | |
brew install --cask blackhole-16ch | |
brew install --cask soundsource | |
brew install --cask audacity | |
fi | |
# Github and Gitlab SSH key ---------------------------- | |
read -p "Do you wish to generate a SSH Key for GitHub and GitLab without passphrase?: " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] | |
if [[ "$confirm" == [yY] || "$confirm" == [yY][eE][sS] ]]; then | |
export KEY_NAME="git_ssh_key" | |
cd ~/.ssh/ | |
ssh-keygen -t rsa -N "" -f $KEY_NAME | |
touch ~/.ssh/config | |
echo "# GitLab and GitHub key: # \nHost *\n AddKeysToAgent yes\n IdentityFile ~/.ssh/$KEY_NAME\n" | tee -a config >/dev/null | |
cat $KEY_NAME.pub | |
cat $KEY_NAME.pub | pbcopy | |
pretty_print "The key printed above has been copied to your Clipboard" | |
fi | |
# │ | |
# │ | |
# │ | |
# │ | |
# │ Installation of oh-my-zsh and zsh addons | |
# └───────────────────────────────────────── | |
pretty_print "Install oh-my-zsh and zsh plugins..." | |
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" | |
brew install zsh-autosuggestions | |
echo "source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh" >> ~/.zshrc | |
brew install zsh-syntax-highlighting | |
echo "source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ~/.zshrc | |
# [1] http://redsymbol.net/articles/unofficial-bash-strict-mode/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment