-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTEAM-Deploy.cmd
473 lines (409 loc) · 13 KB
/
TEAM-Deploy.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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
@echo off
setlocal EnableDelayedExpansion
cd /d %~dp0
set pathbase=%~dp0
set configfile=%pathbase%TEAM-Deploy.cfg
set moduleLocation=%pathbase%Modules
set imageLocation=%pathbase%Images
set answerfileLocation=%pathbase%Answerfiles
set associationfileLocation=%pathbase%Associationfiles
set packageLocation=%pathbase%Packages
for /f "delims=" %%a in (%configfile%) do set "%%a"
set dism=dism
if exist %adkLocation% set dism=%adkLocation%\dism.exe
call :updateDriveInfo
call :updateImageList
call :updateImageInfo
call :updateAnswerfileList
call :updateAnswerfileInfo
call :updateAssociationfileList
call :updateAssociationfileInfo
call :updatePackageList
call :updatePackageInfo
call :updatePEBootType
:menuMain
set paddedSizeSystem= (%sizeSystem%MB)
set paddedSizeMSR= (%sizeMSR%MB)
set paddedSizeRecovery= (%sizeRecovery%MB)
cls
call :writeMenuHeader "Main Menu"
call :writeMenuEntry "[A] Architecture: %arch%" "[L] Drive: %driveName%"
call :writeMenuEntry "[I] Image: %image%" "[T] Type: %partitionTable%"
call :writeMenuEntry "[E] Index: %imageIndex%" "[B] Bootloader: %bootType%"
echo.
call :writeMenuEntry "[U] Answerfile: %answerfile%" "[S] System: %letterSystem%: %paddedSizeSystem:~-8%"
call :writeMenuEntry "[F] Assocfile: %associationfile%" " MSR: -- %paddedSizeMSR:~-8%"
call :writeMenuEntry "[P] Provisioning: %package%" "[W] Windows: %letterOS%:"
call :writeMenuEntry "" "[R] Recovery: %letterRecovery%: %paddedSizeRecovery:~-8%"
echo.
echo. [X] Exit
echo. [G] Start
echo.
set instruction=
set /P instruction=Please make a selection:
if /i "%instruction%" EQU "X" (
exit /b
) else if /i "%instruction%" EQU "A" (
if "%arch%" EQU "X64" (
set arch=X86
) else (
set arch=X64
)
set imageID=X
set ImageIndex=X
set answerID=X
set assocID=X
call :updateImageInfo
call :updateAnswerfileInfo
call :updateAssociationfileInfo
) else if /i "%instruction%" EQU "E" (
if "%imageIndex%" NEQ "-------------" (
goto menuIndexSelection
)
) else if /i "%instruction%" EQU "S" (
goto menuSystemPartition
) else if /i "%instruction%" EQU "W" (
goto menuWindowsPartition
) else if /i "%instruction%" EQU "R" (
goto menuRecoveryPartition
) else if /i "%instruction%" EQU "B" (
if "%bootType%" EQU "UEFI" (
set bootType=BIOS
) else if "%bootType%" EQU "BIOS" (
set bootType=ALL
) else if "%bootType%" EQU "-------------" (
set bootType=UEFI
) else (
set bootType=-------------
)
) else if /i "%instruction%" EQU "T" (
if "%partitionTable%" EQU "GPT" (
set partitionTable=MBR
) else (
set partitionTable=GPT
)
) else if /I "%instruction%" EQU "L" (
goto menuDriveSelection
) else if /I "%instruction%" EQU "I" (
goto menuImageSelection
) else if /i "%instruction%" EQU "U" (
goto menuAnswerfileSelection
) else if /i "%instruction%" EQU "F" (
goto menuAssociationfileSelection
) else if /i "%instruction%" EQU "P" (
goto menuPackageSelection
) else if /i "%instruction%" EQU "G" (
goto menuDeployment
)
goto menuMain
:menuDriveSelection
cls
call :writeMenuHeader "Drive Selection"
echo list disk > %temp%\team_deploy_diskpart.txt
for /f "usebackq skip=5 tokens=*" %%a in (`diskpart /s %temp%\team_deploy_diskpart.txt`) do echo. %%a
del %temp%\team_deploy_diskpart.txt > nul
echo.
echo.
echo.
echo Enter drive number or ^<X^> to disable partitioning.
set /P diskID=Drive's ID (%diskID%):
call :updateDriveInfo
goto menuMain
:menuSystemPartition
cls
call :writeMenuHeader "System Partition"
echo. Bootloader partition, recommended size: 200MB, configurable in TEAM-Deploy.cfg.
echo. Contains the bootloader for BIOS or UEFI boot.
echo.
echo. Drive letter: %letterSystem%
echo. Size (MB): %sizeSystem%
echo.
set newLetterSystem=%letterSystem%
set /P newLetterSystem=Please enter a drive letter the partition will be mounted as (%letterSystem%):
set newLetterSystem=%newLetterSystem:~0,1%
for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do set "newLetterSystem=!newLetterSystem:%%a=%%a!"
echo %newLetterSystem%|findstr /r "[a-zA-Z]" > nul
if %errorlevel% EQU 1 goto menuSystemPartition
set letterSystem=%newLetterSystem%
goto menuMain
:menuWindowsPartition
cls
call :writeMenuHeader "Windows Partition"
echo. Windows partition, will span the rest of the drive minus the recovery partition.
echo. Partition the image will be deployed to.
echo.
echo. Drive letter: %letterOS%
echo.
set newLetterOS=%letterOS%
set /P newLetterOS=Please enter a drive letter the partition will be mounted as (%letterOS%):
set newLetterOS=%newLetterOS:~0,1%
for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do set "newLetterOS=!newLetterOS:%%a=%%a!"
echo %newLetterOS%|findstr /r "[a-zA-Z]" > nul
if %errorlevel% EQU 1 goto menuWindowsPartition
set letterOS=%newLetterOS%
goto menuMain
:menuRecoveryPartition
cls
call :writeMenuHeader "Recovery Partition"
echo. Recovery partition, recommended size: 1000MB, configurable in TEAM-Deploy.cfg.
echo. Contains the recovery image for Windows.
echo.
echo. Drive letter: %letterRecovery%
echo. Size (MB): %sizeRecovery%
echo.
set newLetterRecovery=%letterRecovery%
set /P newLetterRecovery=Please enter a drive letter the partition will be mounted as (%letterRecovery%):
set newLetterRecovery=%newLetterRecovery:~0,1%
for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do set "newLetterRecovery=!newLetterRecovery:%%a=%%a!"
echo %newLetterRecovery%|findstr /r "[a-zA-Z]" > nul
if %errorlevel% EQU 1 goto menuRecoveryPartition
set letterRecovery=%newLetterRecovery%
goto menuMain
:menuImageSelection
call :updateImageList
cls
call :writeMenuHeader "Image Selection"
for /l %%b in (1,1,%i%) do echo %%b. !image[%%b]!
echo.
echo.
echo.
echo Please enter the image number or ^<X^> to disable image deployment.
set newImageID=%imageID%
set /P newImageID=Image number (%imageID%):
echo %newImageID%|findstr /r "[xX0-9]" > nul
if %errorlevel% EQU 1 goto menuImageSelection
set imageID=%newImageID%
call :updateImageInfo
goto menuMain
:menuIndexSelection
cls
call :writeMenuHeader "Index Selection"
echo.
dism /get-imageinfo /imagefile:"%imagepath%"
echo.
echo Please enter the image index to deploy.
set newImageIndex=%imageIndex%
set /P newImageIndex=Index (%imageIndex%):
echo %newImageIndex%|findstr /r "[1-9]" > nul
if %errorlevel% EQU 1 goto menuIndexSelection
set imageIndex=%newImageIndex%
goto menuMain
:menuAnswerfileSelection
call :updateAnswerfileList
cls
call :writeMenuHeader "Answerfile Selection"
for /l %%b in (1,1,%i%) do echo %%b. !answer[%%b]!
echo.
echo.
echo.
set newAnswerID=%answerID%
set /P newAnswerID=Please enter answerfile number or ^<X^> to disable answerfile (%answerID%):
echo %newAnswerID%|findstr /r "[xX0-9]" > nul
if %errorlevel% EQU 1 goto menuAnswerfileSelection
set answerID=%newAnswerID%
call :updateAnswerfileInfo
goto menuMain
:menuAssociationfileSelection
call :updateAssociationfileList
cls
call :writeMenuHeader "Associationfile Selection"
for /l %%b in (1,1,%i%) do echo %%b. !assoc[%%b]!
echo.
echo.
echo.
set newAssocID=%assocID%
set /P newAssocID=Please enter the association file number or ^<X^> to disable association file (%assocID%):
echo %newAssocID%|findstr /r "[xX0-9]" > nul
if %errorlevel% EQU 1 goto menuAssociationfileSelection
set assocID=%newAssocID%
call :updateAssociationfileInfo
goto menuMain
:menuPackageSelection
call :updatePackageList
cls
call :writeMenuHeader "Provisioning Package Selection"
for /l %%b in (1,1,%i%) do echo %%b. !package[%%b]!
echo.
echo.
echo.
echo Please enter the package number or ^<X^> to disable package deployment.
set newPackageID=%packageID%
set /P newPackageID=Package number (%packageID%):
echo %newPackageID%|findstr /r "[xX0-9]" > nul
if %errorlevel% EQU 1 goto menuPackageSelection
set packageID=%newPackageID%
call :updatePackageInfo
goto menuMain
:menuDeployment
cls
call :writeMenuHeader "Deployment"
if /i "%diskID%" NEQ "X" echo. Drive %driveName% will be formatted as %partitionTable%.
if /i "%imageID%" NEQ "X" echo. Index %imageIndex% from image %image% will be extracted to %letterOS%:\.
if /i "%bootType%" NEQ "-------------" echo. %bootType% bootloader will be created on %letterSystem%:\ with reference to %letterOS%:\Windows.
if /i "%answerID%" NEQ "X" echo. The answerfile %answerfile% will be applied to %letterOS%:\.
if /i "%assocID%" NEQ "X" echo. The associationfile %associationfile% will be applied to %letterOS%:\.
if /i "%packageID%" NEQ "X" echo. Provisioning package %packagefile% will be applied to %letterOS%:\.
echo.
set safe=
set /p safe=Start deployment? (y/n)
if /I "%safe%" EQU "n" goto menuMain
if /I "%safe%" NEQ "y" goto menuDeployment
cls
call :writeMenuHeader "Deployment"
if /I "%diskID%" EQU "X" goto continue
if /I "%partitionTable%" EQU "MBR" goto mbrPart
echo. Partitioning %driveName% as GPT with drive letters %letterSystem%, %letterOS%, %letterRecovery%...
echo.
call %moduleLocation%\Partition_GPT.cmd %diskID% %sizeSystem% %sizeMSR% %sizeRecovery% %letterSystem% %letterOS% %letterRecovery%
echo.
echo. Partitioning has finished.
goto continue
:mbrPart
echo. Partitioning %driveName% as MBR with drive letters %letterSystem%, %letterOS%, %letterRecovery%...
echo.
call %moduleLocation%\Partition_MBR.cmd %diskID% %sizeSystem% %sizeRecovery% %letterSystem% %letterOS% %letterRecovery%
echo.
echo. Partitioning has finished.
:continue
echo.
if /I "%imageID%" NEQ "X" (
echo. Extracting index %imageIndex% from %image% Image to %letterOS%:\...
echo.
call "%moduleLocation%\Deploy_Image.cmd" %dism% %imagepath% %imageIndex% %letterOS%
echo.
echo. The image extraction has finished.
)
echo.
if "%bootType%" NEQ "-------------" (
echo. Writing %bootType% bootloader to %letterSystem%:\
echo.
call "%moduleLocation%\Create_Bootloader.cmd" %letterOS% %letterSystem% %bootType%
echo.
echo. The bootloader was successfully written.
)
echo.
if /i "%answerID%" NEQ "X" (
echo. Copying Answer file %answerfile% to %letterOS%:\Windows\Panther...
call "%moduleLocation%\Deploy_Answerfile.cmd" %letterOS% %answerfilePath%
echo.
echo. Copying finished.
)
echo.
if /i "%assocID%" NEQ "X" (
echo. Applying Association file %associationfile%...
call %moduleLocation%\Deploy_Associationfile.cmd %dism% %letterOS% %associationfilePath%
echo.
echo Apply finished.
)
if /i "%packageID%" NEQ "X" (
echo. Applying Provisioning Package %package%...
call %moduleLocation%\Deploy_Package.cmd %dism% %letterOS% %packagefilePath%
echo.
echo Apply finished.
)
echo.
echo. Deployment complete.
echo.
pause
goto menuMain
:updatePEBootType
wpeutil UpdateBootInfo 1>nul 2>nul
if %errorlevel% EQU 9009 exit /b
reg query HKLM\System\CurrentControlSet\Control /v PEFirmwareType | find "0x2" >nul
if %errorlevel% EQU 1 (
set bootType=BIOS
set partitionTable=MBR
)
exit /b
:updateDriveInfo
if /i "%diskID%" EQU "X" (
set driveName=-------------
exit /b
)
echo select disk %diskID% > %temp%\team_deploy_diskpart.txt
echo detail disk >> %temp%\team_deploy_diskpart.txt
for /f "usebackq skip=8 tokens=*" %%a in (`diskpart /s %temp%\team_deploy_diskpart.txt`) do (
set driveName=%%a
exit /b
)
exit /b
:updateImageList
set i=0
for %%a in (%imageLocation%\%arch%\*.wim %imageLocation%\%arch%\*.esd) do (
set /a i=i+1
set image[!i!]=%%~na%%~xa
)
if %i% EQU 0 set imageID=X
exit /b
:updateImageInfo
if /i "%imageID%" EQU "X" (
set image=-------------
set imageIndex=-------------
set imagepath=
exit /b
)
set image=!image[%imageID%]!
set imageIndex=1
set imagepath=%imageLocation%\%arch%\%image%
exit /b
:updateAnswerfileList
set i=0
for %%a in (%answerfileLocation%\%arch%\*.xml) do (
set /a i=i+1
set answer[!i!]=%%~na%%~xa
)
if %i% EQU 0 set answerID=X
exit /b
:updateAnswerfileInfo
if /i "%answerID%" EQU "X" (
set answerfile=-------------
set answerfilePath=
exit /b
)
set answerfile=!answer[%answerID%]!
set answerfilePath=%answerfileLocation%\%arch%\%answerfile%
exit /b
:updateAssociationfileList
set i=0
for %%a in (%associationfileLocation%\%arch%\*.xml) do (
set /a i=i+1
set assoc[!i!]=%%~na%%~xa
)
if %i% EQU 0 set assocID=X
exit /b
:updateAssociationfileInfo
if /i "%assocID%" EQU "X" (
set associationfile=-------------
set associationfilePath=
exit /b
)
set associationfile=!assoc[%assocID%]!
set associationfilePath=%associationfileLocation%\%arch%\%associationfile%
exit /b
:updatePackageList
set i=0
for %%a in (%packagelocation%\%arch%\*.spp) do (
set /a i=i+1
set package[!i!]=%%~na%%~xa
)
if %i% EQU 0 set packageID=X
exit /b
:updatePackageInfo
if /i "%packageID%" EQU "X" (
set package=-------------
set packagePath=
exit /b
)
set package=!package[%packageID%]!
set packagePath=%packageLocation%\%arch%\%package%
exit /b
:writeMenuHeader
echo.
echo. TEAM-Computer Deployment Tool - %~1
echo.
exit /b
:writeMenuEntry
set l=%~1
set r=%~2
echo. %l:~0,55% %r:~0,55%
exit /b