-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.bat
More file actions
255 lines (223 loc) · 6.01 KB
/
Copy pathupdate.bat
File metadata and controls
255 lines (223 loc) · 6.01 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
@echo off
REM === KEEP WINDOW OPEN WRAPPER ===
if not defined UPDATE_WRAPPER (
set "UPDATE_WRAPPER=1"
cmd /k "%~f0" %*
exit /b
)
setlocal EnableDelayedExpansion
title T2AutoTron 2.1 - Updater
color 0E
echo.
echo ===============================================
echo T2AutoTron 2.1 - Update Tool
echo ===============================================
echo.
REM Get script directory
set "SCRIPT_DIR=%~dp0"
cd /d "%SCRIPT_DIR%"
REM Check for git
where git >nul 2>&1
if errorlevel 1 (
color 0E
echo Git is not installed - attempting to install...
echo.
call :InstallGit
where git >nul 2>&1
if errorlevel 1 (
echo.
echo ERROR: Could not install Git automatically.
echo.
echo Please install Git manually from: https://git-scm.com/
echo Then run this update script again.
echo.
pause
exit /b 1
)
echo Git installed successfully!
echo.
)
REM Check if this is a git repo - if not, convert it
git rev-parse --git-dir >nul 2>&1
if errorlevel 1 (
echo This folder is not yet connected to Git.
echo Converting to Git-enabled install...
echo.
call :ConvertToGit
if errorlevel 1 (
color 0C
echo.
echo ERROR: Could not convert to Git repository.
echo.
pause
exit /b 1
)
echo.
echo Successfully connected to Git!
echo.
)
REM Make sure we have the remote
git remote -v | findstr "origin" >nul 2>&1
if errorlevel 1 (
echo Adding remote origin...
git remote add origin https://github.com/gregtee2/T2AutoTron.git
)
echo [1/4] Checking for updates...
git fetch origin stable 2>nul
if errorlevel 1 (
echo Fetching all branches...
git fetch origin
)
REM Count commits behind
for /f %%i in ('git rev-list HEAD..origin/stable --count 2^>nul') do set "BEHIND=%%i"
if "!BEHIND!"=="" set "BEHIND=0"
if "!BEHIND!"=="0" (
color 0A
echo.
echo ===============================================
echo Already up to date!
echo ===============================================
echo.
pause
exit /b 0
)
echo Found !BEHIND! new commit(s)!
echo.
echo Recent changes:
echo -----------------------------------------------
git log HEAD..origin/stable --oneline --no-decorate -10
echo -----------------------------------------------
echo.
REM Check for local changes
git diff --quiet 2>nul
if errorlevel 1 (
echo Stashing local changes...
git stash push -m "Auto-stash before update"
set "STASHED=1"
)
REM Pull updates - use reset for clean update
echo [2/4] Downloading updates...
git checkout stable 2>nul || git checkout -b stable origin/stable 2>nul
git reset --hard origin/stable
if errorlevel 1 (
color 0C
echo ERROR: Update failed!
echo.
pause
exit /b 1
)
REM Update dependencies
echo.
echo [3/4] Updating backend dependencies...
cd /d "%SCRIPT_DIR%v3_migration\backend"
call npm install --silent 2>nul
if errorlevel 1 (
echo Running full install...
call npm install
)
echo.
echo [4/4] Updating frontend dependencies...
cd /d "%SCRIPT_DIR%v3_migration\frontend"
call npm install --silent 2>nul
if errorlevel 1 (
echo Running full install...
call npm install
)
cd /d "%SCRIPT_DIR%"
REM Restore stashed changes if any
if defined STASHED (
echo.
echo Restoring your local changes...
git stash pop 2>nul
)
REM Done!
echo.
color 0A
echo ===============================================
echo Update Complete!
echo ===============================================
echo.
echo Updated !BEHIND! commit(s).
echo.
echo To start T2AutoTron, double-click:
echo start_servers.bat
echo.
echo ===============================================
echo.
pause
exit /b 0
REM ===================================================
REM Function: Install Git
REM ===================================================
:InstallGit
echo -----------------------------------------------
echo Installing Git...
echo -----------------------------------------------
REM Try winget first
where winget >nul 2>&1
if not errorlevel 1 (
echo Using Windows Package Manager...
winget install Git.Git --accept-package-agreements --accept-source-agreements -h
REM Refresh PATH
set "PATH=%PATH%;C:\Program Files\Git\cmd"
where git >nul 2>&1
if not errorlevel 1 (
exit /b 0
)
)
REM Try Chocolatey
where choco >nul 2>&1
if not errorlevel 1 (
echo Using Chocolatey...
choco install git -y
set "PATH=%PATH%;C:\Program Files\Git\cmd"
where git >nul 2>&1
if not errorlevel 1 (
exit /b 0
)
)
echo.
echo Could not install Git automatically.
echo Please install from: https://git-scm.com/download/win
exit /b 1
REM ===================================================
REM Function: Convert ZIP install to Git
REM ===================================================
:ConvertToGit
echo -----------------------------------------------
echo Connecting to T2AutoTron repository...
echo -----------------------------------------------
echo.
REM Initialize git repo
git init
if errorlevel 1 (
echo ERROR: git init failed
exit /b 1
)
REM Add remote
git remote add origin https://github.com/gregtee2/T2AutoTron.git
if errorlevel 1 (
echo ERROR: Could not add remote
exit /b 1
)
REM Fetch the stable branch
echo Fetching latest version...
git fetch origin stable
if errorlevel 1 (
echo ERROR: Could not fetch from repository
exit /b 1
)
REM Reset to stable branch (keeps local files, marks them as modified if different)
git reset origin/stable
if errorlevel 1 (
echo ERROR: Could not reset to stable
exit /b 1
)
REM Checkout stable branch
git checkout -b stable
if errorlevel 1 (
echo ERROR: Could not checkout stable branch
exit /b 1
)
echo Connected to T2AutoTron repository!
exit /b 0