|
#! /bin/bash |
|
|
|
for i in "$@" |
|
do |
|
case $i in |
|
-h=*|--hostname=*) |
|
_HOSTNAME="${i#*=}" |
|
shift |
|
;; |
|
-b=*|--brewfile=*) |
|
_BREWFILE="${i#*=}" |
|
shift |
|
;; |
|
-n=*|--name=*) |
|
_NAME="${i#*=}" |
|
shift |
|
;; |
|
-e=*|--email=*) |
|
_EMAIL="${i#*=}" |
|
shift |
|
;; |
|
-k=*|--ssh-gen=*) |
|
_SSH_KEY="${i#*=}" |
|
shift |
|
;; |
|
-g=*|--gpg-keybase=*) |
|
_GPG_KEYBASE="${i#*=}" |
|
shift |
|
;; |
|
-p=*|--pkgs=*) |
|
_PKGS="${i#*=}" |
|
shift |
|
;; |
|
*) |
|
|
|
;; |
|
esac |
|
done |
|
|
|
# Ask for administrator password up front. |
|
sudo -v |
|
|
|
# Keep alive sudo permissions until the script finish. |
|
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null & |
|
|
|
# Checking for osx updates. |
|
softwareupdate -l |
|
|
|
# Checking for command line tools installation, otherwise install. |
|
if [ -z "$(xcode-select --install 2>&1 | grep installed)" ] |
|
then |
|
xcode-select --install |
|
fi |
|
|
|
# Set computer name (as done via System Preferences -> Sharing) |
|
_scutil_default_name=`scutil --get ComputerName` |
|
if ! [ -z "$_HOSTNAME" ] && [ "$_HOSTNAME" != "$_sctil_default_name" ] |
|
then |
|
sudo scutil --set ComputerName "$_HOSTNAME" |
|
sudo scutil --set HostName "$_HOSTNAME" |
|
sudo scutil --set LocalHostName "$_HOSTNAME" |
|
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string "$_HOSTNAME" |
|
fi |
|
|
|
# Link iCloud to ~ to avoid using path with spaces |
|
if ! [ -d "$HOME/iCloud" ] |
|
then |
|
ln -s ~/Library/Mobile\ Documents/com\~apple\~CloudDocs ~/iCloud |
|
fi |
|
|
|
# Check if brew is installed otherwise run the install. |
|
if ! [ -x "$(command -v brew)" ] |
|
then |
|
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" |
|
fi |
|
|
|
# Make sure brew is good to go |
|
if [ -z "$(brew doctor | grep ready)" ] |
|
then |
|
echo "Ups! something is wrong with your brew." |
|
fi |
|
|
|
brew update |
|
brew upgrade |
|
brew install zsh vim llvm |
|
|
|
if ! [ -x "$(command -v mackup)" ]; then |
|
brew install mackup |
|
fi |
|
|
|
if ! [ -x "$(command -v asdf)" ]; then |
|
brew install asdf |
|
fi |
|
|
|
if ! [ -x "$(command -v mas)" ]; then |
|
brew install mas |
|
mas install 497799835 |
|
|
|
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer |
|
sudo xcodebuild -license accept |
|
fi |
|
|
|
if [ -r "$_BREWFILE" ] |
|
then |
|
brew bundle --file=$_BREWFILE |
|
brew cleanup |
|
fi |
|
|
|
# Oh my zsh |
|
if ! [ -d "$HOME/.oh-my-zsh" ] |
|
then |
|
# Install oh-my-zsh |
|
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" |
|
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting |
|
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestion |
|
fi |
|
|
|
# Configure ultimate vim |
|
if ! [ -d "$HOME/.vim_runtime" ] |
|
then |
|
git clone https://github.com/amix/vimrc.git $HOME/.vim_runtime |
|
sh $HOME/.vim_runtime/install_awesome_vimrc.sh |
|
else |
|
cd $HOME/.vim_runtime && git pull --rebase && cd - |
|
fi |
|
|
|
# Configure Dooms ecmacs |
|
if ! [ -d "$HOME/.emacs.d" ] |
|
then |
|
brew tap railwaycat/emacsmacport |
|
brew cask install emacs-mac |
|
git clone https://github.com/hlissner/doom-emacs $HOME/.emacs.d |
|
$HOME/.emacs.d/bin/doom install |
|
fi |
|
|
|
if ! [ -z "$_NAME" ] && ! [ -z "$_EMAIL" ] |
|
then |
|
git config --global user.name $_NAME |
|
git config --global user.email $_EMAIL |
|
git config --global credential.helper osxkeychain |
|
git config --global core.excludesfile ~/.gitignore |
|
fi |
|
|
|
# Setup SSH |
|
if ! [ -d "$HOME/.ssh" ] && ! [ -z "$_SSH_KEY" ] |
|
then |
|
ssh-keygen -t rsa -b 4096 -C $_EMAIL |
|
fi |
|
|
|
if ! [ -d "$HOME/.gnupg" ] && ! [ -z "$_GPG_KEYBASE" ] |
|
then |
|
hostname | pbcopy |
|
brew cask install keybase |
|
brew install pinentry-mac |
|
keybase login ar4mirez |
|
keybase pgp export -q $_GPG_KEYBASE | gpg --import |
|
keybase pgp export -q $_GPG_KEYBASE --secret | gpg --allow-secret-key-import --import |
|
git config --global user.signingkey $_GPG_KEYBASE |
|
git config --global commit.gpgsign true |
|
|
|
echo 'default-key $KEYBASE_GPG_KEY_ID' > ~/.gnupg/gpg.conf |
|
echo 'no-tty' > ~/.gnupg/gpg.conf |
|
echo 'pinentry-program /usr/local/bin/pinentry-mac' > ~/.gnupg/gpg-agent.conf |
|
fi |
|
|
|
if ! [ -z $_PKGS ] |
|
then |
|
ASDF_PKGS=( |
|
"python:3.8.2,2.7.17" |
|
"nodejs::$HOME/.asdf/plugins/nodejs/bin/import-release-team-keyring" |
|
"golang:latest" |
|
"dotnet-core:3.1.200" |
|
"cf:latest" |
|
"java:adopt-openjdk-13.0.2+8::. $HOME/.asdf/plugins/java/set-java-home.sh" |
|
"clojure:latest" |
|
"deno:latest" |
|
"dep:latest" |
|
"istioctl:latest" |
|
"kotlin:latest" |
|
"kubectl:latest" |
|
"k6:latest" |
|
"k9s:latest" |
|
"kops:latest" |
|
"kind:latest" |
|
"kubefedctl:latest" |
|
"kustomize:latest" |
|
"kubectx:latest" |
|
"bazel:latest" |
|
"direnv:latest" |
|
"doctl:latest" |
|
"erlang:latest" |
|
"fluxctl:latest" |
|
"gcloud:latest" |
|
"gohugo:latest" |
|
"haskell:latest" |
|
"helm:latest" |
|
"mkcert:latest" |
|
"operator-sdk:latest" |
|
"packer:latest" |
|
"protoc:latest" |
|
"rancher:latest" |
|
"rke:latest" |
|
"ruby:latest" |
|
"rust:latest" |
|
"sbt:latest" |
|
"scala:latest" |
|
"skaffold:latest" |
|
"solidity:latest" |
|
"terraform:latest" |
|
"terraform-docs:latest" |
|
"terraform-validator:latest" |
|
"tflint:latest" |
|
"tfsec:latest" |
|
"tmux:latest" |
|
"vault:latest" |
|
"velero:latest" |
|
) |
|
|
|
for p in "${ASDF_PKGS[@]}"; do |
|
_pkg="$(cut -d':' -f1 <<<"$p")" |
|
_ver="$(cut -d':' -f2 <<<"$p")" |
|
_cmd_pre="$(cut -d':' -f3 <<<"$p")" |
|
_cmd_post="$(cut -d':' -f4 <<<"$p")" |
|
_global="" |
|
|
|
echo "adding plugin: ${_pkg}" |
|
asdf plugin-add "${_pkg}" |
|
|
|
echo "executing pre command: ${_cmd_pre}" |
|
$($_cmd_pre) |
|
|
|
IFS=',' read -ra VERS <<< "$_ver" |
|
for v in "${VERS[@]}"; do |
|
echo "${_pkg} installing version: ${v}" |
|
asdf install ${_pkg} ${v} |
|
|
|
echo "${_pkg} reshim version: ${v}" |
|
asdf reshim ${_pkg} ${v} |
|
|
|
_global="${_global} ${v}" |
|
done |
|
|
|
echo "setting global: ${_global}" |
|
asdf global ${_pkg} ${_global} |
|
|
|
echo "executing post command: ${_cmd_post}" |
|
$($_cmd_post) |
|
done |
|
fi |