forked from mmuncan1980/xmrig_setup_m0dd3d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_moneroocean_miner.bat
360 lines (292 loc) · 14.3 KB
/
setup_moneroocean_miner.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
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
@echo off
set VERSION=2.5
rem printing greetings
echo MoneroOcean mining setup script v%VERSION%.
echo ^(please report issues to [email protected] email^)
echo.
net session >nul 2>&1
if %errorLevel% == 0 (set ADMIN=1) else (set ADMIN=0)
rem command line arguments
set WALLET=%1
rem this one is optional
set EMAIL=%2
rem checking prerequisites
if [%WALLET%] == [] (
echo Script usage:
echo ^> setup_moneroocean_miner.bat ^<wallet address^> [^<your email address^>]
echo ERROR: Please specify your wallet address
exit /b 1
)
for /f "delims=." %%a in ("%WALLET%") do set WALLET_BASE=%%a
call :strlen "%WALLET_BASE%", WALLET_BASE_LEN
if %WALLET_BASE_LEN% == 106 goto WALLET_LEN_OK
if %WALLET_BASE_LEN% == 95 goto WALLET_LEN_OK
echo ERROR: Wrong wallet address length (should be 106 or 95): %WALLET_BASE_LEN%
exit /b 1
:WALLET_LEN_OK
if ["%USERPROFILE%"] == [""] (
echo ERROR: Please define USERPROFILE environment variable to your user directory
exit /b 1
)
if not exist "%USERPROFILE%" (
echo ERROR: Please make sure user directory %USERPROFILE% exists
exit /b 1
)
where powershell >NUL
if not %errorlevel% == 0 (
echo ERROR: This script requires "powershell" utility to work correctly
exit /b 1
)
where find >NUL
if not %errorlevel% == 0 (
echo ERROR: This script requires "find" utility to work correctly
exit /b 1
)
where findstr >NUL
if not %errorlevel% == 0 (
echo ERROR: This script requires "findstr" utility to work correctly
exit /b 1
)
where tasklist >NUL
if not %errorlevel% == 0 (
echo ERROR: This script requires "tasklist" utility to work correctly
exit /b 1
)
if %ADMIN% == 1 (
where sc >NUL
if not %errorlevel% == 0 (
echo ERROR: This script requires "sc" utility to work correctly
exit /b 1
)
)
rem calculating port
set /a "EXP_MONERO_HASHRATE = %NUMBER_OF_PROCESSORS% * 700 / 1000"
if [%EXP_MONERO_HASHRATE%] == [] (
echo ERROR: Can't compute projected Monero hashrate
exit
)
if %EXP_MONERO_HASHRATE% gtr 8192 ( set PORT=18192 & goto PORT_OK )
if %EXP_MONERO_HASHRATE% gtr 4096 ( set PORT=14096 & goto PORT_OK )
if %EXP_MONERO_HASHRATE% gtr 2048 ( set PORT=12048 & goto PORT_OK )
if %EXP_MONERO_HASHRATE% gtr 1024 ( set PORT=11024 & goto PORT_OK )
if %EXP_MONERO_HASHRATE% gtr 512 ( set PORT=10512 & goto PORT_OK )
if %EXP_MONERO_HASHRATE% gtr 256 ( set PORT=10256 & goto PORT_OK )
if %EXP_MONERO_HASHRATE% gtr 128 ( set PORT=10128 & goto PORT_OK )
if %EXP_MONERO_HASHRATE% gtr 64 ( set PORT=10064 & goto PORT_OK )
if %EXP_MONERO_HASHRATE% gtr 32 ( set PORT=10032 & goto PORT_OK )
if %EXP_MONERO_HASHRATE% gtr 16 ( set PORT=10016 & goto PORT_OK )
if %EXP_MONERO_HASHRATE% gtr 8 ( set PORT=10008 & goto PORT_OK )
if %EXP_MONERO_HASHRATE% gtr 4 ( set PORT=10004 & goto PORT_OK )
if %EXP_MONERO_HASHRATE% gtr 2 ( set PORT=10002 & goto PORT_OK )
set PORT=10001
:PORT_OK
rem printing intentions
set "LOGFILE=%USERPROFILE%\moneroocean\xmrig.log"
echo I will download, setup and run in background Monero CPU miner with logs in %LOGFILE% file.
echo If needed, miner in foreground can be started by %USERPROFILE%\moneroocean\miner.bat script.
echo Mining will happen to %WALLET% wallet.
if not [%EMAIL%] == [] (
echo ^(and %EMAIL% email as password to modify wallet options later at https://moneroocean.stream site^)
)
echo.
if %ADMIN% == 0 (
echo Since I do not have admin access, mining in background will be started using your startup directory script and only work when your are logged in this host.
) else (
echo Mining in background will be performed using moneroocean_miner service.
)
echo.
echo JFYI: This host has %NUMBER_OF_PROCESSORS% CPU threads, so projected Monero hashrate is around %EXP_MONERO_HASHRATE% KH/s.
echo.
pause
rem start doing stuff: preparing miner
echo [*] Removing previous moneroocean miner (if any)
sc stop moneroocean_miner
sc delete moneroocean_miner
taskkill /f /t /im xmrig.exe
:REMOVE_DIR0
echo [*] Removing "%USERPROFILE%\moneroocean" directory
timeout 5
rmdir /q /s "%USERPROFILE%\moneroocean" >NUL 2>NUL
IF EXIST "%USERPROFILE%\moneroocean" GOTO REMOVE_DIR0
echo [*] Downloading MoneroOcean advanced version of xmrig to "%USERPROFILE%\xmrig.zip"
powershell -Command "$wc = New-Object System.Net.WebClient; $wc.DownloadFile('https://raw.githubusercontent.com/MoneroOcean/xmrig_setup/master/xmrig.zip', '%USERPROFILE%\xmrig.zip')"
if errorlevel 1 (
echo ERROR: Can't download MoneroOcean advanced version of xmrig
goto MINER_BAD
)
echo [*] Unpacking "%USERPROFILE%\xmrig.zip" to "%USERPROFILE%\moneroocean"
powershell -Command "Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory('%USERPROFILE%\xmrig.zip', '%USERPROFILE%\moneroocean')"
if errorlevel 1 (
echo [*] Downloading 7za.exe to "%USERPROFILE%\7za.exe"
powershell -Command "$wc = New-Object System.Net.WebClient; $wc.DownloadFile('https://raw.githubusercontent.com/MoneroOcean/xmrig_setup/master/7za.exe', '%USERPROFILE%\7za.exe')"
if errorlevel 1 (
echo ERROR: Can't download 7za.exe to "%USERPROFILE%\7za.exe"
exit /b 1
)
echo [*] Unpacking stock "%USERPROFILE%\xmrig.zip" to "%USERPROFILE%\moneroocean"
"%USERPROFILE%\7za.exe" x -y -o"%USERPROFILE%\moneroocean" "%USERPROFILE%\xmrig.zip" >NUL
del "%USERPROFILE%\7za.exe"
)
del "%USERPROFILE%\xmrig.zip"
echo [*] Checking if advanced version of "%USERPROFILE%\moneroocean\xmrig.exe" works fine ^(and not removed by antivirus software^)
powershell -Command "$out = cat '%USERPROFILE%\moneroocean\config.json' | %%{$_ -replace '\"donate-level\": *\d*,', '\"donate-level\": 1,'} | Out-String; $out | Out-File -Encoding ASCII '%USERPROFILE%\moneroocean\config.json'"
"%USERPROFILE%\moneroocean\xmrig.exe" --help >NUL
if %ERRORLEVEL% equ 0 goto MINER_OK
:MINER_BAD
if exist "%USERPROFILE%\moneroocean\xmrig.exe" (
echo WARNING: Advanced version of "%USERPROFILE%\moneroocean\xmrig.exe" is not functional
) else (
echo WARNING: Advanced version of "%USERPROFILE%\moneroocean\xmrig.exe" was removed by antivirus
)
echo [*] Looking for the latest version of Monero miner
for /f tokens^=2^ delims^=^" %%a IN ('powershell -Command "[Net.ServicePointManager]::SecurityProtocol = 'tls12, tls11, tls'; $wc = New-Object System.Net.WebClient; $str = $wc.DownloadString('https://github.com/xmrig/xmrig/releases/latest'); $str | findstr msvc-win64.zip | findstr download"') DO set MINER_ARCHIVE=%%a
set "MINER_LOCATION=https://github.com%MINER_ARCHIVE%"
echo [*] Downloading "%MINER_LOCATION%" to "%USERPROFILE%\xmrig.zip"
powershell -Command "[Net.ServicePointManager]::SecurityProtocol = 'tls12, tls11, tls'; $wc = New-Object System.Net.WebClient; $wc.DownloadFile('%MINER_LOCATION%', '%USERPROFILE%\xmrig.zip')"
if errorlevel 1 (
echo ERROR: Can't download "%MINER_LOCATION%" to "%USERPROFILE%\xmrig.zip"
exit /b 1
)
:REMOVE_DIR1
echo [*] Removing "%USERPROFILE%\moneroocean" directory
timeout 5
rmdir /q /s "%USERPROFILE%\moneroocean" >NUL 2>NUL
IF EXIST "%USERPROFILE%\moneroocean" GOTO REMOVE_DIR1
echo [*] Unpacking "%USERPROFILE%\xmrig.zip" to "%USERPROFILE%\moneroocean"
powershell -Command "Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory('%USERPROFILE%\xmrig.zip', '%USERPROFILE%\moneroocean')"
if errorlevel 1 (
echo [*] Downloading 7za.exe to "%USERPROFILE%\7za.exe"
powershell -Command "$wc = New-Object System.Net.WebClient; $wc.DownloadFile('https://raw.githubusercontent.com/MoneroOcean/xmrig_setup/master/7za.exe', '%USERPROFILE%\7za.exe')"
if errorlevel 1 (
echo ERROR: Can't download 7za.exe to "%USERPROFILE%\7za.exe"
exit /b 1
)
echo [*] Unpacking advanced "%USERPROFILE%\xmrig.zip" to "%USERPROFILE%\moneroocean"
"%USERPROFILE%\7za.exe" x -y -o"%USERPROFILE%\moneroocean" "%USERPROFILE%\xmrig.zip" >NUL
if errorlevel 1 (
echo ERROR: Can't unpack "%USERPROFILE%\xmrig.zip" to "%USERPROFILE%\moneroocean"
exit /b 1
)
del "%USERPROFILE%\7za.exe"
)
del "%USERPROFILE%\xmrig.zip"
echo [*] Checking if stock version of "%USERPROFILE%\moneroocean\xmrig.exe" works fine ^(and not removed by antivirus software^)
powershell -Command "$out = cat '%USERPROFILE%\moneroocean\config.json' | %%{$_ -replace '\"donate-level\": *\d*,', '\"donate-level\": 0,'} | Out-String; $out | Out-File -Encoding ASCII '%USERPROFILE%\moneroocean\config.json'"
"%USERPROFILE%\moneroocean\xmrig.exe" --help >NUL
if %ERRORLEVEL% equ 0 goto MINER_OK
if exist "%USERPROFILE%\moneroocean\xmrig.exe" (
echo WARNING: Stock version of "%USERPROFILE%\moneroocean\xmrig.exe" is not functional
) else (
echo WARNING: Stock version of "%USERPROFILE%\moneroocean\xmrig.exe" was removed by antivirus
)
exit /b 1
:MINER_OK
echo [*] Miner "%USERPROFILE%\moneroocean\xmrig.exe" is OK
for /f "tokens=*" %%a in ('powershell -Command "hostname | %%{$_ -replace '[^a-zA-Z0-9]+', '_'}"') do set PASS=%%a
if [%PASS%] == [] (
set PASS=na
)
if not [%EMAIL%] == [] (
set "PASS=%PASS%:%EMAIL%"
)
powershell -Command "$out = cat '%USERPROFILE%\moneroocean\config.json' | %%{$_ -replace '\"url\": *\".*\",', '\"url\": \"gulf.moneroocean.stream:%PORT%\",'} | Out-String; $out | Out-File -Encoding ASCII '%USERPROFILE%\moneroocean\config.json'"
powershell -Command "$out = cat '%USERPROFILE%\moneroocean\config.json' | %%{$_ -replace '\"user\": *\".*\",', '\"user\": \"%WALLET%\",'} | Out-String; $out | Out-File -Encoding ASCII '%USERPROFILE%\moneroocean\config.json'"
powershell -Command "$out = cat '%USERPROFILE%\moneroocean\config.json' | %%{$_ -replace '\"pass\": *\".*\",', '\"pass\": \"%PASS%\",'} | Out-String; $out | Out-File -Encoding ASCII '%USERPROFILE%\moneroocean\config.json'"
powershell -Command "$out = cat '%USERPROFILE%\moneroocean\config.json' | %%{$_ -replace '\"max-cpu-usage\": *\d*,', '\"max-cpu-usage\": 100,'} | Out-String; $out | Out-File -Encoding ASCII '%USERPROFILE%\moneroocean\config.json'"
set LOGFILE2=%LOGFILE:\=\\%
powershell -Command "$out = cat '%USERPROFILE%\moneroocean\config.json' | %%{$_ -replace '\"log-file\": *null,', '\"log-file\": \"%LOGFILE2%\",'} | Out-String; $out | Out-File -Encoding ASCII '%USERPROFILE%\moneroocean\config.json'"
copy /Y "%USERPROFILE%\moneroocean\config.json" "%USERPROFILE%\moneroocean\config_background.json" >NUL
powershell -Command "$out = cat '%USERPROFILE%\moneroocean\config_background.json' | %%{$_ -replace '\"background\": *false,', '\"background\": true,'} | Out-String; $out | Out-File -Encoding ASCII '%USERPROFILE%\moneroocean\config_background.json'"
rem preparing script
(
echo @echo off
echo tasklist /fi "imagename eq xmrig.exe" ^| find ":" ^>NUL
echo if errorlevel 1 goto ALREADY_RUNNING
echo start /low %%~dp0xmrig.exe %%^*
echo goto EXIT
echo :ALREADY_RUNNING
echo echo Monero miner is already running in the background. Refusing to run another one.
echo echo Run "taskkill /IM xmrig.exe" if you want to remove background miner first.
echo :EXIT
) > "%USERPROFILE%\moneroocean\miner.bat"
rem preparing script background work and work under reboot
if %ADMIN% == 1 goto ADMIN_MINER_SETUP
if exist "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" (
set "STARTUP_DIR=%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
goto STARTUP_DIR_OK
)
if exist "%USERPROFILE%\Start Menu\Programs\Startup" (
set "STARTUP_DIR=%USERPROFILE%\Start Menu\Programs\Startup"
goto STARTUP_DIR_OK
)
echo ERROR: Can't find Windows startup directory
exit /b 1
:STARTUP_DIR_OK
echo [*] Adding call to "%USERPROFILE%\moneroocean\miner.bat" script to "%STARTUP_DIR%\moneroocean_miner.bat" script
(
echo @echo off
echo "%USERPROFILE%\moneroocean\miner.bat" --config="%USERPROFILE%\moneroocean\config_background.json"
) > "%STARTUP_DIR%\moneroocean_miner.bat"
echo [*] Running miner in the background
call "%STARTUP_DIR%\moneroocean_miner.bat"
goto OK
:ADMIN_MINER_SETUP
echo [*] Downloading tools to make moneroocean_miner service to "%USERPROFILE%\nssm.zip"
powershell -Command "$wc = New-Object System.Net.WebClient; $wc.DownloadFile('https://raw.githubusercontent.com/MoneroOcean/xmrig_setup/master/nssm.zip', '%USERPROFILE%\nssm.zip')"
if errorlevel 1 (
echo ERROR: Can't download tools to make moneroocean_miner service
exit /b 1
)
echo [*] Unpacking "%USERPROFILE%\nssm.zip" to "%USERPROFILE%\moneroocean"
powershell -Command "Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory('%USERPROFILE%\nssm.zip', '%USERPROFILE%\moneroocean')"
if errorlevel 1 (
echo [*] Downloading 7za.exe to "%USERPROFILE%\7za.exe"
powershell -Command "$wc = New-Object System.Net.WebClient; $wc.DownloadFile('https://raw.githubusercontent.com/MoneroOcean/xmrig_setup/master/7za.exe', '%USERPROFILE%\7za.exe')"
if errorlevel 1 (
echo ERROR: Can't download 7za.exe to "%USERPROFILE%\7za.exe"
exit /b 1
)
echo [*] Unpacking "%USERPROFILE%\nssm.zip" to "%USERPROFILE%\moneroocean"
"%USERPROFILE%\7za.exe" x -y -o"%USERPROFILE%\moneroocean" "%USERPROFILE%\nssm.zip" >NUL
if errorlevel 1 (
echo ERROR: Can't unpack "%USERPROFILE%\nssm.zip" to "%USERPROFILE%\moneroocean"
exit /b 1
)
del "%USERPROFILE%\7za.exe"
)
del "%USERPROFILE%\nssm.zip"
echo [*] Creating moneroocean_miner service
sc stop moneroocean_miner
sc delete moneroocean_miner
"%USERPROFILE%\moneroocean\nssm.exe" install moneroocean_miner "%USERPROFILE%\moneroocean\xmrig.exe"
if errorlevel 1 (
echo ERROR: Can't create moneroocean_miner service
exit /b 1
)
"%USERPROFILE%\moneroocean\nssm.exe" set moneroocean_miner AppDirectory "%USERPROFILE%\moneroocean"
"%USERPROFILE%\moneroocean\nssm.exe" set moneroocean_miner AppPriority BELOW_NORMAL_PRIORITY_CLASS
"%USERPROFILE%\moneroocean\nssm.exe" set moneroocean_miner AppStdout "%USERPROFILE%\moneroocean\stdout"
"%USERPROFILE%\moneroocean\nssm.exe" set moneroocean_miner AppStderr "%USERPROFILE%\moneroocean\stderr"
echo [*] Starting moneroocean_miner service
"%USERPROFILE%\moneroocean\nssm.exe" start moneroocean_miner
if errorlevel 1 (
echo ERROR: Can't start moneroocean_miner service
exit /b 1
)
echo
echo Please reboot system if moneroocean_miner service is not activated yet (if "%USERPROFILE%\moneroocean\xmrig.log" file is empty)
goto OK
:OK
echo
echo [*] Setup complete
pause
exit /b 0
:strlen string len
setlocal EnableDelayedExpansion
set "token=#%~1" & set "len=0"
for /L %%A in (12,-1,0) do (
set/A "len|=1<<%%A"
for %%B in (!len!) do if "!token:~%%B,1!"=="" set/A "len&=~1<<%%A"
)
endlocal & set %~2=%len%
exit /b