File: install.ps1

package info (click to toggle)
incus 6.21.0-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 27,496 kB
  • sloc: sh: 17,280; ansic: 3,201; python: 458; makefile: 340; ruby: 51; sql: 50; lisp: 6
file content (49 lines) | stat: -rw-r--r-- 1,908 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
$IsAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)

if (!$IsAdmin) {
    Write-Host "This script requires local administrator privilege. Rerun the script in an administrator PowerShell."
    exit 1
}

$destFolder = "C:\Program Files\Incus-Agent"

$targetDrive = Get-WmiObject -Class Win32_Volume | Where-Object { $_.Label -eq "incus-agent" }

if (!$targetDrive) {
    Write-Host "Drive containing the agent was not found."
    exit 1
}

Write-Host "Drive containing the agent was found: $($targetDrive.DriveLetter)"

if (!(Test-Path $destFolder)) {
    Write-Host "Creating $destFolder..."
    New-Item -ItemType Directory -Path $destFolder -Force | Out-Null
    
    if (!$?) {
        Write-Host "Could not create $destFolder..."
        exit 1
    }
}

Write-Host "Copying the content of the CD-ROM to $destFolder..."
Copy-Item `
    -Path "$($targetDrive.DriveLetter)\incus-agent-setup.*" `
    -Destination "$destFolder\" `
    -Force

if (!$?) {
    Write-Host "Failed to copy the agent files."
    exit 1
}

# Override the scheduled task even if it exists
$destFolder = "C:\Program Files\Incus-Agent"
$taskFile = "$destFolder\incus-agent-setup.ps1"
$taskAction = New-ScheduledTaskAction -Execute "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Argument "-ExecutionPolicy Bypass -File `"$taskFile`""
$taskTrigger = New-ScheduledTaskTrigger -AtStartup
$taskPrincipal = New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest
Register-ScheduledTask -Action $taskAction -Trigger $taskTrigger -Principal $taskPrincipal -TaskName "Incus Agent Setup" -Description "Every setup required for the Incus agent including copying the files, opening the firewall, etc." -Force

# Start the PowerShell script to simulate start up
& "$taskFile"