-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.bat
More file actions
221 lines (196 loc) · 5.41 KB
/
Copy pathsetup.bat
File metadata and controls
221 lines (196 loc) · 5.41 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
@echo off
setlocal EnableDelayedExpansion
chcp 65001 >nul 2>&1
title PULSAR Setup
echo.
echo ============================================
echo PULSAR - Setup
echo ============================================
echo.
:: Track what was done
set "DID_PYTHON=0"
set "DID_PIP=0"
set "DID_DEPS=0"
set "DID_PATH=0"
:: ============================================
:: Step 1: Check Python
:: ============================================
echo [1/4] Checking Python...
python --version >nul 2>&1
if errorlevel 1 (
echo.
echo ERROR: Python not found.
echo Download from: https://www.python.org/downloads/
echo IMPORTANT: Check "Add Python to PATH" during installation.
echo.
pause
exit /b 1
)
:: Parse version
for /f "tokens=2 delims= " %%V in ('python --version 2^>^&1') do set "PYVER=%%V"
for /f "tokens=1,2 delims=." %%A in ("%PYVER%") do (
set "PYMAJOR=%%A"
set "PYMINOR=%%B"
)
if !PYMAJOR! LSS 3 (
echo ERROR: Python !PYVER! is too old. Python 3.6+ is required.
echo Download from: https://www.python.org/downloads/
echo.
pause
exit /b 1
)
if !PYMAJOR! EQU 3 if !PYMINOR! LSS 6 (
echo ERROR: Python !PYVER! is too old. Python 3.6+ is required.
echo Download from: https://www.python.org/downloads/
echo.
pause
exit /b 1
)
echo Found Python !PYVER!
set "DID_PYTHON=1"
:: ============================================
:: Step 2: Check pip
:: ============================================
echo.
echo [2/4] Checking pip...
pip --version >nul 2>&1
if errorlevel 1 (
echo pip not found, installing...
python -m ensurepip --default-pip >nul 2>&1
pip --version >nul 2>&1
if errorlevel 1 (
echo.
echo ERROR: Could not install pip.
echo Try manually: python -m ensurepip --default-pip
echo.
pause
exit /b 1
)
echo pip installed successfully.
set "DID_PIP=1"
) else (
for /f "tokens=1,2 delims= " %%A in ('pip --version 2^>^&1') do set "PIPVER=%%B"
echo Found pip !PIPVER!
)
:: ============================================
:: Step 3: Install dependencies
:: ============================================
echo.
echo [3/4] Checking dependencies...
set "NEED_INSTALL=0"
python -c "import numpy" >nul 2>&1
if errorlevel 1 set "NEED_INSTALL=1"
python -c "import astropy" >nul 2>&1
if errorlevel 1 set "NEED_INSTALL=1"
if !NEED_INSTALL! EQU 1 (
echo Installing required packages...
echo.
pip install -r "%~dp0requirements.txt"
if errorlevel 1 (
echo.
echo WARNING: Some packages may have failed to install.
echo You can retry manually: pip install -r requirements.txt
echo.
) else (
echo.
echo Dependencies installed successfully.
)
set "DID_DEPS=1"
) else (
echo Core dependencies already installed.
)
:: ============================================
:: Step 4: Add Commands/ to PATH
:: ============================================
echo.
echo [4/4] Checking PATH...
set "CMDDIR=%~dp0Commands"
:: Remove trailing backslash if present
if "!CMDDIR:~-1!"=="\" set "CMDDIR=!CMDDIR:~0,-1!"
:: Check if already in PATH
echo !PATH! | find /I "%CMDDIR%" >nul
if not errorlevel 1 (
echo Commands/ already in PATH.
goto :summary
)
echo Commands/ is not in PATH.
echo.
echo Add to PATH?
echo [Y] System PATH (requires admin)
echo [U] User PATH only
echo [N] Skip
choice /c YUN /m "Choose: "
if errorlevel 3 goto :summary
if errorlevel 2 (
set "TARGET=USER"
set "REGKEY=HKCU\Environment"
) else (
set "TARGET=SYSTEM"
set "REGKEY=HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
)
:: If system PATH selected, ensure admin
if /I "!TARGET!"=="SYSTEM" (
net session >nul 2>&1
if errorlevel 1 (
echo.
echo Admin rights required for System PATH.
echo Falling back to User PATH...
set "TARGET=USER"
set "REGKEY=HKCU\Environment"
)
)
:: Read current registry PATH
set "OLDPATH="
for /f "tokens=2,*" %%A in ('reg query "!REGKEY!" /v Path 2^>nul') do set "OLDPATH=%%B"
:: Double-check it's not already there (registry PATH vs runtime PATH)
echo !OLDPATH! | find /I "%CMDDIR%" >nul
if not errorlevel 1 (
echo Already in !TARGET! PATH.
goto :summary
)
:: Build and set new PATH
if defined OLDPATH (
set "NEWPATH=!OLDPATH!;%CMDDIR%"
) else (
set "NEWPATH=%CMDDIR%"
)
reg add "!REGKEY!" /v Path /t REG_EXPAND_SZ /d "!NEWPATH!" /f >nul
if errorlevel 1 (
echo ERROR: Failed to update PATH.
goto :summary
)
:: Broadcast WM_SETTINGCHANGE
powershell -Command "[Environment]::SetEnvironmentVariable('Path',[Environment]::GetEnvironmentVariable('Path','User'),'User')" >nul 2>&1
echo Added to !TARGET! PATH: %CMDDIR%
echo Restart your console to apply.
set "DID_PATH=1"
:: ============================================
:: Step 5: Summary
:: ============================================
:summary
echo.
echo ============================================
echo Setup complete
echo ============================================
echo.
if !DID_PYTHON! EQU 1 echo [OK] Python !PYVER!
if !DID_PIP! EQU 1 (
echo [OK] pip installed
) else (
echo [OK] pip
)
if !DID_DEPS! EQU 1 (
echo [OK] Dependencies installed
) else (
echo [OK] Dependencies (already present)
)
if !DID_PATH! EQU 1 (
echo [OK] PATH updated
) else (
echo [--] PATH (unchanged)
)
echo.
echo Optional: install astrometry.net for plate solving
echo (see SCRIPTS.md, autosolve section)
echo.
pause