summaryrefslogtreecommitdiff
path: root/meshmc/bootstrap.cmd
blob: 9da8b46195cc3bef30f36c68bb33c827d8d44082 (plain)
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
@echo off
rem SPDX-License-Identifier: GPL-3.0-or-later
rem SPDX-FileCopyrightText: 2026 Project Tick
rem
rem MeshMC Bootstrap Script (Windows)
rem Checks dependencies, installs via vcpkg/scoop, and sets up lefthook.

setlocal EnableDelayedExpansion

cd /d "%~dp0"

echo.
echo [INFO]  MeshMC Bootstrap
echo ---------------------------------------------
echo.

rem ── Submodules ──────────────────────────────────────────────────────────────
if not exist ".git" (
    echo [ERR]  Not a git repository. Please run this script from the project root. 1>&2
    exit /b 1
)

echo [INFO]  Setting up submodules...
git submodule update --init --recursive
if errorlevel 1 (
    echo [ERR]  Submodule initialization failed. 1>&2
    exit /b 1
)
echo [ OK ]  Submodules initialized
echo.

rem ── Check for scoop ─────────────────────────────────────────────────────────
set "HAS_SCOOP=0"
where scoop >nul 2>&1 && set "HAS_SCOOP=1"

if "%HAS_SCOOP%"=="0" (
    echo [WARN]  Scoop is not installed.
    echo [INFO]  Installing Scoop...
    powershell -NoProfile -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force; Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression"
    if errorlevel 1 (
        echo [ERR]  Scoop installation failed. Install manually from https://scoop.sh 1>&2
        exit /b 1
    )
    rem Refresh PATH
    set "PATH=%USERPROFILE%\scoop\shims;%PATH%"
    echo [ OK ]  Scoop installed
) else (
    echo [ OK ]  Scoop is installed
)
echo.

rem ── Check for vcpkg ─────────────────────────────────────────────────────────
set "HAS_VCPKG=0"
where vcpkg >nul 2>&1 && set "HAS_VCPKG=1"

if "%HAS_VCPKG%"=="0" (
    echo [WARN]  vcpkg is not installed.
    echo [INFO]  You can install vcpkg via: scoop install vcpkg
    echo [INFO]  Or clone from https://github.com/microsoft/vcpkg
)
echo.

rem ── Dependency Checks ──────────────────────────────────────────────────────
echo [INFO]  Checking dependencies...
echo.

set "MISSING="

call :check_cmd npm npm
call :check_cmd Go go
call :check_cmd lefthook lefthook
call :check_cmd reuse reuse
call :check_cmd CMake cmake
call :check_cmd Git git

echo.

rem ── Install Missing Dependencies via Scoop ─────────────────────────────────
if not defined MISSING (
    echo [ OK ]  All command-line dependencies are already installed!
    goto :vcpkg_libs
)

echo [INFO]  Missing dependencies: %MISSING%
echo [INFO]  Installing via Scoop...
echo.

rem Add extras bucket for some packages
scoop bucket add extras >nul 2>&1
scoop bucket add main >nul 2>&1

echo !MISSING! | findstr /i "npm" >nul && (
    echo [INFO]  Installing Node.js ^(includes npm^)...
    scoop install nodejs
)

echo !MISSING! | findstr /i "Go" >nul && (
    echo [INFO]  Installing Go...
    scoop install go
)

echo !MISSING! | findstr /i "CMake" >nul && (
    echo [INFO]  Installing CMake...
    scoop install cmake
)

echo !MISSING! | findstr /i "reuse" >nul && (
    echo [INFO]  Installing reuse via pip...
    where pip >nul 2>&1 || scoop install python
    pip install reuse
)

echo !MISSING! | findstr /i "lefthook" >nul && (
    echo [INFO]  Installing lefthook...
    where go >nul 2>&1 && (
        go install github.com/evilmartians/lefthook@latest
        set "PATH=%GOPATH%\bin;%USERPROFILE%\go\bin;%PATH%"
    ) || (
        scoop install lefthook
    )
)

echo.
echo [ OK ]  Package installation complete
echo.

rem ── vcpkg Libraries ─────────────────────────────────────────────────────────
:vcpkg_libs
where vcpkg >nul 2>&1
if errorlevel 1 (
    echo [WARN]  vcpkg not found. Skipping C/C++ library installation.
    echo [WARN]  You will need to manually install: qt6, quazip, zlib, extra-cmake-modules
    goto :setup_lefthook
)

echo [INFO]  Installing C/C++ libraries via vcpkg...

set "VCPKG_TRIPLET=x64-windows"

vcpkg install qt5-base:%VCPKG_TRIPLET% >nul 2>&1 || (
    echo [INFO]  Installing Qt6...
    vcpkg install qtbase:%VCPKG_TRIPLET%
)

echo [INFO]  Installing quazip...
vcpkg install quazip:%VCPKG_TRIPLET%

echo [INFO]  Installing zlib...
vcpkg install zlib:%VCPKG_TRIPLET%

echo [INFO]  Installing extra-cmake-modules...
vcpkg install ecm:%VCPKG_TRIPLET%

echo.
echo [ OK ]  vcpkg libraries installed
echo.

rem ── Lefthook Setup ─────────────────────────────────────────────────────────
:setup_lefthook
where lefthook >nul 2>&1
if errorlevel 1 (
    echo [ERR]  lefthook is not available. Cannot set up git hooks. 1>&2
    exit /b 1
)

echo [INFO]  Setting up lefthook...
lefthook install
if errorlevel 1 (
    echo [ERR]  lefthook install failed. 1>&2
    exit /b 1
)
echo [ OK ]  Lefthook hooks installed into .git\hooks
echo.

echo ---------------------------------------------
echo [ OK ]  Bootstrap successful! You're all set.
echo.

endlocal
exit /b 0

rem ── Helper Functions ────────────────────────────────────────────────────────
:check_cmd
set "NAME=%~1"
set "CMD=%~2"
where %CMD% >nul 2>&1
if errorlevel 1 (
    echo [WARN]  %NAME% is NOT installed
    set "MISSING=!MISSING! %NAME%"
) else (
    for /f "delims=" %%i in ('where %CMD%') do (
        echo [ OK ]  %NAME% is installed ^(%%i^)
        goto :eof
    )
)
goto :eof