summarylogtreecommitdiffstats
path: root/configure-initscript.sh
blob: 95d9e9cc5bb8042b99948eceef28b755b5ae33bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash

action="$1" # add, remove, or status
serviceName="$2"
startLevel="$3"
stopLevel="$4"

# Notes:
# This package does not need a vmware service to make VMware usable, so this script says that vmware service is always started.
# vmware-workstation-server service is named vmware-hostd in this package.

case "$serviceName" in
   vmware-workstation-server)
      serviceName="vmware-hostd"
      ;;
esac

#echo $serviceName && exit # DEBUG

addService() {
   if [ "$serviceName" != "vmware" ]; then
      systemctl start $serviceName.service
      systemctl enable $serviceName.service
   fi
}

removeService() {
   if [ "$serviceName" != "vmware" ]; then
      systemctl stop $serviceName.service
      systemctl disable $serviceName.service
   fi
}

# Check to see whether a program is set to start on boot.
checkService() {
   if [ "$serviceName" = "vmware" ]; then
      retval=0
   else
      systemctl is-active $serviceName.service > /dev/null
      retval=$?
   fi

   if [ "$retval" = "0" ]; then
      echo 'on'
      exit 5
   else
      echo 'off'
      exit 6
   fi
}

usage() {
      echo "Syntax for this script is as follows:"
      echo ""
      echo " $0 <action> <serviceName>"
      echo ""
      echo " action      - add or remove"
      echo " serviceName - The name of the service"
      echo ""
      echo ""
      echo " $0 status <serviceName>"
      echo " serviceName - The name of the service"
      echo ""
}



case $action in
   add)
      # Don't allow any empty arguments for add
      if [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ] || [ "$4" = "" ]; then
         usage
         exit 1
      fi
      addService
      ;;
   remove)
      # Don't allow any empty arguments for remove
      if [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ] || [ "$4" = "" ]; then
         usage
         exit 1
      fi
      removeService
      ;;
   status)
      # We only need the serviceName to check status
      if [ "$1" = "" ] || [ "$2" = "" ]; then
         usage
         exit 1
      fi
      checkService
      ;;
   *)
      usage
      exit 1
      ;;
esac