Write-Host "Checking Admin permissions and stopping script if not running as admin" $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) if ($currentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Output "PowerShell is running as an Administrator, continuing." } else { Add-Type -AssemblyName System.Windows.Forms [Windows.Forms.MessageBox]::Show("Please run PowerShell as an Administrator and try again. (Right click and Run as Administrator)", "Administrator Required", [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Warning) exit } Write-Host "Downloading application with git or web-request" try { $gitVersion = git --version Write-Host "Git is installed. Version: $gitVersion" Set-Location C:\opt\essential-metrics git pull if (-not $?) { throw "Git pull failed due to local changes that would be overwritten." }Write-Host "Repository updated successfully"} catch { Write-Host "Git is not installed, not in PATH, or git pull failed. Falling back to Invoke-WebRequest."Write-Host "Git is not installed or not in PATH. Falling back to Invoke-WebRequest."$zipUrl = "https://github.com/essentialmetrics/essential-metrics/zipball/master/" $destinationPath = "C:\\opt\\installs\\essential-metrics.zip" Invoke-WebRequest -Uri $zipUrl -OutFile $destinationPath Write-Host "Repository ZIP downloaded successfully to $destinationPath" $extractPath = "C:\\opt\\essential-metrics-update" Expand-Archive -LiteralPath $destinationPath -DestinationPath $extractPath Copy-Item -Path "C:\opt\essential-metrics-update\essentialmetrics*\*" -Destination "C:\opt\essential-metrics" -Recurse -Force Remove-Item -Path "C:\\opt\\installs\\essential-metrics.zip" Remove-Item -Path "C:\\opt\\essential-metrics-update" -Recurse Write-Host "Repository ZIP extracted to $extractPath" } Write-Host "Update completed"
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updating UPDATE.md to include a git pull fail scenario, using invoke-…
…webrequest when this happens
- Loading branch information
Dale Brennan
committed
Feb 5, 2024
1 parent
5b0ca9b
commit 105eed6
Showing
1 changed file
with
0 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.