-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_framework.py
55 lines (49 loc) · 2.64 KB
/
update_framework.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
# -*- coding: utf-8 -*-
# Octowire Framework
# Copyright (c) ImmunIT - Jordan Ovrè / Paul Duncan
# License: Apache 2.0
# Paul Duncan / Eresse <[email protected]>
# Jordan Ovrè / Ghecko <[email protected]>
import argparse
import psutil
import subprocess
import sys
import time
from octowire.utils.Colors import Colors
def main(pid, logfile, package_path):
"""
The main function. Loop until the calling process is completed or timeout is reached.
:param pid: The pid of the parent process.
:param logfile: The file path where installation logs will be written.
:return: Nothing
"""
python_path = sys.executable
with open(logfile, "w") as f:
f.write("Start waiting for the completion of the calling process (owfupdate).\n")
timeout = time.time() + 60
while time.time() < timeout:
if not psutil.pid_exists(pid):
pipes = subprocess.Popen([python_path, '-m', 'pip', 'install', '--upgrade', f'./{package_path}'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = pipes.communicate()
if pipes.returncode != 0:
f.write("{}[X]{} Error while updating the octowire-framework package: {}\n"
.format(Colors.FAIL, Colors.ENDC, stderr.strip()))
else:
f.write("{}[V]{} The octowire-framework was successfully updated.\n".format(Colors.OKGREEN,
Colors.ENDC))
break
else:
f.write("{}[X]{} Timeout reached while waiting for the completion of the calling process (owfupdate)."
" Please run the 'owfupdate' command again to try to update the octowire-framework package.\n"
.format(Colors.FAIL, Colors.ENDC))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="{}This script is not intended to be run manually. It is "
"called by the 'owfupdate' command. Run it at your own risk.{}".format(
Colors.BOLD, Colors.ENDC))
parser.add_argument("-p", "--pid", help="The pid of the parent process.", type=int, required=True)
parser.add_argument("-f", "--logfile", help="The path of the file to log the update process status", required=True)
parser.add_argument("-d", "--package_path", help="The path of the octowire-framework package directory",
required=True)
args = parser.parse_args()
main(args.pid, args.logfile, args.package)