Add is_debian() convenience function

This commit is contained in:
Lance Edgar 2020-09-23 22:40:59 -05:00
parent e8821b3395
commit 7471dd1bf5
2 changed files with 23 additions and 1 deletions

View file

@ -64,6 +64,27 @@ def is_link(c, path, use_sudo=False):
return False if result.failed else True
def get_os_release_id(c):
"""
Return the "ID" field from `/etc/os-release` file
"""
contents = c.run('cat /etc/os-release').stdout.strip()
data = {}
for line in contents.split('\n'):
field, value = line.split('=')
data[field] = value
return data['ID']
def is_debian(c):
"""
Return boolean indicating if this machine is Debian (proper, as opposed to
some derivative).
"""
release_id = get_os_release_id(c)
return release_id == 'debian'
def get_debian_version(c):
"""
Fetch the version of Debian running on the target system.