Skip to content

Instantly share code, notes, and snippets.

@dotysan
Last active April 18, 2017 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotysan/a4d563350ff2c0c4caea to your computer and use it in GitHub Desktop.
Save dotysan/a4d563350ff2c0c4caea to your computer and use it in GitHub Desktop.
Remotely install Homebrew over ssh.

Look up OS X release.

there$ sw_vers -productVersion
10.9.5

Go to https://developer.apple.com/downloads/ and get the best release of Command Line Tools for Xcode. For example, the latest version for OS X 10.9 is http://adcdownload.apple.com/Developer_Tools/Command_Line_Tools_OS_X_10.9_for_Xcode__Xcode_6.2/commandlinetoolsosx10.9forxcode6.2.dmg.

After downloading the DMG, run the script to extract the PKG file, copy it to the remote host, and install everything.

here:Downloads$ ./remote-headless-brew.sh me@there [commandlinetools*.dmg]
#! /bin/bash -ex
#
# First download the OS X Command Line Tools for Xcode, then run this
# script to remotely install Homebrew.
#
there=${1-bonehead@192.0.2.1}
dmg=${2-commandlinetoolsosx10.9forxcode6.2.dmg}
# mount up the DMG
mnt=$(hdiutil attach "$dmg" |grep -o '/Volumes/.*')
# get the name of the PKG
pkg=$(find "$mnt" -iname '*.pkg')
# copy it over
rsync "$pkg" "$there:"
# strip off the local path
pkg=$(basename "$pkg")
set +e
# remotely extract/install the package
ssh -t "$there" "set -ex
PATH=\"\$PATH:/usr/local/bin\"
xcode-select -p ||sudo installer -pkg \"$pkg\" -target /
xcode-select -p
! brew info
# TODO: get rid of the tty so ruby doesn't wait for user
ruby -e \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)\"
brew info
brew doctor
"
# unmount
hdiutil detach "$mnt"
@dotysan
Copy link
Author

dotysan commented Apr 18, 2017

Hrmm...think I need to work a sudo xcodebuild -license into teh process nowadays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment