#!/bin/bash
clear
# ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# :: Initial info messages                                                  ::
# ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo "
              ..:: Ubuntu 8.04 VM-Tools install script ::..
-------------------------------------------------------------------------------
version: 1.11 SERVER
 author: Jimmy Merrild Krag (beruic)
 e-mail: beruic@hotmail.com
    ICQ: 105566566

     Please notify me of errors you may encounter, so they can be addressed
     
For method and inspiration, many thanks goes to:
http://peterc.org/2008/62-how-to-install-vmware-tools-on-ubuntu-hardy-804-under-vmware-fusion.html

http://lifein0and1.com/2008/05/16/fixed-problems-vmware-tools-in-ubuntu-hardy-heron-server-as-guest/

and

http://www.howtogeek.com/howto/ubuntu/install-vmware-tools-on-ubuntu-edgy-eft/

To cancel, press [Ctrl]+C
To continue, press [Enter]"
read pause

clear
# ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# :: To do                                                                  ::
# ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo "
                        ..:: IMPORTANT (1/2) ::..
-------------------------------------------------------------------------------

   This script is made with VMware Server as host, and may not work on other
   systems.

   Before you proceed, you should choose [VM > Install VMware Tools...] from
   the menu in the VMware Server Console.
   The rest of the process will be taken care of by this script.

   Note: You will be asked for your sudo'ers password during the process.









To cancel, press [Ctrl]+C
To continue, press [Enter]"
read pause
headers_location=`uname -r`
toggle_reboot=" no"
until [ "X$input" = "Xinstall" ]
do
clear
# ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# :: Message                                                                ::
# ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo "
                        ..:: IMPORTANT (2/2) ::..
-------------------------------------------------------------------------------

   During the last step of the installation you may be asked about lot of paths
   during the installation. Most of them will do fine with the default option
   (Just press [Enter]), but there may be trouble finding your C headers.
   In this case, your headers will be found at:

      /usr/src/linux-headers-$headers_location

   You may want to write this down.


   After the installation, you must reboot your computer.
   Do you wish the computer to be automatically rebooted after install?

    Current choice: [$toggle_reboot]
    Note: There will be a 15 seconds delay where you can cancel the reboot.


To toggle reboot on or off, write \"reboot\", and press [Enter]
To begin the installation process, write \"install\", and press [Enter]"
read input

if [ "X$input" = "Xreboot" ]
then
  if [ "X$toggle_reboot" = "X no" ]
  then
    toggle_reboot="yes"
  else
    toggle_reboot=" no"
  fi
fi

done

clear
echo "

         -------------------!!!!! WARNING !!!!!----------------------
         |                                                          |
         | The installation processes wil begin after this message. |
         |                                                          |
         | This is the last chance to cancel the installation with  |
         | nothing changed.                                         |
         |                                                          |
         |  To cancel, press [Ctrl]+C                               |
         |  To continue, press [Enter]                              |
         -----------------------------------------------------------










"
read pause

sudo mount /dev/cdrom
cd ~
mkdir vmtools-install-tmp
cd vmtools-install-tmp
cp /media/cdrom*/VMware*.gz ~/vmtools-install-tmp
sudo apt-get install -y build-essential linux-headers-`uname -r` libproc-dev libdumbnet-dev
wget "http://downloads.sourceforge.net/open-vm-tools/open-vm-tools-2008.06.03-96374.tar.gz?modtime=1210988775&big_mirror=0"

tar xzvf VMware*.gz
tar xzvf open-vm-tools*.gz

cd open-vm-tools-2008.06.03-96374/
./configure --without-x && make
cd modules/linux/

for i in *; do mv ${i} ${i}-only; tar -cf ${i}.tar ${i}-only; done
cd ../../..
mv -f open-vm-tools-2008.06.03-96374/modules/linux/*.tar vmware-tools-distrib/lib/modules/source/

cd vmware-tools-distrib/

sudo ./vmware-install.pl
cd ~
rm -rf vmtools-install-tmp/

clear
echo "
                         ..:: Congratulations ::..
-------------------------------------------------------------------------------

   The installation is complete

-------------------------------------------------------------------------------
"
if [ "X$toggle_reboot" = "Xyes" ]
then
  reboot_timer=15
  for ((a=reboot_timer; a >= 1 ; a--))
  do
  clear
  echo "
                         ..:: Congratulations ::..
-------------------------------------------------------------------------------

   The installation is complete
  
   Rebooting automatically in [$a] second(s)...













To cancel, press [Ctrl]+C
-------------------------------------------------------------------------------
  "
  sleep 1
  done
  sudo reboot
fi
read pause

