forked from SebiAi/custom-nothing-glyph-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstall-Dependencies.bat
293 lines (244 loc) · 11.8 KB
/
Install-Dependencies.bat
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
@echo off
setlocal
REM +-----------------------------------------------------------------------------------------------------------------------+
REM / This script installs the necessary software and packages for the custom-nothing-glyph-tools - if not already present. /
REM / /
REM / ATTENTION: /
REM / Please do not execute this script standalone. Download AND EXTRACT the project and execute it from there. /
REM +-----------------------------------------------------------------------------------------------------------------------+
title Install dependencies for Custom Glyphs
REM ----------------------------------Check for Windows build-------------------------------------------
REM Run the PowerShell command and save the output to a variable
for /f %%i in ('powershell -command "[System.Environment]::OSVersion.Version.Build"') do (
set "build=%%i"
)
REM Check if the build version is greater than or equal to 16299 - also works for Windows 11 (has build 22000 or higher)
REM This is the minimal build where winget is supported
set "threshold=16299"
if %build% lss %threshold% (
REM Inform the user that the build version is not supported and exit
powershell -Command "Add-Type -AssemblyName PresentationFramework;[System.Windows.MessageBox]::Show('This Windows build (%build%) is not supported.' + [Environment]::NewLine + [Environment]::NewLine + 'Please update your Windows installation to build %threshold% or higher!', 'Windows build not supported', [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::ERROR);"
exit /b 1
)
REM ----------------------------------Check for required files-------------------------------------------
REM Check if the file "requirements.txt" exists
if not exist "%~dp0/requirements.txt" (
REM Inform the user that the file "requirements.txt" is missing and exit
powershell -Command "Add-Type -AssemblyName PresentationFramework;[System.Windows.MessageBox]::Show('The file ''requirements.txt'' is missing.' + [Environment]::NewLine + [Environment]::NewLine + 'Please make sure that this script is in the root of the custom-nothing-glyph-tools directory.' + [Environment]::NewLine + [Environment]::NewLine + 'Also DO NOT execute any of the scripts from inside the zip file!', 'File ''requirements.txt'' missing', [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::ERROR);"
exit /b 1
)
REM ----------------------------------Check for arguments-----------------------------------------------
REM Skip printing info if the user passed the --skip-info argument
if /i "%1"=="--skip-info" goto :checkForAdminRights
REM If we need more arguments in the future, we can maybe use this: https://stackoverflow.com/a/4871831/14622654
REM ----------------------------------Print info-------------------------------------------------------
echo This script installs the necessary software and packages for the custom-nothing-glyph-tools - if not already present.
echo It will install most of the dependencies with the open-source package manager WinGet.
echo.
echo You will need an active internet connection for this script to work.
echo.
echo The following dependencies will be installed:
echo * Audacity (optional)
echo * ffmpeg
echo * python
echo * python packages needed (see requirements.txt)
echo.
echo The script will ask for administrator rights when you continue.
REM -----------------------Ask the user if he wants to continue running the script-----------------------
:askToContinue
set /p "continueRunning=Do you want to continue? [y/n]: "
if /i "%continueRunning%" equ "n" exit /b 0
if /i "%continueRunning%" neq "y" goto :askToContinue
REM ---------------------------Check for admin rights-----------------------------------------------------
:checkForAdminRights
@(
(
net session >nul 2>&1
) || (
REM Elevate the script to admin
powershell Start-Process -FilePath '%0' -Verb RunAs -ArgumentList '--skip-info %*'
exit /b 0
)
)
REM ---------------------------Check for .tmp folder------------------------------------------------------
REM Check if the folder ".tmp" exists and create it if it doesn't
if exist "%~dp0/.tmp" (
call :PrintInfo "The folder "".tmp""" exists - using it."
) else (
REM Create the folder ".tmp" and hide it
mkdir "%~dp0/.tmp"
attrib +h "%~dp0/.tmp" /s /d
)
REM ---------------------------Check for winget-----------------------------------------------------------
:tryWinget
@(
(
winget >nul 2>&1
) && (
goto :install
)
)
REM ---------------------------Automated WinGet install--------------------------------------------------
call :PrintInfo "Downloading WinGet and its dependencies..."
@(
(
REM Download the latest version of WinGet and save it to the .tmp folder as WinGet.msixbundle
powershell -Command "Invoke-WebRequest -Uri "https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -OutFile "%~dp0/.tmp/WinGet.msixbundle""
REM Get hash of the latest version of WinGet from web and save it to the .tmp folder as hash.txt
powershell -Command "Invoke-WebRequest -Uri "https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.txt" -OutFile "%~dp0/.tmp/hash.txt""
REM Download winget dependencies (Microsoft.VCLibs, Microsoft.UI.Xaml) and save them to the .tmp folder (https://learn.microsoft.com/en-us/windows/package-manager/winget/#install-winget-on-windows-sandbox)
powershell -Command "Invoke-WebRequest -Uri "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx" -OutFile "%~dp0/.tmp/Microsoft.VCLibs.x64.14.00.Desktop.appx""
powershell -Command "Invoke-WebRequest -Uri "https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.7.3/Microsoft.UI.Xaml.2.7.x64.appx" -OutFile "%~dp0/.tmp/Microsoft.UI.Xaml.2.7.x64.appx""
) || (
REM Error downloading
call :PrintError "Could not download WinGet. Do you have a working internet connection?"
goto :manualInstall
)
)
REM Get hash of WinGet.msixbundle and save it to the .tmp folder as file_hash.txt
CertUtil -hashfile "%~dp0/.tmp/WinGet.msixbundle" SHA256 > %~dp0/.tmp/file_hash.txt
REM Get the hash value from the hash.txt file
(for /L %%i in (1,1,1) do set /P "hash=") < "%~dp0/.tmp/hash.txt"
call :PrintInfo "The file hash should be: %hash%"
REM Get the hash value from the file_hash.txt file
(for /L %%i in (1,1,2) do set /P "file_hash=") < "%~dp0/.tmp/file_hash.txt"
call :PrintInfo "The file hash is: %file_hash%"
REM Compare the hash values
if "%file_hash%"=="%hash%" (
call :PrintInfo "The hashes match!"
) else (
call :PrintInfo "The hashes do not match."
goto :manualInstall
)
REM If the installation doesn't fail, try if winget works now
@(
(
powershell -Command "Add-AppxPackage "%~dp0/.tmp/WinGet.msixbundle" -DependencyPath "%~dp0/.tmp/Microsoft.VCLibs.x64.14.00.Desktop.appx, %~dp0/.tmp/Microsoft.UI.Xaml.2.7.x64.appx""
) && (
goto :tryWinget
)
)
call :PrintWarning "Automatic installation failed."
REM ---------------------------Manual WinGet install-----------------------------------------------------
:manualInstall
call :PrintInfo "Please install/update AppInstaller from the Microsoft Store."
REM Open the Microsoft Store page for AppInstaller
start ms-windows-store://pdp/?ProductId=9nblggh4nns1
echo.
pause
goto :tryWinget
REM ---------------------------Install dependencies-----------------------------------------------------
:install
REM Ask the user if they want to install Audacity or not which is optional
set /p "install=Do you want to install Audacity? [y/n]: "
if /i "%install%"=="y" goto :fullInstall
if /i "%install%"=="n" goto :basicInstall
goto :install
:fullInstall
REM Install Audacity
winget install Audacity.Audacity
echo.
:basicInstall
REM Install the rest of the programs
@(
(
ffmpeg -version >nul 2>&1
) && (
call :PrintInfo "ffmpeg is already installed. Skipping..."
) || (
REM ffmpeg is not installed, install it
call :PrintInfo "Installing ffmpeg..."
winget install Gyan.FFmpeg
)
)
echo.
REM if Get-Package Python* is not throwing an error check if python is in the path and if it is, skip the installation
@(
(
powershell -Command "Get-Package 'Python 3*'" >nul 2>&1
) && (
call :PrintInfo "python is already installed. Skipping..."
) || (
REM python is not installed, install it
call :PrintInfo "Installing python..."
winget install Python.Python.3.11
goto :refreshEnv
)
)
setlocal enabledelayedexpansion
@(
(
python --version >nul 2>&1
) && (
call :PrintInfo "python is already in PATH. Skipping..."
REM No need to refresh environment variables if python is already working
goto :installPythonStuff
) || (
REM python is not installed, install it
call :PrintWarning "python is not in path."
REM ask for user to uninstall current found package using powershell -Command "Get-Package Python*" and then install python using winget
set /p "reInstall=Do you want to uninstall and reinstall python using winget? [y/N]: "
if /i "!reInstall!"=="y" (
echo.
call :PrintInfo "Uninstalling python..."
winget uninstall Python
echo.
call :PrintInfo "Installing python..."
winget install Python.Python.3.11
goto :refreshEnv
)
endlocal
call :PrintError "Python is not in PATH! Please add python to the PATH manually. See here: https://docs.python.org/3/using/windows.html#excursus-setting-environment-variables"
pause
call :CleanUp
exit /b 0
)
)
endlocal
REM ---------------------------Refresh environment variables--------------------------------------------------
:refreshEnv
echo.
call :PrintInfo "Refreshing environment variables..."
@(
(
REM Download code from @badrelmers on GitHub to refresh environment variables.
REM This downloaded code is part of badrelmers/RefrEnv (https://github.com/badrelmers/RefrEnv) which is released under the GPL-3.0 license.
REM Go to https://github.com/badrelmers/RefrEnv/blob/main/LICENSE for full license details.
powershell -Command "Invoke-WebRequest -Uri "https://raw.githubusercontent.com/badrelmers/RefrEnv/main/refrenv.bat" -OutFile "%~dp0/.tmp/refrenv.bat""
) && (
call %~dp0/.tmp/refrenv.bat
) || (
REM Download failed - inform the user
call :PrintWarning "Could not refresh environment. Please install the python packages manually: python -m pip install -r requirements.txt"
pause
call :CleanUp
exit /b 0
)
)
REM ---------------------------Install python packages--------------------------------------------------
:installPythonStuff
echo.
REM Install the python packages
call :PrintInfo "Installing python packages..."
python -m pip install -r %~dp0/requirements.txt
echo.
REM ---------------------------Clean-up--------------------------------------------------
:end
powershell Write-Host -ForegroundColor Green 'Success!'
pause
REM delete the .tmp folder and exit
call :CleanUp
exit /b 0
REM ----------------------------------Convenience functions------------------------------------------------------
:CleanUp
rd /S /Q "%~dp0/.tmp"
exit /b 0
:PrintError
powershell Write-Host -ForegroundColor Red '[ERROR] %*'
exit /b 0
:PrintWarning
powershell Write-Host -ForegroundColor Yellow '[WARNING] %*'
exit /b 0
:PrintInfo
powershell Write-Host -ForegroundColor DarkCyan '[INFO] %*'
exit /b 0