Its always fun getting stuff to work so if you don't mind, lets take this a step further

.
#!/bin/sh
#
# Copyright 1998 VMware, Inc. All rights reserved.
#
# This script manages the services needed to run VMware software
# Basic support for IRIX style chkconfig
# chkconfig: 3 90 08
# description: Manages the services needed to run VMware software
# Basic support for the Linux Standard Base Specification 1.0.0 (to be used by
# insserv for exemple)
### BEGIN INIT INFO
# Provides: VMware
# Required-Start: $network $syslog
# Required-Stop:
# Default-Start: 3 5
# Default-Stop:
# Description: Manages the services needed to run VMware software
### END INIT INFO
# BEGINNING_OF_TMPDIR_DOT_SH
#!/bin/sh
# Create a temporary directory
#
# They are a lot of small utility programs to create temporary files in a
# secure way, but none of them is standard. So I wrote this --hpreg
make_tmp_dir() {
local dirname="$1" # OUT
local prefix="$2" # IN
local tmp
local serial
local loop
tmp="${TMPDIR:-/tmp}"
# Don't overwrite existing user data
# -> Create a directory with a name that didn't exist before
#
# This may never succeed (if we are racing with a malicious process), but at
# least it is secure
serial=0
loop='yes'
while [ "$loop" = 'yes' ]; do
# Check the validity of the temporary directory. We do this in the loop
# because it can change over time
if [ ! -d "$tmp" ]; then
echo 'Error: "'"$tmp"'" is not a directory.'
echo
exit 1
fi
if [ ! -w "$tmp" -o ! -x "$tmp" ]; then
echo 'Error: "'"$tmp"'" should be writable and executable.'
echo
exit 1
fi
# Be secure
# -> Don't give write access to other users (so that they can not use this
# directory to launch a symlink attack)
if mkdir -m 0755 "$tmp"'/'"$prefix$serial" >/dev/null 2>&1; then
loop='no'
else
serial=`expr "$serial" + 1`
if [ "`expr "$serial" % 200`" = '0' ]; then
echo 'Warning: The "'"$tmp"'" directory may be under attack.'
echo
fi
fi
done
eval "$dirname"'="$tmp"'"'"'/'"'"'"$prefix$serial"'
}
# END_OF_TMPDIR_DOT_SH
vmware_etc_dir=/etc/vmware
#
# Make the old installer aware of the new installer.sh mechanism.
# Kludge time

#
if [ "$1" = "stop" ]; then
ppid=`grep '^PPid:' /proc/"$$"/status | cut -f 2`
if [ "`grep '^Name:' /proc/"$ppid"/status | cut -f 2`" = 'install.pl' ]; then
# The old installer called this script
vmware_installer="$vmware_etc_dir"/installer.sh
if [ -x "$vmware_installer" ]; then
echo 'A previous installation of VMware software has been detected.'
echo
echo 'The previous installation was made by the '"`"$vmware_installer" kind`"' installer,'
echo 'which is more recent than this installer.'
echo 'This means that your are trying to downgrade or remove VMware software.'
echo -n 'Do you really want to do this? (yes/no) [n] '
read answer
echo
case "$answer" in
y|Y|yes|Yes|YES)
make_tmp_dir 'tmpdir' 'vmware-installer'
"$vmware_installer" convertdb old "$tmpdir"'/prev_db.tar.gz'
"$vmware_installer" uninstall
if [ ! "$?" -eq 0 ]; then
rm -rf "$tmpdir"
echo
echo 'Failure'
echo
exit 1
fi
made_dir='0'
if [ ! -d '/etc/vmware' ]; then
mkdir -m 0755 '/etc/vmware'
made_dir='1'
fi
tar -C / -xzopf "$tmpdir"'/prev_db.tar.gz'
rm -rf "$tmpdir"
if [ "$made_dir" = '1' ]; then
echo 'directory /etc/vmware' >> '/etc/vmware/locations'
fi
exit 0
;;
*)
# Prevent the display of the old installer's error message
kill "$ppid"
exit 1
;;
esac
else
echo 'Error: Unable to find the previous installer object '"$vmware_installer"'.'
echo
# Exit with 0 otherwise the user will never be able to re-install
exit 0
fi
fi
fi
#
# From now on, this is a normal startup script. I swear.
#
# Since this script is installed, our main database should be installed too and
# should contain the basic information
vmware_db="$vmware_etc_dir"/locations
if [ ! -r "$vmware_db" ]; then
echo 'Warning: Unable to find '"`vmware_product_name`""'"'s main database '"$vmware_db"'.'
echo
exit 1
fi
# BEGINNING_OF_DB_DOT_SH
#!/bin/sh
#
# Manage an installer database
#
# Add an answer to a database in memory
db_answer_add() {
local dbvar="$1" # IN/OUT
local id="$2" # IN
local value="$3" # IN
local answers
local i
eval "$dbvar"'_answer_'"$id"'="$value"'
eval 'answers="$'"$dbvar"'_answers"'
# There is no double quote around $answers on purpose
for i in $answers; do
if [ "$i" = "$id" ]; then
return
fi
done
answers="$answers"' '"$id"
eval "$dbvar"'_answers="$answers"'
}
# Remove an answer from a database in memory
db_answer_remove() {
local dbvar="$1" # IN/OUT
local id="$2" # IN
local new_answers
local answers
local i
eval 'unset '"$dbvar"'_answer_'"$id"
new_answers=''
eval 'answers="$'"$dbvar"'_answers"'
# There is no double quote around $answers on purpose
for i in $answers; do
if [ "$i" != "$id" ]; then
new_answers="$new_answers"' '"$i"
fi
done
eval "$dbvar"'_answers="$new_answers"'
}
# Load all answers from a database on stdin to memory (<dbvar>_answer_*
# variables)
db_load_from_stdin() {
local dbvar="$1" # OUT
eval "$dbvar"'_answers=""'
while read -r action p1 p2; do
if [ "$action" = 'answer' ]; then
db_answer_add "$dbvar" "$p1" "$p2"
elif [ "$action" = 'remove_answer' ]; then
db_answer_remove "$dbvar" "$p1"
fi
done
}
# Load all answers from a database on disk to memory (<dbvar>_answer_*
# variables)
db_load() {
local dbvar="$1" # OUT
local dbfile="$2" # IN
db_load_from_stdin "$dbvar" < "$dbfile"
}
# Iterate through all answers in a database in memory, calling <func> with
# id/value pairs and the remaining arguments to this function
db_iterate() {
local dbvar="$1" # IN
local func="$2" # IN
shift 2
local answers
local i
local value
eval 'answers="$'"$dbvar"'_answers"'
# There is no double quote around $answers on purpose
for i in $answers; do
eval 'value="$'"$dbvar"'_answer_'"$i"'"'
"$func" "$i" "$value" "$@"
done
}
# If it exists in memory, remove an answer from a database (disk and memory)
db_remove_answer() {
local dbvar="$1" # IN/OUT
local dbfile="$2" # IN
local id="$3" # IN
local answers
local i
eval 'answers="$'"$dbvar"'_answers"'
# There is no double quote around $answers on purpose
for i in $answers; do
if [ "$i" = "$id" ]; then
echo 'remove_answer '"$id" >> "$dbfile"
db_answer_remove "$dbvar" "$id"
return
fi
done
}
# Add an answer to a database (disk and memory)
db_add_answer() {
local dbvar="$1" # IN/OUT
local dbfile="$2" # IN
local id="$3" # IN
local value="$4" # IN
db_remove_answer "$dbvar" "$dbfile" "$id"
echo 'answer '"$id"' '"$value" >> "$dbfile"
db_answer_add "$dbvar" "$id" "$value"
}
# Add a file to a database on disk
# 'file' is the file to put in the database (it may not exist on the disk)
# 'tsfile' is the file to get the timestamp from, '' if no timestamp
db_add_file() {
local dbfile="$1" # IN
local file="$2" # IN
local tsfile="$3" # IN
local date
if [ "$tsfile" = '' ]; then
echo 'file '"$file" >> "$dbfile"
else
date=`date -r "$tsfile" '+%s' 2> /dev/null`
if [ "$date" != '' ]; then
date=' '"$date"
fi
echo 'file '"$file$date" >> "$dbfile"
fi
}
# Add a directory to a database on disk
db_add_dir() {
local dbfile="$1" # IN
local dir="$2" # IN
echo 'directory '"$dir" >> "$dbfile"
}
# END_OF_DB_DOT_SH
db_load 'vmdb' "$vmware_db"
# This comment is a hack to prevent RedHat distributions from outputing
# "Starting <basename of this script>" when running this startup script.
# We just need to write the word daemon followed by a space --hpreg.
# This defines echo_success() and echo_failure() on RedHat
if [ -r "$vmdb_answer_INITSCRIPTSDIR"'/functions' ]; then
. "$vmdb_answer_INITSCRIPTSDIR"'/functions'
fi
# This defines $rc_done and $rc_failed on S.u.S.E.
if [ -f /etc/rc.config ]; then
# Don't include the entire file: there could be conflicts
rc_done=`(. /etc/rc.config; echo "$rc_done")`
rc_failed=`(. /etc/rc.config; echo "$rc_failed")`
else
# Make sure the ESC byte is literal: Ash does not support echo -e
rc_done='[71G done'
rc_failed='[71Gfailed'
fi
subsys=vmware
driver=vmmon
ppuser=vmppuser
vnet=vmnet
bridge=vmnet-bridge
dhcpd=vmnet-dhcpd
netifup=vmnet-netifup
natd=vmnet-natd
ping=vmware-ping
smbd=vmware-smbd
nmbd=vmware-nmbd
#
# Utilities
#
# BEGINNING_OF_IPV4_DOT_SH
#!/bin/sh
#
# IPv4 address functions
#
# Thanks to Owen DeLong <owen@delong.com> for pointing me at bash's arithmetic
# expansion ability, which is a lot faster than using 'expr' --hpreg
#
# Compute the subnet address associated to a couple IP/netmask
ipv4_subnet() {
local ip="$1"
local netmask="$2"
# Split quad-dotted addresses into bytes
# There is no double quote around the back-quoted expression on purpose
# There is no double quote around $ip and $netmask on purpose
set -- `IFS='.'; echo $ip $netmask`
echo $(($1 & $5)).$(($2 & $6)).$(($3 & $7)).$(($4 & $8))
}
# Compute the broadcast address associated to a couple IP/netmask
ipv4_broadcast() {
local ip="$1"
local netmask="$2"
# Split quad-dotted addresses into bytes
# There is no double quote around the back-quoted expression on purpose
# There is no double quote around $ip and $netmask on purpose
set -- `IFS='.'; echo $ip $netmask`
echo $(($1 | (255 - $5))).$(($2 | (255 - $6))).$(($3 | (255 - $7))).$(($4 | (255 - $8)))
}
# END_OF_IPV4_DOT_SH
# Are we running in a VM?
vmware_inVM() {
"$vmware_etc_dir"/checkvm >/dev/null 2>&1
}
# This is a function in case a future product name contains language-specific
# escape characters.
vmware_product_name() {
echo 'VMware Workstation'
exit 0
}
#
# Count the number of running virtual machines
# by looking at the number of references to the
# $driver module.
#
countVMs() {
# Beware of module dependancies here. An exact match is important
/sbin/lsmod | awk 'BEGIN {n = 0;} {if ($1 == "'"$driver"'") n = $3;} END {print n;}'
}
# Is a given module loaded?
isLoaded() {
local module="$1"
/sbin/lsmod | awk 'BEGIN {n = "no";} {if ($1 == "'"$module"'") n = "yes";} END {print n;}'
}
# Check if there is an IP route for a given subnet via a given interface
# Return true if there is _NO_ such route
noRoutePresent() {
local subnet="$1" # IN
local intf="$2" # IN
# Beware, there may be several identical routes
[ "`/sbin/route -n | grep '^'"$subnet"'.*'"$intf"'$'`" = '' ]
}
#
# Check that the IP address we are going to assign to the host machine on
# a private IP network does not already exist
#
# NB: If you don't want to do this test, just substitute
# false for it.
#
lookForHostOnlyNetwork() {
local ip="$1"
"$vmdb_answer_BINDIR"/"$ping" -q "$ip"
}
# Build a Linux kernel integer version
kernel_version_integer() {
echo $(((($1 * 256) + $2) * 256 + $3))
}
# Get the running kernel integer version
get_version_integer() {
local version_uts
local v1
local v2
local v3
version_uts=`uname -r`
# There is no double quote around the back-quoted expression on purpose
# There is no double quote around $version_uts on purpose
set -- `IFS='.'; echo $version_uts`
v1="$1"
v2="$2"
v3="$3"
# There is no double quote around the back-quoted expression on purpose
# There is no double quote around $v3 on purpose
set -- `IFS='-ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz'; echo $v3`
v3="$1"
kernel_version_integer "$v1" "$v2" "$v3"
}
# Do we need the ppuser module?
isPpuserNeeded() {
local version_integer
version_integer=`get_version_integer`
echo $(((`kernel_version_integer '2' '1' '127'` <= $version_integer) && ($version_integer <= `kernel_version_integer '2' '3' '9'`)))
}
vmware_failed() {
if [ "`type -t 'echo_failure' 2>/dev/null`" = 'function' ]; then
echo_failure
else
echo -n "$rc_failed"
fi
}
vmware_success() {
if [ "`type -t 'echo_success' 2>/dev/null`" = 'function' ]; then
echo_success
else
echo -n "$rc_done"
fi
}