2020-09-02 13:04:58 +00:00
|
|
|
#
|
|
|
|
|
# Copyright 2020 Ettus Research, a National Instruments Company
|
|
|
|
|
#
|
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
#
|
|
|
|
|
"""
|
|
|
|
|
Utilities for checking the filesystem status
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import hashlib
|
|
|
|
|
import pathlib
|
|
|
|
|
import subprocess
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
def get_uhd_version(filesystem_root='/'):
|
|
|
|
|
file = pathlib.Path(filesystem_root, 'usr/bin/uhd_config_info')
|
|
|
|
|
versionstring = subprocess.check_output([file, '--version']).decode('utf-8').splitlines()[0]
|
2021-04-20 15:06:23 +00:00
|
|
|
return versionstring
|
2020-09-02 13:04:58 +00:00
|
|
|
|
|
|
|
|
def get_mender_artifact(filesystem_root='/', parse_manually=False):
|
|
|
|
|
def parse_artifact(output):
|
|
|
|
|
for line in output.splitlines():
|
|
|
|
|
if line.startswith('artifact_name='):
|
|
|
|
|
return line[14:]
|
|
|
|
|
return None
|
|
|
|
|
if filesystem_root != '/':
|
|
|
|
|
parse_manually = True
|
|
|
|
|
if parse_manually:
|
|
|
|
|
# parse mender artifact manually
|
|
|
|
|
file = pathlib.Path(filesystem_root, 'etc/mender/artifact_info')
|
|
|
|
|
if not file.exists():
|
2020-10-22 15:34:56 +00:00
|
|
|
return None
|
2020-09-02 13:04:58 +00:00
|
|
|
return parse_artifact(file.read_text())
|
2020-10-22 15:34:56 +00:00
|
|
|
try:
|
2024-05-02 11:47:30 +00:00
|
|
|
output = subprocess.check_output(['/usr/bin/mender', 'show-artifact']).decode('utf-8')
|
2020-09-02 13:04:58 +00:00
|
|
|
return output.splitlines()[0]
|
2020-10-22 15:34:56 +00:00
|
|
|
except:
|
|
|
|
|
return None
|
2020-09-02 13:04:58 +00:00
|
|
|
|
|
|
|
|
def get_fs_version(filesystem_root='/'):
|
|
|
|
|
file = pathlib.Path(filesystem_root, 'etc/version')
|
|
|
|
|
if not file.exists():
|
2020-10-22 15:34:56 +00:00
|
|
|
return None
|
2020-09-02 13:04:58 +00:00
|
|
|
return file.read_text().splitlines()[0]
|
|
|
|
|
|
|
|
|
|
def get_opkg_status_date(date_only=False, filesystem_root='/'):
|
|
|
|
|
if date_only:
|
|
|
|
|
tformat = "%Y-%m-%d"
|
|
|
|
|
else:
|
|
|
|
|
tformat = "%Y-%m-%d %H:%M:%S"
|
|
|
|
|
file = pathlib.Path(filesystem_root, 'var/lib/opkg/status')
|
|
|
|
|
if not file.exists():
|
2020-10-22 15:34:56 +00:00
|
|
|
return None
|
2020-09-02 13:04:58 +00:00
|
|
|
return time.strftime(tformat, time.gmtime(file.stat().st_mtime))
|
|
|
|
|
|
|
|
|
|
def get_opkg_status_md5sum(filesystem_root='/'):
|
|
|
|
|
file = pathlib.Path(filesystem_root, 'var/lib/opkg/status')
|
|
|
|
|
if not file.exists():
|
2020-10-22 15:34:56 +00:00
|
|
|
return None
|
2021-04-19 11:12:28 +00:00
|
|
|
return hashlib.md5(file.read_bytes()).hexdigest()
|