From 0036d0cae975457779c431fdc96d73b09e4ae149 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 4 Sep 2024 13:08:52 +0000 Subject: [PATCH] autosign: new `macos_ramdisk_setup`, `macos_ramdisk_delete` ops --- mmgen/autosign.py | 9 ++++++--- mmgen/data/version | 2 +- mmgen/main_autosign.py | 14 ++++++++++++++ mmgen/platform/darwin/util.py | 3 +++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/mmgen/autosign.py b/mmgen/autosign.py index 691c195a..06b10089 100755 --- a/mmgen/autosign.py +++ b/mmgen/autosign.py @@ -612,6 +612,12 @@ class Autosign: if not no_unmount: self.do_umount() + def macos_ramdisk_setup(self): + self.ramdisk.create() + + def macos_ramdisk_delete(self): + self.ramdisk.destroy() + def _get_macOS_ramdisk_size(self): from .platform.darwin.util import MacOSRamDisk, warn_ramdisk_too_small # allow 1MB for each Monero wallet @@ -648,9 +654,6 @@ class Autosign: except: die(2,f"Unable to create wallet directory '{self.wallet_dir}'") - if sys.platform == 'darwin': - self.ramdisk.create() - remove_wallet_dir() create_wallet_dir() self.gen_key(no_unmount=True) diff --git a/mmgen/data/version b/mmgen/data/version index 921bb519..d8529835 100644 --- a/mmgen/data/version +++ b/mmgen/data/version @@ -1 +1 @@ -15.0.dev5 +15.0.dev6 diff --git a/mmgen/main_autosign.py b/mmgen/main_autosign.py index 8d621b30..5fcf873b 100755 --- a/mmgen/main_autosign.py +++ b/mmgen/main_autosign.py @@ -20,6 +20,8 @@ autosign: Auto-sign MMGen transactions, message files and XMR wallet output files """ +import sys + from .util import msg,die,fmt_list,exit_if_mswin,async_run exit_if_mswin('autosigning') @@ -70,6 +72,10 @@ setup - full setup: run ‘gen_key’ and create temporary signing wallet(s) for all configured coins xmr_setup - set up Monero temporary signing wallet(s). Not required in normal operation: use ‘setup’ with --xmrwallets instead +macos_ramdisk_setup - set up the ramdisk used for storing the temporary signing + wallet(s) (macOS only). Required only when creating the wallet(s) + manually, without ‘setup’ +macos_ramdisk_delete - delete the macOS ramdisk wait - start in loop mode: wait-mount-sign-unmount-wait wipe_key - wipe the wallet encryption key on the removable device, making signing transactions or stealing the user’s seed impossible. @@ -189,6 +195,8 @@ valid_cmds = ( 'gen_key', 'setup', 'xmr_setup', + 'macos_ramdisk_setup', + 'macos_ramdisk_delete', 'sign', 'wait', 'clean', @@ -214,6 +222,8 @@ cfg._post_init() if cmd == 'gen_key': asi.gen_key() elif cmd == 'setup': + if sys.platform == 'darwin': + asi.macos_ramdisk_setup() asi.setup() from .ui import keypress_confirm if cfg.xmrwallets and keypress_confirm( cfg, '\nContinue with Monero setup?', default_yes=True ): @@ -226,6 +236,10 @@ elif cmd == 'xmr_setup': asi.do_mount() asi.xmr_setup() asi.do_umount() +elif cmd.startswith('macos_ramdisk'): + if sys.platform != 'darwin': + die(1, f'The ‘{cmd}’ operation is for the macOS platform only') + getattr(asi, cmd)() elif cmd == 'sign': main(do_loop=False) elif cmd == 'wait': diff --git a/mmgen/platform/darwin/util.py b/mmgen/platform/darwin/util.py index 09aeb2c4..081de926 100755 --- a/mmgen/platform/darwin/util.py +++ b/mmgen/platform/darwin/util.py @@ -82,6 +82,9 @@ class MacOSRamDisk: run(['diskutil', 'mount', '-mountPoint', str(self.path.absolute()), self.label], stdout=redir, check=True) def destroy(self, quiet=False): + if not self.exists(): + self.cfg._util.qmsg(f'{self.desc.capitalize()} {self.label.hl()} at path {self.path} not found') + return redir = DEVNULL if quiet else None run(['diskutil', 'eject', self.label], stdout=redir, check=True) if not quiet: