MacOS setup with a simple bash script
From time to time I need to setup fresh MacOS installation. It’s not that complicated but since it happens not very often, I tend to forget the exact steps and commands. This blog post is a summary for myself and hopefully an inspiration for you.
Why bash?
Well, since all you have is a clean machine, you need to be cautious about what you depend on. Bash is pretty much commonplace and the last thing you want to do is lurking the web for a missing CLI required for your bootstrap script.
The script itself
There are a few things I do to setup my machine:
Installing packages
Personally I use Homebrew.
bash
bash
once package manager is setup, lets install all the missing pieces:
bash
bash
SSH keys
all right, next let’s take care of SSH keys:
bash
bash
I also like to add config entries for Github and
BitBucket to ~/.ssh/config. The following function
will make sure every time you connect to the servers i.e via git clone, the
SSH client will retrieve the key from MacOS Keychain. The key is stored securely
and you don’t have to type the password anymore!
bash
bash
since we are setting host specific settings anyway, why not add fingerprints as well:
bash
bash
The idea behind known_hosts is pretty simple. The first time you connect to
some host on the internet, the SSH client asks you to confirm its fingerprint.
After all - how can you be sure that the host you are trying to connect to is
not some hacker doing
Man in the Middle
attack? To verify this SSH prints short signature and all you need to do is
compare it to the actual Github fingerprint which you shall obtain through some
other trusted medium, i.e web browser.
For instance Github publishes their servers’ fingerprints here.
Once we have all SSH related functions in place, let’s wire them together:
bash
bash
and finally some sane settings:
bash
bash
Final thoughts
And here you have it, building blocks for your own bootstrap script. No Ansible, no Python, just your plain old bash script easy to debug and customize.
To make the experience even more pleasant to use I added help message and separate subcommands. You can find my setup script in all it’s glory here.
Now, whenever I need to quickly setup new environment I go to
github.com/psmolak/macup, download the
script somewhere on the disk, run chmod +x ./macup && ./macup and voilà!