-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller_win.ps1
97 lines (85 loc) · 4.21 KB
/
installer_win.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
# Request administrator privileges
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
# Ask if the user wants to install home assistant api module
# Doing so will require python version 3.11.2
$installHomeAssistantApi = $false
$pythonInstalled = $false
while ($true) {
$installHomeAssistantApi = Read-Host "Do you want to install the home assistant api module? (y/n)"
if ($installHomeAssistantApi -eq "y" -or $installHomeAssistantApi -eq "n") {
break
}
}
# Check if python is installed
try {
$pythonVersion = (Get-Command python).Version
$pythonInstalled = $true
}
catch {
$pythonInstalled = $false
}
# Install Chocolatey
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
# Refresh env variables
$env:ChocolateyInstall = Convert-Path "$((Get-Command choco).Path)\..\.."
Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
refreshenv
# Check if python version is 3.11.2150.1013
if ($pythonInstalled) {
if ($pythonVersion -ne "3.11.2150.1013") {
Write-Output "Python version is not 3.11.2150.1013, installing python 3.11.2150.1013"
# If home assistant api module is to be installed, install python 3.11.2150.1013
if ($installHomeAssistantApi) {
# Install python 3.11.2150.1013
choco install -y python --version 3.11.2
}
}
}
else {
choco install -y python --version 3.11.2
}
pip3 install --upgrade espmega_lightshow
# Get python.exe path
$pythonPath = (Get-Command pythonw).Source
# Create espmega_lightshow folder in user's home directory
$espmegaLightshowPath = "$env:USERPROFILE\espmega_lightshow"
if (-not (Test-Path $espmegaLightshowPath)) {
New-Item -ItemType Directory -Force -Path $espmegaLightshowPath
}
# Create desktop shortcut
$targetFile = "$env:USERPROFILE\Desktop\ESPMega Lightshow.lnk"
$wshshell = New-Object -ComObject WScript.Shell
$shortcut = $wshshell.CreateShortcut($targetFile)
$shortcut.TargetPath = $pythonPath
$shortcut.Arguments = "-m espmega_lightshow"
# Set the working directory to the espmega_lightshow folder in the user's home directory
$shortcut.WorkingDirectory = $espmegaLightshowPath
# Get Python base path
$pythonRootPath = (Get-Command python).Source | Split-Path -Parent
# Set the icon to icon.ico in the same directory as this python script
$shortcut.IconLocation = $pythonRootPath + "\lib\site-packages\espmega_lightshow\icon.ico"
$shortcut.Save()
# Create start menu shortcut
$targetFile = "$env:USERPROFILE\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\ESPMega Lightshow.lnk"
$wshshell = New-Object -ComObject WScript.Shell
$shortcut = $wshshell.CreateShortcut($targetFile)
$shortcut.TargetPath = $pythonPath
$shortcut.Arguments = "-m espmega_lightshow"
# Set the working directory to the espmega_lightshow folder in the user's home directory
$shortcut.WorkingDirectory = $espmegaLightshowPath
# Set the icon to icon.ico in the same directory as this python script
$shortcut.IconLocation = $pythonRootPath + "\lib\site-packages\espmega_lightshow\icon.ico"
$shortcut.Save()
# Get python.exe path
$pythonDbgPath = (Get-Command python).Source
# Create start menu shortcut to launch the program in debug mode, debug mode runs on python.exe instead of pythonw.exe
$targetFile = "$env:USERPROFILE\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\ESPMega Lightshow (Debug).lnk"
$wshshell = New-Object -ComObject WScript.Shell
$shortcut = $wshshell.CreateShortcut($targetFile)
$shortcut.TargetPath = $pythonDbgPath
$shortcut.Arguments = "-m espmega_lightshow"
# Set the working directory to the espmega_lightshow folder in the user's home directory
$shortcut.WorkingDirectory = $espmegaLightshowPath
# Set the icon to icon.ico in the same directory as this python script
$shortcut.IconLocation = $pythonRootPath + "\lib\site-packages\espmega_lightshow\icon.ico"
$shortcut.Save()