source: internals/2016/linuxloginsmartcardwizard/trunk/project1/configpart1.py @ 16313

Last change on this file since 16313 was 16313, checked in by dcorreia, 3 years ago

Added debug messages, docstrings and tests

File size: 2.2 KB
Line 
1#!/usr/bin/python3
2import os
3import subprocess
4import sys
5
6PAMPKCS11_PACKAGE = "libpam-pkcs11"
7
8# TODO Install PKCS#11 PAM package
9
10
11def installPackage(packageName):
12    '''
13    Installs package using apt-get
14    :param packageName: name of the package
15    :return: True if package was installed with success and False otherwise
16    '''
17    if not hasPackage(packageName):
18        # install package
19        print("DEBUG: installPackage - need to install", packageName, file=sys.stderr)
20        command = "apt-get install " + packageName
21        try:
22            proc = subprocess.Popen(command, shell=True, stdout=open(os.devnull, "wb"), stderr=subprocess.PIPE)
23            print("DEBUG: installPackage - ", proc.stderr.read(), file=sys.stderr)
24
25        except subprocess.CalledProcessError as error:
26            print("DEBUG: installPackage - ", error, file=sys.stderr)
27    return hasPackage(packageName)
28
29def hasPackage(packageName):
30    '''
31    Checks if system has package installed
32    :param packageName: name of the package
33    :return: True if system has package installed and False otherwise
34    '''
35    command = "dpkg -s " + packageName
36    proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
37    print("DEBUG: hasPackage - ", proc.stderr.read(), file=sys.stderr)
38    try:
39        subprocess.check_output("grep Status", shell=True, stdin=proc.stdout, stderr=sys.stdout)
40    except subprocess.CalledProcessError as error:
41        print("DEBUG: hasPackage - ", error.output, file=sys.stderr)
42        return False
43    else:
44        return True
45
46# Tests for package installation module
47if installPackage(PAMPKCS11_PACKAGE):
48    print("Package", PAMPKCS11_PACKAGE, "is installed")
49if installPackage("hello1"):
50    print("Package", "hello1", "is installed")
51else:
52    print("Failed to install package", "hello1")
53
54# TODO Create directories to support configuration files
55
56
57# TODO Copy certificate files to cacerts directory
58
59
60# TODO Get crl file from web link
61
62
63# TODO Generate pam_pkcs11.conf file
64
65
66# TODO Add portuguese CC module to pam_pkcs11.conf file
67
68
69# TODO Change pkcs11 module to be used in pam_pkcs11.conf file
70
71
72# TODO Test this phase of configuration by running pkcs11_inspect
Note: See TracBrowser for help on using the repository browser.