-
Notifications
You must be signed in to change notification settings - Fork 0
/
getbrave_standalone.cmd
178 lines (164 loc) · 4.91 KB
/
getbrave_standalone.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
@echo off
setlocal enabledelayedexpansion
if exist busybox.exe goto first
where /q busybox
if !errorlevel! neq 0 (
echo ^> BusyBox not found^^!
choice /C YN /M "> Do you wish to download BusyBox automatically?"
if !errorlevel! equ 2 (
echo ^> Download BusyBox here: https://frippery.org/files/busybox/busybox.exe
echo ^> Manually put busybox.exe in either the directory containing this script, or your PATH.
goto end
) else (
echo ^> Downloading BusyBox...
curl https://frippery.org/files/busybox/busybox.exe -o busybox.exe
)
)
:: First run
:first
if not exist chrome_proxy.exe (
choice /C YN /M "> Brave Browser not found^! Download?"
if !errorlevel! equ 1 (
set FIRSTRUN=true
goto start
) else if !errorlevel! equ 2 (
goto end
)
)
tasklist | findstr /C:brave.exe >nul
if !errorlevel! equ 0 (
echo ^> Brave is running^^! Continue only if you are certain this specific Brave is not in use.
choice /C YN /M "> Do you wish to continue?"
if !errorlevel! equ 2 (
goto end
)
)
:start
echo Select channel:
echo [1] Release (default)
echo [2] Beta
echo [3] Nightly
set /P _input="> "
if not defined _input set _input=1
echo:
if "%_input%"=="1" goto :Release
if "%_input%"=="2" goto :Beta
if "%_input%"=="3" goto :Nightly
echo:
echo I couldn't understand you, pick one of the options
goto :start
:Release
set CHANNEL=release
goto Arch
:Beta
set CHANNEL=beta
goto Arch
:Nightly
set CHANNEL=nightly
goto Arch
:Arch
choice /C YN /M "> Download 64bit build instead of 32bit?"
if !errorlevel! equ 1 (
set BRAVE_ARCH=x64
set BRAVE_ARCH_GH=x64
goto GitHub
) else if !errorlevel! equ 2 (
set BRAVE_ARCH=x86
set BRAVE_ARCH_GH=ia32
goto GitHub
)
:GitHub
for /F "usebackq" %%a in (
`busybox wget -q https://versions.brave.com/latest/%CHANNEL%-windows-%BRAVE_ARCH%.version -O -`
) do (
set REMOTEVER=%%a
)
if "%FIRSTRUN%"=="true" (
echo ^> Downloading Brave Browser v%REMOTEVER%...
goto :Download
)
for /F "usebackq" %%b in (
`dir /B /A:D ^| busybox grep -Eo "[0-9]+\.[0-9]+\.[0-9]+$"`
) do (
set LOCALVER=%%b
)
:: Comparison
for /F "usebackq" %%c in (
`^(echo %LOCALVER% ^& echo:%REMOTEVER%^) ^| busybox sort -V ^| busybox head -1`
) do (
set NEWESTVER=%%c
)
if %LOCALVER% == %REMOTEVER% (
echo ^> Local: %LOCALVER%, Upstream: %REMOTEVER%
echo ^> Up-to-date^^!
goto end
) else if %LOCALVER% == %NEWESTVER% (
echo ^> Local: %LOCALVER%, Upstream: %REMOTEVER%
echo ^> New version available^^!
choice /C YN /M "> Update?"
if !errorlevel! equ 2 (goto end) else (goto Download)
) else if %REMOTEVER% == %NEWESTVER% (
echo ^> Local: %LOCALVER%, Upstream: %REMOTEVER%
echo ^> Warning: You may have chosen an update channel more downstream than your local version.
echo ^> For example, if you have Nightly version but you chose Beta/Release.
echo ^> Only proceed if you are switching your update channel.
choice /C YN /M "> Do you wish to update anyway?"
if !errorlevel! equ 2 (goto end) else (goto Download)
)
:Download
for /F "usebackq" %%d in (
`busybox wget https://github.com/brave/brave-browser/releases/download/v%REMOTEVER%/brave-v%REMOTEVER%-win32-%BRAVE_ARCH_GH%.zip.sha256 -q -O -`
) do (
set REMOTEHASH=%%d
)
REM don't redownload
if exist brave-v%REMOTEVER%-win32-%BRAVE_ARCH_GH%_%CHANNEL%.zip (
for /F "usebackq" %%e in (
`busybox sha256sum brave-v%REMOTEVER%-win32-%BRAVE_ARCH_GH%_%CHANNEL%.zip`
) do (
set LOCALHASH=%%e
)
REM _ added for when localsize is empty
if _%REMOTEHASH% == _!LOCALHASH! (
echo Brave already downloaded^^!
goto Download_Success
)
)
busybox wget https://github.com/brave/brave-browser/releases/download/v%REMOTEVER%/brave-v%REMOTEVER%-win32-%BRAVE_ARCH_GH%.zip -O brave-v%REMOTEVER%-win32-%BRAVE_ARCH_GH%_%CHANNEL%.zip
if exist brave-v%REMOTEVER%-win32-%BRAVE_ARCH_GH%_%CHANNEL%.zip (
for /F "usebackq" %%f in (
`busybox sha256sum brave-v%REMOTEVER%-win32-%BRAVE_ARCH_GH%_%CHANNEL%.zip`
) do (
set LOCALHASH=%%f
)
REM _ added for when localsize is empty
if _%REMOTEHASH% == _!LOCALHASH! (
goto Download_Success
) else (
echo ^> Hash mismatch^^! Download probably got interrupted^^!
del brave-v%REMOTEVER%-win32-%BRAVE_ARCH_GH%_%CHANNEL%.zip
goto end
)
) else (
echo ^> File doesn't exist^^! Download probably got interrupted^^!
goto end
)
:Download_Success
if not defined FIRSTRUN (
for /D %%g in (*.%LOCALVER%) do rmdir /S /Q %%g
del brave.exe chrome_proxy.exe
)
busybox unzip -o brave-v%REMOTEVER%-win32-%BRAVE_ARCH_GH%_%CHANNEL%.zip
del brave-v%REMOTEVER%-win32-%BRAVE_ARCH_GH%_%CHANNEL%.zip
if not exist brave_portable.cmd (
echo start "" brave.exe --flag-switches-begin --user-data-dir=profile --no-default-browser-check --disable-machine-id --disable-encryption-win --flag-switches-end> brave_portable.cmd
)
echo # Launch brave_portable.cmd^^!
echo # This file contains the update channel this version of Brave is on.> update_channel.txt
echo # Don't put anything here. It will be overwritten every update.> update_channel.txt
echo %CHANNEL%> update_channel.txt
goto end
:end
endlocal
echo:
pause