all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Attila Lendvai <attila@lendvai.name>
To: 50751@debbugs.gnu.org
Cc: Attila Lendvai <attila@lendvai.name>
Subject: [bug#50751] [PATCH 1/2] gnu: python-trezor-agent: Fix key generation with trezor-gpg init
Date: Fri, 24 Sep 2021 13:05:05 +0200	[thread overview]
Message-ID: <20210924110506.4676-1-attila@lendvai.name> (raw)
In-Reply-To: <20210923083045.10372-1-attila@lendvai.name>

Someone with a better understanding of the python infrastructure may be able
to fix it nicer, but it works.

* gnu/packages/finance.scm (trezor-agent): Add comment on why the
undoing of the wrapping is done, and also delete the irrelevant sideffect of
the now undone wrapping.
(python-trezor-agent): Add a patch that changes the python code to handle the
argv[0] changed by the wrapping.
* gnu/packages/patches/trezor-agent-fix-argv0.patch: New file.
---
 gnu/packages/finance.scm                      | 13 +++++++--
 .../patches/trezor-agent-fix-argv0.patch      | 27 +++++++++++++++++++
 2 files changed, 38 insertions(+), 2 deletions(-)
 create mode 100644 gnu/packages/patches/trezor-agent-fix-argv0.patch

diff --git a/gnu/packages/finance.scm b/gnu/packages/finance.scm
index 9b073541de..a123efe207 100644
--- a/gnu/packages/finance.scm
+++ b/gnu/packages/finance.scm
@@ -844,7 +844,8 @@ the Monero GUI client.")
              (commit (string-append "v" version))))
        (file-name (git-file-name name version))
        (sha256
-        (base32 "0q99vbfd3h85s8rnjipnmldixabqmmlk5w9karv6f0rhyi54f4zv"))))
+        (base32 "0q99vbfd3h85s8rnjipnmldixabqmmlk5w9karv6f0rhyi54f4zv"))
+       (patches (search-patches "trezor-agent-fix-argv0.patch"))))
     (build-system python-build-system)
     (arguments
      `(#:phases
@@ -1089,7 +1090,15 @@ the KeepKey Hardware Wallet.")
          (add-after 'wrap 'fixup-agent-py
            (lambda* (#:key inputs outputs #:allow-other-keys)
              (let* ((out (assoc-ref outputs "out")))
-               ;; overwrite the wrapper with the real thing.
+               ;; The wrap phase also wraps trezor_agent.py (besides the
+               ;; public facing executable called trezor-agent). We need to
+               ;; undo that wrapping. The reason this is needed is that the
+               ;; python easy install generates a toplevel script (?) that
+               ;; messes with argv[0] and then re-opens the python
+               ;; module. This fails when the wrapped file is actually a shell
+               ;; script, not a python file.
+               (delete-file (string-append out "/bin/.trezor_agent.py-real"))
+               ;; Overwrite the wrapped one with the real thing.
                (install-file "./trezor_agent.py"
                              (string-append out "/bin"))
              #t))))))
diff --git a/gnu/packages/patches/trezor-agent-fix-argv0.patch b/gnu/packages/patches/trezor-agent-fix-argv0.patch
new file mode 100644
index 0000000000..9462067cd5
--- /dev/null
+++ b/gnu/packages/patches/trezor-agent-fix-argv0.patch
@@ -0,0 +1,27 @@
+diff --git a/libagent/gpg/__init__.py b/libagent/gpg/__init__.py
+index 3711bc8..67085de 100644
+--- a/libagent/gpg/__init__.py
++++ b/libagent/gpg/__init__.py
+@@ -122,15 +122,19 @@ def run_init(device_type, args):
+     verify_gpg_version()
+ 
+     # Prepare new GPG home directory for hardware-based identity
+-    device_name = os.path.basename(sys.argv[0]).rsplit('-', 1)[0]
+-    log.info('device name: %s', device_name)
++    exe_name = os.path.basename(sys.argv[0])
++    # drop the Guix wrapper's dot prefix from the name
++    if exe_name[0] == '.' and exe_name.endswith('-real'):
++        exe_name = exe_name[1:-5:]
++    device_name = exe_name.rsplit('-', 1)[0]
++    log.info('exe name: %s, device name: %s', exe_name, device_name)
+     homedir = args.homedir
+     if not homedir:
+         homedir = os.path.expanduser('~/.gnupg/{}'.format(device_name))
+ 
+     log.info('GPG home directory: %s', homedir)
+ 
+-    if os.path.exists(homedir):
++    if os.path.exists(homedir) and not args.subkey:
+         log.error('GPG home directory %s exists, '
+                   'remove it manually if required', homedir)
+         sys.exit(1)
-- 
2.33.0





  parent reply	other threads:[~2021-09-24 11:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-23  8:30 [bug#50751] [PATCH] gnu: update Trezor support Attila Lendvai
2021-09-23 18:35 ` Sarah Morgensen
2021-09-24 11:05   ` Attila Lendvai
2021-09-24 11:05 ` Attila Lendvai [this message]
2021-09-24 11:05   ` [bug#50751] [PATCH 2/2] " Attila Lendvai
2021-11-28 20:35     ` bug#50751: " Nicolas Goaziou
2021-11-28 20:34   ` [bug#50751] [PATCH 1/2] gnu: python-trezor-agent: Fix key generation with trezor-gpg init Nicolas Goaziou
2021-11-30 20:51     ` Attila Lendvai
2021-12-01 15:34       ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210924110506.4676-1-attila@lendvai.name \
    --to=attila@lendvai.name \
    --cc=50751@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.