-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathappixinstall.ps1
100 lines (78 loc) · 3.07 KB
/
appixinstall.ps1
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function Download-File {
param (
[string]$url,
[string]$file
)
Write-Output "Downloading $url to $file"
$downloader = new-object System.Net.WebClient
$downloader.DownloadFile($url, $file)
}
Function Broadcast-WMSettingsChange {
if (-not ("win32.nativemethods" -as [type])) {
Add-Type -Namespace Win32 -Name NativeMethods -MemberDefinition @"
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr SendMessageTimeout(
IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam,
uint fuFlags, uint uTimeout, out UIntPtr lpdwResult);
"@
}
$HWND_BROADCAST = [intptr]0xffff;
$WM_SETTINGCHANGE = 0x1a;
$result = [uintptr]::zero
# notify all windows of environment block change
[win32.nativemethods]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [uintptr]::Zero, "Environment", 2, 5000, [ref]$result) >$null 2>&1;
}
Function AddTo-SystemPath {
Param(
[string]$Path
)
$oldpath = (Get-ItemProperty -Path "Registry::HKEY_CURRENT_USER\Environment" -Name PATH).path
#if($oldpath -Match $Path) {
if($oldpath.Contains($Path)) {
Write-Output "The folder is already in the PATH."
return
}
if($oldpath.EndsWith(";")) {
$newpath = "$oldpath$Path"
}
else {
$newpath = "$oldpath;$Path"
}
Set-ItemProperty -Path "Registry::HKEY_CURRENT_USER\Environment" -Name PATH -Value $newPath
# Updating the path for the current session
$env:Path = $newpath
# Broadcasting a settings change event so it's picked up by the other processes
Broadcast-WMSettingsChange
}
Write-Output "Starting the Appix ADK installation"
$appixVersion = $env:APPIX_VERSION
if ([string]::IsNullOrEmpty($appixVersion)){
# Determine the latest version
$releases = Invoke-WebRequest https://github.com/Travix-International/Travix.Core.Adk/releases/latest -Headers @{"accept"="application/json"}
# The releases are returned in the format {"id":3622206,"tag_name":"hello-1.0.0.11"}, we have to extract the tag_name.
$releases.Content -match '.*"tag_name":"(.*)".*' | Out-Null
$latestVersion = $Matches[1]
$url = "https://github.com/Travix-International/Travix.Core.Adk/releases/download/$latestVersion/appix.exe"
}
else {
# The version was explicitly specified
$url = "https://github.com/Travix-International/Travix.Core.Adk/releases/download/appix-$appixVersion/appix.exe"
}
# We install into ~/.appix
$appixFolder = Join-Path "$env:USERPROFILE" ".appix"
if(!(Test-Path -Path $appixFolder)) {
New-Item -Path $appixFolder -ItemType directory
}
$appixFile = Join-Path $appixFolder "appix.exe"
if(!(Test-Path -Path $appixFile)) {
Write-Output "Downloading the appix binary to $appixFolder."
}
else {
Write-Output "Appix is already installed in $appixFolder, trying to update."
}
Write-Output "Downloading the Appix ADK from $url."
Download-File $url $appixFile
Write-Output "Download completed. Adding appix folder to the PATH."
AddTo-SystemPath $appixFolder
Write-Output "The Appix ADK has been installed. You can start using it by typing appix."
Write-Output "(You might have to restart your terminal session to refresh your PATH.)"