-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall-PythonGuardian.ps1
More file actions
64 lines (58 loc) · 3.24 KB
/
Copy pathInstall-PythonGuardian.ps1
File metadata and controls
64 lines (58 loc) · 3.24 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<# Install Python Guardian per-user from the EXE or portable ZIP. #>
[CmdletBinding()]
param(
[string]$InstallDir = (Join-Path $env:LOCALAPPDATA 'Programs\PythonGuardian'),
[string]$Python
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$source = $PSScriptRoot
$destination = [System.IO.Path]::GetFullPath($InstallDir)
$sourceFull = [System.IO.Path]::GetFullPath($source)
$payload = @(
'guardian_client.py', 'guardian_common.py', 'guardian_ctl.py', 'guardian_panic.py',
'guardian_report_viewer.pyw', 'python_arg_launcher.pyw', 'python_console_runner.py',
'python_guardian_broker.pyw', 'pyguard.py', 'Install-PythonFileLauncher.ps1',
'Install-PythonGuardianRuntime.ps1', 'Install-PythonGuardian.ps1',
'Uninstall-PythonGuardian.ps1', 'Remove-PythonGuardianFiles.ps1',
'LICENSE', 'README.md', 'readme.txt', 'THIRD_PARTY_NOTICES.txt', 'VERSION'
)
New-Item -ItemType Directory -Path $destination -Force | Out-Null
if ($sourceFull -ne $destination) {
foreach ($name in $payload) {
$item = Join-Path $source $name
if (-not (Test-Path -LiteralPath $item -PathType Leaf)) { throw "Package is missing $name" }
Copy-Item -LiteralPath $item -Destination (Join-Path $destination $name) -Force
}
$injectTarget = Join-Path $destination 'guardian_inject'
New-Item -ItemType Directory -Path $injectTarget -Force | Out-Null
Copy-Item -LiteralPath (Join-Path $source 'guardian_inject\sitecustomize.py') `
-Destination (Join-Path $injectTarget 'sitecustomize.py') -Force
}
Set-Content -LiteralPath (Join-Path $destination '.python-guardian-install') `
-Value 'PythonGuardian 0.1.0' -Encoding ASCII
& (Join-Path $destination 'Install-PythonGuardianRuntime.ps1') -Python $Python
& (Join-Path $destination 'Install-PythonFileLauncher.ps1')
$uninstallKey = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\PythonGuardian'
New-Item -Path $uninstallKey -Force | Out-Null
New-ItemProperty -LiteralPath $uninstallKey -Name DisplayName -Value 'Python Guardian' `
-PropertyType String -Force | Out-Null
New-ItemProperty -LiteralPath $uninstallKey -Name DisplayVersion -Value '0.1.0' `
-PropertyType String -Force | Out-Null
New-ItemProperty -LiteralPath $uninstallKey -Name Publisher -Value 'Thomas M. Schaefer' `
-PropertyType String -Force | Out-Null
New-ItemProperty -LiteralPath $uninstallKey -Name URLInfoAbout `
-Value 'mailto:Tom@6NowPossibleThings.ai' -PropertyType String -Force | Out-Null
$uninstallCommand = "powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"$destination\Uninstall-PythonGuardian.ps1`""
New-ItemProperty -LiteralPath $uninstallKey -Name UninstallString -Value $uninstallCommand `
-PropertyType String -Force | Out-Null
New-ItemProperty -LiteralPath $uninstallKey -Name QuietUninstallString -Value $uninstallCommand `
-PropertyType String -Force | Out-Null
New-ItemProperty -LiteralPath $uninstallKey -Name NoModify -Value 1 `
-PropertyType DWord -Force | Out-Null
New-ItemProperty -LiteralPath $uninstallKey -Name NoRepair -Value 1 `
-PropertyType DWord -Force | Out-Null
Write-Output ''
Write-Output 'Python Guardian 0.1.0 installed successfully.'
Write-Output "Location: $destination"
Write-Output 'Right-click a .py or .pyw file and choose Show more options.'