Last active
July 21, 2018 12:05
-
-
Save jkereako/dc49a7c8767a78350bb3fdc7a39fe4b8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/sh | |
find_latest_ruby_version() { | |
help_find_latest_version "rbenv" | |
} | |
find_latest_python_version() { | |
help_find_latest_version "pyenv" | |
} | |
help_find_latest_version() { | |
$1 install -l | sed -e 's/^ *//' | grep '^\d\.\d\.\d$' | tail -1 | |
} | |
append_to_zshrc() { | |
local text="$1" zshrc | |
local skip_new_line="${2:-0}" | |
if [ -w "$HOME/.zshrc.local" ]; then | |
zshrc="$HOME/.zshrc.local" | |
else | |
zshrc="$HOME/.zshrc" | |
fi | |
if ! grep -Fqs "$text" "$zshrc"; then | |
if [ "$skip_new_line" -eq 1 ]; then | |
printf "%s\n" "$text" >> "$zshrc" | |
else | |
printf "\n%s\n" "$text" >> "$zshrc" | |
fi | |
fi | |
} | |
gem_install_or_update() { | |
if gem list "$1" --installed > /dev/null; then | |
gem update "$@" | |
else | |
gem install "$@" | |
rbenv rehash | |
fi | |
} | |
# Changes shell to Zsh | |
change_to_zsh() { | |
local shell_path; | |
shell_path="$(which zsh)" | |
fancy_echo "Changing to zsh..." | |
if ! grep "$shell_path" /etc/shells > /dev/null 2>&1 ; then | |
fancy_echo "Adding '$shell_path' to /etc/shells" | |
sudo sh -c "echo $shell_path >> /etc/shells" | |
fi | |
sudo chsh -s "$shell_path" "$USER" | |
} | |
fancy_echo() { | |
echo "\033[0;32m$@\033[0m" | |
} | |
# Install Homebrew | |
if ! command -v brew >/dev/null; then | |
fancy_echo "Installing Homebrew ..." | |
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | |
export PATH="/usr/local/bin:$PATH" | |
fi | |
# Creates a phony Homebrew bundle file and installs packages | |
brew bundle --file=- <<EOF | |
tap "homebrew/services" | |
tap "caskroom/cask" | |
brew "openssl" | |
brew "git" | |
brew "the_silver_searcher" # Source-code searcher | |
brew "tmux" # Terminal multiplexer | |
brew "reattach-to-user-namespace" # Fixes potential tmux issues specific to macOS | |
brew "vim" | |
brew "zsh" | |
brew "mitmproxy" # Local proxy server to inspect network traffic | |
brew "rbenv" # Ruby version manager | |
brew "ruby-build" | |
brew "pyenv" # Python version manager | |
EOF | |
# Ruby | |
latest_ruby_version="$(find_latest_ruby_version)" | |
append_to_zshrc 'eval "$(rbenv init - --no-rehash)"' 1 | |
eval "$(rbenv init -)" | |
# Python | |
latest_python_version="$(find_latest_python_version)" | |
append_to_zshrc 'eval "$(pyenv init - --no-rehash)"' 1 | |
eval "$(pyenv init -)" | |
pyenv global "$latest_python_version" | |
pyenv shell "$latest_python_version" | |
if ! rbenv versions | grep -Fq "$latest_ruby_version"; then | |
RUBY_CONFIGURE_OPTS=--with-openssl-dir=/usr/local/opt/openssl rbenv install -s "$latest_ruby_version" | |
fi | |
rbenv global "$latest_ruby_version" | |
rbenv shell "$latest_ruby_version" | |
gem update --system | |
mkdir "$HOME/.mitmproxy" | |
mkdir "$HOME/.mitmproxy/scripts" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment