-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
79 lines (67 loc) · 2.65 KB
/
setup.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
import os
import shutil
import stat
import subprocess
from setuptools import setup
from setuptools.command.install import install
class ServiceInstall(install):
@staticmethod
def exec_cmd(cmd):
try:
subprocess.check_output(cmd.split(' '))
print(cmd)
except subprocess.CalledProcessError as e:
print('could not execute {0}: {1} {2}'.format(cmd, e.returncode, e.output))
def run(self):
install.run(self)
print('creating service')
service_file = 'psync.service'
current_path = os.path.dirname(os.path.realpath(__file__))
psync_service = os.path.join(current_path, 'service', service_file)
if not os.path.exists(psync_service):
print('{0} not found'.format(psync_service))
return
run_systemctl = True
dest_path = '/lib/systemd/system'
if not os.path.exists(dest_path):
print('{0} not found, will not copy service file'.format(dest_path))
run_systemctl = False
else:
dst = os.path.join(dest_path, service_file)
print('copy {0} to {1}'.format(psync_service, dst))
shutil.copy(psync_service, dst)
os.chmod(dst, 0o664)
print('creating runner')
exec_file = 'psync'
psync_exec = os.path.join(current_path, 'service', exec_file)
if not os.path.exists(psync_exec):
print('{0} not found'.format(psync_exec))
return
dest_path = '/usr/sbin'
if not os.path.exists(dest_path):
print('{0} not found, will not copy exec file'.format(dest_path))
run_systemctl = False
else:
dst = os.path.join(dest_path, exec_file)
print('copy {0} to {1}'.format(psync_exec, dst))
shutil.copy(psync_exec, dst)
os.chmod(dst, 0o755)
os.chmod(dst, stat.S_IEXEC)
print('creating config')
config_file = 'psync.conf'
dest_path = '/etc'
if not os.path.exists(dest_path):
print('{0} not found, will not copy config file'.format(dest_path))
else:
dst = os.path.join(dest_path, config_file)
print('copy {0} to {1}'.format(config_file, dst))
shutil.copy(config_file, dst)
if run_systemctl:
self.exec_cmd('systemctl daemon-reload')
self.exec_cmd('systemctl enable psync.service')
self.exec_cmd('systemctl start psync.service')
setup(name='psync',
version='0.1.0',
packages=['psync'],
entry_points={'console_scripts': ['psync = psync.__main__:main']},
cmdclass={'install': ServiceInstall})