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

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

Started back-end development
Added methods for package installation

File size: 1.8 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 is installed and False otherwise
16    '''
17    if not hasPackage(packageName):
18        # install package
19        print("DEBUG: need to install", packageName, file=sys.stderr)
20        command = "apt-get install " + packageName
21        try:
22            subprocess.check_call(command, shell=True, stdout=open(os.devnull, "wb"), stderr=sys.stdout)
23        except subprocess.CalledProcessError as error:
24            print("DEBUG: ", error, file=sys.stderr)
25        else:
26            print("DEBUG:", packageName, "installed", file=sys.stderr)
27
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)
37    try:
38        subprocess.check_output("grep Status", shell=True, stdin=proc.stdout)
39    except subprocess.CalledProcessError as error:
40        print("DEBUG:", error, file=sys.stderr)
41        return False
42    else:
43        return True
44
45
46installPackage(PAMPKCS11_PACKAGE)
47installPackage("hello1")
48
49# TODO Create directories to support configuration files
50
51
52# TODO Copy certificate files to cacerts directory
53
54
55# TODO Get crl file from web link
56
57
58# TODO Generate pam_pkcs11.conf file
59
60
61# TODO Add portuguese CC module to pam_pkcs11.conf file
62
63
64# TODO Change pkcs11 module to be used in pam_pkcs11.conf file
65
66
67# TODO Test this phase of configuration by running pkcs11_inspect
Note: See TracBrowser for help on using the repository browser.