-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemotePythonInstaller.bat
More file actions
333 lines (295 loc) · 11.8 KB
/
RemotePythonInstaller.bat
File metadata and controls
333 lines (295 loc) · 11.8 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
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
@echo off
setlocal
:: Set the directory where Python will be installed
set PYTHON_DIR=C:\pyap
:: Log file for Python installation
set PYTHON_LOG=%TEMP%\python_install.log
:: Check if Python is already installed in the specified directory
if exist "%PYTHON_DIR%\python.exe" (
echo [INFO] Python is already installed at "%PYTHON_DIR%".
goto :check_chrome
)
:: Clean up any existing installation
if exist "%PYTHON_DIR%" (
echo [INFO] Cleaning up existing Python installation...
rmdir /s /q "%PYTHON_DIR%"
)
:: Create the directory if it doesn't exist
if not exist "%PYTHON_DIR%" (
echo [INFO] Creating Python installation directory at "%PYTHON_DIR%"...
mkdir "%PYTHON_DIR%"
)
:: URL of the Python installer
set PYTHON_URL=https://www.python.org/ftp/python/3.11.0/python-3.11.0-amd64.exe
:: Path to save the downloaded Python installer
set PYTHON_INSTALLER_PATH=%PYTHON_DIR%\python-installer.exe
:: Download Python installer using PowerShell
echo [INFO] Downloading Python Installer from "%PYTHON_URL%"...
powershell -command "Invoke-WebRequest -Uri '%PYTHON_URL%' -OutFile '%PYTHON_INSTALLER_PATH%'" || (
echo [ERROR] Failed to download Python Installer.
echo Press any key to close this window.
pause
exit /b
)
:: Install Python silently with retries
echo [INFO] Installing Python...
set MAX_RETRIES=3
set RETRY_COUNT=0
:retry_install
set /a RETRY_COUNT+=1
start /wait "" "%PYTHON_INSTALLER_PATH%" /quiet InstallAllUsers=0 PrependPath=1 TargetDir="%PYTHON_DIR%" InstallLauncherAllUsers=0 /log "%PYTHON_LOG%"
:: Check if Python is installed in the specified directory
if exist "%PYTHON_DIR%\python.exe" (
echo [INFO] Python is successfully installed at "%PYTHON_DIR%".
goto :check_chrome
)
if %RETRY_COUNT% lss %MAX_RETRIES% (
echo [WARN] Python installation failed. Retrying... (Attempt %RETRY_COUNT% of %MAX_RETRIES%)
goto retry_install
) else (
echo [ERROR] Failed to install Python after %MAX_RETRIES% attempts.
echo Check the log at "%PYTHON_LOG%" for more information.
echo Press any key to close this window.
pause
exit /b
)
:check_chrome
:: Check if Chrome is already installed in the specified directory
if exist "%PYTHON_DIR%\chrome-win64\chrome.exe" (
echo [INFO] Chrome is already installed at "%PYTHON_DIR%\chrome-win64".
goto :check_chromedriver
)
:: URL of the Chrome zip
set CHROME_ZIP_URL=https://storage.googleapis.com/chrome-for-testing-public/126.0.6478.126/win64/chrome-win64.zip
set CHROME_ZIP_PATH=%TEMP%\chrome-win64.zip
echo [INFO] Downloading Chrome zip from "%CHROME_ZIP_URL%"...
powershell -command "Invoke-WebRequest -Uri '%CHROME_ZIP_URL%' -OutFile '%CHROME_ZIP_PATH%'" || (
echo [ERROR] Failed to download Chrome zip.
echo Press any key to close this window.
pause
exit /b
)
echo [INFO] Unzipping Chrome zip to "%PYTHON_DIR%"...
powershell -command "Expand-Archive -Path '%CHROME_ZIP_PATH%' -DestinationPath '%PYTHON_DIR%'" || (
echo [ERROR] Failed to unzip Chrome zip.
echo Press any key to close this window.
pause
exit /b
)
:check_chromedriver
:: Check if Chromedriver is already installed in the specified directory
if exist "%PYTHON_DIR%\chromedriver-win64\chromedriver.exe" (
echo [INFO] Chromedriver is already installed at "%PYTHON_DIR%\chromedriver-win64".
goto :update_path
)
:: URL of the Chromedriver zip
set CHROMEDRIVER_ZIP_URL=https://storage.googleapis.com/chrome-for-testing-public/126.0.6478.126/win64/chromedriver-win64.zip
set CHROMEDRIVER_ZIP_PATH=%TEMP%\chromedriver-win64.zip
echo [INFO] Downloading Chromedriver zip from "%CHROMEDRIVER_ZIP_URL%"...
powershell -command "Invoke-WebRequest -Uri '%CHROMEDRIVER_ZIP_URL%' -OutFile '%CHROMEDRIVER_ZIP_PATH%'" || (
echo [ERROR] Failed to download Chromedriver zip.
echo Press any key to close this window.
pause
exit /b
)
echo [INFO] Unzipping Chromedriver zip to "%PYTHON_DIR%"...
powershell -command "Expand-Archive -Path '%CHROMEDRIVER_ZIP_PATH%' -DestinationPath '%PYTHON_DIR%'" || (
echo [ERROR] Failed to unzip Chromedriver zip.
echo Press any key to close this window.
pause
exit /b
)
:update_path
:: Update PATH for this session only
set PATH=%PYTHON_DIR%;%PYTHON_DIR%\Scripts;%PATH%
:: Update pip to the latest version
echo [INFO] Updating pip...
"%PYTHON_DIR%\python.exe" -m pip install --upgrade pip > "%PYTHON_LOG%" 2>&1
if errorlevel 1 (
echo [ERROR] Failed to update pip. Check the log at "%PYTHON_LOG%" for more information.
echo [INFO] Continuing despite the error...
) else (
echo [INFO] pip updated successfully.
)
:: Check and install pandas
echo [INFO] Checking pandas installation...
"%PYTHON_DIR%\Scripts\pip.exe" show pandas >nul 2>&1
if errorlevel 1 (
echo [INFO] pandas is not installed. Installing now...
"%PYTHON_DIR%\Scripts\pip.exe" install pandas --only-binary :all: || (
echo [ERROR] Failed to install pandas.
echo [INFO] Continuing despite the error...
)
) else (
echo [INFO] pandas is already installed.
)
:: Check and install PyQt5
echo [INFO] Checking PyQt5 installation...
"%PYTHON_DIR%\Scripts\pip.exe" show PyQt5 >nul 2>&1
if errorlevel 1 (
echo [INFO] PyQt5 is not installed. Installing now...
"%PYTHON_DIR%\Scripts\pip.exe" install PyQt5 --only-binary :all: || (
echo [ERROR] Failed to install PyQt5.
echo [INFO] Continuing despite the error...
)
) else (
echo [INFO] PyQt5 is already installed.
)
:: Check and install tkinterdnd2
echo [INFO] Checking tkinterdnd2 installation...
"%PYTHON_DIR%\Scripts\pip.exe" show tkinterdnd2 >nul 2>&1
if errorlevel 1 (
echo [INFO] tkinterdnd2 is not installed. Installing now...
"%PYTHON_DIR%\Scripts\pip.exe" install tkinterdnd2 --only-binary :all: || (
echo [ERROR] Failed to install tkinterdnd2.
echo [INFO] Continuing despite the error...
)
) else (
echo [INFO] tkinterdnd2 is already installed.
)
:: Install numpy with a specific version
echo [INFO] Installing numpy==1.26.4...
"%PYTHON_DIR%\Scripts\pip.exe" install numpy==1.26.4 || (
echo [ERROR] Failed to install numpy==1.26.4.
echo [INFO] Continuing despite the error...
)
:: Check and install requests
echo [INFO] Checking requests installation...
"%PYTHON_DIR%\Scripts\pip.exe" show requests >nul 2>&1
if errorlevel 1 (
echo [INFO] requests is not installed. Installing now...
"%PYTHON_DIR%\Scripts\pip.exe" install requests --only-binary :all: || (
echo [ERROR] Failed to install requests.
echo [INFO] Continuing despite the error...
)
) else (
echo [INFO] requests is already installed.
)
:: Check and install fuzzywuzzy
echo [INFO] Checking fuzzywuzzy installation...
"%PYTHON_DIR%\Scripts\pip.exe" show fuzzywuzzy >nul 2>&1
if errorlevel 1 (
echo [INFO] fuzzywuzzy is not installed. Installing now...
"%PYTHON_DIR%\Scripts\pip.exe" install fuzzywuzzy --only-binary :all: || (
echo [ERROR] Failed to install fuzzywuzzy.
echo [INFO] Continuing despite the error...
)
) else (
echo [INFO] fuzzywuzzy is already installed.
)
:: Check and install Pillow
echo [INFO] Checking Pillow installation...
"%PYTHON_DIR%\Scripts\pip.exe" show Pillow >nul 2>&1
if errorlevel 1 (
echo [INFO] Pillow is not installed. Installing now...
"%PYTHON_DIR%\Scripts\pip.exe" install Pillow --only-binary :all: || (
echo [ERROR] Failed to install Pillow.
echo [INFO] Continuing despite the error...
)
) else (
echo [INFO] Pillow is already installed.
)
:: Check and install openpyxl
echo [INFO] Checking openpyxl installation...
"%PYTHON_DIR%\Scripts\pip.exe" show openpyxl >nul 2>&1
if errorlevel 1 (
echo [INFO] openpyxl is not installed. Installing now...
"%PYTHON_DIR%\Scripts\pip.exe" install openpyxl --only-binary :all: || (
echo [ERROR] Failed to install openpyxl.
echo [INFO] Continuing despite the error...
)
) else (
echo [INFO] Openpyxl is already installed.
)
:: Check and install Selenium
echo [INFO] Checking Selenium installation...
"%PYTHON_DIR%\Scripts\pip.exe" show selenium >nul 2>&1
if errorlevel 1 (
echo [INFO] Selenium is not installed. Installing now...
"%PYTHON_DIR%\Scripts\pip.exe" install selenium --only-binary :all: || (
echo [ERROR] Failed to install Selenium.
echo [INFO] Continuing despite the error...
)
) else (
echo [INFO] Selenium is already installed.
)
:: Check and install tkinterdnd2 (New Section)
:: Note: This section has already been added above for tkinterdnd2 installation.
:: Initialize paths for downloading fscpanel.py
echo [INFO] Initializing download paths for fscpanel.py...
set PRIMARY_DOWNLOAD_PATH=%USERPROFILE%\OneDrive - Housing Hope\Desktop\fscpanel.py
set SECONDARY_DOWNLOAD_PATH=%USERPROFILE%\OneDrive\Desktop\fscpanel.py
set FALLBACK_DOWNLOAD_PATH=%USERPROFILE%\Downloads\fscpanel.py
:: Try the primary OneDrive path
if exist "%USERPROFILE%\OneDrive - Housing Hope\Desktop" (
set DOWNLOAD_PATH=%PRIMARY_DOWNLOAD_PATH%
) else (
:: Try the secondary OneDrive path
if exist "%USERPROFILE%\OneDrive\Desktop" (
set DOWNLOAD_PATH=%SECONDARY_DOWNLOAD_PATH%
) else (
:: Fallback to Downloads folder
set DOWNLOAD_PATH=%FALLBACK_DOWNLOAD_PATH%
)
)
:: Always download the latest version of fscpanel.py
echo [INFO] Downloading fscpanel.py from housinghope.site to %DOWNLOAD_PATH%...
curl -L http://housinghopedata.site/fscpanel.py -o "%DOWNLOAD_PATH%" || (
echo [ERROR] Failed to download fscpanel.py.
echo Press any key to close this window.
pause
exit /b
)
:: Copy fscpanel.py to the primary OneDrive desktop
if exist "%PRIMARY_DOWNLOAD_PATH%" (
del "%PRIMARY_DOWNLOAD_PATH%"
)
copy "%DOWNLOAD_PATH%" "%PRIMARY_DOWNLOAD_PATH%" || (
:: If the file copy fails, rename the newly downloaded file
set TIMESTAMP=%DATE:~-4,4%%DATE:~-10,2%%DATE:~-7,2%_%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%
set TIMESTAMP=%TIMESTAMP: =0%
set RENAMED_PATH="%USERPROFILE%\OneDrive - Housing Hope\Desktop\fscpanel_%TIMESTAMP%.py"
rename "%DOWNLOAD_PATH%" "%RENAMED_PATH%" || (
echo [ERROR] Failed to rename fscpanel.py due to unexpected error.
)
echo [INFO] Renamed downloaded fscpanel.py to %RENAMED_PATH% due to an access issue.
) else (
echo [INFO] Copied fscpanel.py to the primary OneDrive desktop.
)
:: Copy fscpanel.py to the secondary OneDrive desktop
if exist "%SECONDARY_DOWNLOAD_PATH%" (
del "%SECONDARY_DOWNLOAD_PATH%"
)
copy "%DOWNLOAD_PATH%" "%SECONDARY_DOWNLOAD_PATH%" || (
:: If the file copy fails, rename the newly downloaded file
set TIMESTAMP=%DATE:~-4,4%%DATE:~-10,2%%DATE:~-7,2%_%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%
set TIMESTAMP=%TIMESTAMP: =0%
set RENAMED_PATH="%USERPROFILE%\OneDrive\Desktop\fscpanel_%TIMESTAMP%.py"
rename "%DOWNLOAD_PATH%" "%RENAMED_PATH%" || (
echo [ERROR] Failed to rename fscpanel.py due to unexpected error.
)
echo [INFO] Renamed downloaded fscpanel.py to %RENAMED_PATH% due to an access issue.
) else (
echo [INFO] Copied fscpanel.py to the secondary OneDrive desktop.
)
:: Copy fscpanel.py to the physical desktop
set PHYSICAL_DESKTOP_PATH=C:\Users\%USERNAME%\Desktop\fscpanel.py
if exist "%PHYSICAL_DESKTOP_PATH%" (
del "%PHYSICAL_DESKTOP_PATH%"
)
copy "%DOWNLOAD_PATH%" "%PHYSICAL_DESKTOP_PATH%" || (
:: If the file copy fails, rename the newly downloaded file
set TIMESTAMP=%DATE:~-4,4%%DATE:~-10,2%%DATE:~-7,2%_%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%
set TIMESTAMP=%TIMESTAMP: =0%
set RENAMED_PATH=C:\Users\%USERNAME%\Desktop\fscpanel_%TIMESTAMP%.py
rename "%DOWNLOAD_PATH%" "%RENAMED_PATH%" || (
echo [ERROR] Failed to rename fscpanel.py due to unexpected error.
)
echo [INFO] Renamed downloaded fscpanel.py to %RENAMED_PATH% due to an access issue.
) else (
echo [INFO] Copied fscpanel.py to the physical desktop.
)
echo [INFO] Installation and setup completed successfully.
echo Press any key to close this window.
pause
endlocal