-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall_nsis.py
143 lines (115 loc) · 3.7 KB
/
install_nsis.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import datetime
import time
import os
import sys
import re
import shutil
import psutil
import win32serviceutil
COMPACT_VERSION='3.6.2'
# COMPACT_VERSION='3.3.25-1'
installPrefix= "c:/Programme/ArangoDB3e 3.6.2/"
installPrefix="C:/tmp"
INSTALLER = "c:/Users/willi/Downloads/ArangoDB3e-" + COMPACT_VERSION + "_win64.exe"
success = True
UNINSTALLER="Uninstall.exe"
TMP_UNINSTALLER="c:/tmp/" + UNINSTALLER
PASSWORD='passvoid'
INSTALLATIONFOLDER = os.path.join(re.sub('/', '\\\\', installPrefix), "PROG")
DBFOLDER = re.sub('/', '\\\\', installPrefix + "/DB")
APPFOLDER = re.sub('/', '\\\\', installPrefix + "/APP")
PASSWORD = "ABCDE"
basebindirectory = INSTALLATIONFOLDER + '\\'
def timestamp():
return datetime.datetime.utcnow().isoformat()
def log(string):
print(timestamp() + " " + string)
class arangoshExecutor(object):
def __init__(self, username, port=8529, passvoid="", jwt=None):
self.username = username
self.passvoid = passvoid
self.jwtfile = jwt
self.port = port
def runCommand(self, command, description):
cmd = [basebindirectory + "usr/bin/arangosh",
"--server.endpoint", "tcp://127.0.0.1:%d" %(int(self.port)),
"--server.username", "%s" % (self.username),
"--server.password", "%s" % (self.passvoid),
"--javascript.execute-string", "%s" % (command)]
log("launching " + description)
# PIPE=subprocess.PIPE
Popen=psutil.Popen
log(str(cmd))
p = Popen(cmd)#, stdout=PIPE, stdin=PIPE, stderr=PIPE, universal_newlines=True)
# print('l')
# l = p.stdout.read()
# print(l)
# print('p')
# e = p.stderr.read()
# print(p)
# print('wait')
return p.wait(timeout=30)
cmd = [INSTALLER,
'/PASSWORD=' + PASSWORD,
'/INSTDIR=' + INSTALLATIONFOLDER,
'/DATABASEDIR=' + DBFOLDER,
'/APPDIR=' + APPFOLDER,
'/PATH=0',
'/S',
'/INSTALL_SCOPE_ALL=1']
print(cmd)
install = psutil.Popen(cmd)
install.wait()
print ("x"*80)
jsVersionCheck = '''
if (db._version()!='%s') { throw 'fail'}
''' % (COMPACT_VERSION)
arangosh = arangoshExecutor(username='root', passvoid=PASSWORD)
print(jsVersionCheck)
service = psutil.win_service_get('ArangoDB')
print(service.status())
if service.status() == 'running':
print("arangod running - first check with arangosh: ")
rc = arangosh.runCommand(jsVersionCheck, 'check version')
if rc != 0:
print("arangosh exited with failure!")
success = False
service.stop()
while service.status() != "stopped":
print(service.status())
time.sleep(1)
service.start()
while service.status() != "running":
print(service.status())
time.sleep(1)
rc = arangosh.runCommand(jsVersionCheck, 'check version')
if rc != 0:
print("arangosh exited with failure!")
success = False
# copy out the uninstaller as the windows facility would do:
shutil.copyfile(os.path.join(INSTALLATIONFOLDER, UNINSTALLER), TMP_UNINSTALLER)
cmd = [TMP_UNINSTALLER, '/PURGE_DB=1', '/S', '_?=' + INSTALLATIONFOLDER]
print(cmd)
uninstall = psutil.Popen(cmd)
uninstall.wait()
if os.path.exists(INSTALLATIONFOLDER):
print("Path not removed: " + INSTALLATIONFOLDER)
success = False
if os.path.exists(APPFOLDER):
print("Path not removed: " + APPFOLDER)
success = False
if os.path.exists(DBFOLDER):
print("Path not removed: " + DBFOLDER)
success = False
try:
print(psutil.win_service_get('ArangoDB'))
service = psutil.win_service_get('ArangoDB')
if service.status() != 'stopped':
print("service shouldn't exist anymore!")
success = False
except:
pass
if not success:
print("exiting with failure.")
sys.exit(1)
sys.exit(0)