Skip to content

Commit c0ec0ac

Browse files
committed
Minor changes for error output
Turns out you can't use symlinks for the sign-file binary either, I'll update the readme
1 parent 9b354cd commit c0ec0ac

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

module-signing-script.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@
7070
'''Global flag for debuging print statements, set by -debug/--debug'''
7171

7272
#Helper methods called by other methods
73-
def handleError (errorMessage: str, exitCode: int, exception: Exception = None):
73+
def handleError (errorMessage: str, exitCode: int, exception: Exception = None, commandExitCode: int = 0):
7474
'''
7575
Error handling function which displays a message, prints an exception (if provided), and exits with an exit code (void).
7676
7777
errorMessage (str): The message to display before exiting
7878
exitCode (int): The code to exit with
7979
exception (Exception) (optional): The exception to print
80+
commandExitCode (int) (optional): The exit code of the command that caused the error
8081
8182
Script Exit codes
8283
- 0: Success, normal exit code
@@ -92,6 +93,10 @@ def handleError (errorMessage: str, exitCode: int, exception: Exception = None):
9293
exitCodes = ['Success, normal exit', 'Package manager not found', 'Unable to sign a kernel module', 'Unable to extract kernel version string', 'Cannot open modules JSON file', 'Modules JSON content is malformed', 'Cannot access modules directory', 'Cannot build akmods for kernel']
9394

9495
print (__title__ + ': Error: ' + errorMessage)
96+
97+
if commandExitCode != 0:
98+
print ('Last command exited with code %d' %commandExitCode)
99+
95100
print ()
96101

97102
if exception != None:
@@ -104,7 +109,7 @@ def handleError (errorMessage: str, exitCode: int, exception: Exception = None):
104109

105110
def executeCommandWithOutput (commandName: str, commandArgs: list = []) -> str:
106111
'''
107-
Fetches a process output and decodes it as a utf-8 string (by default) (str)
112+
Fetches a process output, decodes it as a utf-8 string (by default), and returns it (str)
108113
109114
commandName (str): The name of the command to run
110115
commandArgs (list <string>) (optional): The arguments to supply to the command (-r, etc)
@@ -307,8 +312,9 @@ def signKernel (kernel: str, moduleEntries: list, privateKeyPath: str, publicKey
307312
if DEBUG:
308313
print ('Signing kernel module: %s' %moduleFile)
309314

310-
if executeCommandWithExitStatus ('sudo', [SIGN_BINARY_PATH, 'sha256', privateKeyPath, publicKeyPath, moduleFile]) != 0:
311-
handleError ('Error signing kernel module: %s (Check your password for sudo, that both your keyfiles have correct paths/exist, and the module entries in your json file)' %moduleFile, 2)
315+
signModuleStatus = executeCommandWithExitStatus ('sudo', [SIGN_BINARY_PATH, 'sha256', privateKeyPath, publicKeyPath, moduleFile])
316+
if signModuleStatus != 0:
317+
handleError (errorMessage = 'Error signing kernel module: %s (Check your password for sudo, that both your keyfiles have correct paths/exist, and the module entries in your json file)' %moduleFile, exitCode = 2, commandExitCode = signModuleStatus)
312318

313319
if DEBUG:
314320
print ()

0 commit comments

Comments
 (0)