Skip to content

misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux

Lab VM scripts read the VM account like deploy.ps1 (#283)

Ahmed Nefzaoui9216ba9fe31e
diff --git a/tools/lab/linux-vm/shot-host.sh b/tools/lab/linux-vm/shot-host.sh
index 0e0c2e1e..22708f94 100644
--- a/tools/lab/linux-vm/shot-host.sh
+++ b/tools/lab/linux-vm/shot-host.sh
@@ -5,7 +5,13 @@
# MDM_STATE (a saved downloads.json in the guest) and MDM_SEEN (extension-seen lines) pass through
# to shots.sh. MDM_VM_USER / MDM_VM_PASSWORD as for vm.ps1.
V="${VBOXMANAGE:-/c/Program Files/Oracle/VirtualBox/VBoxManage.exe}"
-user=${MDM_VM_USER:-mdm}; pass=${MDM_VM_PASSWORD:-mdm123456789}
+user=${MDM_VM_USER:-mdm}; pass=${MDM_VM_PASSWORD:-}
+keys="${USERPROFILE:-$HOME}/.mdm-dev/vm-account.txt"
+if [ -z "$pass" ] && [ -f "$keys" ]; then
+ pass=$(sed -n 's/^[[:space:]]*password:[[:space:]]*//p' "$keys" | head -1 | tr -d ' ')
+ [ -n "${MDM_VM_USER:-}" ] || user=$(sed -n 's/^[[:space:]]*user:[[:space:]]*//p' "$keys" | head -1 | tr -d ' ')
+fi
+[ -n "$pass" ] || { echo "no VM account: set MDM_VM_USER and MDM_VM_PASSWORD" >&2; exit 1; }
vm=$1; out=$6
geo=$(MSYS_NO_PATHCONV=1 "$V" guestcontrol "$vm" run --exe /bin/bash --username "$user" --password "$pass" --timeout 150000 --wait-stdout -- \
-c "MDM_STATE=${MDM_STATE:-} MDM_SEEN='${MDM_SEEN:-}' bash /home/$user/lab/shots.sh $2 $3 $4 $5" 2>/dev/null | tail -1)
diff --git a/tools/lab/linux-vm/vm.ps1 b/tools/lab/linux-vm/vm.ps1
index a6344f63..0aba5999 100644
--- a/tools/lab/linux-vm/vm.ps1
+++ b/tools/lab/linux-vm/vm.ps1
@@ -48,7 +48,7 @@ doesn't exist yet): a live snapshot saves the whole memory, and under Hyper-V (V
mode, "VT-x is not available") it stalled with an empty .sav file and had to be killed.
The VM's name, user and password come from MDM_VM, MDM_VM_USER and MDM_VM_PASSWORD (defaults:
-mdm-ubuntu, mdm, and the lab's throwaway password). Commands run with the desktop session's
+mdm-ubuntu and mdm; the password has no default). Commands run with the desktop session's
DISPLAY and D-Bus, so GUI programs open on the VM's screen.
#>
param(
@@ -64,7 +64,16 @@ $ErrorActionPreference = 'Stop'
$vbox = Join-Path $env:ProgramFiles 'Oracle\VirtualBox\VBoxManage.exe'
$vm = if ($env:MDM_VM) { $env:MDM_VM } else { 'mdm-ubuntu' }
$user = if ($env:MDM_VM_USER) { $env:MDM_VM_USER } else { 'mdm' }
-$pass = if ($env:MDM_VM_PASSWORD) { $env:MDM_VM_PASSWORD } else { 'mdm123456789' }
+$pass = $env:MDM_VM_PASSWORD
+# Or the developer key folder's vm-account.txt ("user: <name>" and "password: <word>" lines).
+$keys = Join-Path $env:USERPROFILE '.mdm-dev\vm-account.txt'
+if (-not $pass -and (Test-Path $keys)) {
+ foreach ($line in Get-Content $keys) {
+ if (-not $env:MDM_VM_USER -and $line -match '^\s*user:\s*(\S+)') { $user = $Matches[1] }
+ if ($line -match '^\s*password:\s*(\S+)') { $pass = $Matches[1] }
+ }
+}
+if (-not $pass) { throw "no VM account: set MDM_VM_USER and MDM_VM_PASSWORD" }
$auth = @('--username', $user, '--password', $pass)
function Invoke-Guest([string] $Command, [string] $On = $vm) {