From 7845e9461b5030e567340f9397be952c7546e9d7 Mon Sep 17 00:00:00 2001 From: Quinta <0pietroquintavalle0@gmail.com> Date: Sun, 9 Jun 2024 14:42:39 +0200 Subject: [PATCH] Revised Powershell script testing --- Test-ObsidianInstallation.ps1 | 53 ++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/Test-ObsidianInstallation.ps1 b/Test-ObsidianInstallation.ps1 index caaefab..a3b02c6 100644 --- a/Test-ObsidianInstallation.ps1 +++ b/Test-ObsidianInstallation.ps1 @@ -27,7 +27,7 @@ function Test-ObsidianDownload { Write-Output "Simulating download failure..." Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name "ProxyEnable" -Value 1 Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name "ProxyServer" -Value "127.0.0.1:8080" - Start-Sleep -Seconds 5 + Start-Sleep -Seconds 10 # Ensure proxy settings take effect Write-Output "Downloading Obsidian installer..." try { @@ -63,8 +63,59 @@ function Test-InvalidPluginConfig { } } +function Test-ObsidianInstallation { + Write-Output "Testing Obsidian installation..." + + Write-Output "Installing Obsidian for Windows..." + if (-Not (Get-Command choco -ErrorAction SilentlyContinue)) { + Write-Output "Chocolatey is not installed. Installing Chocolatey..." + Set-ExecutionPolicy Bypass -Scope Process -Force; + [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; + $script = (New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1') + Invoke-Command -ScriptBlock ([ScriptBlock]::Create($script)) + } + choco install -y jq + + Write-Output "Downloading Obsidian installer..." + Invoke-WebRequest -Uri "https://github.com/obsidianmd/obsidian-releases/releases/download/v1.6.3/Obsidian.1.6.3.exe" -OutFile "ObsidianInstaller.exe" + + # Check if the installer was downloaded + if (Test-Path "ObsidianInstaller.exe") { + Write-Output "Running Obsidian installer..." + $startProcess = Start-Process -FilePath .\ObsidianInstaller.exe -ArgumentList "/S" -PassThru -Wait + Write-Output "Installer exit code: $($startProcess.ExitCode)" + + # Check for Obsidian executable in possible installation paths + $obsidianPaths = @( + "C:\Program Files\Obsidian\Obsidian.exe", + "$env:LOCALAPPDATA\Programs\Obsidian\Obsidian.exe", + "$env:LOCALAPPDATA\Obsidian\Obsidian.exe" + ) + + $obsidianInstalled = $false + foreach ($path in $obsidianPaths) { + if (Test-Path $path) { + $obsidianInstalled = $true + Write-Output "Obsidian found at $path" + break + } + } + + if ($obsidianInstalled) { + Write-Output "Obsidian installed successfully." + } else { + Write-Output "Obsidian installation failed." + exit 1 + } + } else { + Write-Output "Failed to download Obsidian installer." + exit 1 + } +} + # Run tests Test-AdminPrivilege Test-ChocolateyInstallation Test-ObsidianDownload Test-InvalidPluginConfig +Test-ObsidianInstallation