forked from dracoventions/TWCManager
-
Notifications
You must be signed in to change notification settings - Fork 55
/
TWCManager.py
executable file
·34 lines (26 loc) · 1.01 KB
/
TWCManager.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
#!/usr/bin/env python3
import os
import grp
import pwd
import sys
# If we are being run as root, drop privileges to twcmanager user
# This avoids any potential permissions issues if it is run as root and settings.json is created as root
if os.getuid() == 0:
user = "twcmanager"
groups = [g.gr_gid for g in grp.getgrall() if user in g.gr_mem]
_, _, uid, gid, gecos, root, shell = pwd.getpwnam(user)
groups.append(gid)
os.setgroups(groups)
os.setgid(gid)
os.setuid(uid)
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + "/lib")
# Remove any local local path references in sys.path, otherwise we'll
# see an error when we try to import TWCManager.TWCManager, as it will see
# us (TWCManager.py) instead of the package (lib/TWCManager) and fail.
if "" in sys.path:
sys.path.remove("")
if "." in sys.path:
sys.path.remove(".")
if os.path.dirname(os.path.realpath(__file__)) in sys.path:
sys.path.remove(os.path.dirname(os.path.realpath(__file__)))
import TWCManager.TWCManager