Created
June 3, 2011 18:05
-
-
Save un33k/1006817 to your computer and use it in GitHub Desktop.
Script to run Linux vmware image on Mac OSX in headless mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Start and stop headless VMs | |
# put this on your path as save it as vm or vm.sh. | |
# no need to turn your vmware on when running on Mac | |
# just run as vm start and it will list all the available vm images. | |
# then choose which one you want to start. perfect for running Linux under OSX | |
# in headless mode for development | |
# Note:, some of this script is from gist (72638254422dc741b299) | |
# Some rework and enhancement to make it work better and handle windows | |
#!/bin/bash | |
if [ -z $1 ] | |
then echo "Usage: vm stop|start|stopall" | |
exit 1 | |
fi | |
VMHOME="${HOME}/Documents/Virtual Machines" | |
VMRUN="/Library/Application Support/VMware Fusion/vmrun" | |
VMS=`find "${VMHOME}" -depth 1 -name "*.vmwarevm"` | |
# Allow spaces in file dir/name | |
ORIG_IFS=${IFS}; IFS=" | |
" | |
# stop all | |
if [ "$1" == "stopall" ]; then | |
# Loop through and shutdown all VMs | |
for opt in $VMS ; do | |
RUNNING=`ls $opt | grep "mem.lck" | wc -l | sed 's/ //g'` | |
if [ "$RUNNING" -gt 0 ]; then | |
# run file | |
`"${VMRUN}" stop "${opt}"` | |
# repair IFS | |
IFS=${ORIG_IFS} | |
fi | |
done | |
fi | |
# choose to stop one | |
if [ "$1" == "stop" ]; then | |
# Loop through and shutdown all VMs | |
select opt in $VMS ; do | |
RUNNING=`ls $opt | grep "mem.lck" | wc -l | sed 's/ //g'` | |
if [ "$RUNNING" -gt 0 ]; then | |
# run file | |
`"${VMRUN}" stop "${opt}"` | |
# repair IFS | |
IFS=${ORIG_IFS} | |
exit 0 | |
fi | |
done | |
fi | |
# choose to start one # a non windows | |
if [ "$1" == "start" ]; then | |
select opt in $VMS ; do | |
RUNNING=`ls $opt | grep "Applications" | wc -l | sed 's/ //g'` | |
if [ "$RUNNING" -gt 0 ]; then | |
# run file | |
echo "Windows not supported" | |
exit 0 | |
else | |
# run file | |
`"${VMRUN}" start "${opt}" nogui` | |
# repair IFS | |
IFS=${ORIG_IFS} | |
exit 0 | |
fi | |
done | |
fi | |
IFS=${ORIG_IFS} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment