Skip to content

Instantly share code, notes, and snippets.

@m4dz
Last active January 27, 2023 01:14
Show Gist options
  • Star 30 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save m4dz/3870653 to your computer and use it in GitHub Desktop.
Save m4dz/3870653 to your computer and use it in GitHub Desktop.
OS X Fresh (Re)Install

OS X ENV (re)Install

This is my personal guide to restore my configuration and setup my system for a fresh install. I use it and keep it updated frequently. Hope it will inspire you on your own way =].

Backup

Before a fresh reinstall, don't forget to backup many things. A regular ghost made with CarbonCopyCloner or Clonezilla is a good solution, but if you can't, you should save the following:

  • MySQL databases (use the script bellow)
  • User preferences
    • ~/Library/Application Support
    • ~/Library/ColorSync/Profiles
    • ~/Library/Fonts
    • ~/Library/Keychains
    • ~/Library/LaunchAgents
    • ~/Library/Preferences
    • ~/Library/QuickLook
  • Configs
    • ~/.gitconfig
    • ~/.glacier-cmd
    • ~/.gnupg
    • ~/.pow
    • ~/.powconfig
    • ~/.s3cfg
    • ~/.ssh

Another pretty good solution is to use Mackup that provides a smart way to keep your dotfiles synced in a cloud storage.

I recommend that you should never store on 3rd parties cloud storage sensible data, like your SSH and GPG private keys. So don't forget to exclude tehm from your Mackup store, and prefer a personnal dedicated solution to host them (as an encrypted USB Key or your personnal server instance like Cozy).

To backup files and data, I use a duplicity script configured to fit my needs. See my config file below.

Installation

After a clean fresh install (format disk and reinstall the base OS and updates), let's install xtras.

Base

You can restore the previously backuped files. If you do so, don't forget to restore permissions : restart in Restore mode with ⌘+R, open the terminal and launch resetpassword2.

Shell

I use ZSH instead of the legacy bash shell. To do so:

$ git clone https://github.com/m4dz/oh-my-zsh.git ~/.oh-my-zsh
$ cd ~/.oh-my-zsh
$ git submodule update --init
$ cd
$ cp ~/.oh-my-zsh/custom/zshenv .zshenv
$ cp ~/.oh-my-zsh/custom/zshrc .zshrc
$ chsh -s /bin/zsh

Homebrew

Homebrew is a package manager for OS X. I use to manage my developer tools, and my desktop apps using its submanager : cask.

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew tap homebrew/php
$ brew tap homebrew/dupes
$ brew install caskroom/cask/brew-cask
$ brew tap caskroom/versions

Local DNS resolver

DNSmasq

You may want a simple dns resolver to handle your requests rather than the ones furbished by your provider. You can also use it to handle the .dev tld for your development projects. So you should use DNSmasq. Be careful that you need Homebrew installed and configured (see previous-section). More informations are detailled here.

$ brew install dnsmasq
$ cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf

Edit the /usr/local/etc/dnsmasq.conf file and add the following lines :

address=/dev/127.0.0.1

# FDN OpenDNS servers
server=80.67.169.12
server=2001:910:800::12
server=80.67.169.40
server=2001:910:800::40

Then enable the daemon and launch it :

$ sudo cp -fv /usr/local/opt/dnsmasq/*.plist /Library/LaunchDaemons
$ sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

Finally, add a resolver:

$ sudo mkdir /etc/resolver
$ sudo echo "nameserver 127.0.0.1" > /etc/resolver/dev

Do not forget to configure local dns server for your network interfaces:

$ networksetup -setdnsservers Ethernet 127.0.0.1
4 networksetup -setdnsservers Wi-Fi 127.0.0.1

(Alternative) Pow

Pow is a tools that combines a local host names resolver (based on the .dev tld) and a rack server for ruby (and others) apps.

$ echo 'export POW_DST_PORT=88' >> ~/.powconfig
$ curl get.pow.cx | sh

Commons tools

Use Mackup for dotfiles syncing, and Duplicity for backups:

$ brew install mackup duplicity
$ mackup restore
$ curl -o /usr/local/bin/duplicity-backup https://raw.githubusercontent.com/zertrin/duplicity-backup/master/duplicity-backup.sh
$ chmod +x /usr/local/bin/duplicity-backup

If you intensively use SSH, you probably want to use SSH Agent Forwarding to connect to your servers using your local key. If so, configure the OS X SSH client to enable Agent Forwarding by editing /etc/ssh_config:

 Host *
   SendEnv LANG LC_*
   ForwardAgent yes

My basic tools for everyday use.

via caskroom

$ brew cask install dropbox trim-enabler alfred iterm2 istat-menus hyperdock appcleaner cocktail gpgtools firefox macdown

via Appstore

  • 1password
  • Divvy
  • Mouseposé
  • DaisyDisk
  • Simplenote

Development Environment

My development envrionment is a little bit complex due to many languages and apps I use everyday. You can simplify it to adapt it to your requirements.

Do not forget to add launch plist files for daemons. You can add the plist for your servers (http, PHP-FPM, Mysql,Memcached…) directly to /Library/LaunchDaemons to start it at boot with root permissions. Use brew info <package> to view extras informations. For Nginx and PHP-FPM, configure user / group to _www in config files ; for Memcache, configure plist file with UserName / GroupName daemon.

Base

$ brew install git git-extras hub
$ brew install ack aria2 apple-gcc42 zsh-completions zsh-syntax-highlighting gettext pidof curl ssh-copy-id s3cmd

$ brew install imagemagick --with-fontconfig --with-ghostscript --with-libtiff --with-webp
$ brew install optipng
	
$ sudo gem install --no-ri --no-rdoc lunchy
	
$ brew install nginx --with-gunzip

;; INSTALL NGINX AS ROOT DAEMON
$ mkdir -p /usr/local/var/{log,run}/nginx
$ sudo chown _www:_www /usr/local/var/{log,run}/nginx
$ sudo cp /usr/local/opt/nginx/*.plist /Library/LaunchDaemons

DB

$ brew install mariadb postgresql memcached sqlite

Python

$ brew install python pyenv pyenv-virtualenv pyenv-pip-rehash

Ruby

$ brew install ruby-build rbenv rbenv-gem-rehash
$ rbenv install 2.1.3
$ gem install --no-ri --no-rdoc bundler

NodeJS

$ brew install node
$ npm -g install bower coffee-script csslint docco grunt-cli jscs jshint

PHP

$ brew install php56 --with-fpm --with-homebrew-curl --with-homebrew-openssl --with-pgsql --without-snmp
$ brew install php56-apcu php56-memcached php56-xdebug php56-yaml
$ brew install drush
	
$ chmod -R ug+w /usr/local/Cellar/php56/5.6.2/lib/php
$ pear config-set php_ini /usr/local/etc/php/5.6/php.ini

Apps

via caskroom

$ brew cask install vagrant virtualbox sequel-pro google-chrome chromium firefox-aurora imagealpha imageoptim

via Appstore

  • Base
  • xScope
  • JPEGmini Lite
  • XCode

Editor

I use sublime text and store the config in a git repository.

$ brew cask install sublime-text3
$ git clone https://github.com/m4dz/ST3-User-package ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/User

Apps

Web tools.

via caskroom

$ brew install weechat
$ brew cask install adium skype

via Appstore

  • tweetbot
  • tweetdeck

Image

  • Adobe CreativeCloud

Medias

via caskroom

$ brew cask install spotify xld handbrake vlc

via Appstore

  • imovie

Productivity

via caskroom

$ brew cask install libreoffice calibre

via appstore

  • Wunderlist
  • Fantastical
  • ReadKit
  • Pages
  • Keynote
  • Glui
  • Cloudapp
  • Mindnode Pro
#!/bin/bash
#
# GPG Sign Key PASSPHRASE
PASSPHRASE=""
GPG_ENC_KEY=""
GPG_SIGN_KEY=""
ROOT="/"
DEST="sftp://[host]//[path]/$(hostname -s)"
INCEXCFILE=/Users/m4dz/.duplicity-backup_local.list
STATIC_OPTIONS="--full-if-older-than 30D"
CLEAN_UP_TYPE="remove-all-but-n-full"
CLEAN_UP_VARIABLE="2"
REMOVE_INCREMENTALS_OLDER_THAN="1"
LOGDIR="/usr/local/var/log/duplicity/"
LOG_FILE="duplicity-`date +%Y-%m-%d_%H-%M`.txt"
LOG_FILE_OWNER="m4dz:admin"
REMOVE_LOGS_OLDER_THAN='30'
VERBOSITY="-v3"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>duplicity-backup</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/duplicity-backup</string>
<string>-c</string>
<string>/Users/m4dz/.duplicity-backup.conf</string>
<string>--backup</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>18</integer>
<key>Minute</key>
<integer>35</integer>
</dict>
</dict>
</plist>
#! /bin/bash
BACKUP_DIR="/usr/local/var/backup"
MYSQL_USER="backup"
MYSQL_PASSWORD="backup"
MYSQL=/usr/local/bin/mysql
MYSQLDUMP=/usr/local/bin/mysqldump
mkdir -p "$BACKUP_DIR/mysql"
databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema)"`
for db in $databases; do
$MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db | gzip > "$BACKUP_DIR/mysql/$db.gz"
done
user _www _www;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
keepalive_timeout 0;
gzip on;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~* \.php$ {
fastcgi_pass unix:/usr/local/var/run/php-fpm.sock;
include fastcgi.conf;
}
}
include /usr/local/etc/nginx/conf.d/*.conf;
include /usr/local/etc/nginx/sites-enabled/*;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment