<# igworker 0.1.2 installer for Windows. Generated at release time by scripts/sign-release.sh; do not edit the generated file. No administrator rights needed. powershell -ExecutionPolicy Bypass -File install.ps1 install or upgrade, start the task powershell -ExecutionPolicy Bypass -File install.ps1 -Uninstall stop the task and remove everything The SHA-256 of the binary is written into this script, which is fetched over HTTPS: that is the trust anchor for the first install (trust on first use). Every later update is verified by the worker itself against the owner's signing key built into the binary. -NoService installs or removes the files only and leaves the scheduled task alone. #> param([switch]$Uninstall, [switch]$NoService) $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' $Version = '0.1.2' $BaseUrl = 'https://igcoord.app.vlazic.com/releases/0.1.2/' $File = 'igworker_0.1.2_windows_amd64.exe' $Sha256 = '3957efd812532f77af8f0211bfc0799debc356aa6d6a45e43d22dcd4ac1bfcc2' $IgHome = Join-Path $env:LOCALAPPDATA 'igworker' $Config = Join-Path $env:APPDATA 'igworker' $Bin = Join-Path $IgHome 'bin' $Exe = Join-Path $Bin 'igworker.exe' $TaskScript = Join-Path $IgHome 'igworker-task.ps1' function Write-TaskScript { New-Item -ItemType Directory -Force -Path $IgHome | Out-Null Set-Content -LiteralPath $TaskScript -Encoding UTF8 -Value @' <# .SYNOPSIS Registers or removes the igworker scheduled task for the current user. No administrator rights. .DESCRIPTION The task starts "igworker.exe run" at logon of the current user, with limited rights, hidden behind a PowerShell host so no console window stays open. A one-minute repetition with MultipleInstances=IgnoreNew acts as the supervisor: after the worker exits (exit code 75 after a self-update, or a crash) the next repetition starts it again; while it runs, repetitions are ignored. The worker runs only while the user is logged in. -NoStart registers the task without starting it now (setup.exe asks on its finish page). .EXAMPLE powershell -ExecutionPolicy Bypass -File igworker-task.ps1 -Exe "$env:LOCALAPPDATA\igworker\bin\igworker.exe" powershell -ExecutionPolicy Bypass -File igworker-task.ps1 -Uninstall #> param( [string]$Exe = (Join-Path $env:LOCALAPPDATA 'igworker\bin\igworker.exe'), [switch]$Uninstall, [switch]$NoStart ) $ErrorActionPreference = 'Stop' $TaskName = 'igworker' if ($Uninstall) { if (Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue) { Stop-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false } Get-Process -Name igworker -ErrorAction SilentlyContinue | Stop-Process -Force Write-Host 'igworker scheduled task removed.' return } if (-not (Test-Path -LiteralPath $Exe)) { throw "igworker not found at $Exe" } $user = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name $command = "& '$($Exe -replace "'", "''")' run; exit `$LASTEXITCODE" $action = New-ScheduledTaskAction -Execute 'powershell.exe' ` -Argument "-NoProfile -NonInteractive -WindowStyle Hidden -Command `"$command`"" ` -WorkingDirectory (Split-Path -Parent $Exe) $trigger = New-ScheduledTaskTrigger -AtLogOn -User $user $trigger.Repetition = (New-ScheduledTaskTrigger -Once -At (Get-Date) ` -RepetitionInterval (New-TimeSpan -Minutes 1)).Repetition $settings = New-ScheduledTaskSettingsSet ` -MultipleInstances IgnoreNew ` -ExecutionTimeLimit ([TimeSpan]::Zero) ` -RestartCount 999 -RestartInterval (New-TimeSpan -Minutes 1) ` -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries ` -StartWhenAvailable ` -Priority 7 $principal = New-ScheduledTaskPrincipal -UserId $user -LogonType Interactive -RunLevel Limited Register-ScheduledTask -TaskName $TaskName -Action $action -Trigger $trigger ` -Settings $settings -Principal $principal -Force | Out-Null if ($NoStart) { Write-Host "igworker scheduled task registered for $user; it starts at the next logon." return } Start-ScheduledTask -TaskName $TaskName Write-Host "igworker scheduled task registered for $user and started." '@ } if ($Uninstall) { if (-not $NoService) { Write-TaskScript & $TaskScript -Uninstall } Remove-Item -Recurse -Force -LiteralPath $IgHome, $Config -ErrorAction SilentlyContinue Write-Host 'Removed igworker, its scheduled task, configuration and keys.' return } $arch = if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE } # Windows on ARM runs the amd64 build under x64 emulation. if ($arch -ne 'AMD64' -and $arch -ne 'ARM64') { throw "unsupported CPU $arch" } New-Item -ItemType Directory -Force -Path $Bin | Out-Null $tmp = Join-Path $Bin 'igworker.download.exe' try { Write-Host "Downloading $File" Invoke-WebRequest -UseBasicParsing -Uri ($BaseUrl + $File) -OutFile $tmp $got = (Get-FileHash -Algorithm SHA256 -LiteralPath $tmp).Hash.ToLowerInvariant() if ($got -ne $Sha256) { throw "SHA-256 mismatch for ${File}: got $got, want $Sha256; nothing installed" } & $tmp --selftest | Out-Null if ($LASTEXITCODE -ne 0) { throw "the downloaded binary does not run on this machine (windows-amd64)" } Write-TaskScript if (-not $NoService) { & $TaskScript -Uninstall } Move-Item -Force -LiteralPath $tmp -Destination $Exe # Start the update state afresh for this version (a reinstall ends any trial) and keep the # highest manifest sequence seen, at least this release's, so no older manifest is accepted. $state = Join-Path $Bin 'igworker.update.json' $seq = 4 if (Test-Path -LiteralPath $state) { try { $old = (Get-Content -Raw -LiteralPath $state | ConvertFrom-Json).max_sequence if ($old -gt $seq) { $seq = $old } } catch {} } # ASCII: the worker's JSON reader does not accept a byte order mark. @{ current = $Version; trial = $false; attempts = 0; max_sequence = $seq } | ConvertTo-Json | Set-Content -LiteralPath $state -Encoding ASCII } finally { Remove-Item -Force -LiteralPath $tmp -ErrorAction SilentlyContinue } if (-not $NoService) { & $TaskScript -Exe $Exe } Write-Host "Installed igworker $Version (windows-amd64) in $Bin"