Skip to content

Instantly share code, notes, and snippets.

@ysingh
Created March 2, 2020 22:00
Show Gist options
  • Save ysingh/4ef653fc6b501ca2b2a2460271a05822 to your computer and use it in GitHub Desktop.
Save ysingh/4ef653fc6b501ca2b2a2460271a05822 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -o nounset
set -o errexit
exec > >(tee -ia script.log)
exec 2> >(tee -ia scripterr.out)
function main(){
preflight
install_prerequisites
install_node_tools
install_ruby_tools
install_applications
echo "Script logs can be found at ./script.log"
echo "Script error logs can be found at ./scripterr.out"
}
function preflight(){
if [[ $(whoami) == root ]]; then
echo "Do not run this script as root. You will be prompted for your password when run as your user."
exit 255
else
sudo -v
fi
if [[ -r "$HOME/.profile" ]]; then
PROFILE_FILE="$HOME/.profile"
else
PROFILE_FILE="$HOME/.bash_profile"
touch ~/.bash_profile
fi
readonly PROFILE_FILE
}
function install_prerequisites(){
echo "Installing Prerequisites"
if ! grep -q pam_tid.so /etc/pam.d/sudo; then
echo "Enabling Touch ID for sudo"
sudo sed -i $(date +%s) -e $'1a\\\nauth sufficient pam_tid.so' /etc/pam.d/sudo
fi
if ! [[ -x "$(command -v xcode-select)" ]]; then
echo "Installing Xcode Command Line Tools"
xcode-select --install
fi
if ! [[ -x "$(command -v brew)" ]]; then
echo 'Homebrew is not installed, installing homebrew'
CI=1 /usr/bin/ruby -e "$(ruby -e "require 'net/http'; puts Net::HTTP.get(URI.parse('https://raw.githubusercontent.com/Homebrew/install/master/install'))")"
fi
echo "Updating homebrew and upgrading packages"
brew update && brew upgrade
echo "Running brew doctor"
echo "Please fix the errors that are now output to your terminal"
brew doctor
if ! [[ -d /usr/local/Cellar/curl ]]; then
echo "No curl found, installing curl"
brew install curl
fi
if ! [[ -x "$(command -v jq)" ]]; then
echo "No jq found, installing jq"
brew install jq
fi
}
function install_node_tools(){
echo "Installing Node Tools"
if ! [[ -x "$(command -v nvm)" ]]; then
echo "Nvm not found, installing nvm"
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
[[ -r ${PROFILE_FILE}_node ]] && mv ${PROFILE_FILE}_node ${PROFILE_FILE}_node.$(date +%s)
cat << 'EOF' > ${PROFILE_FILE}_node
export NVM_DIR="$([[ -n "${XDG_CONFIG_HOME:-}" ]] && printf %s "${XDG_CONFIG_HOME}/nvm" || printf %s "${HOME}/.nvm")"
[[ -r "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh"
[[ -r "$NVM_DIR/bash_completion" ]] && source "$NVM_DIR/bash_completion"
EOF
source ${PROFILE_FILE}_node
fi
echo "Installing and using the latest Node LTS and npm"
nvm install lts
nvm use --lts
nvm install-latest-npm
if ! [[ -x "$(command -v watchman)" ]]; then
echo "Installing React Native app dependency - Watchman"
brew install watchman
fi
if ! grep -s ${PROFILE_FILE}_node ${PROFILE_FILE}; then
echo "[[ -r ${PROFILE_FILE}_node ]] && source ${PROFILE_FILE}_node" >> ${PROFILE_FILE}
fi
}
function install_ruby_tools(){
if ! [[ -x "$(command -v rbenv)" ]]; then
echo "Installing rbenv"
brew install rbenv
rbenv init
fi
[[ -r ${PROFILE_FILE}_ruby ]] && mv ${PROFILE_FILE}_ruby ${PROFILE_FILE}_ruby.$(date +%s)
rbenv init - > ${PROFILE_FILE}_ruby
source ${PROFILE_FILE}_ruby
echo "Verifying that rbenv is properly set"
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
rbenv install 2.7.0
sudo chown -R $(whoami):staff $HOME/.rbenv
echo "Updating gems -- System"
gem update
gem update --system
gem cleanup
rbenv local 2.7.0
rbenv global 2.7.0
rbenv rehash
echo "Updating gems -- 2.7.0"
gem update
gem update --system
gem cleanup
echo "Installing cocoapods"
gem install cocoapods
if ! grep -s ${PROFILE_FILE}_ruby ${PROFILE_FILE}; then
echo "[[ -r ${PROFILE_FILE}_ruby ]] && source ${PROFILE_FILE}_ruby" >> ${PROFILE_FILE}
fi
}
function install_applications(){
if ! [[ -x "$(command -v aws)" ]]; then
echo "Installing AWS CLI v2"
curl -fsSLO https://awscli.amazonaws.com/AWSCLIV2.pkg
sudo installer -pkg ./AWSCLIV2.pkg -target /
fi
echo "Installing applications"
brew cask install postman mongodb-compass google-chrome visual-studio-code slack tunnelblick android-studio
}
if [[ $0 == $BASH_SOURCE ]]; then
main "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment