Skip to content

Commit

Permalink
Merge pull request #215 from olcf/verifyinstall_backend
Browse files Browse the repository at this point in the history
Update verifyinstall.py
  • Loading branch information
carljbai authored Dec 11, 2023
2 parents f82d307 + b5c3c95 commit 080065e
Showing 1 changed file with 84 additions and 10 deletions.
94 changes: 84 additions & 10 deletions libpkpass/commands/verifyinstall.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
"""This is used to check the os requirements"""
from os import path
from platform import python_version
from re import search
from subprocess import check_output, CalledProcessError
from shutil import which
from libpkpass.commands.command import Command

from libpkpass.errors import BadBackendError
from libpkpass._version import get_versions

class VerifyInstall(Command):
####################################################################
Expand All @@ -23,7 +27,7 @@ def _run_command_execution(self):
####################################################################
"""Run function for class."""
####################################################################
yield from print_messages(check_required_software, "installed software check")
yield from print_messages(check_required_software, "installed software check", SCBackend=self.args["SCBackend"])
yield from print_messages(
check_passdb,
"passdb check",
Expand All @@ -41,36 +45,106 @@ def _run_command_execution(self):
def _validate_args(self):
pass

def get_backend(SCBackend):
if SCBackend == "opensc":
return(SCBackend)
elif SCBackend == "yubi":
return(SCBackend)
raise BadBackendError(SCBackend)



def check_exists(name):
####################################################################
"""Check whether a program exists in path"""
####################################################################
return which(name) is not None
path=which(name)
if path is not None:
return path

def check_exists_brew(name):
whichcmd="brew --prefix --installed "+ name + " 2> /dev/null"
try:
path=check_output(whichcmd, shell=True).decode('utf-8').strip()
#print(path)
except CalledProcessError:
path=None
return path

def print_messages(func, msg, **kwargs):
yield f"Starting {msg}"
yield func(**kwargs)

def check_brew():
if which("brew"):
return True
else:
return False
#may need an exception here to catch which not existing

def check_required_software():
required_tools = {
"pkcs15-tool (available via opensc)": ["pkcs15-tool"],
"ssl (openssl or libressl)": ["openssl", "libressl"],
}
def check_required_software(**kwargs):
print("Using Python Version "+python_version())
print("Using Pkpass Version: "+get_versions()["version"])
SCBackend=get_backend(kwargs['SCBackend'])
print("Using SCBackend: "+SCBackend)
if SCBackend=="yubi":
required_tools = {
"ssl (openssl or libressl)": ["openssl", "libressl"],
"yubico-piv-tool": ["yubico-piv-tool", "libp11"],
}
elif SCBackend=="opensc":
required_tools = {
"pkcs15-tool (available via opensc)": ["pkcs15-tool", "opensc"],
"ssl (openssl or libressl)": ["openssl", "libressl"],
}
not_found = []
found = []
paths = []
brew=check_brew()
for key, value in required_tools.items():
found_tool = False
for tool in value:
if check_exists(tool):
found_tool = True
if brew:
brewexists=check_exists_brew(tool)
if brewexists:
found.append(tool)
found_tool = True
print(tool+" is installed with brew")
paths.append(brewexists)
else:
exists=check_exists(tool)
if exists:
found.append(tool)
found_tool = True
print(tool+" is installed")
paths.append(exists)
if not found_tool:
not_found.append(key)
matches = dict(zip(found,paths))
if not_found:
return "The following packages were not found: \n\t%s" % "\n\t".join(not_found)
if brew and SCBackend=="yubi":
check_links(matches)
return "Successful installed software check"

def check_links(software):
software['local']="/usr/local"
for package,path in software.items():
pathlib=path+"/lib"
needspkcs=["openssl","libp11","local"]
needslibykcs=["yubico-piv-tool","local"]
checkdir=check_output(["ls","-l",pathlib]).decode('utf-8').strip()
if search("engines-3", checkdir):
if search("pkcs11.dylib", check_output(["ls","-l",pathlib+"/engines-3"]).decode('utf-8').strip()):
print("pkcs11.dylib exists in "+pathlib+"/engines-3")
elif package in needspkcs:
print("Required packages are installed, however no file was detected at "+pathlib+"/engines-3/pkcs11.dylib . A link may be needed.")
if search("libykcs11.dylib", checkdir):
print("libykcs11.dylib exists in "+pathlib)
elif package in needslibykcs:
print("Required packages are installed, however no file was detected at "+pathlib+"libykcs11.dylib . A link may be needed.")



def check_passdb(cabundle, pwstore, certpath=None, keypath=None, connect=None):
ret_msg = []
Expand Down

0 comments on commit 080065e

Please sign in to comment.