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