-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Nitrokey Start upgrade process #255
base: master
Are you sure you want to change the base?
Changes from all commits
dab337a
a0aa8de
e4ac7a3
a489cb4
88bbbf4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,9 @@ | |
# http://opensource.org/licenses/MIT>, at your option. This file may not be | ||
# copied, modified, or distributed except according to those terms. | ||
|
||
|
||
import fnmatch | ||
import os | ||
import os.path | ||
from subprocess import check_output | ||
from sys import stderr, stdout | ||
from time import sleep | ||
|
@@ -16,7 +18,7 @@ | |
from tqdm import tqdm | ||
from usb.core import USBError | ||
|
||
from pynitrokey.helpers import local_critical, local_print | ||
from pynitrokey.helpers import confirm_keyboard_interrupt, local_critical, local_print | ||
from pynitrokey.start.gnuk_token import get_gnuk_device | ||
from pynitrokey.start.threaded_log import ThreadLog | ||
from pynitrokey.start.upgrade_by_passwd import ( | ||
|
@@ -164,6 +166,12 @@ def set_identity(identity): | |
default=False, | ||
help="Use firmware for early 'Nitrokey Start' key hardware revisions", | ||
) | ||
@click.option( | ||
"--force", | ||
is_flag=True, | ||
default=False, | ||
help="Execute the firmware update even if environment sanity checks fail", | ||
) | ||
def update( | ||
regnual, | ||
gnuk, | ||
|
@@ -175,9 +183,24 @@ def update( | |
yes, | ||
skip_bootloader, | ||
green_led, | ||
force, | ||
): | ||
"""update device's firmware""" | ||
|
||
if not find_udev_rules(): | ||
if force: | ||
local_print( | ||
"Warning: Could not find Nitrokey udev rules but will continue anyway as --force is set." | ||
) | ||
else: | ||
local_critical( | ||
"Failed to find Nitrokey udev rules. These udev rules are required for the update.", | ||
"Please see the nitropy documentation for information on installing these rules:", | ||
" https://docs.nitrokey.com/software/nitropy/linux/udev.html", | ||
"If you want to continue anyway, you can use the --force option.", | ||
support_hint=False, | ||
) | ||
|
||
args = ( | ||
regnual, | ||
gnuk, | ||
|
@@ -198,11 +221,28 @@ def update( | |
"use one from: https://github.com/Nitrokey/nitrokey-start-firmware)", | ||
) | ||
|
||
if IS_LINUX: | ||
with ThreadLog(logger.getChild("dmesg"), "dmesg -w"): | ||
with confirm_keyboard_interrupt("Cancelling the update may brick your device."): | ||
if IS_LINUX: | ||
with ThreadLog(logger.getChild("dmesg"), "dmesg -w"): | ||
start_update(*args) | ||
else: | ||
start_update(*args) | ||
else: | ||
start_update(*args) | ||
|
||
|
||
def find_udev_rules() -> bool: | ||
dirs = [ | ||
"/usr/lib/udev/rules.d", | ||
"/usr/local/lib/udev/rules.d", | ||
"/run/udev/rules.d", | ||
"/etc/udev/rules.d", | ||
] | ||
for d in dirs: | ||
if os.path.isdir(d): | ||
for name in os.listdir(d): | ||
if fnmatch.fnmatch(name, "??-nitrokey.rules"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIR using anything starting with number over |
||
logger.info(f"Found matching udev file at {os.path.join(d, name)}") | ||
return True | ||
return False | ||
|
||
|
||
@click.command() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed when testing my (unrelated) changes on top this PR - there is an udev-related advice in
local_critical()
, which seems to be redundant now, so probably should be removed.GH review functionality doesn't allow me to attach a comment to an unchanged line, so putting it here. The line I'm talking about is:
f"- Please check if you have udev rules installed: {UDEV_URL}"