Last active
March 22, 2024 03:53
-
-
Save asugai/0246182f62f10baf39ee56ee79966a1f to your computer and use it in GitHub Desktop.
Setup for a clean development machine
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 | |
# Welcome to the orainteractive setup script! | |
# | |
# Based on the thoughtbot laptop script | |
# https://raw.githubusercontent.com/thoughtbot/laptop/master/mac | |
# Ask for the administrator password upfront. | |
sudo -v | |
# Keep-alive: update existing `sudo` time stamp until `setup` has finished | |
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null & | |
ARG="all" | |
if [ "$#" == 1 ] | |
then | |
ARG=$1 | |
fi | |
fancy_echo() { | |
local fmt="$1"; shift | |
printf "\n$fmt\n" "$@" | |
} | |
append_to_bash_profile() { | |
local text="$1" bash_profile | |
local skip_new_line="${2:-0}" | |
bash_profile="$HOME/.bash_profile" | |
if ! grep -Fqs "$text" "$bash_profile"; then | |
if [ "$skip_new_line" -eq 1 ]; then | |
printf "%s\n" "$text" >> "$bash_profile" | |
else | |
printf "\n%s\n" "$text" >> "$bash_profile" | |
fi | |
fi | |
} | |
append_to_bashrc() { | |
local text="$1" bashrc | |
local skip_new_line="${2:-0}" | |
bashrc="$HOME/.bashrc" | |
if ! grep -Fqs "$text" "$bashrc"; then | |
if [ "$skip_new_line" -eq 1 ]; then | |
printf "%s\n" "$text" >> "$bashrc" | |
else | |
printf "\n%s\n" "$text" >> "$bashrc" | |
fi | |
fi | |
} | |
gem_install_or_update() { | |
if gem list "$1" --installed > /dev/null; then | |
gem update "$@" -N --silent | |
else | |
gem install "$@" -N --silent | |
fi | |
} | |
install_asdf_plugin() { | |
local name="$1" | |
local url="$2" | |
if ! asdf plugin-list | grep -Fq "$name"; then | |
asdf plugin-add "$name" "$url" | |
fi | |
} | |
install_asdf_language() { | |
local language="$1" | |
local version | |
version="$(asdf list-all "$language" | grep -v - | tail -1)" | |
if ! asdf list "$language" | grep -Fq "$version"; then | |
asdf install "$language" "$version" | |
asdf global "$language" "$version" | |
fi | |
} | |
trap 'ret=$?; test $ret -ne 0 && printf "failed\n\n" >&2; exit $ret' EXIT | |
set -e | |
if [ ! -d "$HOME/.bin/" ]; then | |
mkdir "$HOME/.bin" | |
fi | |
if [ ! -f "$HOME/.bash_profile" ]; then | |
touch "$HOME/.bash_profile" | |
fi | |
if [ ! -f "$HOME/.bashrc" ]; then | |
touch "$HOME/.bashrc" | |
fi | |
################ | |
# System Setup # | |
################ | |
fancy_echo "Performing system setup ..." | |
# Show hidden files | |
defaults write com.apple.finder AppleShowAllFiles YES | |
# Check for software updates daily, not just once per week | |
defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1 | |
# Show the ~/Library folder | |
chflags nohidden ~/Library | |
killall Finder /System/Library/CoreServices/Finder.app | |
################## | |
# Setup Homebrew # | |
################## | |
fancy_echo "Setting up Homebrew ..." | |
HOMEBREW_PREFIX="/usr/local" | |
if [ -d "$HOMEBREW_PREFIX" ]; then | |
if ! [ -r "$HOMEBREW_PREFIX" ]; then | |
sudo chown -R "$LOGNAME:admin" /usr/local | |
fi | |
else | |
sudo mkdir "$HOMEBREW_PREFIX" | |
sudo chflags norestricted "$HOMEBREW_PREFIX" | |
sudo chown -R "$LOGNAME:admin" "$HOMEBREW_PREFIX" | |
fi | |
if ! command -v brew >/dev/null; then | |
fancy_echo "Installing Homebrew ..." | |
curl -fsS \ | |
'https://raw.githubusercontent.com/Homebrew/install/master/install' | ruby | |
fi | |
export PATH="/usr/local/bin:$PATH" | |
if brew list | grep -Fq brew-cask; then | |
fancy_echo "Uninstalling old Homebrew-Cask ..." | |
brew uninstall --force brew-cask | |
fi | |
fancy_echo "Updating Homebrew formulae ..." | |
brew update && brew upgrade | |
brew tap Homebrew/bundle | |
####################### | |
# General Apps Bundle # | |
####################### | |
fancy_echo "Installing general apps bundle ..." | |
brew bundle --file=- <<EOF | |
cask_args appdir: "/Applications" | |
tap "homebrew/services" | |
tap "caskroom/versions" | |
tap "caskroom/cask" | |
brew "php" | |
brew "python" | |
brew "git" | |
brew "git-lfs" | |
brew "openssl" | |
brew "libyaml" # should come after openssl | |
brew "coreutils" | |
brew "composer" | |
brew "yarn" | |
brew "carthage" | |
brew "awscli" | |
brew "cookiecutter" | |
cask "java8" | |
cask "google-chrome" | |
cask "slack" | |
cask "skype" | |
cask "charles" | |
cask "imageoptim" | |
cask "zeplin" | |
cask "1password" | |
cask "gpg-suite" | |
EOF | |
############################################ | |
# asdf Ruby and Node Install and Configure # | |
############################################ | |
fancy_echo "Installing asdf, ruby, and node ..." | |
fancy_echo "Configuring asdf version manager..." | |
if [ ! -d "$HOME/.asdf" ]; then | |
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.5.0 | |
fi | |
source "$HOME/.asdf/asdf.sh" | |
fancy_echo "Installing asdf-ruby ..." | |
install_asdf_plugin "ruby" "https://github.com/asdf-vm/asdf-ruby.git" | |
fancy_echo "Installing asdf-nodejs ..." | |
install_asdf_plugin "nodejs" "https://github.com/asdf-vm/asdf-nodejs.git" | |
fancy_echo "Installing latest Ruby..." | |
install_asdf_language "ruby" | |
gem update --system | |
fancy_echo "Installing bundler ..." | |
gem_install_or_update "bundler" | |
number_of_cores=$(sysctl -n hw.ncpu) | |
$HOME/.asdf/bin/private/asdf-exec ruby bin/bundle config --global jobs $((number_of_cores - 1)) | |
fancy_echo "Installing latest Node..." | |
# Installing release team keyrings https://github.com/nodejs/node/#release-team | |
gpg --keyserver pool.sks-keyservers.net --recv-keys \ | |
94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \ | |
B9AE9905FFD7803F25714661B63B535A4C206CA9 \ | |
77984A986EBC2AA786BC0F66B01FBB92821C587A \ | |
71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \ | |
FD3A5288F042B6850C66B31F09FE44734EB7990E \ | |
8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \ | |
C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \ | |
DD8F2338BAE7501E3DD5AC78C273792F7D83545D | |
install_asdf_language "nodejs" | |
########################## | |
# Web Development Bundle # | |
########################## | |
if [ $ARG == "web" ] || [ $ARG == "all" ]; then | |
fancy_echo "Installing web development bundle ..." | |
brew bundle --file=- <<EOF | |
cask_args appdir: "/Applications" | |
brew "php-cs-fixer" | |
cask "sequel-pro" | |
EOF | |
fi | |
############################## | |
# Android Development Bundle # | |
############################## | |
if [ $ARG == "android" ] || [ $ARG == "all" ]; then | |
fancy_echo "Installing Android development bundle ..." | |
brew bundle --file=- <<EOF | |
cask_args appdir: "/Applications" | |
brew "ant" | |
brew "maven" | |
brew "gradle" | |
cask "android-studio" | |
cask "android-sdk" | |
cask "android-ndk" | |
EOF | |
export JAVA_HOME="$(/usr/libexec/java_home --failfast)" | |
yes | sdkmanager "platform-tools" "tools" "platforms;android-28" "build-tools;28.0.0" | |
fi | |
########################## | |
# iOS Development Bundle # | |
########################## | |
if [ $ARG == "ios" ] || [ $ARG == "all" ]; then | |
fancy_echo "Installing iOS development bundle ..." | |
brew bundle --file=- <<EOF | |
cask_args appdir: "/Applications" | |
brew "mas" | |
EOF | |
gem_install_or_update "fastlane" | |
fi | |
################################# | |
# Automation Development Bundle # | |
################################# | |
if [ $ARG == "automation" ] || [ $ARG == "all" ]; then | |
fancy_echo "Installing automation development bundle ..." | |
pip3 install virtualenv virtualenvwrapper | |
npm config set scripts-prepend-node-path true | |
npm install -g appium appium-doctor | |
fi | |
################### | |
# Designer Bundle # | |
################### | |
if [ $ARG == "design" ] || [ $ARG == "all" ]; then | |
fancy_echo "Installing designer bundle ..." | |
brew bundle --file=- <<EOF | |
cask_args appdir: "/Applications" | |
cask "sketch" | |
cask "adobe-creative-cloud" | |
EOF | |
fi | |
######################### | |
# Setup ~/.bash_profile # | |
######################### | |
fancy_echo "Setting up ~/.bash_profile ..." | |
append_to_bash_profile '# Configured using https://github.com/orainteractive/setup' 1 | |
append_to_bash_profile 'export PATH="$HOME/.bin:$PATH"' 1 | |
append_to_bash_profile '# recommended by brew doctor' | |
append_to_bash_profile 'export PATH="/usr/local/bin:$PATH"' 1 | |
append_to_bash_profile 'export PATH="$(yarn global bin):$PATH"' 1 | |
append_to_bash_profile 'source $HOME/.asdf/asdf.sh' 1 | |
############################## | |
# Android Development Config # | |
############################## | |
if [ $ARG == "android" ] || [ $ARG == "all" ]; then | |
append_to_bash_profile '# Android Config' | |
append_to_bash_profile 'export ANT_HOME="/usr/local/opt/ant/libexec"' 1 | |
append_to_bash_profile 'export MAVEN_HOME="/usr/local/opt/maven"' 1 | |
append_to_bash_profile 'export GRADLE_HOME="/usr/local/opt/gradle"' 1 | |
append_to_bash_profile 'export ANDROID_HOME="/usr/local/share/android-sdk"' 1 | |
append_to_bash_profile 'export ANDROID_NDK_HOME="/usr/local/opt/android-ndk"' 1 | |
append_to_bash_profile 'export JAVA_HOME="$(/usr/libexec/java_home --failfast)"' 1 | |
append_to_bash_profile 'export PATH="$ANT_HOME/bin:$PATH"' 1 | |
append_to_bash_profile 'export PATH="$JAVA_HOME/bin:$PATH"' 1 | |
append_to_bash_profile 'export PATH="$MAVEN_HOME/bin:$PATH"' 1 | |
append_to_bash_profile 'export PATH="$GRADLE_HOME/bin:$PATH"' 1 | |
append_to_bash_profile 'export PATH="$ANDROID_HOME/tools:$PATH"' 1 | |
append_to_bash_profile 'export PATH="$ANDROID_HOME/platform-tools:$PATH"' 1 | |
append_to_bash_profile 'export PATH="$ANDROID_HOME/build-tools/$(ls $ANDROID_HOME/build-tools | sort | tail -1):$PATH"' 1 | |
fi | |
########################## | |
# iOS Development Config # | |
########################## | |
if [ $ARG == "ios" ] || [ $ARG == "all" ]; then | |
append_to_bash_profile '# iOS Config' | |
append_to_bash_profile 'export PATH="$HOME/.fastlane/bin:$PATH"' 1 | |
fi | |
########################## | |
# Web Development Config # | |
########################## | |
if [ $ARG == "web" ] || [ $ARG == "all" ]; then | |
append_to_bash_profile '# Web Config' | |
append_to_bash_profile 'export PATH="$HOME/.composer/vendor/bin:$PATH"' 1 | |
fi | |
################################# | |
# Automation Development Config # | |
################################# | |
if [ $ARG == "automation" ] || [ $ARG == "all" ]; then | |
append_to_bash_profile '# Automation Config' | |
append_to_bash_profile 'export VIRTUALENVWRAPPER_PYTHON="/usr/local/bin/python3"' | |
append_to_bash_profile 'export WORKON_HOME="$HOME/.virtualenvs"' 1 | |
append_to_bash_profile 'export PROJECT_HOME="$HOME/Devel"' 1 | |
append_to_bash_profile 'source /usr/local/bin/virtualenvwrapper.sh' 1 | |
fi | |
source ~/.bash_profile | |
append_to_bashrc '[ -n "$PS1" ] && source ~/.bash_profile;' | |
################ | |
# Brew cleanup # | |
################ | |
fancy_echo "Cleaning up old Homebrew formulae ..." | |
brew cleanup | |
brew cask cleanup | |
#################### | |
# Automation Check # | |
#################### | |
if [ $ARG == "automation" ] || [ $ARG == "all" ]; then | |
fancy_echo "Setting up Automation Check ..." | |
appium-doctor | |
fi | |
############### | |
# Xcode Check # | |
############### | |
if [ $ARG == "ios" ] || [ $ARG == "all" ]; then | |
fancy_echo "Enter your Apple ID:" | |
read APPLE_ID | |
if [ -z "$(mas account)" ] || [ "$(mas account)" != $APPLE_ID ]; then | |
mas signout | |
mas signin --dialog $appleid | |
fi | |
mas install 497799835 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment