-
Notifications
You must be signed in to change notification settings - Fork 27
/
setup.py
78 lines (70 loc) · 2.22 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
#!/usr/bin/env python3
from distutils.core import setup
from distutils.command.install import install
from distutils.dir_util import mkpath
import pkg_resources
import os
import sys
import shutil
#import imp
import importlib
class post_install(install):
def run(self):
prefix = getattr(self, "install_data", "/") or "/"
root = getattr(self, "root", "/") or "/"
print("Using '%s' as root" % root)
if root == "/":
if os.getuid() != 0:
print("ERROR: Can't install to root '/' without root permissions")
sys.exit(1)
# cleanup old egg-info files
try:
while True:
p = pkg_resources.get_distribution("pymultimonaprs")
for f in os.listdir(p.location):
if f.startswith("pymultimonaprs") and f.endswith(".egg-info"):
egg_info = os.path.join(p.location, f)
try:
print("Deleting old egg-info: %s" % egg_info)
os.unlink(egg_info)
except:
pass
importlib.reload(pkg_resources)
except pkg_resources.DistributionNotFound:
pass
install.run(self)
if root == "/":
# fix prefix in systemd.service file
unitfile = os.path.join(root, "/usr/lib/systemd/system", "pymultimonaprs.service")
print(unitfile)
new_content = open(unitfile).read().replace("/usr/bin", "%s/bin" % prefix)
open(unitfile, "w").write(new_content)
# install config file
print("")
cd = os.path.dirname(os.path.realpath(__file__))
src = os.path.join(cd, "pymultimonaprs.json")
dest = os.path.join(root, "etc/pymultimonaprs.json")
dest_new = os.path.join(root, "etc/pymultimonaprs.json.new")
mkpath(os.path.dirname(dest))
if os.path.isfile(dest):
print("Warning: %s already exists! Saved new config file to %s" % (dest, dest_new))
shutil.copyfile(src, dest_new)
else:
print("Installing config file to %s" % dest)
shutil.copyfile(src, dest)
setup(
name='pymultimonaprs',
version='1.3.2',
license='GPL',
description='RF2APRS-IG Gateway',
author='Dominik Heidler',
author_email='dominik@heidler.eu',
url='http://github.com/asdil12/pymultimonaprs',
packages=['pymultimonaprs'],
scripts=['bin/pymultimonaprs'],
data_files=[
#('/etc', ['pymultimonaprs.json']),
('/usr/lib/systemd/system', ['pymultimonaprs.service']),
],
cmdclass={'install': post_install},
)