-
Notifications
You must be signed in to change notification settings - Fork 188
Expand file tree
/
Copy pathmintupdate-automation
More file actions
executable file
·77 lines (66 loc) · 2.61 KB
/
Copy pathmintupdate-automation
File metadata and controls
executable file
·77 lines (66 loc) · 2.61 KB
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/python3
# pylint: disable=E0602
import json
import os
import sys
import subprocess
from pathlib import Path
if not os.getuid() == 0:
print("This command needs to be run as root or with sudo.")
sys.exit(1)
if len(sys.argv) != 3 or sys.argv[1] not in ("upgrade", "autoremove", "blacklist", "download") or sys.argv[2] not in ("enable", "disable"):
print("Bad arguments")
sys.exit(1)
# import AUTOMATIONS dict
with open("/usr/share/linuxmint/mintupdate/automation/index.json") as f:
AUTOMATIONS = json.load(f)
automation_id = sys.argv[1]
def do_enable(_automation_id):
(filename, name, touchfile) = AUTOMATIONS[_automation_id]
if touchfile is not None or sys.argv[1] == "blacklist":
if name == "systemd":
touch = Path(touchfile)
touch.parent.mkdir(parents=True, exist_ok=True)
touch.touch(exist_ok=True)
basename = os.path.basename(filename)
subprocess.run(["/bin/systemctl", "start", basename])
subprocess.run(["/bin/systemctl", "enable", basename])
else:
default = "/usr/share/linuxmint/mintupdate/automation/%s.default" % _automation_id
os.system("cp %s %s" % (default, filename))
print("%s %s created." % (name, filename))
if sys.argv[1] == "blacklist":
add_user_blacklist(filename)
def do_disable(_automation_id):
(filename, name, touchfile) = AUTOMATIONS[_automation_id]
if touchfile is not None:
if name == "systemd":
touch = Path(touchfile)
touch.parent.mkdir(parents=True, exist_ok=True)
touch.unlink(missing_ok=True)
basename = os.path.basename(filename)
subprocess.run(["/bin/systemctl", "stop", basename])
subprocess.run(["/bin/systemctl", "disable", basename])
else:
os.system("rm -f %s" % filename)
print("%s %s removed." % (name, filename))
def add_user_blacklist(outfile):
import tempfile
try:
infile = os.path.join(tempfile.gettempdir(), "mintUpdate/blacklist")
with open(infile, "r") as export:
with open(outfile, "a") as f:
for line in export:
f.write(line)
os.remove(infile)
print("User blacklist exported.")
except:
pass
if sys.argv[2] == "enable":
do_enable(automation_id)
if automation_id == "upgrade":
do_enable("blacklist")
# Enable the cleanup service in case it was disabled manually
subprocess.run(["/bin/systemctl", "enable", "mintupdate-automation-cleanup.service"])
else:
do_disable(automation_id)