forked from channeldorg/channeld-ue-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup.bat
129 lines (116 loc) · 4.67 KB
/
Setup.bat
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
@echo off
set ChanneldVersion=v0.5.0
set ChanneldRepoUrl=https://github.com/metaworking/channeld.git
set WorkspaceDir=%~dp0
set ChanneldLocalSourceDir=%~dp0Source\ThirdParty\channeld
set ErrorMessages=run %~dp0%~n0.bat again
echo Start setup
echo checking git...
where git
if NOT %ERRORLEVEL% == 0 (
echo ERROR: Please install git[https://git-scm.com/downloads] first and %ErrorMessages%.
exit /b 1
)
echo 'git' is installed.
echo Checking golang...
where go
if %ERRORLEVEL% == 0 (
echo 'golang' is installed.
goto skipInstallGo
)
:prompt
: If go is not installed, prompt to install golang.
set /p installGolang='channel' runs with golang, do you want to install golang now? [y/n]
if "%installGolang%" == "y" (
goto downloadGo
) else if "%installGolang%" == "n" (
goto cannelInstallGo
) else (
goto prompt
)
:downloadGo
set golangVersion=1.18.10
set golangOS=windows
set golangArch=amd64
set golangDownloadUrl=https://golang.org/dl/go%golangVersion%.%golangOS%-%golangArch%.msi
set golangDownloadPath=%TEMP%\go%golangVersion%.%golangOS%-%golangArch%.msi
echo Try to dowanload golang installer from %golangDownloadUrl%.
echo Downloading...
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%golangDownloadUrl%', '%golangDownloadPath%')"
if %ERRORLEVEL% == 0 (
goto installGo
)
: If dowanload failed, try to use https://golang.google.cn/dl/ to download the golang installer.
set golangDownloadUrl=https://golang.google.cn/dl/go%golangVersion%.%golangOS%-%golangArch%.msi
echo Download failed, try to download golang installer from %golangDownloadUrl%.
echo Downloading...
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%golangDownloadUrl%', '%golangDownloadPath%')"
if %ERRORLEVEL% == 0 (
goto installGo
)
: If dowanload failed, exit the script.
echo Download golang installer failed.
goto cannelInstallGo
:installGo
echo Installing golang...
msiexec /i "%golangDownloadPath%" /passive /qr /norestart /log "%TEMP%\golang_install.log"
if NOT %ERRORLEVEL% == 0 (
echo Download golang install failed.
goto cannelInstallGo
)
goto installGoFinfished
:cannelInstallGo
echo ERROR: Please install Golang[https://go.dev/dl/] first and %ErrorMessages%.
exit /b 2
:installGoFinfished
echo Installing Golang is complete.
:skipInstallGo
if NOT DEFINED CHANNELD_PATH (
goto cloneChanneld
) else if NOT EXIST "%CHANNELD_PATH%\.git" (
set ChanneldLocalSourceDir=%CHANNELD_PATH%
goto cloneChanneld
) else (
goto skipCloneChanneld
)
:cloneChanneld
:: Clone channeld from github
if NOT EXIST "%ChanneldLocalSourceDir%\.git" (
echo Clone channeld:%ChanneldVersion% from %ChanneldRepoUrl% ...
git -c advice.detachedHead=false clone --branch %ChanneldVersion% %ChanneldRepoUrl% "%ChanneldLocalSourceDir%"
if NOT %ERRORLEVEL% == 0 (
echo ERROR: Clone channel:%ChanneldVersion% failed, please clone channeld[%ChanneldRepoUrl%]:%ChanneldVersion% manually and %ErrorMessages%.
exit /b 3
)
: If clone failed with internal error like "unable to access", the ERRORLEVEL still be 0, so we need to check the .git dir.
if NOT EXIST "%ChanneldLocalSourceDir%\.git" (
echo ERROR: Clone channel:%ChanneldVersion% failed, please clone channeld[%ChanneldRepoUrl%]:%ChanneldVersion% manually and %ErrorMessages%.
exit /b 3
)
echo Clone channeld:%ChanneldVersion% successfully, the source code is at %ChanneldLocalSourceDir%
)
:skipCloneChanneld
:: Set CHANNELD_PATH user env to channeld source dir when the CHANNELD_PATH is not set
if NOT DEFINED CHANNELD_PATH (
echo Set user environment variable CHANNELD_PATH to %ChanneldLocalSourceDir%
setx CHANNELD_PATH %ChanneldLocalSourceDir%
:: invoke refreshenv.bat to make the CHANNELD_PATH take effect
call "%~dp0Source\ThirdParty\refrenv.bat"
echo If you are not running the script via cmd.exe, please restart your shell before update ChanneldUE source code !!!
) else (
echo CHANNELD_PATH is already set to %CHANNELD_PATH%
)
:setupPostMergeHook
echo Set post-merge hook to .git\hooks
set PostMergeHook=%~dp0.git\hooks\post-merge
echo #!/bin/bash > "%PostMergeHook%"
echo "$(cd $(dirname ${BASH_SOURCE[0]}); pwd)/../../Source/ThirdParty/update_channeld.sh" >> "%PostMergeHook%"
echo exit 0 >> "%PostMergeHook%"
echo Downloading channeld dependencies...
cd "%ChanneldLocalSourceDir%"
set GOPROXY=https://goproxy.io,direct
go mod download -x
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
cd "%WorkspaceDir%"
echo Setup Completed