-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.bat
More file actions
195 lines (164 loc) · 6.18 KB
/
Copy pathinstall.bat
File metadata and controls
195 lines (164 loc) · 6.18 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
@echo off
setlocal EnableDelayedExpansion
set "SCRIPT_DIR=%~dp0"
set "PYTHON_VERSION=3.11.9"
set "PYTHON_URL=https://www.python.org/ftp/python/3.11.9/python-3.11.9-amd64.exe"
set "PYTHON_INSTALLER=%TEMP%\python-3.11.9-amd64.exe"
set "VENV_DIR=%SCRIPT_DIR%venv"
set "FFMPEG_URL=https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip"
set "FFMPEG_ZIP=%TEMP%\ffmpeg.zip"
set "FFMPEG_DIR=%SCRIPT_DIR%ffmpeg"
:: Candidate install locations (user install first, then system)
set "PYTHON_USER=%LOCALAPPDATA%\Programs\Python\Python311\python.exe"
set "PYTHON_SYS=C:\Python311\python.exe"
echo.
echo File Share Server - Installer
echo ================================
echo.
:: ── Step 1: Find or install Python 3.11.9 ─────────────────────────────────────
set "PYTHON_EXE="
:: Check user install path
if exist "%PYTHON_USER%" (
"%PYTHON_USER%" --version 2>nul | findstr /C:"3.11" >nul
if !errorlevel! == 0 (
set "PYTHON_EXE=%PYTHON_USER%"
echo [OK] Found Python 3.11 at: !PYTHON_EXE!
goto :create_venv
)
)
:: Check system install path
if exist "%PYTHON_SYS%" (
"%PYTHON_SYS%" --version 2>nul | findstr /C:"3.11" >nul
if !errorlevel! == 0 (
set "PYTHON_EXE=%PYTHON_SYS%"
echo [OK] Found Python 3.11 at: !PYTHON_EXE!
goto :create_venv
)
)
:: Check PATH
where python >nul 2>&1
if !errorlevel! == 0 (
python --version 2>nul | findstr /C:"3.11" >nul
if !errorlevel! == 0 (
for /f "delims=" %%i in ('where python') do (
set "PYTHON_EXE=%%i"
goto :found_in_path
)
:found_in_path
echo [OK] Found Python 3.11 in PATH: !PYTHON_EXE!
goto :create_venv
)
)
:: ── Download and install Python 3.11.9 ────────────────────────────────────────
echo [..] Python 3.11.9 not found. Downloading installer...
echo URL: %PYTHON_URL%
echo.
powershell -NoProfile -Command ^
"Invoke-WebRequest -Uri '%PYTHON_URL%' -OutFile '%PYTHON_INSTALLER%' -UseBasicParsing"
if !errorlevel! neq 0 (
echo.
echo [ERROR] Download failed. Check your internet connection and try again.
pause
exit /b 1
)
echo [OK] Download complete.
echo [..] Installing Python 3.11.9 (user install, no admin required)...
echo.
"%PYTHON_INSTALLER%" /quiet ^
InstallAllUsers=0 ^
PrependPath=1 ^
Include_test=0 ^
Include_launcher=1
if !errorlevel! neq 0 (
echo.
echo [ERROR] Python installation failed (exit code: !errorlevel!).
echo Try running the installer manually: %PYTHON_INSTALLER%
pause
exit /b 1
)
del /q "%PYTHON_INSTALLER%" 2>nul
echo [OK] Python 3.11.9 installed.
:: After install, resolve the path
if exist "%PYTHON_USER%" (
set "PYTHON_EXE=%PYTHON_USER%"
) else (
echo.
echo [ERROR] Installation finished but python.exe was not found at expected location:
echo %PYTHON_USER%
echo Please restart this script or install Python manually.
pause
exit /b 1
)
:: ── Step 2: Create virtual environment ────────────────────────────────────────
:create_venv
echo.
echo [..] Creating virtual environment in: %VENV_DIR%
if exist "%VENV_DIR%" (
echo [..] Existing venv found, removing it...
rmdir /s /q "%VENV_DIR%"
)
"%PYTHON_EXE%" -m venv "%VENV_DIR%"
if !errorlevel! neq 0 (
echo [ERROR] Failed to create virtual environment.
pause
exit /b 1
)
echo [OK] Virtual environment created.
:: ── Step 3: Install dependencies ──────────────────────────────────────────────
echo.
echo [..] Installing dependencies from requirements.txt...
"%VENV_DIR%\Scripts\python.exe" -m pip install --upgrade pip --quiet
"%VENV_DIR%\Scripts\pip.exe" install -r "%SCRIPT_DIR%requirements.txt" --quiet
if !errorlevel! neq 0 (
echo [ERROR] pip install failed.
pause
exit /b 1
)
echo [OK] Dependencies installed.
:: ── Step 4: Download ffmpeg ───────────────────────────────────────────────────
echo.
if exist "%FFMPEG_DIR%\ffmpeg.exe" (
echo [OK] ffmpeg already present, skipping download.
goto :create_start
)
echo [..] Downloading ffmpeg...
powershell -NoProfile -Command ^
"Invoke-WebRequest -Uri '%FFMPEG_URL%' -OutFile '%FFMPEG_ZIP%' -UseBasicParsing"
if !errorlevel! neq 0 (
echo [WARN] ffmpeg download failed. Video thumbnails will not work.
echo You can manually place ffmpeg.exe in: %FFMPEG_DIR%
goto :create_start
)
echo [..] Extracting ffmpeg...
mkdir "%FFMPEG_DIR%" 2>nul
powershell -NoProfile -Command ^
"Add-Type -Assembly System.IO.Compression.FileSystem; $z = [IO.Compression.ZipFile]::OpenRead('%FFMPEG_ZIP%'); $entry = $z.Entries | Where-Object { $_.Name -eq 'ffmpeg.exe' } | Select-Object -First 1; [IO.Compression.ZipFileExtensions]::ExtractToFile($entry, '%FFMPEG_DIR%\ffmpeg.exe', $true); $z.Dispose()"
del /q "%FFMPEG_ZIP%" 2>nul
if exist "%FFMPEG_DIR%\ffmpeg.exe" (
echo [OK] ffmpeg installed.
) else (
echo [WARN] ffmpeg extraction failed. Video thumbnails will not work.
)
:: ── Step 5: Create start.bat ───────────────────────────────────────────────────
:create_start
echo.
echo [..] Creating start.bat...
(
echo @echo off
echo title File Share Server
echo cd /d "%%~dp0"
echo call "%%~dp0venv\Scripts\activate.bat"
echo python server.py
echo pause
) > "%SCRIPT_DIR%start.bat"
echo [OK] start.bat created.
:: ── Done ──────────────────────────────────────────────────────────────────────
echo.
echo ================================
echo Installation complete!
echo.
echo To start the server, run: start.bat
echo ================================
echo.
pause
endlocal