-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.py
executable file
·68 lines (52 loc) · 1.86 KB
/
install.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
#!/usr/bin/env python3
import os
import sys
import json
from shutil import copyfile
import subprocess
if os.getegid() != 0:
print("You must run this as root. Cannot continue")
sys.exit(1)
package_path = None
lib_path = '/var/lib/polypy'
config_path = '/etc/polypy/'
share_path = '/usr/share/polypy/'
local_bin = '/usr/local/bin/'
python_packages = [ 'pip --upgrade', 'docopt', 'requests', 'pwgen_secure']
commands = []
commands.append("apt update".split(" "))
commands.append("apt -y upgrade".split(" "))
commands.append("apt install python3-pip".split(" "))
for pkg in python_packages:
commands.append("pip3 install {}".format(pkg).split(" "))
for command in commands:
print("Executing: {}".format(" ".join(command)))
proc = subprocess.call(command)
paths = [lib_path, config_path, share_path]
for path in sys.path:
if '/usr/local/lib' in path:
package_path = os.path.join(path, "poly_py_tools")
if not os.path.exists(package_path):
os.mkdir(package_path)
for path in paths:
if not os.path.exists(path):
os.mkdir(path)
for root, dirs, files in os.walk(os.path.join(os.getcwd(), "poly_py_tools")):
for file in files:
src = os.path.join(root, file)
copyfile(src, os.path.join(package_path, file))
copyfile("lib/10k-most-common.txt", os.path.join(lib_path, "10k-most-common.txt"))
copyfile("lib/csvguess.json", os.path.join(lib_path, "csvguess.json"))
copyfile("polypy.py", os.path.join('/usr/local/bin/', 'polypy'))
os.chmod(os.path.join('/usr/local/bin/', 'polypy'), 0o777)
configs = {}
configs['lib_path'] = lib_path
configs['share_path'] = share_path
configs['config_path'] = config_path
configs['package_path'] = package_path
configs['server_addr'] = None
configs['paths'] = None
f = open(os.path.join(config_path, 'polypy.conf'), 'w')
f.write(json.JSONEncoder().encode(configs))
f.close()
print("Setup complete.")