-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.cmd
More file actions
118 lines (77 loc) · 2.48 KB
/
Copy pathsetup.cmd
File metadata and controls
118 lines (77 loc) · 2.48 KB
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
@echo off
setlocal
set "SETUP_EXIT=0"
set "SETUP_IS_ADMIN=0"
net session >nul 2>&1
if errorlevel 1 (
echo Setup requires admin privileges, relaunching...
sudo rio -e "setup.cmd"
if errorlevel 1 set "SETUP_EXIT=1"
goto :END
)
set "SETUP_IS_ADMIN=1"
:: pull repo
echo Pulling...
git pull
if errorlevel 1 (
set "SETUP_EXIT=1"
goto :END
)
:: default binary folder
if not exist "%USERPROFILE%\.bin" (
mkdir "%USERPROFILE%\.bin"
)
:: environment upgrader
echo Loading upgrader...
set "UPGRADER_DIR=%ProgramData%\env-upgrader"
if not exist "%UPGRADER_DIR%" (
mkdir "%UPGRADER_DIR%"
)
icacls "%UPGRADER_DIR%" /inheritance:r /grant:r "*S-1-5-32-544:(OI)(CI)F" "*S-1-5-18:(OI)(CI)F" >nul
if errorlevel 1 (
echo Failed to secure upgrader directory
set "SETUP_EXIT=1"
goto :CLEAN_UPGRADER
)
set "UPGRADER_TMP=%UPGRADER_DIR%\env_upgrader_%RANDOM%_%RANDOM%.exe"
set "UPGRADER_HASH=%UPGRADER_TMP%.sha256"
curl -fsSL --connect-timeout 15 --max-time 900 -o "%UPGRADER_TMP%" "https://coalaura.github.io/env/bin/upgrader-win.exe"
if errorlevel 1 (
echo Failed to download upgrader
set "SETUP_EXIT=1"
) else (
curl -fsSL --connect-timeout 15 --max-time 900 -o "%UPGRADER_HASH%" "https://coalaura.github.io/env/bin/upgrader-win.exe.sha256"
if errorlevel 1 (
echo Failed to download upgrader checksum
set "SETUP_EXIT=1"
) else (
powershell.exe -NoProfile -Command "$expected = (Get-Content -Raw -LiteralPath $env:UPGRADER_HASH).Trim().ToLowerInvariant(); if ($expected -notmatch '^[0-9a-f]{64}$') { exit 1 }; $actual = (Get-FileHash -Algorithm SHA256 -LiteralPath $env:UPGRADER_TMP).Hash.ToLowerInvariant(); if ($actual -cne $expected) { exit 1 }"
if errorlevel 1 (
echo Failed to verify upgrader
set "SETUP_EXIT=1"
) else (
echo Running upgrader...
"%UPGRADER_TMP%" go zig upx starship bun biome builder vet time wtf coreutils
if errorlevel 1 (
set "SETUP_EXIT=1"
)
)
)
)
:CLEAN_UPGRADER
if defined UPGRADER_TMP del /q "%UPGRADER_TMP%" "%UPGRADER_HASH%" 2>nul
if "%SETUP_EXIT%"=="0" (
call update.cmd
if errorlevel 1 (
set "SETUP_EXIT=1"
)
)
:END
if "%SETUP_EXIT%"=="0" goto :EXIT
if not "%SETUP_IS_ADMIN%"=="1" goto :EXIT
echo %CMDCMDLINE% | findstr /i /c:" /c" >nul
if errorlevel 1 goto :EXIT
echo Setup failed. Press any key to close...
pause >nul
:EXIT
endlocal & exit /b %SETUP_EXIT%