Home > Mac administration, Mac OS X, Scripting, VMware > Installing the latest VMware Tools in OS X VMs with AutoPkg

Installing the latest VMware Tools in OS X VMs with AutoPkg

As part of working with OS X VMs in VMware Fusion and ESXi, I’ve regularly installed the VMware Tools and have even found ways to incorporate their installation into my build process. However, getting the latest VMware Tools installer into my VM building workflow has usually involved at least one manual step or having a system management tool handle the installation for me. I wanted something that was completely automated without needing to also install a system management client. My end goal was that I didn’t have to worry about doing anything; the latest VMware Tools for my OS X VM would just be installed into the VM as part of the build process.

After doing some research and testing, I have a solution that looks like it does just that. For more details, see below the jump.

My colleague Joe Chilcote had adapted using AutoPkg to install Puppet LabsPuppet and Facter tools into VMs, using the script available from the link below:

https://github.com/chilcote/vfuse/blob/master/packer-scripts/puppet.sh



Update – 5-10-2016: Joe let me know that his script was a fork of Tim Sutton‘s Puppet / Facter installation script, so credit to Tim for the original idea.


My colleague Jesse Peterson had written a VMware Tools provider for AutoPkg, which was designed to download the latest copy of VMware Tools for OS X:

https://github.com/autopkg/jessepeterson-recipes/blob/master/VMware/VMwareToolsURLProvider.py

I had already used Jesse’s AutoPkg provider to build AutoPkg recipes to download, uncompress and extract the VMware Tools installer, so I decided to see if I could leverage Joe’s technique with my existing VMwareTools.pkg recipe for AutoPkg. I also wanted to make sure to clean all AutoPkg-related parts from the system, as I didn’t want to leave traces behind on what could otherwise be a completely unconfigured OS X VM. After some work, I have a script which does the following:

  1. Downloads AutoPkg from GitHub using git.
  2. Adds the AutoPkg recipe repo containing the VMwareTools .download and .pkg recipes
  3. Redirects the AutoPkg cache to a temp location.
  4. Downloads the current release version of VMware Tools for OS X using AutoPkg and extracts the installer package.
  5. Installs the latest VMware Tools using the AutoPkg-generated installer package.


#!/bin/bash
# fork of Tim Sutton's osx-vm-template script:
# https://github.com/timsutton/osx-vm-templates/blob/master/scripts/puppet.sh
# Install the latest VMware Tools using AutoPkg recipes
# https://github.com/autopkg/autopkg
#
# Note: Either Xcode.app or the Xcode command line tools
# must be installed and licensed before running this script.
#
# Download AutoPkg from GitHub using git
AUTOPKG_DIR=$(mktemp -d /tmp/autopkg-XXXX)
git clone https://github.com/autopkg/autopkg "$AUTOPKG_DIR"
AUTOPKG="$AUTOPKG_DIR/Code/autopkg"
# Add the recipes repo containing the
# VMwareTools .download and .pkg recipes
"${AUTOPKG}" repo-add rtrouton-recipes
# Redirect the AutoPkg cache to a temp location
defaults write com.github.autopkg CACHE_DIR -string "$(mktemp -d /tmp/autopkg-cache-XXX)"
# Store the location of the AutoPkg cache
cache_path=$(defaults read com.github.autopkg CACHE_DIR)
# Downloads the current release version of VMware Tools for OS X
# and builds an installer package.
"${AUTOPKG}" run VMwareTools.pkg
# Install VMware Tools using the AutoPkg-generated installer package
pkg_path="$(/usr/bin/find ${cache_path} -maxdepth 2 \( -iname \VMware*\.pkg -o -iname \VMware*\.mpkg \))"
/usr/sbin/installer -pkg "${pkg_path}" -target /
# Clean up
/bin/rm -rf "${AUTOPKG_DIR}"
# If this script is run on a logged-out machine,
# a /var/root/Library/AutoPkg directory will be
# created. As part of the clean-up process, this
# folder will be removed.
if [[ -d "/var/root/Library/AutoPkg" ]]; then
/bin/rm -rf "/var/root/Library/AutoPkg"
fi
# If this script is run by while logged-in, an
# AutoPkg directory will be created in the logged-in
# user's home folder. As part of the clean-up process, this
# folder will be removed, but only if the AutoPkg directory
# is owned by root. If the AutoPkg directory is not owned by
# root, it will be left alone as it may contain previously-created
# AutoPkg downloads and cached recipes.
if [[ "echo $HOME" != "" ]] && [[ -d "$HOME/Library/AutoPkg" ]]; then
OWNERSHIP_CHECK=`/usr/bin/stat -F "$HOME/Library/AutoPkg" | awk '{ print $3 }'`
if [[ "${OWNERSHIP_CHECK}" = "root" ]]; then
/bin/rm -rf "$HOME/Library/AutoPkg"
fi
fi

view raw

gistfile1.sh

hosted with ❤ by GitHub

Post-installation

Once VMware Tools has been installed by the script, the OS X VM where VMware Tools has been installed must be restarted in order to enable VMware Tools’ functionality.

Notes

One thing I found in my testing is that git would be needed for this process, so an essential pre-requisite for running this script is installing git.

This can be most easily accomplished by installing Xcode or the Xcode command line tools (CLT). Both will include git, so installing either should work. One gotcha I ran into during my testing is that Xcode / Xcode CLT usually require accepting Apple’s license before you’ll be able to use git, so make sure the license has been accepted prior to running this script.

I’ve posted the script to my GitHub repo at the following address:

https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/install_latest_vmware_tools

This script is also available as a payload-free installer package, stored as a .zip file in the payload_free_installer directory.

  1. No comments yet.
  1. No trackbacks yet.

Leave a comment