-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.ps1
156 lines (132 loc) · 5.46 KB
/
install.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#requires -version 2.0
param (
[string]$packages = "@@PACKAGE@@",
[string]$app_name = "@@NAME@@",
[switch]$help = $false
)
function Test-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
if ((Test-Admin) -eq $false) {
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-executionpolicy Bypass -noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
exit
}
if ($help) {
echo "install.ps1: installation for Lucterios"
echo " install.ps1 -help"
echo " install.ps1 [-packages <packages>] [-app_name <application_name>]"
echo "option:"
echo " -help: show this help"
echo " -packages: define the packages list to install (default: '$packages')"
echo " -app_name: define the application name for shortcut (default: '$app_name')"
exit 0
}
Try {
$lucterios_path="c:\lucterios2"
cd $lucterios_path
$env:Path="$lucterios_path\Python;$lucterios_path\Python\Scripts;$env:Path"
echo ""
echo "------ install @@NAME@@ #@@BUILD@@ ------"
echo ""
python -m pip -U install pip==24.0 2>&1 | Out-Null
echo "=> python -m pip -U install pip==24.0"
python -m pip uninstall PIL
python -m pip uninstall Pillow
foreach($package in $packages.split()) {
echo "===> python -m pip install -U $package"
python -m pip install -U $package @@PIPOPTION@@
}
python -m pip install -U pip==24.0 2>&1 | Out-Null
python -m pip list
python Python\Scripts\lucterios_admin.py update | python Python\Scripts\lucterios_admin.py refreshall | Out-Null
echo ""
echo "------ create starter bat ------"
echo ""
if (Test-Path $lucterios_path\launch_lucterios.ps1) {
del $lucterios_path\launch_lucterios.ps1
}
if (Test-Path $lucterios_path\lucterios_gui.ps1) {
del $lucterios_path\lucterios_gui.ps1
}
if (Test-Path $lucterios_path\lucterios_qt.ps1) {
del $lucterios_path\lucterios_qt.ps1
}
if (Test-Path $lucterios_path\lucterios_admin.ps1) {
del $lucterios_path\lucterios_admin.ps1
}
if (Test-Path $lucterios_path\virtual_for_lucterios) {
del -r $lucterios_path\virtual_for_lucterios | Out-Null
}
if (!(Test-Path $lucterios_path\extra_url)) {
echo "# Pypi servers" | Out-File -Encoding ascii -Append -FilePath $lucterios_path\extra_url
}
echo "#requires -version 2.0" >> $lucterios_path\lucterios_admin.ps1
echo "" >> $lucterios_path\lucterios_admin.ps1
echo "echo '$app_name GUI launcher'" >> $lucterios_path\lucterios_admin.ps1
echo "" >> $lucterios_path\lucterios_admin.ps1
echo "cd $lucterios_path" >> $lucterios_path\lucterios_admin.ps1
echo "" >> $lucterios_path\lucterios_admin.ps1
echo "`$env:Path='$lucterios_path\Python;$lucterios_path\Python\Scripts;$env:Path'" >> $lucterios_path\lucterios_admin.ps1
echo "`$env:TCL_LIBRARY='$lucterios_path\Python\tcl\tcl8.6'" >> $lucterios_path\lucterios_admin.ps1
echo "`$env:TK_LIBRARY='$lucterios_path\Python\tcl\tcl8.6'" >> $lucterios_path\lucterios_admin.ps1
echo "`$env:LUCTERIOS_INSTALL='@@BUILD@@'" >> $lucterios_path\lucterios_admin.ps1
cp $lucterios_path\lucterios_admin.ps1 $lucterios_path\lucterios_gui.ps1
echo "python Python\Scripts\lucterios_gui.py" >> $lucterios_path\lucterios_gui.ps1
echo "exit" >> $lucterios_path\lucterios_gui.ps1
echo "" >> $lucterios_path\lucterios_gui.ps1
cp $lucterios_path\lucterios_admin.ps1 $lucterios_path\lucterios_qt.ps1
echo "python Python\Scripts\lucterios_qt.py" >> $lucterios_path\lucterios_qt.ps1
echo "exit" >> $lucterios_path\lucterios_qt.ps1
echo "" >> $lucterios_path\lucterios_qt.ps1
echo "python Python\Scripts\lucterios_admin.py `$args[0] `$args[1] `$args[2] `$args[3] `$args[4] `$args[5] `$args[6] `$args[7] `$args[8] `$args[9]" >> $lucterios_path\lucterios_admin.ps1
echo "exit" >> $lucterios_path\lucterios_admin.ps1
echo "" >> $lucterios_path\lucterios_admin.ps1
echo ""
echo "------ refresh shortcut ------"
echo ""
if (Test-Path $env:Public\Desktop\$app_name.lnk) {
del $env:Public\Desktop\$app_name.lnk
}
$icon_path = Get-ChildItem -Path "$lucterios_path\python" -Recurse -Filter "$app_name.ico" | Select-Object -First 1 | % { $_.FullName }
Try {
$qt_version= & python -c 'from PyQt5.QtCore import QT_VERSION_STR;print(QT_VERSION_STR)'
}Catch {
$qt_version="---"
}
if ($qt_version -eq $null) {$qt_version="???"}
echo ">> Qt = $qt_version"
$WshShell = New-Object -ComObject WScript.shell
$Shortcut = $WshShell.CreateShortcut("$lucterios_path\$app_name.lnk")
$Shortcut.TargetPath = "PowerShell.exe"
if ($qt_version.Substring(0,2).equals("5.")) {
$Shortcut.Arguments = "-WindowStyle Hidden -ExecutionPolicy Bypass -File $lucterios_path\lucterios_qt.ps1"
} else {
$Shortcut.Arguments = "-WindowStyle Hidden -ExecutionPolicy Bypass -File $lucterios_path\lucterios_gui.ps1"
}
if (($icon_path -ne "") -and (Test-Path $icon_path)) {
$Shortcut.IconLocation = "$icon_path"
}
$Shortcut.WindowStyle = 7
$Shortcut.Save()
echo ""
echo "------ refresh permission ------"
echo ""
$acl = Get-Acl $lucterios_path
$sid = new-object System.Security.Principal.SecurityIdentifier "S-1-1-0"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($sid,"FullControl","ContainerInherit,ObjectInherit","None","Allow")
$acl.SetAccessRule($accessRule)
$acl | Set-Acl $lucterios_path
$rc=0
}Catch {
echo ""
echo "Error:$_.Exception.Message"
echo ""
echo "**** $app_name not installed ****"
$rc=1
}
echo "============ END ============="
echo "Press a key..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Write-Host ""
exit $rc