-
Notifications
You must be signed in to change notification settings - Fork 17
/
goluwa.cmd
213 lines (167 loc) · 4.78 KB
/
goluwa.cmd
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
@echo off
SetLocal EnableDelayedExpansion
if "%~1" == "_DL" (
call:DownloadFile "%~2" "%~3"
goto:eof
)
(set | find "ProgramFiles(x86)" > NUL) && (echo "!ProgramFiles(x86)!" | find "x86") > NUL && set ARCH=x64|| set ARCH=x86
set OS=windows
set ARG_LINE=%*
set BRANCH=develop
set BINARY_DIR=core\bin\!OS!_!ARCH!
set BINARY_NAME=luajit.exe
set BASE_BINARY_URL=https://gitlab.com/CapsAdmin/goluwa-binaries/raw/master/core/bin/!OS!_!ARCH!/
set BASE_SCRIPT_URL=https://gitlab.com/CapsAdmin/goluwa/raw/!BRANCH!/
set HTTP_TUNNEL=http://80.203.97.200:4123/
set SCRIPT_PATH=core/lua/boot.lua
IF %0 == "%~0" set RAN_FROM_FILEBROWSER=1
if defined VSCODE_CWD (
set RAN_FROM_FILEBROWSER=0
)
if defined TERM_PROGRAM (
set RAN_FROM_FILEBROWSER=0
)
:Start
call:Main
goto:eof
:Main
SetLocal
if not exist "!BINARY_DIR!" ( mkdir "!BINARY_DIR!" )
if not exist "core" ( mkdir "core" )
if not exist "core\lua" ( mkdir "core\lua" )
if not exist "!BINARY_DIR!\lua_downloaded_and_validated" (
call:DownloadFile "!BASE_BINARY_URL!lua51.dll" "!BINARY_DIR!\lua51.dll"
)
if not exist "!BINARY_DIR!\!BINARY_NAME!" (
call:GetLua "!BASE_BINARY_URL!!BINARY_NAME!" "!BINARY_DIR!" "!BINARY_NAME!"
)
if not exist "!SCRIPT_PATH!" (
call:DownloadFile "!BASE_SCRIPT_URL!!SCRIPT_PATH!" "!SCRIPT_PATH!"
)
set "GOLUWA_ARG_LINE=!ARG_LINE!"
set GOLUWA_SCRIPT_PATH=!SCRIPT_PATH!
set GOLUWA_RAN_FROM_FILEBROWSER=!RAN_FROM_FILEBROWSER!
set GOLUWA_BINARY_DIR=!BINARY_DIR!
set GOLUWA_BRANCH=!BRANCH!
set "cmd_line=!BINARY_DIR!\!BINARY_NAME! !SCRIPT_PATH!"
IF !RAN_FROM_FILEBROWSER! equ 1 (
set "GOLUWA_ARG_LINE=--verbose"
!cmd_line!
set err=%errorlevel%
) else (
!cmd_line!
set err=%errorlevel%
)
if !err! neq 0 (
pause
)
EndLocal
goto:eof
:GetLua
SetLocal
set url=%~1
set directory=%~2
set filename=%~3
set abs_path=%~2\%~3
if not exist "!directory!\lua_downloaded_and_validated" (
call:DownloadFile "!url!" "!abs_path!"
!abs_path! -e "os.exit(1)"
if !errorlevel! neq 1 (
call:AlertBox "exit code from lua does not match 'os.exit(1)'" "error"
del !abs_path!
pause
EndLocal
goto:eof
)
echo. 2>!directory!\lua_downloaded_and_validated
)
EndLocal
goto:eof
:DownloadFile
SetLocal
set url=%~1
set output_path=%~2
if "%windir%" == "C:\ReactOS" (
echo "!url!"
echo "!output_path!"
dwnl "!url!" "!output_path!"
) else (
if not exist !SystemRoot!\System32\where.exe (
set tmp_name=!TEMP!\lua_one_click_jscript_download.js
del /F !tmp_name! 2>NUL
echo //test > !tmp_name!
if not exist !tmp_name! (
call:AlertBox "unable to create temp file !tmp_name! !" "error"
exit /b
)
set forward_slash_path=!output_path:\=/!
echo try { >> !tmp_name!
echo var req = new ActiveXObject^("Microsoft.XMLHTTP"^) >> !tmp_name!
echo req.Open^("GET","!HTTP_TUNNEL!!url!",false^) >> !tmp_name!
echo req.Send^(^) >> !tmp_name!
echo var stream = new ActiveXObject^("ADODB.Stream"^) >> !tmp_name!
echo stream.Type = 1 >> !tmp_name!
echo stream.Open^(^) >> !tmp_name!
echo stream.Write^(req.responseBody^) >> !tmp_name!
echo stream.SaveToFile^("!forward_slash_path!", 2^) >> !tmp_name!
echo stream.Close^(^) >> !tmp_name!
echo } catch^(err^) { >> !tmp_name!
echo WScript.Echo^("jscript error: "+err.description^) >> !tmp_name!
echo WScript.Quit^(1^) >> !tmp_name!
echo } >> !tmp_name!
cscript /Nologo /E:JScript !tmp_name!
if !errorlevel! neq 0 (
call:AlertBox "failed to execute JScript to download file" "error"
goto:eof
)
del /F !tmp_name! 2>NUL
) else (
where curl
if !errorlevel! equ 0 (
curl -L --url "!url!" --output "!output_path!"
if !errorlevel! neq 0 (
call:AlertBox "curl failed to execute with error code !errorlevel!" "error"
)
goto:eof
) else (
where powershell
if !errorlevel! equ 0 (
PowerShell -NoLogo -NoProfile -NonInteractive "(New-Object System.Net.WebClient).DownloadFile('!url!','!output_path!')"
if !errorlevel! neq 0 (
call:AlertBox "powershell failed to execute with error code !errorlevel!" "error"
)
goto:eof
)
)
call:AlertBox "unable to find curl or powershell"
exit /b
)
)
EndLocal
goto:eof
:AlertBox
SetLocal
set msg=%~1
set title=%~2
IF !RAN_FROM_FILEBROWSER! equ 1 (
set tmp_name=!TEMP!\lua_one_click_jscript_msgbox.vbs
del /F !tmp_name! 2>NUL
echo ' test > !tmp_name!
if not exist !tmp_name! (
echo "unable to create temp file !tmp_name! for message box !"
echo !title!: !msg!
goto:eof
)
set forward_slash_path=!output_path:\=/!
echo MsgBox "!msg!", vbOKOnly, "!title!" >> !tmp_name!
cscript /Nologo !tmp_name!
if !errorlevel! neq 0 (
echo "Failed to execute vbscript for message box"
echo !title!: !msg!
)
del /F !tmp_name! 2>NUL
) else (
echo !title!: !msg!
)
EndLocal
goto:eof