Skip to content

Instantly share code, notes, and snippets.

@bruienne
Last active December 14, 2015 21:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bruienne/5154118 to your computer and use it in GitHub Desktop.
Save bruienne/5154118 to your computer and use it in GitHub Desktop.
Configuration script for use with veewee to automatically install the Linux guest tools.
#!/bin/bash
#Mount and install the VMware Fusion guest tools using default settings
kernel=`uname -s`
if [ "${kernel}" == "Linux" ]; then veewee_user="veewee"; elif [ "${kernel}" == "Darwin" ]; then veewee_user="vagrant"; fi
echo "**** Our kernel is ${kernel} and our user is ${veewee_user}."
if [ $kernel == "Linux" ]; then
#Set Linux-specific paths and ISO filename
home_dir="/home/$veewee_user"
iso_name="linux.iso"
mount_point="/mnt"
#Run install, unmount ISO and remove it
cd ${home_dir}
/bin/mount -o loop ${iso_name} ${mount_point}
tar zxf ${mount_point}/*.tar.gz && cd vmware-tools-distrib && ./vmware-install.pl --default
/bin/umount ${mount_point}
/bin/rm -rf ${home_dir}/${iso_name} ${home_dir}/vmware-tools-distrib
elif [ $kernel = "Darwin" ]; then
# Set Darwin-specific path and ISO filename
home_dir="/Users/$veewee_user"
iso_name=`basename $(find ${home_dir} -name "*.iso")`
# If a valid ISO was found mount it
cd ${home_dir}
if [[ ${iso_name} != '' ]]; then
mount_point=`/usr/bin/hdiutil attach -nobrowse -mountrandom /tmp ${home_dir}/${iso_name} | awk '/tmp/{print $3}'`
# If the ISO mounted properly install the PKG from the mount point
if [[ ${mount_point} =~ /tmp/.* ]]; then
/usr/sbin/installer -pkg "$(find ${mount_point} -name '*pkg')" -target /
/usr/bin/hdiutil detach ${mount_point}
/bin/rm -rf ${home_dir}/${iso_name}
else
echo "VMware Tools ISO did not mount properly, skipping install."
fi
else
echo "VMware Tools ISO not found, skipping install."
fi
fi
@bruienne
Copy link
Author

Assumes guest tools ISO has already been copied into the VM by including ":vm_options => [ 'download_tools' => true ]" in your definition. Needs its filename included in the postinstall_files array, this is already present (but commented) out in some definition templates. For OS X guests change "linux.iso" to "darwin.iso" and for Windows to "windows.iso".

@bruienne
Copy link
Author

Overhauled the script to work for both Linux and OS X guests. Need a better method to get the user name since Linux guests use "veewee" while OS X guests use "vagrant". This could be resolved by using "veewee" as the standard user as well in the OS X guest template.

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