-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWSL_Setup.cmd
389 lines (330 loc) · 13.4 KB
/
WSL_Setup.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
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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
:::: Windows Subsystem for Linux [WSL] ::::
::#############################################################################
:: #DESCRIPTION#
::
:: SCRIPT STYLE: Interactive
:: Automated installation and setup for Windows Subsystem for Linux (WSL)
::
::#############################################################################
:::: Developer ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Author: David Geeraerts
:: Location: Olympia, Washington USA
:: E-Mail: [email protected]
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: GitHub :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: https://github.com/cal-sc/WSL
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: License ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Copyleft License(s)
:: GNU GPL v3 (General Public License)
:: https://www.gnu.org/licenses/gpl-3.0.en.html
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Versioning Schema ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: VERSIONING INFORMATION ::
:: Semantic Versioning used ::
:: http://semver.org/ ::
:: Major.Minor.Revision ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Command shell ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@Echo Off
@SETLOCAL enableextensions
SET $PROGRAM_NAME=WSL_Setup
SET $Version=1.6.0
SET $BUILD=20240911 0900
Title %$PROGRAM_NAME%
Prompt WSL$G
color 8F
mode con:cols=75 lines=40
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Configuration - Basic ::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Declare Global variables
:: All User variables are set within here.
:: Defaults
:: uses user profile location for logs
SET "$LOGPATH=%APPDATA%\WSL"
SET "$LOG=WSL_Setup.log
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Configuration - Advanced :::::::::::::::::::::::::::::::::::::::::::::::::
:: Advanced Settings
:: DEBUG
:: {0 [Off/No] , 1 [On/Yes]}
SET $DEGUB_MODE=0
::#############################################################################
:: !!!! Everything below here is 'hard-coded' [DO NOT MODIFY] !!!!
::#############################################################################
:::: Default Program Variables ::::::::::::::::::::::::::::::::::::::::::::::::
:: Program Variables
SET $STATUS_ADMIN=
SET $STATUS_VT=
SET $STATUS_MICROSOFT-WINDOWS-SUBSYSTEM-LINUX=
SET $STATUS_VIRTUALMACHINEPLATFORM=
SET $STATUS_REBOOT=
SET $STATUS_WSL_KERNEL_UPDATE=
SET $STATUS_WSL_DEFAULT_VERSION=
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Directory ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:CD
:: Launched from directory
SET "$PROGRAM_PATH=%~dp0"
:: Setup logging
IF NOT EXIST "%$LOGPATH%\var" MD "%$LOGPATH%\var"
cd /D "%$PROGRAM_PATH%"
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Session Log Header :::::::::::::::::::::::::::::::::::::::::::::::::::::::
:wLog
:: Start session and write to log
echo Start: %DATE% %TIME% >> "%$LogPath%\%$LOG%"
echo Program Name: %$PROGRAM_NAME% >> "%$LogPath%\%$LOG%"
echo Program Version: %$Version% >> "%$LogPath%\%$LOG%"
echo Program Build: %$BUILD% >> "%$LogPath%\%$LOG%"
if %$DEGUB_MODE% EQU 1 echo Program Build: %$BUILD% >> "%$LogPath%\%$LOG%"
echo Program Path: %$PROGRAM_PATH% >> "%$LogPath%\%$LOG%"
echo PC: %COMPUTERNAME% >> "%$LogPath%\%$LOG%"
echo User: %USERNAME% >> "%$LogPath%\%$LOG%"
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Administrator Privilege Check ::::::::::::::::::::::::::::::::::::::::::::
:subA
SET $ADMIN_STATUS=0
openfiles.exe 1> "%$LOGPATH%\var\var_$Admin_Status_M.txt" 2> "%$LOGPATH%\var\var_$Admin_Status_E.txt" && (SET $ADMIN_STATUS=1)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Goto start
:::: banner :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:banner
:: CONSOLE MENU ::
cls
echo ********************************************************************
echo Windows Subsystem for Linux [WSL]
echo Version: %$Version%
IF %$DEGUB_MODE% EQU 1 echo Build: %$BUILD%
echo.
echo %DATE% %TIME%
echo.
echo ********************************************************************
echo.
GoTo:EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: HUD ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:HUD
echo --------------------------------------------------------------------
echo Part I
echo Administrative Privelage: %$STATUS_ADMIN%
echo Virtualization: %$STATUS_VT%
echo Feature Microsoft-Windows-Subsystem-Linux: %$STATUS_MICROSOFT-WINDOWS-SUBSYSTEM-LINUX%
echo Feature VirtualMachinePlatform: %$STATUS_VIRTUALMACHINEPLATFORM%
echo Reboot: %$STATUS_REBOOT%
echo --------------------------------------------------------------------
echo.
echo Part II
echo WSL Kernel update: %$STATUS_WSL_KERNEL_UPDATE%
echo WSL Default version: %$STATUS_WSL_DEFAULT_VERSION%
echo --------------------------------------------------------------------
GoTo:EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: GNU ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GNU
echo.
echo . .
echo / \
echo ((__-^^-,-^^-__))
echo `-_---' `---_-'
echo ^<__^|o` 'o^|__^>
echo \ ` /
echo ): :(
echo :o_o:
echo "-"
echo.
GoTo:EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Start ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:start
CALL :banner
CALL :HUD
echo.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo CHECKING DEPENDENCIES...
echo.
:::: Admin Privelage Check ::::::::::::::::::::::::::::::::::::::::::::::::::::
:admin
echo Checking if running with Administrative privelage...
echo (Running with Administrative privelage is required!)
echo.
IF %$ADMIN_STATUS% EQU 1 (
echo Running with Administrative privelage!
SET $STATUS_ADMIN=Pass
)
IF %$ADMIN_STATUS% EQU 0 (
color 4E
echo NOT running with Administrative privelage!
echo Right-click script, "Run as administrator"!
echo Script will now abort!
echo.
SET $STATUS_ADMIN=FAILED
pause
GoTo end
)
echo.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Check WSL Installation :::::::::::::::::::::::::::::::::::::::::::::::::::::
wsl --status
SET $STATUS_WSL=%ERRORLEVEL%
IF %$STATUS_WSL% EQU 0 (echo WSL already installed.
SET $STATUS_VT=Enabled
SET $STATUS_MICROSOFT-WINDOWS-SUBSYSTEM-LINUX=Done
SET $STATUS_VIRTUALMACHINEPLATFORM=Done
SET $STATUS_REBOOT=Done
wsl --status | find /I "2" 2> nul
IF %ERRORLEVEL% EQU 0 SET $STATUS_WSL_DEFAULT_VERSION=2
GoTo uwal)
IF %$STATUS_WSL% EQU 50 echo WSL not installed; will try quick method...
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: WSL Quick method :::::::::::::::::::::::::::::::::::::::::::::::::::
SET $WSL_INSTALL=1
wsl --install --no-distribution
SET $WSL_INSTALL_ERROR=%ERRORLEVEL%
SET $STATUS_VT=Enabled
SET $STATUS_MICROSOFT-WINDOWS-SUBSYSTEM-LINUX=Done
SET $STATUS_VIRTUALMACHINEPLATFORM=Done
SET $STATUS_REBOOT=Activated
IF %$WSL_INSTALL_ERROR% EQU 0 (shutdown -r -t 15 /c "WSL Setup requires reboot..." /d p:2:4
GoTo uwal)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM Below code is old.
:::: START OF OLD code:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Check if complete ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
IF EXIST "%$LOGPATH%\WSL-Setup_Complete.txt" (
CALL :banner
call :GNU
color 0A
echo.
echo WSL setup is done!
echo Successfully installed on this system!
echo WSL is successfully installed on this system! >> "%$LogPath%\%$LOG%"
echo.
GoTo jumpC
)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:checkPI
IF EXIST "%$LOGPATH%\var\Part-I-Reboot.txt" (
SET $STATUS_VT=Check
SET $STATUS_MICROSOFT-WINDOWS-SUBSYSTEM-LINUX=Done
SET $STATUS_VIRTUALMACHINEPLATFORM=Done
SET $STATUS_REBOOT=Done
GoTo PartII
)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Manual method::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
CALL :banner
CALL :HUD
echo.
Echo Something didn't go according to plan, trying more manual method....
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::Virtualization Check ::::::::::::::::::::::::::::::::::::::::::::::::::::::
:VT
CALL :banner
CALL :HUD
SET $VT_CHECK=0
echo.
echo Checking to see if:
echo [VT] Virtualization Enabled In Firmware (BIOS) is turned on...
echo.
REM The following can not be relied on, as WSL can work with these being false.
wmic CPU GET VirtualizationFirmwareEnabled /VALUE > "%$LOGPATH%\var\$VirtualizationFirmwareEnabled.txt"
wmic CPU GET VMMonitorModeExtensions /VALUE > "%$LOGPATH%\var\$VMMonitorModeExtensions.txt"
wmic CPU GET SecondLevelAddressTranslationExtensions /VALUE > "%$LOGPATH%\var\$SecondLevelAddressTranslationExtensions.txt"
find /I "VirtualizationFirmwareEnabled=TRUE" "%$LOGPATH%\var\$VirtualizationFirmwareEnabled.txt" 1> nul 2> nul && (SET $VT_CHECK=1)
echo %$VT_CHECK% > "%$LOGPATH%\var\$VT_CHECK.txt"
IF %$VT_CHECK% EQU 1 ECHO Virtualization Enabled in the firmware, i.e. BIOS!
SET $STATUS_VT=Check
echo.
IF %$VT_CHECK% EQU 1 GoTo skipVT
echo Hyper-V virtualization not detected!
echo Searching for hypervisor...
systeminfo | FIND /I "Hyper-V Requirements:" > "%$LOGPATH%\var\$HYPER-V_REQUIREMENTS.txt"
SET $HYPERVISOR=0
echo $HYPERVISOR: %$HYPERVISOR% > "%$LOGPATH%\var\$HYPERVISOR.txt"
FIND /I "A hypervisor has been detected." "%$LOGPATH%\var\$HYPER-V_REQUIREMENTS.txt" 1> nul 2> nul && (SET $HYPERVISOR=1)
IF %$HYPERVISOR% EQU 0 GoTo skipHypervisor
echo A non-hyper-V hypervisor has been detected!
echo This might be a virtual machine.
echo Do you want to proceed anyway?
Choice /C YN /T 60 /D Y /m "[Y]es or [N]o":
IF %ERRORLEVEL% EQU 2 GoTo errHyper
IF %ERRORLEVEL% EQU 1 GoTo skipVT
:errHyper
color 4E
echo Virtualization disabled in the firmware ^(BIOS^)!
echo ...or non-Hyper-V hypervisor detected!
echo.
echo Virtualization is required for Hyper-V and WSL!
echo Turn on [VT] Virtualization in the BIOS.
echo Script will now abort!
echo.
SET $STATUS_VT=FAILED
PAUSE
GoTo end
:skipVT
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
CALL :banner
CALL :HUD
:::: DISM :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Dism /online /Get-FeatureInfo /FeatureName:Microsoft-Windows-Subsystem-Linux > "%$LOGPATH%\var\$FEATURE_MICROSOFT-WINDOWS-SUBSYSTEM-LINUX.txt"
FIND /I "State : Enabled" "%$LOGPATH%\var\$FEATURE_MICROSOFT-WINDOWS-SUBSYSTEM-LINUX.txt" 1> nul 2> nul && (SET $STATUS_MICROSOFT-WINDOWS-SUBSYSTEM-LINUX=Check) && GoTo skipFMWSL
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
SET $STATUS_MICROSOFT-WINDOWS-SUBSYSTEM-LINUX=Done
:skipFMWSL
CALL :banner
CALL :HUD
Dism /online /Get-FeatureInfo /FeatureName:VirtualMachinePlatform > "%$LOGPATH%\var\$VIRTUALMACHINEPLATFORM.txt"
FIND /I "State : Enabled" "%$LOGPATH%\var\$VIRTUALMACHINEPLATFORM.txt" 1> nul 2> nul && (SET $STATUS_VIRTUALMACHINEPLATFORM=Check) && GoTo skipVMP
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
SET $STATUS_VIRTUALMACHINEPLATFORM=Done
:skipVMP
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
CALL :banner
CALL :HUD
IF EXIST "%$LOGPATH%\var\Part-I-Reboot.txt" (SET $STATUS_REBOOT=Check) && GoTo skipReboot
echo WSL Setup reboot: %DATE% %TIME% > "%$LOGPATH%\var\Part-I-Reboot.txt"
SET $STATUS_REBOOT=Rebooting
shutdown /r /t 10 /c "WSL Setup requires reboot..." /d p:2:4
echo rebooting: %date% %time% >> "%$LogPath%\%$LOG%"
echo. >> "%$LogPath%\%$LOG%"
echo.
CALL :banner
CALL :HUD
echo.
PAUSE
:skipReboot
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Part II ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:Conf
CALL :banner
CALL :HUD
wsl --set-default-version 2
SET $STATUS_WSL_DEFAULT_VERSION=2
echo WSL Setup Part-II: %DATE% %TIME% > "%$LOGPATH%\var\Part-II-Complete.txt"
IF EXIST "%$LOGPATH%\var\Part-II-Complete.txt" echo WSL Setup completed: %DATE% %TIME% > "%$LOGPATH%\WSL-Setup_Complete.txt"
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: END OF OLD code:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WSL Kernel update:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:uwal
wsl --update
SET $STATUS_WSL_KERNEL_UPDATE=Done
GoTo End
:::: End ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:End
::IF EXIST "%$LOGPATH%\WSL-Setup_Complete.txt" IF %$DEGUB_MODE% EQU 0 RD /S /Q "%$LOGPATH%\var"
CALL :banner
CALL :HUD
CALL :GNU
echo.
echo WSL (Windows Subsystem for Linux) installation is complete!
::IF EXIST "%$LOGPATH%\WSL-Setup_Complete.txt" (
:: color 0A
:: echo WSL Setup Completed!
:: )
::IF NOT EXIST "%$LOGPATH%\WSL-Setup_Complete.txt" echo WSL Setup is not complete!
:jumpC
echo.
echo End %DATE% %TIME% >> "%$LogPath%\%$LOG%"
timeout /t 30
exit