1 | @echo off
|
---|
2 | rem $Id: RepackExtPack.cmd 76553 2019-01-01 01:45:53Z vboxsync $
|
---|
3 | rem rem @file
|
---|
4 | rem Windows NT batch script for repacking an extension pack with blessed .r0 files.
|
---|
5 | rem
|
---|
6 |
|
---|
7 | rem
|
---|
8 | rem Copyright (C) 2018-2019 Oracle Corporation
|
---|
9 | rem
|
---|
10 | rem This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | rem available from http://www.virtualbox.org. This file is free software;
|
---|
12 | rem you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | rem General Public License (GPL) as published by the Free Software
|
---|
14 | rem Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | rem VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | rem hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | rem
|
---|
18 |
|
---|
19 |
|
---|
20 | setlocal ENABLEEXTENSIONS
|
---|
21 | setlocal
|
---|
22 |
|
---|
23 | rem
|
---|
24 | rem Check for environment variables we need.
|
---|
25 | rem
|
---|
26 | if ".%KBUILD_DEVTOOLS%" == "." (echo KBUILD_DEVTOOLS is not set & goto end_failed)
|
---|
27 | rem if ".%KBUILD_BIN_PATH%" == "." (echo KBUILD_BIN_PATH is not set & goto end_failed)
|
---|
28 |
|
---|
29 | rem
|
---|
30 | rem Parse arguments.
|
---|
31 | rem
|
---|
32 | set _MY_OPT_BINDIR_X86=..\..\..\win.x86\@KBUILD_TYPE@\bin
|
---|
33 | set _MY_OPT_BINDIR_AMD64=..\..\..\win.amd64\@KBUILD_TYPE@\bin
|
---|
34 | set _MY_OPT_INPUT=
|
---|
35 | set _MY_OPT_OUTPUT=
|
---|
36 | set _MY_OPT_STAGE_DIR=.\repack-extpack-%RANDOM%
|
---|
37 | for %%i in (%_MY_OPT_STAGE_DIR%) do set _MY_OPT_STAGE_DIR=%%~fi
|
---|
38 | set _MY_OPT_SIGN_CAT=1
|
---|
39 |
|
---|
40 | :argument_loop
|
---|
41 | if ".%1" == "." goto no_more_arguments
|
---|
42 |
|
---|
43 | if ".%1" == ".-h" goto opt_h
|
---|
44 | if ".%1" == ".-?" goto opt_h
|
---|
45 | if ".%1" == "./h" goto opt_h
|
---|
46 | if ".%1" == "./H" goto opt_h
|
---|
47 | if ".%1" == "./?" goto opt_h
|
---|
48 | if ".%1" == ".-help" goto opt_h
|
---|
49 | if ".%1" == ".--help" goto opt_h
|
---|
50 |
|
---|
51 | if ".%1" == ".-a" goto opt_a
|
---|
52 | if ".%1" == ".--bindir-amd64" goto opt_a
|
---|
53 | if ".%1" == ".-b" goto opt_b
|
---|
54 | if ".%1" == ".--bindir-x86" goto opt_b
|
---|
55 | if ".%1" == ".-i" goto opt_i
|
---|
56 | if ".%1" == ".--input" goto opt_i
|
---|
57 | if ".%1" == ".-o" goto opt_o
|
---|
58 | if ".%1" == ".--output" goto opt_o
|
---|
59 | if ".%1" == ".-s" goto opt_s
|
---|
60 | if ".%1" == ".--stage-dir" goto opt_s
|
---|
61 | echo syntax error: Unknown option: %1
|
---|
62 | echo Try --help to list valid options.
|
---|
63 | goto end_failed
|
---|
64 |
|
---|
65 | :argument_loop_next_with_value
|
---|
66 | shift
|
---|
67 | shift
|
---|
68 | goto argument_loop
|
---|
69 |
|
---|
70 | :opt_a
|
---|
71 | if ".%~2" == "." goto syntax_error_missing_value
|
---|
72 | set _MY_OPT_BINDIR_AMD64=%~f2
|
---|
73 | goto argument_loop_next_with_value
|
---|
74 |
|
---|
75 | :opt_b
|
---|
76 | if ".%~2" == "." goto syntax_error_missing_value
|
---|
77 | set _MY_OPT_BINDIR_X86=%~f2
|
---|
78 | goto argument_loop_next_with_value
|
---|
79 |
|
---|
80 | :opt_h
|
---|
81 | echo This script repacks an extension pack replacing windows .r0 files with
|
---|
82 | echo blessed copies from the bin directory. The ASSUMPTION here is that prior
|
---|
83 | echo to invoking this script, the UnpackBlessedDrivers.cmd script was executed
|
---|
84 | echo both for win.amd64 and win.x86.
|
---|
85 | echo .
|
---|
86 | echo Usage: RepackExtPack.cmd [-b bindir-x86] [-a bindir-amd64] [-s staging-dir]
|
---|
87 | echo -i input.vbox-extpack -o output.vbox-extpack
|
---|
88 | echo .
|
---|
89 | echo Warning! This script should normally be invoked from the win.x86 repack directory.
|
---|
90 | goto end_failed
|
---|
91 |
|
---|
92 | :opt_i
|
---|
93 | if ".%~2" == "." goto syntax_error_missing_value
|
---|
94 | set _MY_OPT_INPUT=%~f2
|
---|
95 | goto argument_loop_next_with_value
|
---|
96 |
|
---|
97 | :opt_o
|
---|
98 | if ".%~2" == "." goto syntax_error_missing_value
|
---|
99 | set _MY_OPT_OUTPUT=%~f2
|
---|
100 | goto argument_loop_next_with_value
|
---|
101 |
|
---|
102 | :opt_s
|
---|
103 | if ".%~2" == "." goto syntax_error_missing_value
|
---|
104 | set _MY_OPT_STAGE_DIR=%~f2
|
---|
105 | goto argument_loop_next_with_value
|
---|
106 |
|
---|
107 | :syntax_error_missing_value
|
---|
108 | echo syntax error: missing or empty option value after %1
|
---|
109 | goto end_failed
|
---|
110 |
|
---|
111 | :error_bindir_amd64_does_not_exist
|
---|
112 | echo syntax error: Specified AMD64 BIN directory does not exist: "%_MY_OPT_BINDIR_AMD64%"
|
---|
113 | goto end_failed
|
---|
114 |
|
---|
115 | :error_bindir_x86_does_not_exist
|
---|
116 | echo syntax error: Specified x86 BIN directory does not exist: "%_MY_OPT_BINDIR_X86%"
|
---|
117 | goto end_failed
|
---|
118 |
|
---|
119 | :error_input_not_found
|
---|
120 | echo error: Input file does not exist: "%_MY_OPT_INPUT%"
|
---|
121 | goto end_failed
|
---|
122 |
|
---|
123 | :error_stage_dir_exists
|
---|
124 | echo error: Temporary staging directory exists: "%_MY_OPT_STAGE_DIR%"
|
---|
125 | goto end_failed
|
---|
126 |
|
---|
127 | :no_more_arguments
|
---|
128 | rem
|
---|
129 | rem Validate and adjust specified options.
|
---|
130 | rem
|
---|
131 | if not exist "%_MY_OPT_BINDIR_X86%" goto error_bindir_x86_does_not_exist
|
---|
132 | if not exist "%_MY_OPT_BINDIR_AMD64%" goto error_bindir_amd64_does_not_exist
|
---|
133 |
|
---|
134 | if ".%_MY_OPT_INPUT%" == "." set _MY_OPT_INPUT=%_MY_OPT_BINDIR_X86%\Oracle_VM_VirtualBox_Extension_Pack.vbox-extpack
|
---|
135 | if not exist "%_MY_OPT_INPUT%" goto error_input_not_found
|
---|
136 |
|
---|
137 | if ".%_MY_OPT_OUTPUT%" == "." for %%i in ("%_MY_OPT_INPUT%") do set _MY_OPT_OUTPUT=.\%%~nxi
|
---|
138 |
|
---|
139 | rem Make _MY_OPT_STAGE_DIR absolute.
|
---|
140 | if exist "%_MY_OPT_STAGE_DIR%" goto error_stage_dir_exists
|
---|
141 |
|
---|
142 | rem
|
---|
143 | rem Modify PATH to facilitate using our zip, gzip and manifest tools
|
---|
144 | rem
|
---|
145 | rem TODO: Use RTTar for creation too.
|
---|
146 | rem TODO: Not sure how well the bsdtar output actually work with 5.1...
|
---|
147 | rem TODO: Check whether we need stupid cygwin to get the right execute bits (x) on unix.
|
---|
148 | rem
|
---|
149 | set PATH=%PATH%;%_MY_OPT_BINDIR_AMD64%
|
---|
150 | set _MY_TOOL_TAR_EXPAND="%_MY_OPT_BINDIR_AMD64%\tools\RTTar.exe" -x
|
---|
151 | set _MY_TOOL_TAR_CREATE="%KBUILD_DEVTOOLS%\win.x86\gnuwin32\r1\bin\bsdtar.exe" -c --format ustar
|
---|
152 | set _MY_TOOL_GZIP=%_MY_OPT_BINDIR_AMD64%\tools\RTGzip.exe
|
---|
153 | set _MY_TOOL_MANIFEST=%_MY_OPT_BINDIR_AMD64%\tools\RTManifest.exe
|
---|
154 |
|
---|
155 | rem
|
---|
156 | rem Unpack the extension pack.
|
---|
157 | rem
|
---|
158 | echo * Unpacking "%_MY_OPT_INPUT" to "%_MY_OPT_STAGE_DIR%"...
|
---|
159 | mkdir "%_MY_OPT_STAGE_DIR%" || goto end_failed
|
---|
160 | %_MY_TOOL_TAR_EXPAND% -vzf "%_MY_OPT_INPUT%" -C "%_MY_OPT_STAGE_DIR%" || goto end_failed_cleanup
|
---|
161 |
|
---|
162 | rem
|
---|
163 | rem Copy over the blessed .r0 files.
|
---|
164 | rem
|
---|
165 | echo * Copying over blessed .r0 binaries...
|
---|
166 | if not exist "%_MY_OPT_STAGE_DIR%\win.x86" goto no_win_x86
|
---|
167 | for %%i in ("%_MY_OPT_STAGE_DIR%\win.x86\*.r0") do (
|
---|
168 | echo -=- %%i
|
---|
169 | copy /y "%_MY_OPT_BINDIR_X86%\%%~nxi" "%_MY_OPT_STAGE_DIR%\win.x86" || goto end_failed_cleanup
|
---|
170 | )
|
---|
171 | :no_win_x86
|
---|
172 |
|
---|
173 | for %%i in ("%_MY_OPT_STAGE_DIR%\win.amd64\*.r0") do (
|
---|
174 | echo -=- %%i
|
---|
175 | copy /y "%_MY_OPT_BINDIR_AMD64%\%%~nxi" "%_MY_OPT_STAGE_DIR%\win.amd64" || goto end_failed_cleanup
|
---|
176 | )
|
---|
177 |
|
---|
178 | rem
|
---|
179 | rem Recreate the manifest.
|
---|
180 | rem
|
---|
181 | echo * Collecting files for manifest...
|
---|
182 | set _MY_MANIFEST_FILES=
|
---|
183 | for /D %%d in ("%_MY_OPT_STAGE_DIR%\*") do (
|
---|
184 | for %%f in ("%%d\*") do call set _MY_MANIFEST_FILES=%%_MY_MANIFEST_FILES%% %%~nxd/%%~nxf
|
---|
185 | )
|
---|
186 | for %%f in ("%_MY_OPT_STAGE_DIR%\*") do (
|
---|
187 | if not "%%~nxf" == "ExtPack.manifest" if not "%%~nxf" == "ExtPack.signature" call set _MY_MANIFEST_FILES=%%_MY_MANIFEST_FILES%% %%~nxf
|
---|
188 | )
|
---|
189 | rem echo _MY_MANIFEST_FILES=%_MY_MANIFEST_FILES%
|
---|
190 |
|
---|
191 | echo * Creating manifest...
|
---|
192 | echo on
|
---|
193 | "%_MY_TOOL_MANIFEST%" --manifest "%_MY_OPT_STAGE_DIR%\ExtPack.manifest" --chdir "%_MY_OPT_STAGE_DIR%" %_MY_MANIFEST_FILES% || goto end_failed_cleanup
|
---|
194 | @echo off
|
---|
195 |
|
---|
196 | rem
|
---|
197 | rem Repackage the damn thing.
|
---|
198 | rem
|
---|
199 | @echo * Packing extension pack...
|
---|
200 |
|
---|
201 | echo on
|
---|
202 | %_MY_TOOL_TAR_CREATE% -vf "%_MY_OPT_OUTPUT%.tmp" -C "%_MY_OPT_STAGE_DIR%" . || goto end_failed_cleanup
|
---|
203 | "%_MY_TOOL_GZIP%" -9 -n "%_MY_OPT_OUTPUT%.tmp" || goto end_failed_cleanup
|
---|
204 | move /Y "%_MY_OPT_OUTPUT%.tmp.gz" "%_MY_OPT_OUTPUT%" || goto end_failed_cleanup
|
---|
205 | echo off
|
---|
206 |
|
---|
207 | rem
|
---|
208 | rem Cleanup and we're good.
|
---|
209 | rem
|
---|
210 | echo * Cleaning up...
|
---|
211 | rmdir /s /q "%_MY_OPT_STAGE_DIR%"
|
---|
212 |
|
---|
213 | echo * Successfully created: "%_MY_OPT_OUTPUT%
|
---|
214 | goto end
|
---|
215 |
|
---|
216 | :end_failed_cleanup
|
---|
217 | @rmdir /s /q "%_MY_OPT_STAGE_DIR%"
|
---|
218 | @if exist "%_MY_OPT_OUTPUT%.tmp" del "%_MY_OPT_OUTPUT%.tmp"
|
---|
219 | @if exist "%_MY_OPT_OUTPUT%.tmp.gz" del "%_MY_OPT_OUTPUT%.tmp.gz"
|
---|
220 |
|
---|
221 | :end_failed
|
---|
222 | @endlocal
|
---|
223 | @endlocal
|
---|
224 | @echo * Failed!
|
---|
225 | @exit /b 1
|
---|
226 |
|
---|
227 | :end
|
---|
228 | @endlocal
|
---|
229 | @endlocal
|
---|
230 |
|
---|