-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvmwfix.py
90 lines (72 loc) · 2.39 KB
/
vmwfix.py
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
#!/usr/bin/env python3.5
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 13 22:45:25 2017
@author: hhemied
"""
import os
import sys
import subprocess
from shutil import copyfile
import hashlib
Red = '\033[91m'
Green = '\033[92m'
Default = '\033[0m'
LIB = "/usr/lib/vmware/lib/libvmwareui.so/libvmwareui.so"
BS = "/etc/vmware/bootstrap"
useLibs = "VMWARE_USE_SHIPPED_LIBS"
deps = ["kernel-headers", "kernel-devel", "gcc", "dkms", "glibc-headers"]
vmmon = "/usr/lib/vmware/modules/source/vmmon.tar"
vmnet = "/usr/lib/vmware/modules/source/vmnet.tar"
"""
building md5sum function
"""
def md5(fname):
hash_md5 = hashlib.md5()
with open(fname, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
"""
Installing Dependencies
"""
print(Green, "\nInstalling dependencies ...\n", Default)
for pkg in deps:
os.system("sudo dnf install -y {}".format(pkg))
"""
checking VMWare Workstation installed or not
"""
print("\nChecking VMWare workstation ...")
if os.path.exists(LIB):
print("libvmwareui.so present, continuing...")
else:
print(Red, " VMWare Workstation not detected, exit!", Default)
sys.exit(1)
"""
Bootstrapping VMWare bundle libs
"""
print("Writing necessary values to {} if needed".format(BS))
if os.path.exists(BS):
if useLibs in open(BS).read():
print("Bootrap file \"{}\" has the value of \"{}\"".format(BS, useLibs))
else:
with open(BS, 'a') as file:
file.write("export VMWARE_USE_SHIPPED_LIBS=force")
print(Green, "\nRebuilding VMWare Modules ...\n", Default)
subprocess.call("sudo vmware-modconfig --console --install-all", shell=True)
"Manipulating FS to build its structure"
mylibs = subprocess.check_output("rpm -ql glib2|grep '/usr/lib64/libg.*so\.0$'", shell=True)
for mylib in mylibs.split():
tgtlib = os.path.join("/usr/lib/vmware/lib/", os.path.basename(mylib.decode("utf-8")), os.path.basename(mylib.decode("utf-8")))
if not os.path.exists(tgtlib + ".back"):
copyfile(tgtlib, tgtlib + ".backup")
print("Manipulating {} ....".format(tgtlib))
# coping files
copyfile(mylib.decode("utf-8"), tgtlib)
print()
print(Green, "Fixing Networking issue ...", Default)
if md5(vmmon) != md5("vmmon.tar"):
copyfile("./vmmon.tar", vmmon)
if md5(vmnet) != md5("vmnet.tar"):
copyfile("./vmnet.tar", vmnet)
print(Green, "\nEnjoy VMWare WorkStation", Default)