Skip to content

Instantly share code, notes, and snippets.

@jmo
Forked from codeinthehole/osx_bootstrap.sh
Last active May 12, 2024 19:13
Show Gist options
  • Save jmo/0d48e055beaca21b659e47500b5edb86 to your computer and use it in GitHub Desktop.
Save jmo/0d48e055beaca21b659e47500b5edb86 to your computer and use it in GitHub Desktop.
Script to install stuff I want on a new OSX machine
#!/usr/bin/env bash
#
# Bootstrap script for setting up a new OSX machine
#
# This should be idempotent so it can be run multiple times.
# Change this
HOSTNAME="mini"
echo "Starting bootstrapping"
# Set hostname
# TODO check if name is already set first
echo " Set computer name to $HOSTNAME (as done via System Preferences → Sharing)"
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
dscacheutil -flushcache
# Check for Homebrew, install if we don't have it
if test ! $(which brew); then
echo "Installing homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
# Update homebrew recipes
brew update
# emacs
brew tap d12frosted/emacs-plus
brew install emacs-plus@29
brew install mu
brew install aspell
brew install offline-imap
brew install openssl # for certs
brew install pinentry pinentry-mac # for gpg integration
# use `brew list -1` to see which packages you have installed.
PACKAGES=(
# GNU core utilities (those that come with OS X are outdated)
coreutils
gnu-sed
gnu-tar
gnu-indent
gnu-which
grep
gawk
curl
# GNU `find`, `locate`, `updatedb`, and `xargs`, g-prefixed
findutils
# bash 5
bash
# Compiler toolchain
# TODO need to install xcode first? (xcode-select --install)
gcc
autoconf
automake
make
# Required
git
git-flow-avh
git-lfs
# go
go
gofumpt
golangci-lint
gopls
buf
# linters
codespell
editorconfig
hadolint
pre-commit
prettier
shellcheck
shfmt
sqlfluff
yamllint
# useful utils
ack
asdf
awscli
csvkit
dos2unix
exercism
fzf
gettext
gnupg
graphviz
grpcurl
guile
htop
jq
lesspipe
mitmproxy
plantuml
pv
pwgen
python
python3
pypy
ripgrep
ruby
s3cmd
terminal-notifier
tig
tldr
tmux
tree
tree-sitter
vim
websocat
wget
xsv
zsh
)
echo "Installing packages..."
brew install ${PACKAGES[@]}
SERVICES=(
offline-imap
)
echo "Starting services..."
# TODO doesn't work?
brew services start ${SERVICES[@]}
# use `brew cask list -1` to see which packages you have installed.
CASKS=(
alfred
bankid
amethyst
cyberduck
dbeaver-community
java
#android-sdk
#android-studio
docker
dropbox
firefox
gimp
hammerspoon
google-chrome
google-cloud-sdk
gpg-suite
iterm2
libreoffice
mactex
postman
pritunl
skype
slack
spotify
the-unarchiver
tunnelblick
visual-studio-code
virtualbox
vlc
zoom
)
echo "Installing cask apps..."
brew install --cask ${CASKS[@]}
echo "Installing fonts..."
brew tap homebrew/cask-fonts
# https://discourse.brew.sh/t/brew-cask-install-font-inconsolata-fails/7461/4
# seems like svn is now required?
brew install svn
FONTS=(
font-inconsolata
)
brew install --cask ${FONTS[@]}
echo "Cleaning up..."
brew cleanup
if test $(which zsh); then
# change to zsh
sudo sh -c "echo /usr/local/bin/zsh >> /etc/shells"
chsh -s /usr/local/bin/zsh
# TODO seems zsh want's us to fix some permissions that brew sets, need
# to run this command
# compaudit | xargs chmod g-w,o-w
echo "Installing oh-my-zsh..."
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
echo "Installing powerlevel10k theme..."
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
echo "Install zsh-syntax-highlighting plugin..."
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
fi
# echo "Installing Python packages..."
# PYTHON_PACKAGES=(
# )
# sudo pip install ${PYTHON_PACKAGES[@]}
# echo "Installing Ruby gems"
# RUBY_GEMS=(
# )
# sudo gem install ${RUBY_GEMS[@]}
# Node.JS
#
# Install system nodejs from brew and use it to install global npm packages.
brew install node
brew install yarn
# echo "Installing global npm packages..."
# NPM_PACKAGES=()
# yarn global add ${NPM_PACKAGES[@]}
# Default global packages to install when installing a new node version
NVM_DIR=~/.nvm
[[ ! -d $NVM_DIR ]] && mkdir $NVM_DIR
cat <<EOT > $NVM_DIR/default-packages
eslint
http-server
livedown
localtunnel
prettier
typescript
ts-node
typescript-language-server
EOT
# Install nvm
if test ! $(which nvm); then
echo "Installing nvm..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
fi
# Install the latest lts of node js using nvm for development
# Load nvm so we can use it to install node
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# Install latest lts and set as default
nvm install --lts
# Racket
# brew cask install racket
# Elm
# brew install elm
# yarn global elm-oracle elm-upgrade
# TODO append to .nvmrc
# Haskell
# brew install haskell-stack
# stack setup
# stack install ghc-mod hasktags hlint hoogle stylish-haskell
# TODO docker images
# TODO go binaries
echo "Configuring OSX..."
# See https://github.com/mathiasbynens/dotfiles/blob/master/.macos for more
# and https://macos-defaults.com/
# Set fast key repeat rate
defaults write NSGlobalDomain KeyRepeat -int 2
# Set short delay until first key repeat
defaults write NSGlobalDomain InitialKeyRepeat -int 10
# Require password as soon as screensaver or sleep mode starts
# NOTE: this doesn't seem to work anymore, you need to manually turn this on in
# Preferences > Security & Privacy > Turn on screen saver immediatly".
# defaults write com.apple.screensaver askForPassword -int 1
# defaults write com.apple.screensaver askForPasswordDelay -int 0
# TODO enable firewall, goto Security & Privacy > Firewall > Turn on
# Finder: show filename extensions by default
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
# Finder: show hidden files byd default
defaults write com.apple.finder "AppleShowAllFiles" -bool "true"
# Finder: show status bar
defaults write com.apple.finder ShowStatusBar -bool true
# Finder: show path bar
defaults write com.apple.finder ShowPathbar -bool true
# Finder: use list view in all Finder windows by default
# Four-letter codes for the other view modes: `icnv`, `clmv`, `glyv`
defaults write com.apple.finder FXPreferredViewStyle -string "Nlsv"
# Enable tap-to-click
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true
defaults -currentHost write NSGlobalDomain com.apple.mouse.tapBehavior -int 1
# Disable "natural" scroll
defaults write NSGlobalDomain com.apple.swipescrolldirection -bool false
# Automatically hide and show the Dock
defaults write com.apple.dock autohide -bool true
# Hot corners
# Possible values:
# 0: no-op
# 2: Mission Control
# 3: Show application windows
# 4: Desktop
# 5: Start screen saver
# 6: Disable screen saver
# 7: Dashboard
# 10: Put display to sleep
# 11: Launchpad
# Top left screen corner enable screen saver
defaults write com.apple.dock wvous-tl-corner -int 5
defaults write com.apple.dock wvous-tl-modifier -int 0
# Top right screen corner disable screen saver
defaults write com.apple.dock wvous-tr-corner -int 6
defaults write com.apple.dock wvous-tr-modifier -int 0
# Don't rearrange spaces based on most recent use
defaults write com.apple.dock mru-spaces -bool false
# Don't switch space when opening an application
defaults write NSGlobalDomain "AppleSpacesSwitchOnActivate" -bool "false"
# Set menu bar clock format
# TODO doesn't work any more?
# defaults write com.apple.menuextra.clock DateFormat -string "EEE d MMM HH:mm:ss"
# TODO set display scren resolution to scaled
# TODO change caps to ctrl
# Turn off ui sound effects
defaults write com.apple.systemsound "com.apple.sound.uiaudio.enabled" -int 0
# Keyboard: Disable Keyboard > Shortcuts > Spotligh > Show Spotlight search
# Keyboard: Disable Keyboard > Shortcuts > Input sources > Select the previous input source
# Keyboard: Disable Keyboard > Shortcuts > Input sources > Change Input > Ctrl-Space and Ctrl-Apple-Space
echo "Creating folder structure..."
[[ ! -d ~/.local/bin ]] && mkdir -p ~/.local/bin
[[ ! -d ~/.local/tmp ]] && mkdir -p ~/.local/tmp
[[ ! -d ~/.local/var/logs ]] && mkdir -p ~/.local/var/logs
[[ ! -d ~/private ]] && mkdir -p ~/private
[[ ! -d ~/tmp ]] && mkdir -p ~/tmp
# TODO sync dotfiles
# rsync -chaHEi .Xresources .authinfo.gpg .aws .bash* .config .emacs.d .git* .gsutil .hammerspoon .kube .lesshst .netrc .node_repl_history .npmrc .offlineimap* .oh-my-zsh .psql_history .ssh .xrdb .yarnrc .z .zfunc .zprofile .zsh* Maildir jonas@192.168.86.185:~/tmp/mini4/
# TODO Setup iterm and alfred to use config from dropbox.
# TODO enable swedish pc keyboard layout
# cp ~/Dropbox/settings/Library/Keyboard\ Layouts/Max.keylayout Library/Keyboard\ Layouts/
# echo "Goto Settings > Keyboard > Text Input > Search (Max)"
echo "Bootstrapping complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment