vamp-mcp 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/README.md +23 -9
  2. package/bin/vamp-mcp.mjs +1 -1
  3. package/package.json +1 -1
  4. package/runtime/backends/kvm/debian-preseed.cfg +35 -0
  5. package/runtime/backends/remote_ssh/server.mjs +279 -8
  6. package/runtime/backends/virtualbox/provision.py +69 -21
  7. package/runtime/backends/virtualbox/server.mjs +390 -50
  8. package/runtime/guest_setup/http/postdeb.sh +47 -0
  9. package/runtime/guest_setup/http/postwin.ps1 +28 -0
  10. package/runtime/guest_setup/http/setup-all.ps1 +25 -0
  11. package/runtime/guest_setup/http/setup-win.cmd +7 -0
  12. package/runtime/guest_setup/http/setup.ps1 +29 -0
  13. package/runtime/guest_setup/http/setup.sh +50 -0
  14. package/runtime/guest_setup/kvm/setup-debian.sh +73 -0
  15. package/runtime/guest_setup/kvm/setup-windows.ps1 +52 -0
  16. package/runtime/guest_setup/recorder/README.txt +4 -0
  17. package/runtime/guest_setup/recorder/recorder.zip +0 -0
  18. package/runtime/guest_setup/recorder/setup-user.py +19 -1
  19. package/runtime/guest_setup/recorder/setup-win.cmd +55 -6
  20. package/runtime/guest_setup/recorder/setup.ps1 +57 -6
  21. package/runtime/guest_setup/recorder/setup.sh +18 -1
  22. package/runtime/guest_setup/requirements.txt +2 -0
  23. package/runtime/guest_setup/setup-all.ps1 +35 -0
  24. package/runtime/guest_setup/setup-all.sh +22 -0
  25. package/runtime/guest_setup/vault/Install-VCRuntime.ps1 +26 -0
  26. package/runtime/guest_setup/vault/setup-guest-vault.ps1 +148 -0
  27. package/runtime/guest_setup/vault/setup-guest-vault.sh +75 -0
  28. package/runtime/scripts/macos/setup-host.sh +126 -0
  29. package/runtime/scripts/remote_host_setup.sh +7 -4
  30. package/runtime/scripts/script_server.py +517 -0
@@ -8,18 +8,21 @@ import re
8
8
  import shutil
9
9
  import subprocess
10
10
  import sys
11
+ import time
11
12
  import uuid
12
13
 
13
14
  ROOT=Path(__file__).resolve().parents[2]
14
15
  sys.path.insert(0,str(ROOT/'scripts'))
15
16
  sys.path.insert(0,str(Path(__file__).resolve().parent))
16
- from build_recorder_media import build
17
+ from script_server import SCRIPT_SERVER_PORT, guest_commands, start as start_script_server
17
18
 
18
19
  PUBLIC_CREDENTIALS={'username':'vboxuser','password':'password123!','public_sandbox_credentials':True}
19
20
 
21
+
20
22
  def parse(text):
21
23
  return {m[1].strip():m[2].strip() for line in text.splitlines()
22
- if (m:=re.match(r'([^=]+)="?(.*?)"?$',line.strip()))}
24
+ if (m:=re.match(r'([^=]+)=\"?(.*?)\"?$',line.strip()))}
25
+
23
26
 
24
27
  def executable():
25
28
  if os.environ.get('VBOXMANAGE_PATH'): return os.environ['VBOXMANAGE_PATH']
@@ -28,13 +31,33 @@ def executable():
28
31
  if candidate.is_file():return str(candidate)
29
32
  return shutil.which('VBoxManage') or 'VBoxManage'
30
33
 
31
- def create(iso_path,name=None,memory_mb=None,cpus=None,disk_mb=None,basedir=None,image_index=1,product_key='',windows_confirmed=False,guest_os=None,preflight_only=False,allow_manual_install=False):
34
+
35
+ def assert_no_active_kvm():
36
+ if not sys.platform.startswith('linux'):return
37
+ for uri in ('qemu:///session','qemu:///system'):
38
+ try:
39
+ result=subprocess.run(['virsh','-c',uri,'list','--name'],capture_output=True,text=True,timeout=10)
40
+ except (FileNotFoundError,subprocess.TimeoutExpired):continue
41
+ if result.returncode==0 and result.stdout.strip():
42
+ raise RuntimeError('A KVM VM is active. Shut it down before starting VirtualBox; simultaneous execution can cause VERR_SVM_IN_USE.')
43
+
44
+
45
+ def post_install_command(guest_os, base_url):
46
+ """Post-install hook fetched from the host script server; no ISO is rewritten or mounted."""
47
+ if guest_os=='windows11':
48
+ return f'powershell -ExecutionPolicy Bypass -Command "irm {base_url}/postwin.ps1 | iex"'
49
+ return f'wget -qO /tmp/vamp-postdeb.sh {base_url}/postdeb.sh && sh /tmp/vamp-postdeb.sh'
50
+
51
+
52
+ def create(iso_path,name=None,memory_mb=None,cpus=None,disk_mb=None,basedir=None,image_index=1,product_key='',windows_confirmed=False,guest_os=None,preflight_only=False,allow_manual_install=False,installation_mode="auto",serve_scripts=True,script_server_ttl=3600):
53
+ if installation_mode not in ('auto','manual'):raise ValueError('installation_mode must be auto or manual')
32
54
  name=name or ('VAMP-'+uuid.uuid4().hex[:8])
33
55
  if not re.fullmatch(r'[A-Za-z0-9][A-Za-z0-9_-]{0,63}',name):raise ValueError('Use 1-64 letters/digits/underscore/hyphen for name')
34
56
  iso=Path(iso_path).expanduser().resolve(strict=True)
35
57
  if not iso.is_file():raise ValueError('ISO path must be a readable local file on the VM host')
36
58
  journal={'status':'preparing','vm':name,'credentials':PUBLIC_CREDENTIALS,'events':[],
37
- 'installation_verified':False,'recorder_installed_verified':False}
59
+ 'installation_verified':False,'recorder_installed_verified':False,
60
+ 'guest_setup_transport':f'http://10.0.2.2:{SCRIPT_SERVER_PORT} (host Python script server)'}
38
61
  folder=Path(basedir or Path.home()/'VirtualBox VMs').expanduser().resolve()/name
39
62
  def run(*args,timeout=120):
40
63
  proc=subprocess.run([executable(),*map(str,args)],capture_output=True,text=True,timeout=timeout)
@@ -52,6 +75,7 @@ def create(iso_path,name=None,memory_mb=None,cpus=None,disk_mb=None,basedir=None
52
75
  if not (re.fullmatch(r'Debian[0-9]*_64',os_type) or re.fullmatch(r'Ubuntu[0-9]*_64',os_type) or os_type=='Windows11_64'):
53
76
  raise ValueError(f'Only detected Debian/Ubuntu amd64 or Windows11 x64 ISO supported by this initial profile: {os_type or "unknown"}')
54
77
  unattended_supported=detected.get('IsInstallSupported',detected.get('isInstallSupported','true')).lower() in ('true','1','yes','on')
78
+ if installation_mode=='manual':unattended_supported=False
55
79
  if not unattended_supported and not allow_manual_install:
56
80
  raise ValueError('VirtualBox reports this ISO does not support unattended installation')
57
81
  selected='windows11' if os_type=='Windows11_64' else ('ubuntu' if os_type.startswith('Ubuntu') else 'debian')
@@ -67,6 +91,7 @@ def create(iso_path,name=None,memory_mb=None,cpus=None,disk_mb=None,basedir=None
67
91
  'resource_profile':{'memory_mb':memory_mb,'cpus':cpus,'disk_mb':disk_mb},
68
92
  'windows_confirmation_required':selected=='windows11' and not windows_confirmed,
69
93
  'installation_mode':'unattended' if unattended_supported else 'manual',
94
+ 'guest_setup':{'transport':'http','port':SCRIPT_SERVER_PORT,'commands':guest_commands(SCRIPT_SERVER_PORT)},
70
95
  'credentials':PUBLIC_CREDENTIALS,'iso':str(iso)}
71
96
  if selected=='windows11' and not windows_confirmed:
72
97
  return {'status':'needs_windows_confirmation','no_vm_created':True,'profile':profile,
@@ -82,14 +107,36 @@ def create(iso_path,name=None,memory_mb=None,cpus=None,disk_mb=None,basedir=None
82
107
  help_proc=subprocess.run([executable(),'unattended','install','--help'],capture_output=True,text=True)
83
108
  help_text=help_proc.stdout+help_proc.stderr
84
109
  password_flag='--user-password' if '--user-password' in help_text else '--password'
110
+ assert_no_active_kvm()
85
111
  folder.mkdir(parents=True,exist_ok=False)
86
112
  journal_path=folder/'vamp-install.json'
113
+ def start_verified():
114
+ # startvm waits for its session to open; still verify the hypervisor state.
115
+ run('startvm',name,'--type','headless')
116
+ state=''
117
+ for attempt in range(15):
118
+ state=parse(run('showvminfo',name,'--machinereadable')).get('VMState','unknown')
119
+ if state=='running':
120
+ journal.update(vm_state=state,startup_verified=True)
121
+ return
122
+ if state not in ('starting','restoring'):break
123
+ time.sleep(1)
124
+ raise RuntimeError(f'VM creation completed but startup was not verified (state: {state}); inspect the VM log')
87
125
  def record(stage):
88
126
  journal['events'].append(stage)
89
127
  journal_path.write_text(json.dumps(journal,indent=2)+'\n')
128
+ script_server=None
129
+ if serve_scripts and not os.environ.get('VAMP_SCRIPT_SERVER_DISABLE'):
130
+ try:
131
+ script_server=start_script_server(port=SCRIPT_SERVER_PORT,ttl=script_server_ttl)
132
+ except Exception as exc:
133
+ script_server={'status':'failed','port':SCRIPT_SERVER_PORT,'error':str(exc)}
134
+ journal['script_server']=script_server
135
+ if script_server.get('status')!='running':
136
+ journal['script_server_warning']=('Guest setup scripts are not being served. Start them with '
137
+ f'"python3 scripts/script_server.py start" before the guest runs its post-install step ({script_server.get("error","unknown error")}).')
138
+ base_url=(script_server or {}).get('guest_urls',{}).get('virtualbox_nat') or f'http://10.0.2.2:{SCRIPT_SERVER_PORT}'
90
139
  try:
91
- media=build(folder/'recorder-setup.iso')
92
- record('recorder-media-built')
93
140
  run('createvm','--name',name,'--ostype',os_type,'--register','--basefolder',folder.parent)
94
141
  record('vm-created')
95
142
  from display import preferences
@@ -108,30 +155,30 @@ def create(iso_path,name=None,memory_mb=None,cpus=None,disk_mb=None,basedir=None
108
155
  run('storagectl',name,'--name','IDE','--add','ide')
109
156
  if not unattended_supported:
110
157
  run('storageattach',name,'--storagectl','SATA','--port','1','--device','0','--type','dvddrive','--medium',iso)
111
- run('startvm',name,'--type','separate')
158
+ start_verified()
112
159
  journal.update(status='installation_started',installation_mode='manual',os_type=os_type,
113
- frontend='separate',journal=str(journal_path),
160
+ frontend='headless',journal=str(journal_path),
114
161
  credentials={'public_sandbox_credentials':False,'account_setup':'Choose your account in the OS installer'},
115
- action_required='This ISO needs manual installation. Follow the installer in the VM screen. Choose your own guest account; automatic recorder setup has not run.')
162
+ action_required=(f'This ISO needs a manual installation: complete the stock installer in the VM screen, '
163
+ f'choose your own guest account, then run the guest setup command from '
164
+ f'http://10.0.2.2:{SCRIPT_SERVER_PORT}/ (for example '
165
+ f'"wget -qO- {base_url}/setup.sh | sh"). No ISO was rewritten and no automatic account or recorder setup ran.'))
116
166
  record('manual-installation-started')
117
167
  return journal
118
- # Recorder media stays on a dedicated DVD; unattended owns its own installer/auxiliary slots.
119
- run('storageattach',name,'--storagectl','SATA','--port','3','--device','0','--type','dvddrive','--medium',media['iso'])
120
168
  if os_type=='Windows11_64':
121
169
  from display import insert_additions
122
170
  journal['guest_additions']=insert_additions(name,run=run)
123
- hook='cmd.exe /c "for %%D in (D E F G H I J K L M N O P) do @if exist %%D:\\postwin.cmd call %%D:\\postwin.cmd"'
124
- else:
125
- hook="sh -c 'mkdir -p /tmp/vamp-recorder; for d in /dev/sr*; do mount -o ro \"$d\" /tmp/vamp-recorder 2>/dev/null || continue; if [ -f /tmp/vamp-recorder/postdeb.sh ]; then sh /tmp/vamp-recorder/postdeb.sh; exit $?; fi; umount /tmp/vamp-recorder; done; exit 1'"
126
- args=['unattended','install',name,'--iso',iso,'--user','vboxuser',password_flag,'password123!',
171
+ install_args=['unattended','install',name,'--iso',iso,'--user','vboxuser',password_flag,'password123!',
127
172
  '--full-user-name','VAMP Sandbox User','--hostname',name.lower()+'.vamp.local',
128
- '--no-install-additions','--post-install-command',hook,'--start-vm','separate']
173
+ '--no-install-additions','--post-install-command',post_install_command(selected,base_url)]
129
174
  if os_type=='Windows11_64':
130
- args+=['--image-index',image_index]
131
- if product_key:args+=['--key',product_key]
132
- run(*args,timeout=300)
133
- journal.update(status='installation_started',installation_mode='unattended',os_type=os_type,frontend='separate',
134
- recorder_setup='Debian postinstall; Windows first desktop login',
175
+ install_args+=['--image-index',image_index]
176
+ if product_key:install_args+=['--key',product_key]
177
+ run(*install_args,timeout=300)
178
+ start_verified()
179
+ journal.update(status='installation_started',installation_mode='unattended',os_type=os_type,frontend='headless',
180
+ recorder_setup=f'First login downloads the setup bundle from the host script server on port {SCRIPT_SERVER_PORT}',
181
+ guest_setup_command=f'wget -qO- {base_url}/setup.sh | sh' if selected!='windows11' else f'irm {base_url}/setup.ps1 | iex',
135
182
  requires_ai_loop=False,journal=str(journal_path))
136
183
  record('unattended-installation-started')
137
184
  return journal
@@ -140,6 +187,7 @@ def create(iso_path,name=None,memory_mb=None,cpus=None,disk_mb=None,basedir=None
140
187
  record('failed')
141
188
  raise RuntimeError(f'{exc}; partial setup preserved at {folder}') from exc
142
189
 
190
+
143
191
  if __name__=='__main__':
144
192
  parser=argparse.ArgumentParser(description=__doc__)
145
193
  parser.add_argument('--json-stdin',action='store_true',required=True)