Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #/bin/bash
- SAMBAUSERNAME="stig"
- SERVERNAME="172.16.155.x"
- PASSWORD="sambapassword"
- MOUNTPATH="/Volumes/$SAMBAUSERNAME"
- VMFUSION="/Library/Application Support/VMware Fusion/vmrun"
- VMPATH="/Users/stig/Documents/CentOS/CentOS.vmx"
- EDITOR="/Applications/NetBeans/NetBeans 7.0.app"
- start_vm() {
- PID=`"$VMFUSION" list | grep "$VMPATH"`
- if [ -z $PID ]; then
- echo "Starting Virual Machine $VMPATH"
- "$VMFUSION" -T fusion start "$VMPATH" nogui
- echo 'Waiting for the server to wake up ..'
- ping -s 1 -c 1 $SERVERNAME
- fi
- }
- stop_vm() {
- PID=`"$VMFUSION" list | grep "$VMPATH"`
- if [ $PID > 0 ]; then
- echo "Suspending the virtual machine"
- "$VMFUSION" -T fusion suspend "$VMPATH" nogui
- fi
- }
- mount_samba() {
- if [ ! -d "$MOUNTPATH/" ]; then
- echo "Creating mount folder "
- mkdir $MOUNTPATH
- chmod 777 $MOUNTPATH
- fi
- MOUNTED=`df -T smbfs | grep $SAMBAUSERNAME@$SERVERNAME`
- if [ -z "$MOUNTED" ]; then
- echo "Mounting samba share at $MOUNTPATH"
- mount_smbfs //$SAMBAUSERNAME:$PASSWORD@$SERVERNAME/$SAMBAUSERNAME $MOUNTPATH/
- fi
- }
- unmount_samba() {
- echo "Checking if folder is mounted"
- MOUNTED=`df -T smbfs | grep $SAMBAUSERNAME@$SERVERNAME`
- if [ "$MOUNTED" ]; then
- echo "Unmounting the samba share"
- umount $MOUNTPATH/
- fi
- }
- start_editor() {
- EDITORPID=$(ps aux | grep "$EDITOR" | grep -v grep)
- if [ -z "$EDITORPID" ]; then
- echo "Opening editor"
- open "$EDITOR"
- fi
- }
- start_ssh() {
- echo "Opening ssh session"
- ssh $SAMBAUSERNAME@$SERVERNAME
- }
- case $1 in
- start)
- start_vm
- mount_samba
- start_editor
- start_ssh
- exit 1
- ;;
- stop)
- unmount_samba
- stop_vm
- exit 1
- ;;
- *)
- Echo "Usage: $0 {start|stop}"
- exit 1
- ;;
- esac
Add Comment
Please, Sign In to add comment