@@ -395,6 +395,14 @@ def ensure_host_sandstorm_folder_exists():
395395 with open (keyring_file , "wb" ) as f :
396396 pass
397397
398+ def confirm_overwrite (filepath , noninteractive ):
399+ if noninteractive :
400+ return True
401+ if os .path .exists (filepath ):
402+ resp = input ("This command will overwrite some existing packaging configuration. Proceed? [y/N]: " ).strip ().lower ()
403+ return resp == 'y'
404+ return True
405+
398406class StackPlugin (object ):
399407 def __init__ (self , plugin_name ):
400408 self ._plugin_name = plugin_name
@@ -603,9 +611,14 @@ def setup_vm(args):
603611
604612 # Copy global setup script to e.g. install and configure sandstorm
605613 global_setup_script_path = os .path .join (sandstorm_dir , "global-setup.sh" )
606- with open (global_setup_script_path , "wb" ) as f :
607- f .write (GLOBAL_SETUP_SCRIPT .encode ("UTF-8" ))
608- os .chmod (global_setup_script_path , 0o755 )
614+ noninteractive = getattr (args , 'noninteractive' , False )
615+ if confirm_overwrite (global_setup_script_path , noninteractive ):
616+ with open (global_setup_script_path , "wb" ) as f :
617+ f .write (GLOBAL_SETUP_SCRIPT .encode ("UTF-8" ))
618+ os .chmod (global_setup_script_path , 0o755 )
619+ else :
620+ print ("Aborted." )
621+ return
609622
610623 # Copy stack-specific script to e.g. install and configure nginx, mysql, and php5-fpm
611624 setup_script_path = os .path .join (sandstorm_dir , "setup.sh" )
@@ -667,9 +680,13 @@ def upgrade_vm(args):
667680 print ("Upgrading VM parameters in {}" .format (sandstorm_dir ))
668681 # Copy global setup script to e.g. install and configure sandstorm
669682 global_setup_script_path = os .path .join (sandstorm_dir , "global-setup.sh" )
670- with open (global_setup_script_path , "wb" ) as f :
671- f .write (GLOBAL_SETUP_SCRIPT .encode ("UTF-8" ))
672- os .chmod (global_setup_script_path , 0o755 )
683+ if confirm_overwrite (global_setup_script_path , noninteractive ):
684+ with open (global_setup_script_path , "wb" ) as f :
685+ f .write (GLOBAL_SETUP_SCRIPT .encode ("UTF-8" ))
686+ os .chmod (global_setup_script_path , 0o755 )
687+ else :
688+ print ("Aborted." )
689+ return
673690 # Copy in Vagrantfile
674691 vagrantfile_path = os .path .join (sandstorm_dir , "Vagrantfile" )
675692 with open (vagrantfile_path , "w" ) as f :
@@ -688,14 +705,19 @@ def bring_up_vm(args):
688705
689706def init (args ):
690707 sandstorm_dir = os .path .join (args .work_directory , ".sandstorm" )
691- # Figure out which stack created this runtime, so we can load appropriate additional init args.
692- stack_path = os .path .join (sandstorm_dir , "stack" )
693- with open (stack_path ) as f :
694- stack = f .read ().strip ()
695- stack_plugin = StackPlugin (stack )
696- init_args = stack_plugin .init_args ()
697- # Initialize the package with spk init
698- call_vagrant_command (sandstorm_dir , "ssh" , "-c" , "spk init -p 8000 --keyring=/host-dot-sandstorm/sandstorm-keyring --output=/opt/app/.sandstorm/sandstorm-pkgdef.capnp {} -- /bin/bash /opt/app/.sandstorm/launcher.sh" .format (init_args ))
708+ pkgdef_path = os .path .join (sandstorm_dir , "sandstorm-pkgdef.capnp" )
709+ if confirm_overwrite (pkgdef_path , noninteractive ):
710+ # Figure out which stack created this runtime, so we can load appropriate additional init args.
711+ stack_path = os .path .join (sandstorm_dir , "stack" )
712+ with open (stack_path ) as f :
713+ stack = f .read ().strip ()
714+ stack_plugin = StackPlugin (stack )
715+ init_args = stack_plugin .init_args ()
716+ # Initialize the package with spk init
717+ call_vagrant_command (sandstorm_dir , "ssh" , "-c" , "spk init -p 8000 --keyring=/host-dot-sandstorm/sandstorm-keyring --output=/opt/app/.sandstorm/sandstorm-pkgdef.capnp {} -- /bin/bash /opt/app/.sandstorm/launcher.sh" .format (init_args ))
718+ else :
719+ print ("Aborted." )
720+ return
699721
700722def dev (args ):
701723 sandstorm_dir = os .path .join (args .work_directory , ".sandstorm" )
@@ -1006,6 +1028,7 @@ def main():
10061028 help = "Use this working directory (e.g. for .sandstorm/ \n "
10071029 "and other configuration). [Default: current \n "
10081030 "working directory]" )
1031+ parser .add_argument ('--noninteractive' , action = 'store_true' , help = 'Suppress overwrite prompts (use in scripts)' )
10091032 args = parser .parse_args (sys .argv [1 :])
10101033 operation = op_to_func [args .command ]
10111034 operation (args )
0 commit comments