A script that allows to configure any new macOS and/or Linux desktops in a blink of an eye. It is configured via csv files (script can run different sets of data) and shell scripts for basic installation and cloning of repos.
When passing a csv file (with the structure defined below), user is prompted for confirmation on each step.
For security reasons, and mainly to check the csv will work properly, the script runs in dryrun (fake) mode by default.
Everytime I use a computer for the first time, I spend some hours setting up all the options. This script will now allow me to be up and running in a few minutes.
From a new computer without developer tools, git, ... first thing to do is download this repo as a zip and uncompress the file. Then change the data files at your will. Structure of these files is explained below.
If you want to give this script a try, review the code before running it, change or remove things you don’t want or need. You should just need to update the csv/txt files, as described below. The script per se don't run anything on your computer without data from those csv files. In any case, if you want to use my settings without changing, USE AT YOUR OWN RISK!
The idea behind the batch script and csv files is that you only have to configure data files, and can have as many as you want without having to edit the script. But core dependencies are installed using shell scripts, without prompting Yes/No at each step.
In my case, I run the scripts in this order (better restart Terminal after each of them):
- Install Homebrew and basic tools (bash, git, ansible).
- Download and install dotfiles
- Install nvm and node
- Install neovim and LSP
- Create personal and work folders and clone repos into them
- Install brew formulae from csv files
Note: if you are using an ARM64 mac (M1, M1 Pro, M1 Max, ...) you will read some articles saying you have to enable Rosetta for Terminal. This is no longer true, homebrew has native support for ARM mac chips.
We will first open the terminal and force the use of bash
:
chsh -s /bin/bash
Then, close and open Terminal again. Now we can safely run the .core-install
script to install Homebrew and some core dependencies. Homebrew is the best way so far to install all development dependencies, other software and even fonts:
./.core-install
Do not close the Terminal yet. Now brew
and the basic tools should be installed properly. Just check with:
brew doctor
To make sure we are using the correct version of bash, you can run:
which bash
It should return something like /opt/homebrew/bin/bash
. Similarly for git
.
The strategy will depend on the way you actually backup your dotfiles. In my case, I clone my dotfiles as a bare repo because I don't like the symlinks approach.
You can run the script below:
./.dotfiles
./.node
./.nvim
I am also using a script to create personal and work folders and clone repos into them:
./.repos
From this point on, main .setup.sh
script will read csv files and prompt the user for confirmation at each step.
In my case, I am using:
- Install formulae using
data/brew-formulae.csv
. - Install casks using
data/brew-casks.csv
. - Install fonts using
data/brew-fonts.csv
. - Configure macOS defaults, using
data/defaults-macos.csv
. - Enjoy!
CSV files contain comments and commands, in the following structure:
- What: describes the content of the line, so the script know what to do with it. Possible values are:
#
Big title##
Smaller titleb
Brew formulak
Brew caskc
Commandd
macOS defaultsr
Run command without asking
- Text: used as title or the question prompted to the user, or the name of the brew formula/cask
- Default answer: boolean (true|false) defines the default action when user replies with Enter (or in silent mode)
- Defaults rule or Command to be run for 'Yes' reply
- Command to be run for 'No' reply
Each line MUST contain 5 columns separated by comma. If first column doesn't include one of the keycodes described above, it will just be skipped.
Main .setup.sh
script needs a csv file passed with a -f
argument:
./.setup.sh -f data/brew-formulae.csv
The script will run the csv parser automagically.
You can also pass a -s
optional argument, that will run the whole set of commands without prompting the user for confirmation.
Reminder, for security reasons, and mainly to check the csv/txt will work properly, the script runs in dryrun (fake) mode by default. To make it work for real you MUST pass the -r
argument.
The script will prompt giving you some options on each step (you can run without prompts if using -s
argument) to install the core formulae (note the -r
argument to run it for real):
./.setup.sh -f data/brew-formulae.csv -r
You can then optionally install casks:
./.setup.sh -f data/brew-casks.csv -r
and/or fonts:
./.setup.sh -f data/brew-fonts.csv -r
For a new Mac, next step would be setting some sensible macOS defaults (note the -r
argument to run it for real):
./.setup.sh -f data/defaults-macos.csv -r
The script will prompt giving you some options on each step (you can run without prompts if using -s
argument).
With all these, you should be ready to go and enjoy your new computer.
Issue reports and suggestions are welcome. Thank you.
Big thanx to Mathias Bynens and thoughtbot, inc for their .dotfiles projects. Also Luke Smith for the idea of running a set of commands by reading from a csv file.