I don't buy development machines very often. My current machine was purchased in 2013 and since then I've become a cloud afficianado. I don't expect to have to set boxes up by hand; that should happen automatically. In those six years, I've set up - and torn down - thousands of virtual machines, mainly on AWS but also on my own fleet of Zini and Raspberry PI boxes. Basically all by remote control (they may need a bit of initial manual setup, but after that ...).
So, although I'm tempted to see what would happen if I did the Apple recommended thing and tried to restore from TimeMachine (especially since I've spent a lot of time and effort backing up over the past six years), I'm going to go the opposite way and say "what would happen if I tried to treat this as a cloud box".
One thing I'm fairly sure will happen is that I will waste a lot of time with this.
Hopefully I'll also learn a thing or two.
The Strategy
My fundamental strategy is to create a script on my personal webserver that has all the relevant setup commands in it. Then I'll download that and execute it. It should go off and do three sets of things:- Download and install any tools that can be done on auto-pilot;
- Recover any and all git repositories I want to clone locally;
- Help me get started with other tasks that cannot be done on auto-pilot.
I'm not (at this point) sure what's in the third category; but I'm thinking of software that I might need to purchase or that needs a complicated login to access. If I can't do it all automatically, I'm hoping that I might be able to open the relevant pages in Chrome.
The First Script
So this is what I'm going to run:
$ curl https://gmmapowell.com/autopilot/macbook.sh | bash -x
This references a script that I've put up there from an existing machine linking all the things I'll need to do. You should be able to reference it (it shouldn't have any of my personal data in it, unless you consider the things I find useful on a development machine personal).
First off, it sets up ssh by creating an SSH key and turning on the ssh daemon.
mkdir -p .ssh
if [ ! -r .ssh/id_rsa ] ; then
ssh-keygen -f .ssh/id_rsa -t rsa -b 4096 -q -N ""
fi
if sudo systemsetup -getremotelogin | grep -q Off ; then
sudo systemsetup -setremotelogin On
fi
Then it creates a directory to put things it's going to download from the internet, rather than downloading into Downloads as you'd expect.
mkdir -p autosetup
Then it starts to download and install things. I've had to figure these recipes out by hand, and they'll probably have changed by the next time I want to do this, but "treating it as a cloud" for a moment ...
I can install Chrome:
if [ ! -d "/Applications/Google Chrome.app" ] ; then
curl -s -o autosetup/chrome.dmg
https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg
autosetup/chrome.dmg
volume=`hdiutil attach autosetup/chrome.dmg |
sed -n 's/.*\(\/Volumes.*\)/\1/p'`
cp -r "$volume/Google Chrome.app"
"/Applications/Google Chrome.app"
hdiutil detach "$volume"
fi
Note: I've used indenting to show line wrapping, but in reality long lines are all on one line.
The if block makes sure that we don't put all this effort in multiple times. If you do want to put it in (for example, to move to a later version) you just need to move the existing app into the trash.
The curl line downloads the appropriate dmg file into the autosetup directory. This is basically exactly what you'd do with the browser downloading into Downloads.
To understand hdiutil, I'd suggest going to google; to understand what I've done with it, I'd just suggest running the command and playing with it. Basically, I'm mounting (or opening if you prefer) the dmg file and figuring out where on the file system the directory is placed. I'm then able to find the actual app on that dmg and cp it into Applications. Obviously the final step is to unmount the dmg.
I'm hoping to use Docker a lot to simplify application configuration and avoid downloading and setting up a lot of things. I'm a relative Docker noob, so you'll see other posts dealing with this, but there is a similar construct to install the main Docker runtime.
I run multiple copies of Eclipse, generally with different configurations and plugins, but they basically all start from the same dmg; I download this in much the same way (although the path needs a certain amount of construction) and then copy it into different places as needed.
First off, it sets up ssh by creating an SSH key and turning on the ssh daemon.
mkdir -p .ssh
if [ ! -r .ssh/id_rsa ] ; then
ssh-keygen -f .ssh/id_rsa -t rsa -b 4096 -q -N ""
fi
if sudo systemsetup -getremotelogin | grep -q Off ; then
sudo systemsetup -setremotelogin On
fi
Then it creates a directory to put things it's going to download from the internet, rather than downloading into Downloads as you'd expect.
mkdir -p autosetup
Then it starts to download and install things. I've had to figure these recipes out by hand, and they'll probably have changed by the next time I want to do this, but "treating it as a cloud" for a moment ...
I can install Chrome:
if [ ! -d "/Applications/Google Chrome.app" ] ; then
curl -s -o autosetup/chrome.dmg
https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg
autosetup/chrome.dmg
volume=`hdiutil attach autosetup/chrome.dmg |
sed -n 's/.*\(\/Volumes.*\)/\1/p'`
cp -r "$volume/Google Chrome.app"
"/Applications/Google Chrome.app"
hdiutil detach "$volume"
fi
Note: I've used indenting to show line wrapping, but in reality long lines are all on one line.
The if block makes sure that we don't put all this effort in multiple times. If you do want to put it in (for example, to move to a later version) you just need to move the existing app into the trash.
The curl line downloads the appropriate dmg file into the autosetup directory. This is basically exactly what you'd do with the browser downloading into Downloads.
To understand hdiutil, I'd suggest going to google; to understand what I've done with it, I'd just suggest running the command and playing with it. Basically, I'm mounting (or opening if you prefer) the dmg file and figuring out where on the file system the directory is placed. I'm then able to find the actual app on that dmg and cp it into Applications. Obviously the final step is to unmount the dmg.
I'm hoping to use Docker a lot to simplify application configuration and avoid downloading and setting up a lot of things. I'm a relative Docker noob, so you'll see other posts dealing with this, but there is a similar construct to install the main Docker runtime.
I run multiple copies of Eclipse, generally with different configurations and plugins, but they basically all start from the same dmg; I download this in much the same way (although the path needs a certain amount of construction) and then copy it into different places as needed.
I found I can install git in much the same way using a package from newcontinuum on sourceforge. This avoids installing XCode (for me, as I don't generally do much MacOS or iOS development) and I'm hoping it will be a more up-to-date and complete version.
Moving onwards into the realms of "dodgy" software (i.e. not open source, so probably somewhat guarded), I'm going to consider Microsoft Office 365, Quickbooks and Adobe Creative Cloud.
Office surprised me: there was even a web page telling you exactly what to do. It was almost the easiest thing I did. Of course, you need to register and log in once you've installed it; and I don't think that can be automated.
Quickbooks meandered through the purchase process and then provided me with a download link. I think it's time-limited and all that, but I'm not really sure why. When you download it and open it you still have to enter your credentials.
Adobe Creative Cloud defeated me. It's download appears to be open, but it's hidden behind visiting another page and involves invoking some javascript. I'm sure if I'd tried hard enough, I could have figured it out, but I get bored easily and I need to move on ...
Git Repos
In order to access git, I needed to add the new computer as a collaborator. I probably should have put the effort in to automatically upload the SSH key to the server, but I didn't (I did it by hand).
From there, I wrote another script that attached the SSH key both to the server's authorized_keys map, and also as a github key using the V3 API:
curl -u<user> -XPOST -H"Content-Type: application/json"
--data '{"title":"'"$PUB"'","key":"'"`cat $PUB`"'"}'
https://api.github.com/user/keys
Then I was able to run another script which downloaded all of my personal scripts and configuration and ran all the checkout commands on the various git repos.
Lessons Learned
It certainly is possible to treat the install of a new desktop machine as a cloud install. Many of the problems are the same: much software is not packaged to be easily deployed this way, particularly on a Mac compared to a Linux box.But the payback in the cloud environment is that you do this literally many times a day; on a development machine you probably want to aim for no more than once every couple of years as a freelancer. In a corporate setting, it might be worth the investment, but then you probably have images that you burn from anyway.