Skip to content

Commit

Permalink
update bootc check
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrero committed Jul 16, 2024
1 parent 218364d commit 15a6342
Showing 1 changed file with 1 addition and 37 deletions.
38 changes: 1 addition & 37 deletions dnf/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,52 +643,16 @@ def _is_file_pattern_present(specs):
return False


def is_container():
"""Returns true if DNF is running in a container,
false otherwise.
"""
# This attempts to reimplement
# https://github.com/ostreedev/ostree-rs-ext/blob/b0d1c1e4748c8708149bb6c92998da623260c4c6/lib/src/container_utils.rs#L20
# in python.
container_env_var = 'container'
container_env_file = '/run/.containerenv'
docker_env_file = '/.dockerenv'
# https://stackoverflow.com/questions/20010199/how-to-determine-if-a-process-runs-inside-lxc-docker
if os.getenv(container_env_var) is not None or os.path.isfile(docker_env_file) or os.path.isfile(container_env_file):
return True
else:
return False

def is_bootc_host():
"""Returns true is the system is managed as an immutable container,
false otherwise. If msg is True, a warning message is displayed
for the user.
"""

ostree_booted = '/run/ostree-booted'
usr = '/usr/'

# Check if usr is writtable and we are in a running ostree system.
# We want this code to return true only when the system is in locked state. If someone ran
# bootc overlay or ostree admin unlock we would want normal DNF path to be ran as it will be
# temporary changes (until reboot).
if os.path.isfile(ostree_booted) and not os.access(usr, os.X_OK):
return True
else:
return False

def is_bootc_container():
"""Returns true if DNF is running inside a bootc container,
false otherwise. If True, some packages like kernel might be
installed with that in mind. For example only one kernel is
supported on bootc containers and hosts.
## TODO this is not complete right now as it just checks for
/ostree/ to exists. Also not in use. ##
"""
sysroot_ostree = '/sysroot/ostree'
systemd_env_var = 'INVOCATION_ID'
if is_container() and os.path.exists(sysroot_ostree) and not is_bootc_host() and os.getenv(systemd_env_var) is None:
return True
else:
return False
return os.path.isfile(ostree_booted) and not os.access(usr, os.W_OK)

0 comments on commit 15a6342

Please sign in to comment.