From d4d5f09826cc462464d99f8539f86ceac7de8c08 Mon Sep 17 00:00:00 2001 From: DeFlanko Date: Thu, 26 Dec 2024 11:25:52 -0800 Subject: [PATCH 1/7] Update install_latest_blue_onyx.ps1 Updated install options to include a popup folder selection to install the app. Added 4th bat file for Large models. Updated final color script to break up the Green Noise. Signed-off-by: DeFlanko --- install_latest_blue_onyx.ps1 | 110 ++++++++++++++++++++++------------- 1 file changed, 71 insertions(+), 39 deletions(-) diff --git a/install_latest_blue_onyx.ps1 b/install_latest_blue_onyx.ps1 index 5d58ea9..34de13b 100644 --- a/install_latest_blue_onyx.ps1 +++ b/install_latest_blue_onyx.ps1 @@ -14,7 +14,7 @@ 5. Verifies the ZIP file's integrity using a SHA256 checksum (via regex). 6. Extracts the ZIP into a "temp_unzip" folder inside %USERPROFILE%\.blue-onyx, then flattens it if needed. 7. Copies the new files into %USERPROFILE%\.blue-onyx, overwriting old ones if they exist, without asking permission. - 8. Adds that folder to the PATH (User environment). + 8. Adds that folder to the PATH (System "Machine" environment). 9. Runs "blue_onyx.exe --download-model-path" to download all models into .blue-onyx. 10. Creates .bat files on the user's Desktop with server start / benchmarking / testing commands. #> @@ -50,7 +50,7 @@ try { $versionJsonUrl = "https://github.com/xnorpx/blue-onyx/releases/latest/download/version.json" Write-Host "Downloading version.json from $versionJsonUrl to $versionJsonFile..." Invoke-WebRequest -Uri $versionJsonUrl -OutFile $versionJsonFile -UseBasicParsing -ErrorAction Stop - + if (-not (Test-Path $versionJsonFile)) { throw "Failed to retrieve version.json file from GitHub." } @@ -59,22 +59,22 @@ try { Write-Host "Parsing version.json..." $jsonContent = Get-Content -Path $versionJsonFile -Raw $json = $jsonContent | ConvertFrom-Json - + if (-not $json.version -or -not $json.windows -or -not $json.windows_sha256) { throw "version.json does not contain the required fields (version, windows, windows_sha256)." } - + $zipUrl = "https://github.com/xnorpx/blue-onyx/releases/latest/download/$($json.windows)" $sha256Url = "https://github.com/xnorpx/blue-onyx/releases/latest/download/$($json.windows_sha256)" - + Write-Host "Version: $($json.version)" Write-Host "ZIP URL: $zipUrl" Write-Host "SHA256 URL: $sha256Url" - + # --- 4. Check if ZIP and SHA256 already exist in %TEMP%, else download (cache) --- $zipFile = Join-Path $tempPath $json.windows $sha256File = Join-Path $tempPath $json.windows_sha256 - + if (Test-Path $zipFile) { Write-Host "Found cached ZIP file at $zipFile. Skipping download..." } @@ -82,7 +82,7 @@ try { Write-Host "Downloading ZIP file to $zipFile..." Invoke-WebRequest -Uri $zipUrl -OutFile $zipFile -UseBasicParsing -ErrorAction Stop } - + if (Test-Path $sha256File) { Write-Host "Found cached SHA256 file at $sha256File. Skipping download..." } @@ -90,35 +90,53 @@ try { Write-Host "Downloading SHA256 file to $sha256File..." Invoke-WebRequest -Uri $sha256Url -OutFile $sha256File -UseBasicParsing -ErrorAction Stop } - + # --- 5. Verify the ZIP file's integrity with the SHA256 --- Write-Host "Verifying ZIP file integrity..." $sha256FileContent = Get-Content $sha256File -Raw $pattern = '[A-Fa-f0-9]{64}' # 64 hex characters for a SHA256 hash - + $match = [System.Text.RegularExpressions.Regex]::Match($sha256FileContent, $pattern) if (-not $match.Success) { throw "Could not parse a valid 64-hex SHA256 from the .sha256 file." } $expectedSha256 = $match.Value.ToLower() - + $actualHash = (Get-FileHash -Algorithm SHA256 $zipFile).Hash.ToLower() - + Write-Host "Expected SHA256: $expectedSha256" Write-Host "Actual SHA256: $actualHash" - + if ($expectedSha256 -ne $actualHash) { throw "ZIP file SHA256 does not match expected value!" } Write-Green "SHA256 verification successful." - + # --- 6. Extract the ZIP into a temporary subfolder, then flatten if needed --- - $destinationPath = Join-Path $env:USERPROFILE ".blue-onyx" + + # Get the desired folder from the user using a file dialog + $folderBrowser = New-Object -ComObject Shell.Application + $folder = $folderBrowser.BrowseForFolder(0, "Select Installation Folder, Cancel to install in default location", 0) + if ($folder) { + $destinationPath = Join-Path $folder.Self.Path ".blue-onyx" + } else { + # Handle the case where the user cancels the dialog + Write-Warning "No folder selected, installing in default location." + $destinationPath = Join-Path $env:USERPROFILE ".blue-onyx" + } + if (-not (Test-Path $destinationPath)) { # Create .blue-onyx if it doesn't exist New-Item -ItemType Directory -Path $destinationPath | Out-Null } + # # --- 6. Extract the ZIP into a temporary subfolder, then flatten if needed --- + # $destinationPath = Join-Path $env:USERPROFILE ".blue-onyx" + # if (-not (Test-Path $destinationPath)) { + # # Create .blue-onyx if it doesn't exist + # New-Item -ItemType Directory -Path $destinationPath | Out-Null + # } + # Create a temporary folder under .blue-onyx for unzipping $tempExtractPath = Join-Path $destinationPath "temp_unzip" if (Test-Path $tempExtractPath) { @@ -176,16 +194,16 @@ try { # --- 8. Add that folder to the PATH (for the user environment) --- Write-Host "Adding $destinationPath to User PATH..." - $userPath = [System.Environment]::GetEnvironmentVariable("PATH", "User") - + $userPath = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + if ($userPath -notlike "*$destinationPath*") { if ([string]::IsNullOrEmpty($userPath)) { $newPath = $destinationPath } else { $newPath = "$userPath;$destinationPath" } - - [System.Environment]::SetEnvironmentVariable("PATH", $newPath, "User") + + [System.Environment]::SetEnvironmentVariable("PATH", $newPath, "Machine") # Also update the current session PATH so user can test immediately $env:PATH = "$($env:PATH);$destinationPath" } else { @@ -198,14 +216,16 @@ try { if (-not (Test-Path $exePath)) { throw "Could not find blue_onyx.exe at $exePath. Installation may have failed or the file may be missing." } - # We'll run the exe in a separate process. + # We'll run the exe in a separate process. # This will download models into .blue-onyx folder. & $exePath --download-model-path $destinationPath # --- 10. Create Batch Files on Desktop BEFORE final success text --- - Write-Host "Creating batch files on the Desktop..." + #Write-Host "Creating batch files on the Desktop..." + Write-Host "Creating batch files in the Install folder..." - $desktopPath = [Environment]::GetFolderPath("Desktop") + + #$desktopPath = [Environment]::GetFolderPath("Desktop") # 1. blue_onyx_start_server.bat $startServerContent = @" @@ -214,9 +234,18 @@ try { blue_onyx.exe --port 32168 --gpu-index 0 --log-level info pause "@ - Set-Content -Path (Join-Path $desktopPath "blue_onyx_start_server.bat") -Value $startServerContent -Force + Set-Content -Path (Join-Path $destinationPath "blue_onyx_start_server.bat") -Value $startServerContent -Force + + # 2. blue_onyx_start_server_large_models.bat + $startServerContentLG = @" +:: change --log-level info to --log-level debug for more information +:: add --log-path %temp% to log to file instead +blue_onyx.exe --port 32168 --gpu-index 0 --log-level info --model "$destinationPath\rt-detrv2-x.onnx" +pause +"@ + Set-Content -Path (Join-Path $destinationPath "blue_onyx_start_server_large_models.bat") -Value $startServerContentLG -Force - # 2. blue_onyx_benchmark_my_machine.bat + # 3. blue_onyx_benchmark_my_machine.bat $benchmarkContent = @" ::GPU blue_onyx_benchmark.exe --repeat 100 --save-stats-path . @@ -226,32 +255,35 @@ blue_onyx_benchmark.exe --force-cpu --repeat 100 --save-stats-path . pause "@ - Set-Content -Path (Join-Path $desktopPath "blue_onyx_benchmark_my_machine.bat") -Value $benchmarkContent -Force + Set-Content -Path (Join-Path $destinationPath "blue_onyx_benchmark_my_machine.bat") -Value $benchmarkContent -Force - # 3. test_blue_onyx_server.bat + # 4. test_blue_onyx_server.bat $testServerContent = @" test_blue_onyx.exe --origin http://127.0.0.1:32168 -n 10 --interval 10 pause "@ - Set-Content -Path (Join-Path $desktopPath "test_blue_onyx_server.bat") -Value $testServerContent -Force + Set-Content -Path (Join-Path $destinationPath "test_blue_onyx_server.bat") -Value $testServerContent -Force + + # --- 11. Prompt user to restart shell and exit --- - Write-Green "`nInstallation is complete! Blue Onyx is now installed in:" - Write-Host " $destinationPath" -ForegroundColor Green - - Write-Green "`nDownloaded models into $destinationPath" + Write-Host "`nInstallation is complete! Blue Onyx is now installed in:" -ForegroundColor Green + Write-Host " $destinationPath" -ForegroundColor DarkYellow - Write-Green "`nBatch files created on your Desktop:" - Write-Green " blue_onyx_start_server.bat" - Write-Green " blue_onyx_benchmark_my_machine.bat" - Write-Green " test_blue_onyx_server.bat" + Write-Host "`nDownloaded models into $destinationPath" -ForegroundColor DarkMagenta - Write-Green "`nPlease restart your PowerShell or Command Prompt to ensure the updated PATH is loaded." - Write-Green "`nPlease restart Blue Onyx if this was a reinstall or update." - Write-Green "Done!" + Write-Host "`nBatch files created on your Install Folder:" -ForegroundColor Green + Write-Host " blue_onyx_start_server.bat" -ForegroundColor Yellow + Write-Host " blue_onyx_start_server_large_models.bat" -ForegroundColor Yellow + Write-Host " blue_onyx_benchmark_my_machine.bat" -ForegroundColor Yellow + Write-Host " test_blue_onyx_server.bat" -ForegroundColor Yellow + + Write-Host "`nPlease restart your PowerShell or Command Prompt to ensure the updated PATH is loaded." -ForegroundColor Green + Write-Host "`nPlease restart Blue Onyx if this was a reinstall or update." -ForegroundColor Green + Write-Host "Done!" -ForegroundColor Green } catch { Write-ErrorRed "$($_.Exception.Message)" Write-ErrorRed "Installation failed. Exiting..." exit 1 -} \ No newline at end of file +} From e6bc90f305408513ce0974c4984041fbd490ad28 Mon Sep 17 00:00:00 2001 From: DeFlanko Date: Thu, 26 Dec 2024 12:24:40 -0800 Subject: [PATCH 2/7] Update install_latest_blue_onyx.ps1 Added user inputbox for GPU selection, the value of that selection then gets put into the BAT files. Signed-off-by: DeFlanko --- install_latest_blue_onyx.ps1 | 101 ++++++++++++++++++++++++++--------- 1 file changed, 76 insertions(+), 25 deletions(-) diff --git a/install_latest_blue_onyx.ps1 b/install_latest_blue_onyx.ps1 index 34de13b..20131dc 100644 --- a/install_latest_blue_onyx.ps1 +++ b/install_latest_blue_onyx.ps1 @@ -48,7 +48,7 @@ try { # --- 2. Download version.json into %TEMP% (always) --- $versionJsonFile = Join-Path $tempPath "version.json" $versionJsonUrl = "https://github.com/xnorpx/blue-onyx/releases/latest/download/version.json" - Write-Host "Downloading version.json from $versionJsonUrl to $versionJsonFile..." + Write-Host "Downloading version.json from $versionJsonUrl to $versionJsonFile..." -ForegroundColor Green Invoke-WebRequest -Uri $versionJsonUrl -OutFile $versionJsonFile -UseBasicParsing -ErrorAction Stop if (-not (Test-Path $versionJsonFile)) { @@ -56,7 +56,7 @@ try { } # --- 3. Parse JSON --- - Write-Host "Parsing version.json..." + Write-Host "Parsing version.json..." -ForegroundColor Green $jsonContent = Get-Content -Path $versionJsonFile -Raw $json = $jsonContent | ConvertFrom-Json @@ -67,32 +67,32 @@ try { $zipUrl = "https://github.com/xnorpx/blue-onyx/releases/latest/download/$($json.windows)" $sha256Url = "https://github.com/xnorpx/blue-onyx/releases/latest/download/$($json.windows_sha256)" - Write-Host "Version: $($json.version)" - Write-Host "ZIP URL: $zipUrl" - Write-Host "SHA256 URL: $sha256Url" + Write-Host "Version: $($json.version)" -ForegroundColor Cyan + Write-Host "ZIP URL: $zipUrl" -ForegroundColor Blue + Write-Host "SHA256 URL: $sha256Url" -ForegroundColor Yellow # --- 4. Check if ZIP and SHA256 already exist in %TEMP%, else download (cache) --- $zipFile = Join-Path $tempPath $json.windows $sha256File = Join-Path $tempPath $json.windows_sha256 if (Test-Path $zipFile) { - Write-Host "Found cached ZIP file at $zipFile. Skipping download..." + Write-Host "Found cached ZIP file at $zipFile. Skipping download..." -ForegroundColor Green } else { - Write-Host "Downloading ZIP file to $zipFile..." + Write-Host "Downloading ZIP file to $zipFile..." -ForegroundColor Yellow Invoke-WebRequest -Uri $zipUrl -OutFile $zipFile -UseBasicParsing -ErrorAction Stop } if (Test-Path $sha256File) { - Write-Host "Found cached SHA256 file at $sha256File. Skipping download..." + Write-Host "Found cached SHA256 file at $sha256File. Skipping download..." -ForegroundColor Green } else { - Write-Host "Downloading SHA256 file to $sha256File..." + Write-Host "Downloading SHA256 file to $sha256File..." -ForegroundColor Green Invoke-WebRequest -Uri $sha256Url -OutFile $sha256File -UseBasicParsing -ErrorAction Stop } # --- 5. Verify the ZIP file's integrity with the SHA256 --- - Write-Host "Verifying ZIP file integrity..." + Write-Host "Verifying ZIP file integrity..." -ForegroundColor DarkYellow $sha256FileContent = Get-Content $sha256File -Raw $pattern = '[A-Fa-f0-9]{64}' # 64 hex characters for a SHA256 hash @@ -104,13 +104,13 @@ try { $actualHash = (Get-FileHash -Algorithm SHA256 $zipFile).Hash.ToLower() - Write-Host "Expected SHA256: $expectedSha256" - Write-Host "Actual SHA256: $actualHash" + Write-Host "Expected SHA256: $expectedSha256" -ForegroundColor Yellow + Write-Host "Actual SHA256: $actualHash" -ForegroundColor Yellow if ($expectedSha256 -ne $actualHash) { throw "ZIP file SHA256 does not match expected value!" } - Write-Green "SHA256 verification successful." + Write-Host "SHA256 verification successful." -ForegroundColor Green # --- 6. Extract the ZIP into a temporary subfolder, then flatten if needed --- @@ -121,7 +121,7 @@ try { $destinationPath = Join-Path $folder.Self.Path ".blue-onyx" } else { # Handle the case where the user cancels the dialog - Write-Warning "No folder selected, installing in default location." + Write-Warning "No folder selected, installing in default location." $destinationPath = Join-Path $env:USERPROFILE ".blue-onyx" } @@ -144,7 +144,7 @@ try { } New-Item -ItemType Directory -Path $tempExtractPath | Out-Null - Write-Host "Extracting ZIP contents to $tempExtractPath..." + Write-Host "Extracting ZIP contents to $tempExtractPath..." -ForegroundColor Yellow Expand-Archive -Path $zipFile -DestinationPath $tempExtractPath -Force # Force results into an array so .Count is always valid @@ -161,7 +161,7 @@ try { } # --- 6.5. Check if blue_onyx.exe is running and kill it --- - Write-Host "Checking if blue_onyx.exe is running..." + Write-Host "Checking if blue_onyx.exe is running..." -ForegroundColor Yellow $processName = "blue_onyx" $process = Get-Process -Name $processName -ErrorAction SilentlyContinue @@ -169,7 +169,7 @@ try { Write-Host "$processName.exe is currently running. Attempting to terminate..." try { Stop-Process -Id $process.Id -Force - Write-Green "$processName.exe has been terminated successfully." + Write-Green "$processName.exe has been terminated successfully." -ForegroundColor Green } catch { throw "Failed to terminate $processName.exe. Please close the application manually and retry." @@ -182,18 +182,18 @@ try { } } else { - Write-Host "$processName.exe is not running. Proceeding with installation..." + Write-Host "$processName.exe is not running. Proceeding with installation..." -ForegroundColor Green } # --- 7. Copy new files into .blue-onyx, overwriting if they exist --- - Write-Host "Overwriting existing files in $destinationPath with the new files..." + Write-Host "Overwriting existing files in $destinationPath with the new files..." -ForegroundColor Green Copy-Item -Path (Join-Path $flattenPath '*') -Destination $destinationPath -Recurse -Force # Cleanup the temp_unzip folder Remove-Item -Path $tempExtractPath -Recurse -Force # --- 8. Add that folder to the PATH (for the user environment) --- - Write-Host "Adding $destinationPath to User PATH..." + Write-Host "Adding $destinationPath to User PATH..." -ForegroundColor Green $userPath = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") if ($userPath -notlike "*$destinationPath*") { @@ -211,7 +211,7 @@ try { } # --- 9. Run blue_onyx.exe to download all models --- - Write-Host "Downloading all models into $destinationPath..." + Write-Host "Downloading all models into $destinationPath..." -ForegroundColor DarkMagenta $exePath = Join-Path $destinationPath "blue_onyx.exe" if (-not (Test-Path $exePath)) { throw "Could not find blue_onyx.exe at $exePath. Installation may have failed or the file may be missing." @@ -220,10 +220,61 @@ try { # This will download models into .blue-onyx folder. & $exePath --download-model-path $destinationPath + # Now that we can see all the GPU's identifed when downloading all models. + # Select which GPU blue_onyx will use in bat files. + # Import necessary namespace + # Import necessary namespace + Add-Type -AssemblyName System.Windows.Forms + + # Get a list of available GPUs (replace with your actual GPU detection method) + $gpus = Get-WmiObject Win32_VideoController | Select-Object Name + $gpuNames = $gpus.Name + + # Create a form + $form = New-Object System.Windows.Forms.Form + $form.Text = "Select GPU" + $form.Size = New-Object System.Drawing.Size(400, 250) + $form.StartPosition = 'CenterScreen' + + # Create a label + $label = New-Object System.Windows.Forms.Label + $label.Text = "Select GPU:" + $label.Location = New-Object System.Drawing.Point(20, 20) + $form.Controls.Add($label) + + # Create a combobox + $comboBox = New-Object System.Windows.Forms.ComboBox + $comboBox.Location = New-Object System.Drawing.Point(20, 50) + $comboBox.Width = 300 + $comboBox.DataSource = $gpuNames + $form.Controls.Add($comboBox) + + # Create an OK button + $okButton = New-Object System.Windows.Forms.Button + $okButton.Text = "OK" + $okButton.Location = New-Object System.Drawing.Point(70, 90) + $okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK + $form.Controls.Add($okButton) + + # Show the form and get user selection + $result = $form.ShowDialog() + + # Check if the user clicked OK + if ($result -eq [System.Windows.Forms.DialogResult]::OK) { + # Get the selected GPU name + $selectedGpuName = $comboBox.SelectedItem + + # Get the index of the selected GPU in the list + $selectedGpuIndex = $gpuNames.IndexOf($selectedGpuName) + + # Display the selected GPU index (replace with your desired action) + Write-Host "Blue Onyx will use GPU: ($selectedGpuIndex) $selectedGpuName" -ForegroundColor DarkYellow + } + + # --- 10. Create Batch Files on Desktop BEFORE final success text --- #Write-Host "Creating batch files on the Desktop..." - Write-Host "Creating batch files in the Install folder..." - + Write-Host "Creating batch files in the Install folder..." -ForegroundColor Green #$desktopPath = [Environment]::GetFolderPath("Desktop") @@ -231,7 +282,7 @@ try { $startServerContent = @" :: change --log-level info to --log-level debug for more information :: add --log-path %temp% to log to file instead -blue_onyx.exe --port 32168 --gpu-index 0 --log-level info +blue_onyx.exe --port 32168 --gpu-index $selectedGpuIndex --log-level info pause "@ Set-Content -Path (Join-Path $destinationPath "blue_onyx_start_server.bat") -Value $startServerContent -Force @@ -240,7 +291,7 @@ pause $startServerContentLG = @" :: change --log-level info to --log-level debug for more information :: add --log-path %temp% to log to file instead -blue_onyx.exe --port 32168 --gpu-index 0 --log-level info --model "$destinationPath\rt-detrv2-x.onnx" +blue_onyx.exe --port 32168 --gpu-index $selectedGpuIndex --log-level info --model "$destinationPath\rt-detrv2-x.onnx" pause "@ Set-Content -Path (Join-Path $destinationPath "blue_onyx_start_server_large_models.bat") -Value $startServerContentLG -Force From ddfb07e7345f26506d550c2138685a802ca3e34c Mon Sep 17 00:00:00 2001 From: DeFlanko Date: Thu, 26 Dec 2024 13:21:44 -0800 Subject: [PATCH 3/7] Update install_latest_blue_onyx.ps1 Get a list of available GPUs We also want to exclude "RDP Displays" and Sort the list like how it is in Task Manager so the Index is correct. Signed-off-by: DeFlanko --- install_latest_blue_onyx.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/install_latest_blue_onyx.ps1 b/install_latest_blue_onyx.ps1 index 20131dc..beaa0b2 100644 --- a/install_latest_blue_onyx.ps1 +++ b/install_latest_blue_onyx.ps1 @@ -223,17 +223,17 @@ try { # Now that we can see all the GPU's identifed when downloading all models. # Select which GPU blue_onyx will use in bat files. # Import necessary namespace - # Import necessary namespace Add-Type -AssemblyName System.Windows.Forms # Get a list of available GPUs (replace with your actual GPU detection method) - $gpus = Get-WmiObject Win32_VideoController | Select-Object Name + # We want to exclude RDP Displays, and Sort the list like how it is in Task Manager so the Index is correct. + $gpus = Get-CimInstance Win32_VideoController | Select-Object Name | Where-Object name -NotMatch "Microsoft Remote Display Adapter" |Sort-Object Name $gpuNames = $gpus.Name # Create a form $form = New-Object System.Windows.Forms.Form - $form.Text = "Select GPU" - $form.Size = New-Object System.Drawing.Size(400, 250) + $form.Text = "Blue Onyx GPU Selection" + $form.Size = New-Object System.Drawing.Size(350, 210) $form.StartPosition = 'CenterScreen' # Create a label @@ -252,7 +252,7 @@ try { # Create an OK button $okButton = New-Object System.Windows.Forms.Button $okButton.Text = "OK" - $okButton.Location = New-Object System.Drawing.Point(70, 90) + $okButton.Location = New-Object System.Drawing.Point(135, 90) $okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK $form.Controls.Add($okButton) From ed5cc267482c38993b743f9b1829876f5c180279 Mon Sep 17 00:00:00 2001 From: DeFlanko Date: Fri, 27 Dec 2024 12:02:13 -0800 Subject: [PATCH 4/7] Update install_latest_blue_onyx.ps1 Added Logic to compare the installed version to the JSON on github to determine if installing a newer version is needed or not. Cleaned up step formatting. Signed-off-by: DeFlanko --- install_latest_blue_onyx.ps1 | 445 +++++++++++++++++++---------------- 1 file changed, 239 insertions(+), 206 deletions(-) diff --git a/install_latest_blue_onyx.ps1 b/install_latest_blue_onyx.ps1 index beaa0b2..333f96b 100644 --- a/install_latest_blue_onyx.ps1 +++ b/install_latest_blue_onyx.ps1 @@ -45,74 +45,7 @@ try { New-Item -ItemType Directory -Path $tempPath | Out-Null } - # --- 2. Download version.json into %TEMP% (always) --- - $versionJsonFile = Join-Path $tempPath "version.json" - $versionJsonUrl = "https://github.com/xnorpx/blue-onyx/releases/latest/download/version.json" - Write-Host "Downloading version.json from $versionJsonUrl to $versionJsonFile..." -ForegroundColor Green - Invoke-WebRequest -Uri $versionJsonUrl -OutFile $versionJsonFile -UseBasicParsing -ErrorAction Stop - - if (-not (Test-Path $versionJsonFile)) { - throw "Failed to retrieve version.json file from GitHub." - } - - # --- 3. Parse JSON --- - Write-Host "Parsing version.json..." -ForegroundColor Green - $jsonContent = Get-Content -Path $versionJsonFile -Raw - $json = $jsonContent | ConvertFrom-Json - - if (-not $json.version -or -not $json.windows -or -not $json.windows_sha256) { - throw "version.json does not contain the required fields (version, windows, windows_sha256)." - } - - $zipUrl = "https://github.com/xnorpx/blue-onyx/releases/latest/download/$($json.windows)" - $sha256Url = "https://github.com/xnorpx/blue-onyx/releases/latest/download/$($json.windows_sha256)" - - Write-Host "Version: $($json.version)" -ForegroundColor Cyan - Write-Host "ZIP URL: $zipUrl" -ForegroundColor Blue - Write-Host "SHA256 URL: $sha256Url" -ForegroundColor Yellow - - # --- 4. Check if ZIP and SHA256 already exist in %TEMP%, else download (cache) --- - $zipFile = Join-Path $tempPath $json.windows - $sha256File = Join-Path $tempPath $json.windows_sha256 - - if (Test-Path $zipFile) { - Write-Host "Found cached ZIP file at $zipFile. Skipping download..." -ForegroundColor Green - } - else { - Write-Host "Downloading ZIP file to $zipFile..." -ForegroundColor Yellow - Invoke-WebRequest -Uri $zipUrl -OutFile $zipFile -UseBasicParsing -ErrorAction Stop - } - - if (Test-Path $sha256File) { - Write-Host "Found cached SHA256 file at $sha256File. Skipping download..." -ForegroundColor Green - } - else { - Write-Host "Downloading SHA256 file to $sha256File..." -ForegroundColor Green - Invoke-WebRequest -Uri $sha256Url -OutFile $sha256File -UseBasicParsing -ErrorAction Stop - } - - # --- 5. Verify the ZIP file's integrity with the SHA256 --- - Write-Host "Verifying ZIP file integrity..." -ForegroundColor DarkYellow - $sha256FileContent = Get-Content $sha256File -Raw - $pattern = '[A-Fa-f0-9]{64}' # 64 hex characters for a SHA256 hash - - $match = [System.Text.RegularExpressions.Regex]::Match($sha256FileContent, $pattern) - if (-not $match.Success) { - throw "Could not parse a valid 64-hex SHA256 from the .sha256 file." - } - $expectedSha256 = $match.Value.ToLower() - - $actualHash = (Get-FileHash -Algorithm SHA256 $zipFile).Hash.ToLower() - - Write-Host "Expected SHA256: $expectedSha256" -ForegroundColor Yellow - Write-Host "Actual SHA256: $actualHash" -ForegroundColor Yellow - - if ($expectedSha256 -ne $actualHash) { - throw "ZIP file SHA256 does not match expected value!" - } - Write-Host "SHA256 verification successful." -ForegroundColor Green - - # --- 6. Extract the ZIP into a temporary subfolder, then flatten if needed --- + # --- 2. Define the install folder, this will be used in step 3 --- # Get the desired folder from the user using a file dialog $folderBrowser = New-Object -ComObject Shell.Application @@ -130,165 +63,254 @@ try { New-Item -ItemType Directory -Path $destinationPath | Out-Null } - # # --- 6. Extract the ZIP into a temporary subfolder, then flatten if needed --- - # $destinationPath = Join-Path $env:USERPROFILE ".blue-onyx" - # if (-not (Test-Path $destinationPath)) { - # # Create .blue-onyx if it doesn't exist - # New-Item -ItemType Directory -Path $destinationPath | Out-Null - # } - - # Create a temporary folder under .blue-onyx for unzipping - $tempExtractPath = Join-Path $destinationPath "temp_unzip" - if (Test-Path $tempExtractPath) { - Remove-Item -Recurse -Force $tempExtractPath - } - New-Item -ItemType Directory -Path $tempExtractPath | Out-Null + # --- 3. Decide if Installing a newer verion is needed --- - Write-Host "Extracting ZIP contents to $tempExtractPath..." -ForegroundColor Yellow - Expand-Archive -Path $zipFile -DestinationPath $tempExtractPath -Force + # Download version.json into temporary path + #$tempPath = [System.IO.Path]::GetTempPath() + $versionJsonFile = Join-Path $tempPath "version.json" + $versionJsonUrl = "https://github.com/xnorpx/blue-onyx/releases/latest/download/version.json" - # Force results into an array so .Count is always valid - $directories = @(Get-ChildItem -Path $tempExtractPath -Directory) - $flattenPath = $tempExtractPath + Write-Host "Downloading version.json from $versionJsonUrl to $versionJsonFile..." -ForegroundColor Green + Invoke-WebRequest -Uri $versionJsonUrl -OutFile $versionJsonFile -UseBasicParsing -ErrorAction Stop - if ($directories.Count -eq 1) { - # There's exactly one directory, use it as the flattened path - $flattenPath = $directories[0].FullName - Write-Host "Single top-level folder found, flattening from: $flattenPath" + if (-not (Test-Path $versionJsonFile)) { + throw "Failed to retrieve version.json file from GitHub." } - else { - Write-Host "Multiple or no subfolders found, skipping single-folder flatten logic." + + # Extract version info from JSON + $jsonContent = Get-Content $versionJsonFile | ConvertFrom-Json + $remoteVersion = $jsonContent.version + + # Get local version info by executing blue_onyx.exe --version + # If no version installed then we give it s 0 version + try { + $localVersionOutput = & "$destinationPath\blue_onyx.exe" "--version" + } catch { + $localVersionOutput = "blue-onyx 0.0.0" } + # Extract version from the output; Example outpout: "blue-onyx 0.3.0" + $localVersion = ($localVersionOutput -split " ")[1] + + # Convert version strings to comparable versions + $remoteVersion = [System.Version]::Parse($remoteVersion) + $localVersion = [System.Version]::Parse($localVersion) + + # Compare versions; if local version is lower version or if local verison is not yet installed then install. + if ($remoteVersion -gt $localVersion -or [string]::IsNullOrEmpty($localVersion)){ + Write-Host "newer version ($remoteVersion) is available! Currently Installed version is ($localVersion)." -ForegroundColor DarkYellow + Write-Host "Proceeding with upgrade!" -ForegroundColor DarkYellow + ################################# + ## BEGIN INSTALLING STEPS HERE ## + ################################# + + # --- I1. Parse JSON --- + Write-Host "Parsing version.json..." -ForegroundColor Green + $jsonContent = Get-Content -Path $versionJsonFile -Raw + $json = $jsonContent | ConvertFrom-Json + + if (-not $json.version -or -not $json.windows -or -not $json.windows_sha256) { + throw "version.json does not contain the required fields (version, windows, windows_sha256)." + } + + $zipUrl = "https://github.com/xnorpx/blue-onyx/releases/latest/download/$($json.windows)" + $sha256Url = "https://github.com/xnorpx/blue-onyx/releases/latest/download/$($json.windows_sha256)" + + Write-Host "Version: $($json.version)" -ForegroundColor Cyan + Write-Host "ZIP URL: $zipUrl" -ForegroundColor Blue + Write-Host "SHA256 URL: $sha256Url" -ForegroundColor Yellow - # --- 6.5. Check if blue_onyx.exe is running and kill it --- - Write-Host "Checking if blue_onyx.exe is running..." -ForegroundColor Yellow - $processName = "blue_onyx" - $process = Get-Process -Name $processName -ErrorAction SilentlyContinue + # --- I2. Check if ZIP and SHA256 already exist in %TEMP%, else download (cache) --- + $zipFile = Join-Path $tempPath $json.windows + $sha256File = Join-Path $tempPath $json.windows_sha256 - if ($process) { - Write-Host "$processName.exe is currently running. Attempting to terminate..." - try { - Stop-Process -Id $process.Id -Force - Write-Green "$processName.exe has been terminated successfully." -ForegroundColor Green + if (Test-Path $zipFile) { + Write-Host "Found cached ZIP file at $zipFile. Skipping download..." -ForegroundColor Green } - catch { - throw "Failed to terminate $processName.exe. Please close the application manually and retry." + else { + Write-Host "Downloading ZIP file to $zipFile..." -ForegroundColor Yellow + Invoke-WebRequest -Uri $zipUrl -OutFile $zipFile -UseBasicParsing -ErrorAction Stop } - # Optionally, wait for the process to exit - Start-Sleep -Seconds 2 - if (Get-Process -Name $processName -ErrorAction SilentlyContinue) { - throw "$processName.exe is still running after attempting to terminate." + if (Test-Path $sha256File) { + Write-Host "Found cached SHA256 file at $sha256File. Skipping download..." -ForegroundColor Green + } + else { + Write-Host "Downloading SHA256 file to $sha256File..." -ForegroundColor Green + Invoke-WebRequest -Uri $sha256Url -OutFile $sha256File -UseBasicParsing -ErrorAction Stop } - } - else { - Write-Host "$processName.exe is not running. Proceeding with installation..." -ForegroundColor Green - } - # --- 7. Copy new files into .blue-onyx, overwriting if they exist --- - Write-Host "Overwriting existing files in $destinationPath with the new files..." -ForegroundColor Green - Copy-Item -Path (Join-Path $flattenPath '*') -Destination $destinationPath -Recurse -Force + # --- I3. Verify the ZIP file's integrity with the SHA256 --- + Write-Host "Verifying ZIP file integrity..." -ForegroundColor DarkYellow + $sha256FileContent = Get-Content $sha256File -Raw + $pattern = '[A-Fa-f0-9]{64}' # 64 hex characters for a SHA256 hash - # Cleanup the temp_unzip folder - Remove-Item -Path $tempExtractPath -Recurse -Force + $match = [System.Text.RegularExpressions.Regex]::Match($sha256FileContent, $pattern) + if (-not $match.Success) { + throw "Could not parse a valid 64-hex SHA256 from the .sha256 file." + } + $expectedSha256 = $match.Value.ToLower() - # --- 8. Add that folder to the PATH (for the user environment) --- - Write-Host "Adding $destinationPath to User PATH..." -ForegroundColor Green - $userPath = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + $actualHash = (Get-FileHash -Algorithm SHA256 $zipFile).Hash.ToLower() - if ($userPath -notlike "*$destinationPath*") { - if ([string]::IsNullOrEmpty($userPath)) { - $newPath = $destinationPath - } else { - $newPath = "$userPath;$destinationPath" + Write-Host "Expected SHA256: $expectedSha256" -ForegroundColor Yellow + Write-Host "Actual SHA256: $actualHash" -ForegroundColor Yellow + + if ($expectedSha256 -ne $actualHash) { + throw "ZIP file SHA256 does not match expected value!" } + Write-Host "SHA256 verification successful." -ForegroundColor Green - [System.Environment]::SetEnvironmentVariable("PATH", $newPath, "Machine") - # Also update the current session PATH so user can test immediately - $env:PATH = "$($env:PATH);$destinationPath" - } else { - Write-Host "Path already contains $destinationPath, skipping update." - } + # Create a temporary folder under .blue-onyx for unzipping + $tempExtractPath = Join-Path $destinationPath "temp_unzip" + if (Test-Path $tempExtractPath) { + Remove-Item -Recurse -Force $tempExtractPath + } + New-Item -ItemType Directory -Path $tempExtractPath | Out-Null - # --- 9. Run blue_onyx.exe to download all models --- - Write-Host "Downloading all models into $destinationPath..." -ForegroundColor DarkMagenta - $exePath = Join-Path $destinationPath "blue_onyx.exe" - if (-not (Test-Path $exePath)) { - throw "Could not find blue_onyx.exe at $exePath. Installation may have failed or the file may be missing." - } - # We'll run the exe in a separate process. - # This will download models into .blue-onyx folder. - & $exePath --download-model-path $destinationPath - - # Now that we can see all the GPU's identifed when downloading all models. - # Select which GPU blue_onyx will use in bat files. - # Import necessary namespace - Add-Type -AssemblyName System.Windows.Forms - - # Get a list of available GPUs (replace with your actual GPU detection method) - # We want to exclude RDP Displays, and Sort the list like how it is in Task Manager so the Index is correct. - $gpus = Get-CimInstance Win32_VideoController | Select-Object Name | Where-Object name -NotMatch "Microsoft Remote Display Adapter" |Sort-Object Name - $gpuNames = $gpus.Name - - # Create a form - $form = New-Object System.Windows.Forms.Form - $form.Text = "Blue Onyx GPU Selection" - $form.Size = New-Object System.Drawing.Size(350, 210) - $form.StartPosition = 'CenterScreen' - - # Create a label - $label = New-Object System.Windows.Forms.Label - $label.Text = "Select GPU:" - $label.Location = New-Object System.Drawing.Point(20, 20) - $form.Controls.Add($label) - - # Create a combobox - $comboBox = New-Object System.Windows.Forms.ComboBox - $comboBox.Location = New-Object System.Drawing.Point(20, 50) - $comboBox.Width = 300 - $comboBox.DataSource = $gpuNames - $form.Controls.Add($comboBox) - - # Create an OK button - $okButton = New-Object System.Windows.Forms.Button - $okButton.Text = "OK" - $okButton.Location = New-Object System.Drawing.Point(135, 90) - $okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK - $form.Controls.Add($okButton) - - # Show the form and get user selection - $result = $form.ShowDialog() - - # Check if the user clicked OK - if ($result -eq [System.Windows.Forms.DialogResult]::OK) { - # Get the selected GPU name - $selectedGpuName = $comboBox.SelectedItem - - # Get the index of the selected GPU in the list - $selectedGpuIndex = $gpuNames.IndexOf($selectedGpuName) - - # Display the selected GPU index (replace with your desired action) - Write-Host "Blue Onyx will use GPU: ($selectedGpuIndex) $selectedGpuName" -ForegroundColor DarkYellow - } + Write-Host "Extracting ZIP contents to $tempExtractPath..." -ForegroundColor Yellow + Expand-Archive -Path $zipFile -DestinationPath $tempExtractPath -Force + # Force results into an array so .Count is always valid + $directories = @(Get-ChildItem -Path $tempExtractPath -Directory) + $flattenPath = $tempExtractPath - # --- 10. Create Batch Files on Desktop BEFORE final success text --- - #Write-Host "Creating batch files on the Desktop..." - Write-Host "Creating batch files in the Install folder..." -ForegroundColor Green + if ($directories.Count -eq 1) { + # There's exactly one directory, use it as the flattened path + $flattenPath = $directories[0].FullName + Write-Host "Single top-level folder found, flattening from: $flattenPath" + } + else { + Write-Host "Multiple or no subfolders found, skipping single-folder flatten logic." + } - #$desktopPath = [Environment]::GetFolderPath("Desktop") + # --- I4. Check if blue_onyx.exe is running and kill it --- + Write-Host "Checking if blue_onyx.exe is running..." -ForegroundColor Yellow + $processName = "blue_onyx" + $process = Get-Process -Name $processName -ErrorAction SilentlyContinue + + if ($process) { + Write-Host "$processName.exe is currently running. Attempting to terminate..." + try { + Stop-Process -Id $process.Id -Force + Write-Green "$processName.exe has been terminated successfully." -ForegroundColor Green + } + catch { + throw "Failed to terminate $processName.exe. Please close the application manually and retry." + } + + # Optionally, wait for the process to exit + Start-Sleep -Seconds 2 + if (Get-Process -Name $processName -ErrorAction SilentlyContinue) { + throw "$processName.exe is still running after attempting to terminate." + } + } + else { + Write-Host "$processName.exe is not running. Proceeding with installation..." -ForegroundColor Green + } + + # --- I5. Copy new files into .blue-onyx, overwriting if they exist --- + Write-Host "Overwriting existing files in $destinationPath with the new files..." -ForegroundColor Green + Copy-Item -Path (Join-Path $flattenPath '*') -Destination $destinationPath -Recurse -Force + + # Cleanup the temp_unzip folder + Remove-Item -Path $tempExtractPath -Recurse -Force + + # --- I6. Add that folder to the PATH (for the user environment) --- + Write-Host "Adding $destinationPath to User PATH..." -ForegroundColor Green + $userPath = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + + if ($userPath -notlike "*$destinationPath*") { + if ([string]::IsNullOrEmpty($userPath)) { + $newPath = $destinationPath + } else { + $newPath = "$userPath;$destinationPath" + } - # 1. blue_onyx_start_server.bat - $startServerContent = @" + [System.Environment]::SetEnvironmentVariable("PATH", $newPath, "Machine") + # Also update the current session PATH so user can test immediately + $env:PATH = "$($env:PATH);$destinationPath" + } else { + Write-Host "Path already contains $destinationPath, skipping update." + } + + # --- I8. Run blue_onyx.exe to download all models --- + Write-Host "Downloading all models into $destinationPath..." -ForegroundColor DarkMagenta + $exePath = Join-Path $destinationPath "blue_onyx.exe" + if (-not (Test-Path $exePath)) { + throw "Could not find blue_onyx.exe at $exePath. Installation may have failed or the file may be missing." + } + + # -- I9. GPU Selection --- + # We'll run the exe in a separate process. + # This will download models into .blue-onyx folder. + & $exePath --download-model-path $destinationPath + + # Now that we can see all the GPU's identifed when downloading all models. + # Select which GPU blue_onyx will use in bat files. + # Import necessary namespace + Add-Type -AssemblyName System.Windows.Forms + + # Get a list of available GPUs (replace with your actual GPU detection method) + # We want to exclude RDP Displays, and Sort the list like how it is in Task Manager so the Index is correct. + $gpus = Get-CimInstance Win32_VideoController | Select-Object Name | Where-Object name -NotMatch "Microsoft Remote Display Adapter" |Sort-Object Name + $gpuNames = $gpus.Name + + # Create a form + $form = New-Object System.Windows.Forms.Form + $form.Text = "Blue Onyx GPU Selection" + $form.Size = New-Object System.Drawing.Size(350, 210) + $form.StartPosition = 'CenterScreen' + + # Create a label + $label = New-Object System.Windows.Forms.Label + $label.Text = "Select GPU:" + $label.Location = New-Object System.Drawing.Point(20, 20) + $form.Controls.Add($label) + + # Create a combobox + $comboBox = New-Object System.Windows.Forms.ComboBox + $comboBox.Location = New-Object System.Drawing.Point(20, 50) + $comboBox.Width = 300 + $comboBox.DataSource = $gpuNames + $form.Controls.Add($comboBox) + + # Create an OK button + $okButton = New-Object System.Windows.Forms.Button + $okButton.Text = "OK" + $okButton.Location = New-Object System.Drawing.Point(135, 90) + $okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK + $form.Controls.Add($okButton) + + # Show the form and get user selection + $result = $form.ShowDialog() + + # Check if the user clicked OK + if ($result -eq [System.Windows.Forms.DialogResult]::OK) { + # Get the selected GPU name + $selectedGpuName = $comboBox.SelectedItem + + # Get the index of the selected GPU in the list + $selectedGpuIndex = $gpuNames.IndexOf($selectedGpuName) + + # Display the selected GPU index (replace with your desired action) + Write-Host "Blue Onyx will use GPU: ($selectedGpuIndex) $selectedGpuName" -ForegroundColor DarkYellow + } + + + # --- I10. Create Batch Files on Desktop BEFORE final success text --- + Write-Host "Creating batch files in the Install folder..." -ForegroundColor Green + + # I10_1. blue_onyx_start_server.bat + $startServerContent = @" :: change --log-level info to --log-level debug for more information :: add --log-path %temp% to log to file instead blue_onyx.exe --port 32168 --gpu-index $selectedGpuIndex --log-level info pause "@ - Set-Content -Path (Join-Path $destinationPath "blue_onyx_start_server.bat") -Value $startServerContent -Force + Set-Content -Path (Join-Path $destinationPath "blue_onyx_start_server.bat") -Value $startServerContent -Force - # 2. blue_onyx_start_server_large_models.bat - $startServerContentLG = @" + # I10_2. blue_onyx_start_server_large_models.bat + $startServerContentLG = @" :: change --log-level info to --log-level debug for more information :: add --log-path %temp% to log to file instead blue_onyx.exe --port 32168 --gpu-index $selectedGpuIndex --log-level info --model "$destinationPath\rt-detrv2-x.onnx" @@ -296,8 +318,8 @@ pause "@ Set-Content -Path (Join-Path $destinationPath "blue_onyx_start_server_large_models.bat") -Value $startServerContentLG -Force - # 3. blue_onyx_benchmark_my_machine.bat - $benchmarkContent = @" + # I10_3. blue_onyx_benchmark_my_machine.bat + $benchmarkContent = @" ::GPU blue_onyx_benchmark.exe --repeat 100 --save-stats-path . @@ -306,18 +328,18 @@ blue_onyx_benchmark.exe --force-cpu --repeat 100 --save-stats-path . pause "@ - Set-Content -Path (Join-Path $destinationPath "blue_onyx_benchmark_my_machine.bat") -Value $benchmarkContent -Force + Set-Content -Path (Join-Path $destinationPath "blue_onyx_benchmark_my_machine.bat") -Value $benchmarkContent -Force - # 4. test_blue_onyx_server.bat - $testServerContent = @" + # I10_4. test_blue_onyx_server.bat + $testServerContent = @" test_blue_onyx.exe --origin http://127.0.0.1:32168 -n 10 --interval 10 pause "@ - Set-Content -Path (Join-Path $destinationPath "test_blue_onyx_server.bat") -Value $testServerContent -Force + Set-Content -Path (Join-Path $destinationPath "test_blue_onyx_server.bat") -Value $testServerContent -Force - # --- 11. Prompt user to restart shell and exit --- + # --- I11. Prompt user to restart shell and exit --- Write-Host "`nInstallation is complete! Blue Onyx is now installed in:" -ForegroundColor Green Write-Host " $destinationPath" -ForegroundColor DarkYellow @@ -332,6 +354,17 @@ pause Write-Host "`nPlease restart your PowerShell or Command Prompt to ensure the updated PATH is loaded." -ForegroundColor Green Write-Host "`nPlease restart Blue Onyx if this was a reinstall or update." -ForegroundColor Green Write-Host "Done!" -ForegroundColor Green + + } + ############################# + # --- End of Install Step --- + ############################# + else { + Write-Host "Installed version ($localVersion) is up-to-date or newer than remote version ($remoteVersion)." -ForegroundColor Green + Write-host "Done!" -ForegroundColor Green + # Add logic to inform user that update is not necessary here + } + } catch { Write-ErrorRed "$($_.Exception.Message)" From 7d73c91e23f046f0b3d86adc7150722f29d0823a Mon Sep 17 00:00:00 2001 From: DeFlanko Date: Fri, 27 Dec 2024 13:12:33 -0800 Subject: [PATCH 5/7] Update install_latest_blue_onyx.ps1 Added Popup box for the end user to select where to install the PATH variable. If Self Only then the Variable gets added to User if System Wide then the Variable gets added to the System. Signed-off-by: DeFlanko --- install_latest_blue_onyx.ps1 | 87 ++++++++++++++++++++++++++++++------ 1 file changed, 74 insertions(+), 13 deletions(-) diff --git a/install_latest_blue_onyx.ps1 b/install_latest_blue_onyx.ps1 index 333f96b..31a3076 100644 --- a/install_latest_blue_onyx.ps1 +++ b/install_latest_blue_onyx.ps1 @@ -215,22 +215,83 @@ try { # Cleanup the temp_unzip folder Remove-Item -Path $tempExtractPath -Recurse -Force - # --- I6. Add that folder to the PATH (for the user environment) --- - Write-Host "Adding $destinationPath to User PATH..." -ForegroundColor Green - $userPath = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + # # --- I6. Add that folder to the PATH (for the user environment) --- + # Write-Host "Adding $destinationPath to Environment PATH..." -ForegroundColor Green + # $userPath = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + + # if ($userPath -notlike "*$destinationPath*") { + # if ([string]::IsNullOrEmpty($userPath)) { + # $newPath = $destinationPath + # } else { + # $newPath = "$userPath;$destinationPath" + # } + + # [System.Environment]::SetEnvironmentVariable("PATH", $newPath, "Machine") + # # Also update the current session PATH so user can test immediately + # $env:PATH = "$($env:PATH);$destinationPath" + # } else { + # Write-Host "Path already contains $destinationPath, skipping update." + # } + + # # --- I6. Add that folder to the PATH (based on pop up box selection) --- + Add-Type -AssemblyName System.Windows.Forms - if ($userPath -notlike "*$destinationPath*") { - if ([string]::IsNullOrEmpty($userPath)) { - $newPath = $destinationPath + # Create the form + $form = New-Object System.Windows.Forms.Form + $form.Text = "Install PATH for:" + $form.Size = New-Object System.Drawing.Size(300,150) + $form.StartPosition = "CenterScreen" + + # Create the buttons + $continueButton = New-Object System.Windows.Forms.Button + $continueButton.Text = "Self Only" + $continueButton.Size = New-Object System.Drawing.Size(75,23) + $continueButton.Location = New-Object System.Drawing.Point(50,50) + $continueButton.Add_Click({ + $form.DialogResult = [System.Windows.Forms.DialogResult]::OK + $form.Close() + }) + + $adminButton = New-Object System.Windows.Forms.Button + $adminButton.Text = "System Wide" + $adminButton.Size = New-Object System.Drawing.Size(100,23) + $adminButton.Location = New-Object System.Drawing.Point(150,50) + $adminButton.Add_Click({ + $form.DialogResult = [System.Windows.Forms.DialogResult]::Yes + $form.Close() + }) + + # Add buttons to the form + $form.Controls.Add($continueButton) + $form.Controls.Add($adminButton) + + # Show the form + $result = $form.ShowDialog() + # Note: "Self Only" = OK box and "System Wide" = Yes box + if ($result -eq [System.Windows.Forms.DialogResult]::OK) { + # Continue with the script + Write-Host "Adding $destinationPath to User PATH..." -ForegroundColor Green + $userPath = [System.Environment]::GetEnvironmentVariable("PATH", "User") + + if ($userPath -notlike "*$destinationPath*") { + if ([string]::IsNullOrEmpty($userPath)) { + $newPath = $destinationPath + } else { + $newPath = "$userPath;$destinationPath" + } + + [System.Environment]::SetEnvironmentVariable("PATH", $newPath, "User") + # Also update the current session PATH so user can test immediately + $env:PATH = "$($env:PATH);$destinationPath" } else { - $newPath = "$userPath;$destinationPath" + Write-Host "Path already contains $destinationPath, skipping update." } - - [System.Environment]::SetEnvironmentVariable("PATH", $newPath, "Machine") - # Also update the current session PATH so user can test immediately - $env:PATH = "$($env:PATH);$destinationPath" - } else { - Write-Host "Path already contains $destinationPath, skipping update." + } elseif ($result -eq [System.Windows.Forms.DialogResult]::Yes) { + # Run as admin + $command = "[System.Environment]::SetEnvironmentVariable('PATH', '$newPath', 'Machine')" + Start-Process -FilePath "powershell.exe" -ArgumentList "-Command $command" -Verb RunAs + Start-Sleep -Seconds 2 + Write-Host "Adding $destinationPath to Environment PATH..." -ForegroundColor Green } # --- I8. Run blue_onyx.exe to download all models --- From 272218c15354995ba010fe5f128591472abff813 Mon Sep 17 00:00:00 2001 From: DeFlanko Date: Fri, 27 Dec 2024 13:38:39 -0800 Subject: [PATCH 6/7] Update install_latest_blue_onyx.ps1 If Multiple GPU's detected then present popup selection box, else default value to 0 Signed-off-by: DeFlanko --- install_latest_blue_onyx.ps1 | 91 ++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 41 deletions(-) diff --git a/install_latest_blue_onyx.ps1 b/install_latest_blue_onyx.ps1 index 31a3076..2d34237 100644 --- a/install_latest_blue_onyx.ps1 +++ b/install_latest_blue_onyx.ps1 @@ -233,7 +233,7 @@ try { # Write-Host "Path already contains $destinationPath, skipping update." # } - # # --- I6. Add that folder to the PATH (based on pop up box selection) --- + # # --- I6. Add Install folder to the PATH (based on pop up box selection) --- Add-Type -AssemblyName System.Windows.Forms # Create the form @@ -316,48 +316,57 @@ try { $gpus = Get-CimInstance Win32_VideoController | Select-Object Name | Where-Object name -NotMatch "Microsoft Remote Display Adapter" |Sort-Object Name $gpuNames = $gpus.Name - # Create a form - $form = New-Object System.Windows.Forms.Form - $form.Text = "Blue Onyx GPU Selection" - $form.Size = New-Object System.Drawing.Size(350, 210) - $form.StartPosition = 'CenterScreen' - - # Create a label - $label = New-Object System.Windows.Forms.Label - $label.Text = "Select GPU:" - $label.Location = New-Object System.Drawing.Point(20, 20) - $form.Controls.Add($label) - - # Create a combobox - $comboBox = New-Object System.Windows.Forms.ComboBox - $comboBox.Location = New-Object System.Drawing.Point(20, 50) - $comboBox.Width = 300 - $comboBox.DataSource = $gpuNames - $form.Controls.Add($comboBox) - - # Create an OK button - $okButton = New-Object System.Windows.Forms.Button - $okButton.Text = "OK" - $okButton.Location = New-Object System.Drawing.Point(135, 90) - $okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK - $form.Controls.Add($okButton) - - # Show the form and get user selection - $result = $form.ShowDialog() - - # Check if the user clicked OK - if ($result -eq [System.Windows.Forms.DialogResult]::OK) { - # Get the selected GPU name - $selectedGpuName = $comboBox.SelectedItem - - # Get the index of the selected GPU in the list - $selectedGpuIndex = $gpuNames.IndexOf($selectedGpuName) - - # Display the selected GPU index (replace with your desired action) - Write-Host "Blue Onyx will use GPU: ($selectedGpuIndex) $selectedGpuName" -ForegroundColor DarkYellow + if ($gpus.Count -gt 1) { + # If there are more than 1 GPU, present pop up selection form to user. + Write-Host "Multiple GPUs detected." -ForegroundColor Cyan + + # Create a form + $form = New-Object System.Windows.Forms.Form + $form.Text = "Blue Onyx GPU Selection" + $form.Size = New-Object System.Drawing.Size(350, 210) + $form.StartPosition = 'CenterScreen' + + # Create a label + $label = New-Object System.Windows.Forms.Label + $label.Text = "Select GPU:" + $label.Location = New-Object System.Drawing.Point(20, 20) + $form.Controls.Add($label) + + # Create a combobox + $comboBox = New-Object System.Windows.Forms.ComboBox + $comboBox.Location = New-Object System.Drawing.Point(20, 50) + $comboBox.Width = 300 + $comboBox.DataSource = $gpuNames + $form.Controls.Add($comboBox) + + # Create an OK button + $okButton = New-Object System.Windows.Forms.Button + $okButton.Text = "OK" + $okButton.Location = New-Object System.Drawing.Point(135, 90) + $okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK + $form.Controls.Add($okButton) + + # Show the form and get user selection + $result = $form.ShowDialog() + + # Check if the user clicked OK + if ($result -eq [System.Windows.Forms.DialogResult]::OK) { + # Get the selected GPU name + $selectedGpuName = $comboBox.SelectedItem + + # Get the index of the selected GPU in the list + $selectedGpuIndex = $gpuNames.IndexOf($selectedGpuName) + + # Display the selected GPU index (replace with your desired action) + Write-Host "Blue Onyx will use GPU: ($selectedGpuIndex) $selectedGpuName" -ForegroundColor DarkYellow + } + + } else { + #Since there is only One GPU, we will set the value to 0 to match Task manager. + $selectedGpuIndex = 0 + Write-host "Blue Onyx will use GPU: ($selectedGpuIndex) $($gpuNames[0])" -ForegroundColor DarkYellow } - # --- I10. Create Batch Files on Desktop BEFORE final success text --- Write-Host "Creating batch files in the Install folder..." -ForegroundColor Green From 73c15193bf92b96fb42ac07812a48eddeec865bd Mon Sep 17 00:00:00 2001 From: DeFlanko Date: Fri, 27 Dec 2024 16:35:58 -0800 Subject: [PATCH 7/7] Update install_latest_blue_onyx.ps1 added GPUS to an Array logic Signed-off-by: DeFlanko --- install_latest_blue_onyx.ps1 | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/install_latest_blue_onyx.ps1 b/install_latest_blue_onyx.ps1 index 2d34237..4064f8e 100644 --- a/install_latest_blue_onyx.ps1 +++ b/install_latest_blue_onyx.ps1 @@ -215,24 +215,6 @@ try { # Cleanup the temp_unzip folder Remove-Item -Path $tempExtractPath -Recurse -Force - # # --- I6. Add that folder to the PATH (for the user environment) --- - # Write-Host "Adding $destinationPath to Environment PATH..." -ForegroundColor Green - # $userPath = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") - - # if ($userPath -notlike "*$destinationPath*") { - # if ([string]::IsNullOrEmpty($userPath)) { - # $newPath = $destinationPath - # } else { - # $newPath = "$userPath;$destinationPath" - # } - - # [System.Environment]::SetEnvironmentVariable("PATH", $newPath, "Machine") - # # Also update the current session PATH so user can test immediately - # $env:PATH = "$($env:PATH);$destinationPath" - # } else { - # Write-Host "Path already contains $destinationPath, skipping update." - # } - # # --- I6. Add Install folder to the PATH (based on pop up box selection) --- Add-Type -AssemblyName System.Windows.Forms @@ -313,7 +295,8 @@ try { # Get a list of available GPUs (replace with your actual GPU detection method) # We want to exclude RDP Displays, and Sort the list like how it is in Task Manager so the Index is correct. - $gpus = Get-CimInstance Win32_VideoController | Select-Object Name | Where-Object name -NotMatch "Microsoft Remote Display Adapter" |Sort-Object Name + # Send all GPUs to an Array then count them. + $gpus = @(Get-CimInstance Win32_VideoController | Select-Object Name | Where-Object name -NotMatch "Microsoft Remote Display Adapter" | Sort-Object Name) $gpuNames = $gpus.Name if ($gpus.Count -gt 1) {