#!/bin/sh
+
#
# Copyright 1998 VMware, Inc. All rights reserved.
#
# probe: true
# hide: true
-. /etc/rc.d/init.d/functions
-
-vmware_etc_dir=/etc/vmware
-
-# This is a function in case a future product name contains language-specific
-# escape characters.
-vmware_product_name() {
- echo 'VMware Workstation'
- exit 0
-}
-
-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
-
subsys=vmware
driver=vmmon
vnet=vmnet
smbd=vmware-smbd
nmbd=vmware-nmbd
+vmware_etc_dir=/etc/vmware
+vmware_db="$vmware_etc_dir"/locations
+if [ ! -r "$vmware_db" ]; then
+ echo "Warning: Unable to find VMware Workstation's main database"
+ echo "($vmware_db)."
+ echo
+ exit 1
+fi
+
+# System wide functions
+. /etc/rc.d/init.d/functions
+
#
# Create a temporary directory
#
local loop
tmp="${TMPDIR:-/tmp}"
-
# Don't overwrite existing user data
# -> Create a directory with a name that didn't exist before
#
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"
-}
-
-db_load 'vmdb' "$vmware_db"
-
#
-# Utilities
+# Load database
#
+db_load_from_stdin "vmdb" < "$vmware_db"
+
#
-# IPv4 address functions
+# Utilities
#
-# 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"
echo $(($1 | (255 - $5))).$(($2 | (255 - $6))).$(($3 | (255 - $7))).$(($4 | (255 - $8)))
}
-#
-# Count the number of running virtual machines
-# by looking at the number of references to the
-# $driver module.
+# 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() {
[ "`/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"
-}
-
-#
# Macro definitions
#
# Note:
return 1
}
-# Start a SMB name server on a private IP network
-vmware_start_nmbd() {
- local vHostIf="$1" # IN
-
- # Disable logging to avoid the uncontrolled creation of unmanaged files
- cd "$vmdb_answer_BINDIR" && "$vmdb_answer_BINDIR"/"$nmbd" -D -l /dev/null \
- -s "$vmware_etc_dir"/"$vHostIf"/smb/smb.conf \
- -f /var/run/"$nmbd"-"$vHostIf".pid
-}
-
-# Stop a SMB name server on a private IP network
-vmware_stop_nmbd() {
- local vHostIf="$1" # IN
-
- vmware_stop_pidfile /var/run/"$nmbd"-"$vHostIf".pid
-}
-
-# Start a SMB share server on a private IP network
-vmware_start_smbd() {
- local vHostIf="$1" # IN
-
- # Disable logging to avoid the uncontrolled creation of unmanaged files
- cd "$vmdb_answer_BINDIR" && "$vmdb_answer_BINDIR"/"$smbd" -D -l /dev/null \
- -s "$vmware_etc_dir"/"$vHostIf"/smb/smb.conf \
- -f /var/run/"$smbd"-"$vHostIf".pid
-}
-
-# Stop a SMB share server on a private IP network
-vmware_stop_smbd() {
- local vHostIf="$1" # IN
-
- vmware_stop_pidfile /var/run/"$smbd"-"$vHostIf".pid
-}
-
-# Start a DHCP server on a private IP network
-vmware_start_dhcpd() {
- local vHostIf="$1" # IN
-
- # The daemon already logs its output in the system log, so we can safely
- # trash it
- cd "$vmdb_answer_BINDIR" && "$vmdb_answer_BINDIR"/"$dhcpd" \
- -cf "$vmware_etc_dir"/"$vHostIf"/dhcpd/dhcpd.conf \
- -lf "$vmware_etc_dir"/"$vHostIf"/dhcpd/dhcpd.leases \
- -pf /var/run/"$dhcpd"-"$vHostIf".pid "$vHostIf" >/dev/null 2>&1
-}
-
-# Stop a DHCP server on a private IP network
-vmware_stop_dhcpd() {
- local vHostIf="$1" # IN
-
- vmware_stop_pidfile /var/run/"$dhcpd"-"$vHostIf".pid
-}
-
# Start the host-only network user service
vmware_start_hostonly() {
local vHubNr="$1" # IN
# XXX ping takes 10 seconds to timeout if nobody answers
# that slows boot too much so we do this bit in the
# background.
- if lookForHostOnlyNetwork "$ifIp"; then
+ if "$vmdb_answer_BINDIR"/"$ping" -q "$ifIp"; then
echo 'Host-only networking disabled because '"$ifIp"
echo 'appears to be a real, physical, existing address.'
- echo 'Please run "'"$vmdb_answer_BINDIR"'/vmware-config.pl" to'
- echo 'modify your host-only network configuration.'
+ echo 'Please modify your host-only network configuration.'
exit 1
fi
cd "$vmdb_answer_BINDIR" && "$vmdb_answer_BINDIR"/"$netifup" \
route add -net "$ifNet" netmask "$ifMask" "$vHostIf"
fi
if [ "$run_dhcpd" = 'yes' ]; then
- vmware_start_dhcpd "$vHostIf" || exit 1
+ # Start a DHCP server on a private IP network
+ # The daemon already logs its output in the system log, so we can safely
+ # trash it
+ cd "$vmdb_answer_BINDIR" && "$vmdb_answer_BINDIR"/"$dhcpd" \
+ -cf "$vmware_etc_dir"/"$vHostIf"/dhcpd/dhcpd.conf \
+ -lf "$vmware_etc_dir"/"$vHostIf"/dhcpd/dhcpd.leases \
+ -pf /var/run/"$dhcpd"-"$vHostIf".pid "$vHostIf" >/dev/null 2>&1 || exit 1
fi
if [ "$run_samba" = 'yes' ]; then
- vmware_start_nmbd "$vHostIf" || exit 1
- vmware_start_smbd "$vHostIf" || exit 1
+ # Start a SMB name server on a private IP network
+ # Disable logging to avoid the uncontrolled creation of unmanaged files
+ cd "$vmdb_answer_BINDIR" && "$vmdb_answer_BINDIR"/"$nmbd" -D -l /dev/null \
+ -s "$vmware_etc_dir"/"$vHostIf"/smb/smb.conf \
+ -f /var/run/"$nmbd"-"$vHostIf".pid || exit 1
+ # Start a SMB share server on a private IP network
+ # Disable logging to avoid the uncontrolled creation of unmanaged files
+ cd "$vmdb_answer_BINDIR" && "$vmdb_answer_BINDIR"/"$smbd" -D -l /dev/null \
+ -s "$vmware_etc_dir"/"$vHostIf"/smb/smb.conf \
+ -f /var/run/"$smbd"-"$vHostIf".pid || exit 1
fi
exit 0
}
exit 0
}
-# Start the NAT network user service
-vmware_start_nat() {
- local vHubNr="$1" # IN
-
- cd "$vmdb_answer_BINDIR" && "$vmdb_answer_BINDIR"/"$natd" \
- -d /var/run/"$natd"-"$vHubNr".pid \
- -m /var/run/"$natd"-"$vHubNr".mac \
- -c "$vmware_etc_dir"/vmnet"$vHubNr"/nat/nat.conf
-}
-
-# Stop the NAT network user service
-vmware_stop_nat() {
- local vHubNr="$1" # IN
-
- vmware_stop_pidfile /var/run/"$natd"-"$vHubNr".pid
-}
-
# See how we were called.
case "$1" in
start)
exitcode=`expr "$exitcode" + "$?"`
eval 'nat="$vmdb_answer_VNET_'"$vHubNr"'_NAT"'
if [ "$nat" = 'yes' ]; then
+ # Start the NAT network user service
msg_starting 'NAT networking on /dev/vmnet'"$vHubNr"
busy
- vmware_start_nat "$vHubNr"
+ cd "$vmdb_answer_BINDIR" && "$vmdb_answer_BINDIR"/"$natd" \
+ -d /var/run/"$natd"-"$vHubNr".pid \
+ -m /var/run/"$natd"-"$vHubNr".mac \
+ -c "$vmware_etc_dir"/vmnet"$vHubNr"/nat/nat.conf
[ "$?" -eq 0 ] && ok || fail
exitcode=`expr "$exitcode" + "$?"`
fi
stop)
if [ "`countVMs`" -gt 0 ]; then
- echo 'At least one instance of '"`vmware_product_name`"' is still running.'
- echo 'Please stop all running instances of '"`vmware_product_name`"' first.'
+ echo 'At least one instance of VMware Workstation is still running.'
+ echo 'Please stop all running instances of VMware Workstation first.'
echo
# The unconfigurator handle this exit code differently
exit 2
[ "$?" -eq 0 ] && ok || fail
exitcode=`expr "$exitcode" + "$?"`
elif [ -n "$hostaddr" -a -n "$netmask" ]; then
+ # Stop a DHCP server on a private IP network
msg_stopping "DHCP server on /dev/vmnet$vHubNr"
busy
- vmware_stop_dhcpd "vmnet$vHubNr"
+ vmware_stop_pidfile /var/run/"$dhcpd"-"vmnet$vHubNr".pid
[ "$?" -eq 0 ] && ok || fail
exitcode=`expr "$exitcode" + "$?"`
eval 'samba="$vmdb_answer_VNET_'"$vHubNr"'_SAMBA"'
if [ "$samba" = "yes" ]; then
+ # Stop a SMB share server on a private IP network
msg_stopping 'SMB share server on /dev/vmnet'"$vHubNr"
busy
- vmware_stop_smbd 'vmnet'"$vHubNr"
+ vmware_stop_pidfile /var/run/"$smbd"-'vmnet'"$vHubNr".pid
[ "$?" -eq 0 ] && ok || fail
exitcode=`expr "$exitcode" + "$?"`
-
+ # Stop a SMB name server on a private IP network
msg_stopping 'SMB name server on /dev/vmnet'"$vHubNr"
busy
- vmware_stop_nmbd 'vmnet'"$vHubNr"
+ vmware_stop_pidfile /var/run/"$nmbd"-'vmnet'"$vHubNr".pid
[ "$?" -eq 0 ] && ok || fail
exitcode=`expr "$exitcode" + "$?"`
fi
eval 'nat="$vmdb_answer_VNET_'"$vHubNr"'_NAT"'
if [ "$nat" = "yes" ]; then
+ # Stop the NAT network user service
msg_stopping 'NAT networking on /dev/vmnet'"$vHubNr"
busy
- vmware_stop_nat "$vHubNr"
+ vmware_stop_pidfile /var/run/"$natd"-"$vHubNr".pid
[ "$?" -eq 0 ] && ok || fail
exitcode=`expr "$exitcode" + "$?"`
fi
done
msg_stopping 'Virtual ethernet'
busy
- if [ "`isLoaded "$vnet"`" = 'yes' ]; then
+ if /sbin/lsmod | grep -q ^"$vnet"; then
/sbin/rmmod "$vnet"
fi
[ "$?" -eq "0" ] && ok || fail
exitcode=`expr "$exitcode" + "$?"`
fi
- if [ "$exitcode" -gt 0 ]; then
- exit 1
- fi
+ [ "$exitcode" -gt 0 ] && exit 1
rm -f /var/lock/subsys/"$subsys"
;;
-
status)
if [ "`countVMs`" -gt 0 ]; then
- echo 'At least one instance of '"`vmware_product_name`"' is still running.'
+ echo 'At least one instance of VMware Workstation is still running.'
echo
fi
if [ "$vmdb_answer_NETWORKING" = "yes" ]; then
/sbin/modprobe "$vnet" >/dev/null 2>&1 && echo installed || echo "not installed"
fi
;;
-
restart)
"$0" stop && "$0" start
;;
-
*)
echo "Usage: `basename "$0"` {start|stop|status|restart}"
exit 1