Skip to content

Commit e878170

Browse files
committed
feat: allow setting different root dir for apt
Signed-off-by: egvimo <[email protected]>
1 parent 34dd42e commit e878170

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

apt_info.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# Authors: Kyle Fazzari <[email protected]>
99
# Daniel Swarbrick <[email protected]>
1010

11+
import argparse
1112
import apt
1213
import collections
1314
import contextlib
@@ -74,14 +75,19 @@ def _write_autoremove_pending(registry, cache):
7475
g.set(len(autoremovable_packages))
7576

7677

77-
def _write_reboot_required(registry):
78+
def _write_reboot_required(registry, root_dir):
7879
g = Gauge('node_reboot_required', "Node reboot is required for software updates.",
7980
registry=registry)
80-
g.set(int(os.path.isfile('/run/reboot-required')))
81+
g.set(int(os.path.isfile(os.path.join(root_dir,'run/reboot-required'))))
8182

8283

8384
def _main():
84-
cache = apt.cache.Cache()
85+
parser = argparse.ArgumentParser()
86+
parser.add_argument('-r', '--root-dir', dest='root_dir', type=str, default='/',
87+
help="Set root directory to a different path than /")
88+
args = parser.parse_args()
89+
90+
cache = apt.cache.Cache(rootdir=args.root_dir)
8591

8692
# First of all, attempt to update the index. If we don't have permission
8793
# to do so (or it fails for some reason), it's not the end of the world,
@@ -96,7 +102,7 @@ def _main():
96102
_write_pending_upgrades(registry, cache)
97103
_write_held_upgrades(registry, cache)
98104
_write_autoremove_pending(registry, cache)
99-
_write_reboot_required(registry)
105+
_write_reboot_required(registry, args.root_dir)
100106
print(generate_latest(registry).decode(), end='')
101107

102108

0 commit comments

Comments
 (0)