-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstallServiceAgent.py
More file actions
executable file
·145 lines (125 loc) · 4.9 KB
/
InstallServiceAgent.py
File metadata and controls
executable file
·145 lines (125 loc) · 4.9 KB
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
144
145
#!/usr/bin/env python
import os
import sys
import subprocess
import shutil
import pexpect
from pylib.print_color import *
INSTALL_FOLDER = "ServiceAgentBM"
CLONE_FOLDER = "serviceagent-bm"
CLONE_FOLDER_SA = "serviceagent"
BUILD_FOLDER = "build"
PACKAGE_FOLDER = "package"
SSH_NEWKEY = r'Are you sure you want to continue connecting \(yes/no\)\?'
TARGET_ADDRESS = ''
TARGET_FOLDER = ''
TARGET_PASSWORD = 'root'
SED_SCRIPT = 'replace_workingfolder.sh'
RUN_SCRIPT_SAD = 'run_sad.sh'
RUN_SCRIPT_SAUI = 'run_sauid.sh'
SA_SERVICE = 'obigo-sa'
SA_PROCESS_NAME = 'sa-service'
SAUI_PROCESS_NAME = 'saui-service'
UICCID_FILE = 'uiccid.txt'
CWD = os.path.dirname(os.path.realpath(__file__))
os.chdir(CWD)
def checkPath(path, exist):
if exist == True:
if os.path.exists(path) == False:
printfail(path + " doesn't exist")
sys.exit()
else:
return
if exist == False:
if os.path.exists(path) == True:
printfail(path + " already exist")
sys.exit()
else:
return
def setpassword():
child.logfile = sys.stdout
i = child.expect([pexpect.TIMEOUT, SSH_NEWKEY, '[P|p]assword: '])
if i == 0: # Timeout
print('ERROR!')
print('SSH could not login. Here is what SSH said:')
print(child.before, child.after)
sys.exit (1)
if i == 1: # SSH does not have the public key. Just accept it.
child.sendline('yes')
child.expect('[P|p]assword: ')
child.sendline(TARGET_PASSWORD)
if i == 2: # Target requests password
child.sendline(TARGET_PASSWORD)
child.expect(pexpect.EOF)
if len(sys.argv) < 3:
message = __file__ + " <Target Address> <Target Folder>"
printfail(message)
sys.exit()
TARGET_ADDRESS = sys.argv[1]
TARGET_FOLDER = sys.argv[2]
targetfile = os.path.join(CWD, INSTALL_FOLDER, CLONE_FOLDER, BUILD_FOLDER, PACKAGE_FOLDER, 'armv7-a', 'bin/sa-service')
printheader("##########################################################")
printheader("### Looking for the target file : ")
printheader("### " + targetfile)
printheader("##########################################################")
checkPath(targetfile, True)
printheader("##########################################################")
printheader("### Stopping SA Service : " + SA_SERVICE)
printheader("##########################################################")
child = pexpect.spawn('ssh root@%s systemctl -a | grep obigo; systemctl stop %s'%(TARGET_ADDRESS, SA_SERVICE))
setpassword()
child = pexpect.spawn('ssh root@%s systemctl -a | grep obigo'%(TARGET_ADDRESS))
setpassword()
child = pexpect.spawn('ssh root@%s pkill %s'%(TARGET_ADDRESS, SA_PROCESS_NAME))
setpassword()
child = pexpect.spawn('ssh root@%s pkill %s'%(TARGET_ADDRESS, SAUI_PROCESS_NAME))
setpassword()
printheader("##########################################################")
printheader("### Deleting Target Folder")
printheader("### " + TARGET_ADDRESS + ':' + TARGET_FOLDER)
printheader("##########################################################")
child = pexpect.spawn('ssh root@%s rm -rf %s'%(TARGET_ADDRESS, TARGET_FOLDER))
setpassword()
printheader("##########################################################")
printheader("### Installing binary files to Target")
printheader("### " + TARGET_ADDRESS + ':' + TARGET_FOLDER)
printheader("##########################################################")
child = pexpect.spawn('scp -r %s root@%s:%s'
%(os.path.join(CWD, INSTALL_FOLDER, CLONE_FOLDER, BUILD_FOLDER, PACKAGE_FOLDER, 'armv7-a'),
TARGET_ADDRESS,
TARGET_FOLDER))
setpassword()
printheader("##########################################################")
printheader("### Changing working folder path of " + RUN_SCRIPT_SAD)
printheader("##########################################################")
checkPath(os.path.join(CWD, SED_SCRIPT), True)
child = pexpect.spawn('scp -r %s root@%s:%s'
%(os.path.join(CWD, SED_SCRIPT),
TARGET_ADDRESS,
TARGET_FOLDER))
setpassword()
child = pexpect.spawn("ssh root@%s %s %s"
%(TARGET_ADDRESS,
os.path.join(TARGET_FOLDER, SED_SCRIPT),
os.path.join(TARGET_FOLDER, RUN_SCRIPT_SAD)))
setpassword()
printheader("##########################################################")
printheader("### Changing working folder path of " + RUN_SCRIPT_SAUI)
printheader("##########################################################")
checkPath(os.path.join(CWD, SED_SCRIPT), True)
child = pexpect.spawn('scp -r %s root@%s:%s'
%(os.path.join(CWD, SED_SCRIPT),
TARGET_ADDRESS,
TARGET_FOLDER))
setpassword()
child = pexpect.spawn("ssh root@%s %s %s"
%(TARGET_ADDRESS,
os.path.join(TARGET_FOLDER, SED_SCRIPT),
os.path.join(TARGET_FOLDER, RUN_SCRIPT_SAUI)))
setpassword()
printheader("##########################################################")
printheader("### Copying %s to %s" % (os.path.join(CWD, UICCID_FILE), os.path.join(TARGET_FOLDER, UICCID_FILE)))
printheader("##########################################################")
checkPath(os.path.join(CWD, UICCID_FILE), True)
child = pexpect.spawn('scp %s root@%s:%s'%(UICCID_FILE, TARGET_ADDRESS, os.path.join(TARGET_FOLDER, UICCID_FILE)))
setpassword()