-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstaller
executable file
·120 lines (102 loc) · 4.84 KB
/
installer
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python3
import argparse
import os
import shutil
import stat
import sys
# put ourselves in the right location for installing
os.chdir(os.path.dirname(__file__))
def install(src, dest, name, dirname=None):
print("installing {}...".format(name))
dest_path = os.path.abspath(os.path.expanduser(dest))
src_path = os.path.abspath(os.path.expanduser(src ))
if (dirname != None):
dir_path = os.path.join(dest_path, dirname)
ret = shutil.copytree(src_path, dir_path, copy_function=shutil.copy)
else:
os.makedirs(dest_path, exist_ok=True)
ret = shutil.copy(src_path, dest_path)
print("\t{} installed to {} successfully!".format(name, ret))
def rm(path, name, dirname=None):
print("removing {}...".format(name))
full_path = os.path.abspath(os.path.expanduser(path))
if (dirname != None):
dir_path = os.path.join(full_path, dirname)
shutil.rmtree(dir_path)
else:
os.remove(full_path)
print("\tremoved {}.".format(name))
def _install(args):
if (args.which == "all" or args.which == "config"):
install("./config", args.config_prefix, "config files", "rgbd")
if (args.which == "all" or args.which == "daemon" or args.which == "share"):
install("./daemon", args.share_prefix, "daemon files", "rgbd/daemon")
if (args.which == "all" or args.which == "animations" or args.which == "share"):
install("./animations", args.share_prefix, "animation scripts", "rgbd/animations")
# install lightctl and chmod +x it
if (args.which == "all" or args.which == "bin"):
install("./lightctl", args.bin_dir, "lightctl")
lctl = os.path.abspath(os.path.expanduser(os.path.join(args.bin_dir, "lightctl")))
st = os.stat(lctl)
os.chmod(lctl, st.st_mode | stat.S_IEXEC)
if (args.which == "all" or args.which == "unit_files"):
install("./unitfiles/rgbd.service", args.unit_file_dir, "rgbd unit files (1/2)")
install("./unitfiles/[email protected]", args.unit_file_dir, "rgbd unit files (2/2)")
try:
install("./unitfiles/dbus.socket", args.unit_file_dir, "dbus unit files (1/2)")
install("./unitfiles/dbus.service", args.unit_file_dir, "dbus unit files (2/2)")
except Exception as e:
print("Failed to install dbus unit file(s).")
print("This is possibly due to dbus unit file(s) already existing, and can probably be ignored.")
if (args.which == "all"):
print("\n\nInstallation complete! You can enable & start rgbd with the following command:")
print("\n\tsystemctl --user enable --now rgbd")
print("\nIf you want to use an alternate config file, enable rgbd@[config-file-name].service instead.")
def _uninstall(args):
if (args.which == "all" or args.which == "config"):
rm(args.config_prefix, "config file", "rgbd")
if (args.which == "daemon"):
rm(args.share_prefix, "daemon files", "rgbd/daemon")
elif (args.which == "animations"):
rm(args.share_prefix, "animation scripts", "rgbd/animations")
elif (args.which == "all" or args.which == "share"):
rm(args.share_prefix, "daemon files and animation scripts", "rgbd")
if (args.which == "all" or args.which == "bin"):
rm(os.path.join(args.bin_dir, "lightctl"), "lightctl")
if (args.which == "all" or args.which == "unit_files"):
rm(os.path.join(args.unit_file_dir, "rgbd.service" ), "unit files (1/2)")
rm(os.path.join(args.unit_file_dir, "[email protected]"), "unit files (2/2)")
# we leave dbus services around, since we may not have installed them / other stuff might depend on them.
print("Uninstallation finished.")
def parse_args():
parser = argparse.ArgumentParser()
commands = parser.add_subparsers(dest="command")
inst = commands.add_parser("install")
upd = commands.add_parser("update", help="Uninstalls and then reinstalls specified files")
uninst = commands.add_parser("uninstall")
# for dir copies
parser.add_argument("-c", "--config-prefix", help="The location to install config files to.", default="~/.config/")
parser.add_argument("-s", "--share-prefix", help="The location to install daemon data to.", default="~/.local/share/")
# for individual files
parser.add_argument("-b", "--bin-dir", help="The location to install executable files to.", default="~/.local/bin/")
parser.add_argument("-u", "--unit-file-dir", help="The location to install systemd unit files to.", default="~/.local/share/systemd/user/")
parser.add_argument("which", choices=["animations", "bin", "config", "daemon", "share", "unit_files", "all"])
return parser
if (__name__ == "__main__"):
parser = parse_args()
args = parser.parse_args()
# Only disable this if you __really__ know what you're doing.
if (os.getuid() == 0 or os.geteuid() == 0 or os.getgid() == 0):
print("You shouldn't be running this as root.")
parser.print_help()
sys.exit(-1)
if (args.command == "install"):
_install(args)
elif (args.command == "uninstall"):
_uninstall(args)
elif (args.command == "update"):
_uninstall(args)
_install(args)
else:
parser.print_help()
sys.exit(1)