Browse Source

autosign: new `macos_ramdisk_setup`, `macos_ramdisk_delete` ops

The MMGen Project 6 months ago
parent
commit
0036d0cae9
4 changed files with 24 additions and 4 deletions
  1. 6 3
      mmgen/autosign.py
  2. 1 1
      mmgen/data/version
  3. 14 0
      mmgen/main_autosign.py
  4. 3 0
      mmgen/platform/darwin/util.py

+ 6 - 3
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)

+ 1 - 1
mmgen/data/version

@@ -1 +1 @@
-15.0.dev5
+15.0.dev6

+ 14 - 0
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':

+ 3 - 0
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: