204 |
- |
1 |
"""
|
|
|
2 |
Copyright 2010,2020 VMware, Inc. All rights reserved. -- VMware Confidential
|
|
|
3 |
|
|
|
4 |
VMware USB Arbitrator component installer.
|
|
|
5 |
"""
|
|
|
6 |
|
|
|
7 |
import os
|
|
|
8 |
from vmis.util.path import path
|
|
|
9 |
|
|
|
10 |
DEST = LIBDIR/'vmware'
|
|
|
11 |
|
|
|
12 |
class USBArbitrator(Installer):
|
|
|
13 |
"""
|
|
|
14 |
This class contains the installer logic for the USB Arbitrator component.
|
|
|
15 |
"""
|
|
|
16 |
def InitializeInstall(self, old, new, upgrade):
|
|
|
17 |
self.AddTarget('File', 'bin/*', DEST/'bin')
|
|
|
18 |
self.SetPermission(DEST/'bin/*', BINARY)
|
|
|
19 |
|
|
|
20 |
# Register the init script and link to the appropriate runlevels
|
|
|
21 |
self.RegisterService(name='vmware-USBArbitrator', src='etc/init.d/vmware-USBArbitrator', start=50, stop=8)
|
|
|
22 |
|
|
|
23 |
def PreUninstall(self, old, new, upgrade):
|
|
|
24 |
# Stop the USB Arbitrator init script
|
|
|
25 |
script = INITSCRIPTDIR/'vmware-USBArbitrator'
|
|
|
26 |
# Set "SYSTEMCTL_SKIP_REDIRECT" to skip systemctl when doing
|
|
|
27 |
# start/stop action, such as RHEL 8 which systemctl will bring
|
|
|
28 |
# trouble for USB Arbitrator service start/stop.
|
|
|
29 |
os.environ['SYSTEMCTL_SKIP_REDIRECT'] = "1"
|
|
|
30 |
if script.exists() and self.RunCommand(script, 'stop', ignoreErrors=True).retCode != 0:
|
|
|
31 |
log.Warn('Unable to stop USB Arbitrator service.')
|
|
|
32 |
# Unset "SYSTEMCTL_SKIP_REDIRECT".
|
|
|
33 |
del os.environ['SYSTEMCTL_SKIP_REDIRECT']
|
|
|
34 |
|
|
|
35 |
inits = self.LoadInclude('initscript')
|
|
|
36 |
inits.DeconfigureService('vmware-USBArbitrator')
|
|
|
37 |
|
|
|
38 |
self.pycFile = None
|
|
|
39 |
if upgrade:
|
|
|
40 |
# It means that this is installed vmis and will be uninstalled,
|
|
|
41 |
# the installing Python runtime is version-higher than or equals
|
|
|
42 |
# to ours, remember the .pyc file location to make sure it will
|
|
|
43 |
# be removed in the phase PostUninstall.
|
|
|
44 |
pycFile = getattr(inits, '__cached__', '')
|
|
|
45 |
if not pycFile:
|
|
|
46 |
pyFile = getattr(inits, '__file__', '')
|
|
|
47 |
if pyFile:
|
|
|
48 |
pycFile = self.CompilePythonFile(pyFile)
|
|
|
49 |
if pycFile:
|
|
|
50 |
self.pycFile = path(pycFile)
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
def PostUninstall(self, old, new, upgrade):
|
|
|
54 |
# If there is a backup LIBDIR/'vmware/lib/vmware-usbarbitrator.old'
|
|
|
55 |
# then restore it, otherwise, remove it.
|
|
|
56 |
orig = BINDIR/'vmware-usbarbitrator'
|
|
|
57 |
backup = LIBDIR/'vmware/lib/vmware-usbarbitrator.old'
|
|
|
58 |
try:
|
|
|
59 |
orig.remove()
|
|
|
60 |
except OSError:
|
|
|
61 |
# Pass if it is already gone
|
|
|
62 |
pass
|
|
|
63 |
if backup.exists():
|
|
|
64 |
backup.copyfile(str(orig))
|
|
|
65 |
orig.chmod(0o755)
|
|
|
66 |
backup.remove()
|
|
|
67 |
|
|
|
68 |
if self.pycFile and self.pycFile.exists():
|
|
|
69 |
# Remove the initscript.pyc file if it is still existing.
|
|
|
70 |
self.pycFile.unlink(ignore_errors=True)
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
def PostInstall(self, old, new, upgrade):
|
|
|
74 |
# If an arbitrator already exists and it's not a symlink, back
|
|
|
75 |
# it up and create a symlink to our new ones. This must be
|
|
|
76 |
# done for co-installs with WS 7.x
|
|
|
77 |
arb = BINDIR/'vmware-usbarbitrator'
|
|
|
78 |
if arb.exists():
|
|
|
79 |
if not arb.islink():
|
|
|
80 |
# Make the destination directory if it doesn't already exist
|
|
|
81 |
dest = path(LIBDIR/'vmware/lib')
|
|
|
82 |
if not dest.exists():
|
|
|
83 |
dest.makedirs()
|
|
|
84 |
# Backup the program (Don't use a path, explicitly convert to a string)
|
|
|
85 |
arb.copyfile(str(LIBDIR/'vmware/lib/vmware-usbarbitrator.old'))
|
|
|
86 |
arb.remove()
|
|
|
87 |
else:
|
|
|
88 |
# Remove the old link
|
|
|
89 |
arb.remove()
|
|
|
90 |
|
|
|
91 |
# Now that our space in the BINDIR is clear, install the symlink.
|
|
|
92 |
path(LIBDIR/'vmware/bin/vmware-usbarbitrator').symlink(str(arb))
|
|
|
93 |
|
|
|
94 |
inits = self.LoadInclude('initscript')
|
|
|
95 |
inits.ConfigureService('vmware-USBArbitrator',
|
|
|
96 |
'This services starts and stops the USB Arbitrator.',
|
|
|
97 |
'localfs', # Start
|
|
|
98 |
'localfs', # Stop
|
|
|
99 |
'',
|
|
|
100 |
'',
|
|
|
101 |
50,
|
|
|
102 |
8)
|
|
|
103 |
|
|
|
104 |
# Set "SYSTEMCTL_SKIP_REDIRECT" to skip systemctl when doing
|
|
|
105 |
# start/stop action, such as RHEL 8 which systemctl will bring
|
|
|
106 |
# trouble for USB Arbitrator service start/stop.
|
|
|
107 |
os.environ['SYSTEMCTL_SKIP_REDIRECT'] = "1"
|
|
|
108 |
# Stop the USB Arbitrator init script
|
|
|
109 |
script = INITSCRIPTDIR/'vmware-USBArbitrator'
|
|
|
110 |
if script.exists() and self.RunCommand(script, 'stop', ignoreErrors=True).retCode != 0:
|
|
|
111 |
log.Warn('Unable to stop current USB Arbitrator service. Not fatal.')
|
|
|
112 |
|
|
|
113 |
# Start the USB Arbitrator init script
|
|
|
114 |
script = INITSCRIPTDIR/'vmware-USBArbitrator'
|
|
|
115 |
if script.exists() and self.RunCommand(script, 'start', ignoreErrors=True).retCode != 0:
|
|
|
116 |
log.Error('Unable to start USB Arbitrator service.')
|
|
|
117 |
# Unset "SYSTEMCTL_SKIP_REDIRECT".
|
|
|
118 |
del os.environ['SYSTEMCTL_SKIP_REDIRECT']
|