-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_initd
executable file
·49 lines (40 loc) · 1.52 KB
/
remove_initd
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
#!/usr/bin/python3
import sys, re, os, initdutils
if len(sys.argv) > 1:
initfile = sys.argv[1]
# If the absolute path isn't specified, assume it's relative to
# cwd; if that doesn't exist, try /etc/init.d
ap = os.path.abspath(initfile)
if os.path.exists(ap):
initfile = ap
else:
initfile = os.path.join('/etc/init.d', initfile)
else:
print('Usage: %s /etc/init.d/<init-script>' % sys.argv[0], file=sys.stderr)
sys.exit(1)
headers = initdutils.scan_initfile(initfile)
provides = headers.get('Provides')
if provides:
facilities = initdutils.load_facilities()
depends = initdutils.load_depends()
for facility in provides:
if facility in facilities:
entries = {}
for entry in facilities[facility].items():
if entry[0] != initfile:
entries[entry[0]] = entry[1]
facilities[facility] = entries
for (initscript, needed) in depends.items():
for facility in needed:
if facility[0] == "$":
continue
if not facilities.get(facility) and facility in provides:
print('Unable to remove %s: %s needs %s\n' % (
initfile, initscript, facility), file=sys.stderr)
sys.exit(1)
if initfile in depends:
del depends[initfile]
initdutils.save_depends(depends)
initdutils.save_facilities(facilities)
initfile = initfile.replace('/etc/init.d/', '')
os.system('/usr/sbin/update-rc.d -f %s remove' % initfile)