VirtualBox

source: vbox/trunk/src/VBox/Installer/win/Scripts/RepackExtPack.cmd@ 96407

Last change on this file since 96407 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette