bugfix: error checking was broken by release 1.7.1 (c8776b42c0)

This commit is contained in:
Kevin Woley
2025-02-20 15:27:39 -08:00
parent efd7c78f59
commit ce170f0685
2 changed files with 37 additions and 16 deletions

View File

@@ -20,22 +20,31 @@ $ConfigScript = Join-Path $PSScriptRoot "config.ps1"
$ResticExe = Join-Path $InstallPath $ExeName
$LogPath = Join-Path $InstallPath "logs"
# make LASTEXITCODE global to enable error checking for Invoke-Expression commands
$global:LASTEXITCODE=0
# =========== end configuration =========== #
# download restic
if(-not (Test-Path $ResticExe)) {
$url = $null
if([Environment]::Is64BitOperatingSystem){
$url = "https://github.com/restic/restic/releases/download/v0.17.3/restic_0.17.3_windows_amd64.zip"
$url = "fixmetestingnotrealhttps://github.com/restic/restic/releases/download/v0.17.3/restic_0.17.3_windows_amd64.zip"
}
else {
$url = "https://github.com/restic/restic/releases/download/v0.17.3/restic_0.17.3_windows_386.zip"
}
$output = Join-Path $InstallPath "restic.zip"
Invoke-WebRequest -Uri $url -OutFile $output
Expand-Archive -LiteralPath $output $InstallPath
Remove-Item $output
Get-ChildItem *.exe | Rename-Item -NewName $ExeName
try {
$output = Join-Path $InstallPath "restic.zip"
Invoke-WebRequest -Uri $url -OutFile $output
Expand-Archive -LiteralPath $output $InstallPath
Remove-Item $output
Get-ChildItem *.exe | Rename-Item -NewName $ExeName
}
catch {
Write-Error "[[Install]] restic.exe download failed. Check errors and resolve: $_"
exit 1
}
}
# Apply global paramters to $ResticExe, after the $ResticExe has been downloaded/confirmed to exist
@@ -47,6 +56,9 @@ if(-not [String]::IsNullOrEmpty($GlobalParameters)) {
# This is enabled by default unless configuration disables self-update
if ([String]::IsNullOrEmpty($SelfUpdateEnabled) -or ($SelfUpdateEnabled -eq $true)) {
Invoke-Expression "$ResticExe self-update"
if($LASTEXITCODE) {
Write-Warning "[[Update]] Restic self-update failed. Check errors and resolve: $_"
}
}
# Create log directory if it doesn't exit
@@ -62,11 +74,11 @@ if(-not (Test-Path $LocalExcludeFile)) {
# Initialize the restic repository
Invoke-Expression "$ResticExe --verbose init"
if($?) {
Write-Output "[[Init]] Repository successfully initialized."
if($LASTEXITCODE) {
Write-Warning "[[Init]] Repository initialization failed. Check errors and resolve: $_"
}
else {
Write-Warning "[[Init]] Repository initialization failed. Check errors and resolve."
Write-Output "[[Init]] Repository successfully initialized."
}
# Scheduled Windows Task Scheduler to run the backup
@@ -82,7 +94,7 @@ if($null -eq $backup_task) {
Write-Output "[[Scheduler]] Backup task scheduled."
}
catch {
Write-Warning "[[Scheduler]] Scheduling failed."
Write-Error "[[Scheduler]] Setting up backup task schedule failed: $_"
}
}
else {