1 | /* $Id: UnattendedInstaller.cpp 69238 2017-10-24 16:11:07Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * UnattendedInstaller class and it's descendants implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2017 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_MAIN_UNATTENDED
|
---|
23 | #include "LoggingNew.h"
|
---|
24 | #include "VirtualBoxBase.h"
|
---|
25 | #include "VirtualBoxErrorInfoImpl.h"
|
---|
26 | #include "AutoCaller.h"
|
---|
27 | #include <VBox/com/ErrorInfo.h>
|
---|
28 |
|
---|
29 | #include "MachineImpl.h"
|
---|
30 | #include "UnattendedImpl.h"
|
---|
31 | #include "UnattendedInstaller.h"
|
---|
32 | #include "UnattendedScript.h"
|
---|
33 |
|
---|
34 | #include <VBox/err.h>
|
---|
35 | #include <iprt/ctype.h>
|
---|
36 | #include <iprt/fsisomaker.h>
|
---|
37 | #include <iprt/fsvfs.h>
|
---|
38 | #include <iprt/getopt.h>
|
---|
39 | #include <iprt/path.h>
|
---|
40 | #include <iprt/stream.h>
|
---|
41 | #include <iprt/vfs.h>
|
---|
42 | #ifdef RT_OS_SOLARIS
|
---|
43 | # undef ES /* Workaround for someone dragging the namespace pollutor sys/regset.h. Sigh. */
|
---|
44 | #endif
|
---|
45 | #include <iprt/formats/iso9660.h>
|
---|
46 | #include <iprt/cpp/path.h>
|
---|
47 |
|
---|
48 |
|
---|
49 | using namespace std;
|
---|
50 |
|
---|
51 |
|
---|
52 | /* static */ UnattendedInstaller *UnattendedInstaller::createInstance(VBOXOSTYPE enmOsType, const Utf8Str &strGuestOsType,
|
---|
53 | Unattended *pParent)
|
---|
54 | {
|
---|
55 | UnattendedInstaller *pUinstaller = NULL;
|
---|
56 |
|
---|
57 | if (strGuestOsType.find("Windows") != RTCString::npos)
|
---|
58 | {
|
---|
59 | if (enmOsType >= VBOXOSTYPE_WinVista)
|
---|
60 | pUinstaller = new UnattendedWindowsXmlInstaller(pParent);
|
---|
61 | else
|
---|
62 | pUinstaller = new UnattendedWindowsSifInstaller(pParent);
|
---|
63 | }
|
---|
64 | else
|
---|
65 | {
|
---|
66 | if (enmOsType == VBOXOSTYPE_Debian || enmOsType == VBOXOSTYPE_Debian_x64)
|
---|
67 | pUinstaller = new UnattendedDebianInstaller(pParent);
|
---|
68 | else if (enmOsType >= VBOXOSTYPE_Ubuntu && enmOsType <= VBOXOSTYPE_Ubuntu_x64)
|
---|
69 | pUinstaller = new UnattendedUbuntuInstaller(pParent);
|
---|
70 | else if (enmOsType >= VBOXOSTYPE_RedHat && enmOsType <= VBOXOSTYPE_RedHat_x64)
|
---|
71 | pUinstaller = new UnattendedRedHat67Installer(pParent);
|
---|
72 | else if (enmOsType >= VBOXOSTYPE_FedoraCore && enmOsType <= VBOXOSTYPE_FedoraCore_x64)
|
---|
73 | pUinstaller = new UnattendedFedoraInstaller(pParent);
|
---|
74 | else if (enmOsType >= VBOXOSTYPE_Oracle && enmOsType <= VBOXOSTYPE_Oracle_x64)
|
---|
75 | pUinstaller = new UnattendedOracleLinuxInstaller(pParent);
|
---|
76 | #if 0 /* doesn't work, so convert later. */
|
---|
77 | else if (enmOsType == VBOXOSTYPE_OpenSUSE || enmOsType == VBOXOSTYPE_OpenSUSE_x64)
|
---|
78 | pUinstaller = new UnattendedSuseInstaller(new UnattendedSUSEXMLScript(pParent), pParent);
|
---|
79 | #endif
|
---|
80 | }
|
---|
81 | return pUinstaller;
|
---|
82 | }
|
---|
83 |
|
---|
84 |
|
---|
85 | //////////////////////////////////////////////////////////////////////////////////////////////////////
|
---|
86 | /*
|
---|
87 | *
|
---|
88 | *
|
---|
89 | * Implementation Unattended functions
|
---|
90 | *
|
---|
91 | */
|
---|
92 | //////////////////////////////////////////////////////////////////////////////////////////////////////
|
---|
93 |
|
---|
94 | /*
|
---|
95 | *
|
---|
96 | * UnattendedInstaller public methods
|
---|
97 | *
|
---|
98 | */
|
---|
99 | UnattendedInstaller::UnattendedInstaller(Unattended *pParent,
|
---|
100 | const char *pszMainScriptTemplateName, const char *pszPostScriptTemplateName,
|
---|
101 | const char *pszMainScriptFilename, const char *pszPostScriptFilename,
|
---|
102 | DeviceType_T enmBootDevice /*= DeviceType_DVD */)
|
---|
103 | : mMainScript(pParent, pszMainScriptTemplateName, pszMainScriptFilename)
|
---|
104 | , mPostScript(pParent, pszPostScriptTemplateName, pszPostScriptFilename)
|
---|
105 | , mpParent(pParent)
|
---|
106 | , meBootDevice(enmBootDevice)
|
---|
107 | {
|
---|
108 | AssertPtr(pParent);
|
---|
109 | Assert(*pszMainScriptTemplateName);
|
---|
110 | Assert(*pszMainScriptFilename);
|
---|
111 | Assert(*pszPostScriptTemplateName);
|
---|
112 | Assert(*pszPostScriptFilename);
|
---|
113 | Assert(enmBootDevice == DeviceType_DVD || enmBootDevice == DeviceType_Floppy);
|
---|
114 | }
|
---|
115 |
|
---|
116 | UnattendedInstaller::~UnattendedInstaller()
|
---|
117 | {
|
---|
118 | mpParent = NULL;
|
---|
119 | }
|
---|
120 |
|
---|
121 | HRESULT UnattendedInstaller::initInstaller()
|
---|
122 | {
|
---|
123 | /*
|
---|
124 | * Calculate the full main script template location.
|
---|
125 | */
|
---|
126 | if (mpParent->i_getScriptTemplatePath().isNotEmpty())
|
---|
127 | mStrMainScriptTemplate = mpParent->i_getScriptTemplatePath();
|
---|
128 | else
|
---|
129 | {
|
---|
130 | int vrc = RTPathAppPrivateNoArchCxx(mStrMainScriptTemplate);
|
---|
131 | if (RT_SUCCESS(vrc))
|
---|
132 | vrc = RTPathAppendCxx(mStrMainScriptTemplate, "UnattendedTemplates");
|
---|
133 | if (RT_SUCCESS(vrc))
|
---|
134 | vrc = RTPathAppendCxx(mStrMainScriptTemplate, mMainScript.getDefaultTemplateFilename());
|
---|
135 | if (RT_FAILURE(vrc))
|
---|
136 | return mpParent->setErrorBoth(E_FAIL, vrc,
|
---|
137 | mpParent->tr("Failed to construct path to the unattended installer script templates (%Rrc)"),
|
---|
138 | vrc);
|
---|
139 | }
|
---|
140 |
|
---|
141 | /*
|
---|
142 | * Calculate the full post script template location.
|
---|
143 | */
|
---|
144 | if (mpParent->i_getPostInstallScriptTemplatePath().isNotEmpty())
|
---|
145 | mStrPostScriptTemplate = mpParent->i_getPostInstallScriptTemplatePath();
|
---|
146 | else
|
---|
147 | {
|
---|
148 | int vrc = RTPathAppPrivateNoArchCxx(mStrPostScriptTemplate);
|
---|
149 | if (RT_SUCCESS(vrc))
|
---|
150 | vrc = RTPathAppendCxx(mStrPostScriptTemplate, "UnattendedTemplates");
|
---|
151 | if (RT_SUCCESS(vrc))
|
---|
152 | vrc = RTPathAppendCxx(mStrPostScriptTemplate, mPostScript.getDefaultTemplateFilename());
|
---|
153 | if (RT_FAILURE(vrc))
|
---|
154 | return mpParent->setErrorBoth(E_FAIL, vrc,
|
---|
155 | mpParent->tr("Failed to construct path to the unattended installer script templates (%Rrc)"),
|
---|
156 | vrc);
|
---|
157 | }
|
---|
158 |
|
---|
159 | /*
|
---|
160 | * Construct paths we need.
|
---|
161 | */
|
---|
162 | if (isAuxiliaryFloppyNeeded())
|
---|
163 | {
|
---|
164 | mStrAuxiliaryFloppyFilePath = mpParent->i_getAuxiliaryBasePath();
|
---|
165 | mStrAuxiliaryFloppyFilePath.append("aux-floppy.img");
|
---|
166 | }
|
---|
167 | if (isAuxiliaryIsoNeeded())
|
---|
168 | {
|
---|
169 | mStrAuxiliaryIsoFilePath = mpParent->i_getAuxiliaryBasePath();
|
---|
170 | if (!isAuxiliaryIsoIsVISO())
|
---|
171 | mStrAuxiliaryIsoFilePath.append("aux-iso.iso");
|
---|
172 | else
|
---|
173 | mStrAuxiliaryIsoFilePath.append("aux-iso.viso");
|
---|
174 | }
|
---|
175 |
|
---|
176 | /*
|
---|
177 | * Check that we've got the minimum of data available.
|
---|
178 | */
|
---|
179 | if (mpParent->i_getIsoPath().isEmpty())
|
---|
180 | return mpParent->setError(E_INVALIDARG, mpParent->tr("Cannot proceed with an empty installation ISO path"));
|
---|
181 | if (mpParent->i_getUser().isEmpty())
|
---|
182 | return mpParent->setError(E_INVALIDARG, mpParent->tr("Empty user name is not allowed"));
|
---|
183 | if (mpParent->i_getPassword().isEmpty())
|
---|
184 | return mpParent->setError(E_INVALIDARG, mpParent->tr("Empty password is not allowed"));
|
---|
185 |
|
---|
186 | LogRelFunc(("UnattendedInstaller::savePassedData(): \n"));
|
---|
187 | return S_OK;
|
---|
188 | }
|
---|
189 |
|
---|
190 | #if 0 /* Always in AUX ISO */
|
---|
191 | bool UnattendedInstaller::isAdditionsIsoNeeded() const
|
---|
192 | {
|
---|
193 | /* In the VISO case, we'll add the additions to the VISO in a subdir. */
|
---|
194 | return !isAuxiliaryIsoIsVISO() && mpParent->i_getInstallGuestAdditions();
|
---|
195 | }
|
---|
196 |
|
---|
197 | bool UnattendedInstaller::isValidationKitIsoNeeded() const
|
---|
198 | {
|
---|
199 | /* In the VISO case, we'll add the validation kit to the VISO in a subdir. */
|
---|
200 | return !isAuxiliaryIsoIsVISO() && mpParent->i_getInstallTestExecService();
|
---|
201 | }
|
---|
202 | #endif
|
---|
203 |
|
---|
204 | bool UnattendedInstaller::isAuxiliaryIsoNeeded() const
|
---|
205 | {
|
---|
206 | /* In the VISO case we use the AUX ISO for GAs and TXS. */
|
---|
207 | return isAuxiliaryIsoIsVISO()
|
---|
208 | && ( mpParent->i_getInstallGuestAdditions()
|
---|
209 | || mpParent->i_getInstallTestExecService());
|
---|
210 | }
|
---|
211 |
|
---|
212 |
|
---|
213 | HRESULT UnattendedInstaller::prepareUnattendedScripts()
|
---|
214 | {
|
---|
215 | LogFlow(("UnattendedInstaller::prepareUnattendedScripts()\n"));
|
---|
216 |
|
---|
217 | /*
|
---|
218 | * The script template editor calls setError, so status codes just needs to
|
---|
219 | * be passed on to the caller. Do the same for both scripts.
|
---|
220 | */
|
---|
221 | HRESULT hrc = mMainScript.read(getTemplateFilePath());
|
---|
222 | if (SUCCEEDED(hrc))
|
---|
223 | {
|
---|
224 | hrc = mMainScript.parse();
|
---|
225 | if (SUCCEEDED(hrc))
|
---|
226 | {
|
---|
227 | /* Ditto for the post script. */
|
---|
228 | hrc = mPostScript.read(getPostTemplateFilePath());
|
---|
229 | if (SUCCEEDED(hrc))
|
---|
230 | {
|
---|
231 | hrc = mPostScript.parse();
|
---|
232 | if (SUCCEEDED(hrc))
|
---|
233 | {
|
---|
234 | LogFlow(("UnattendedInstaller::prepareUnattendedScripts: returns S_OK\n"));
|
---|
235 | return S_OK;
|
---|
236 | }
|
---|
237 | LogFlow(("UnattendedInstaller::prepareUnattendedScripts: parse failed on post script (%Rhrc)\n", hrc));
|
---|
238 | }
|
---|
239 | else
|
---|
240 | LogFlow(("UnattendedInstaller::prepareUnattendedScripts: error reading post install script template file (%Rhrc)\n", hrc));
|
---|
241 | }
|
---|
242 | else
|
---|
243 | LogFlow(("UnattendedInstaller::prepareUnattendedScripts: parse failed (%Rhrc)\n", hrc));
|
---|
244 | }
|
---|
245 | else
|
---|
246 | LogFlow(("UnattendedInstaller::prepareUnattendedScripts: error reading installation script template file (%Rhrc)\n", hrc));
|
---|
247 | return hrc;
|
---|
248 | }
|
---|
249 |
|
---|
250 | HRESULT UnattendedInstaller::prepareMedia(bool fOverwrite /*=true*/)
|
---|
251 | {
|
---|
252 | LogRelFlow(("UnattendedInstaller::prepareMedia:\n"));
|
---|
253 | HRESULT hrc = S_OK;
|
---|
254 | if (isAuxiliaryFloppyNeeded())
|
---|
255 | hrc = prepareAuxFloppyImage(fOverwrite);
|
---|
256 | if (SUCCEEDED(hrc))
|
---|
257 | {
|
---|
258 | if (isAuxiliaryIsoNeeded())
|
---|
259 | {
|
---|
260 | hrc = prepareAuxIsoImage(fOverwrite);
|
---|
261 | if (FAILED(hrc))
|
---|
262 | {
|
---|
263 | LogRelFlow(("UnattendedInstaller::prepareMedia: prepareAuxIsoImage failed\n"));
|
---|
264 |
|
---|
265 | /* Delete the floppy image if we created one. */
|
---|
266 | if (isAuxiliaryFloppyNeeded())
|
---|
267 | RTFileDelete(getAuxiliaryFloppyFilePath().c_str());
|
---|
268 | }
|
---|
269 | }
|
---|
270 | }
|
---|
271 | LogRelFlow(("UnattendedInstaller::prepareMedia: returns %Rrc\n", hrc));
|
---|
272 | return hrc;
|
---|
273 | }
|
---|
274 |
|
---|
275 | /*
|
---|
276 | *
|
---|
277 | * UnattendedInstaller protected methods
|
---|
278 | *
|
---|
279 | */
|
---|
280 | HRESULT UnattendedInstaller::prepareAuxFloppyImage(bool fOverwrite)
|
---|
281 | {
|
---|
282 | Assert(isAuxiliaryFloppyNeeded());
|
---|
283 |
|
---|
284 | /*
|
---|
285 | * Create the image and get a VFS to it.
|
---|
286 | */
|
---|
287 | RTVFS hVfs;
|
---|
288 | HRESULT hrc = newAuxFloppyImage(getAuxiliaryFloppyFilePath().c_str(), fOverwrite, &hVfs);
|
---|
289 | if (SUCCEEDED(hrc))
|
---|
290 | {
|
---|
291 | /*
|
---|
292 | * Call overridable method to copies the files onto it.
|
---|
293 | */
|
---|
294 | hrc = copyFilesToAuxFloppyImage(hVfs);
|
---|
295 |
|
---|
296 | /*
|
---|
297 | * Relase the VFS. On failure, delete the floppy image so the operation can
|
---|
298 | * be repeated in non-overwrite mode and we don't leave any mess behind.
|
---|
299 | */
|
---|
300 | RTVfsRelease(hVfs);
|
---|
301 |
|
---|
302 | if (FAILED(hrc))
|
---|
303 | RTFileDelete(getAuxiliaryFloppyFilePath().c_str());
|
---|
304 | }
|
---|
305 | return hrc;
|
---|
306 | }
|
---|
307 |
|
---|
308 | HRESULT UnattendedInstaller::newAuxFloppyImage(const char *pszFilename, bool fOverwrite, PRTVFS phVfs)
|
---|
309 | {
|
---|
310 | /*
|
---|
311 | * Open the image file.
|
---|
312 | */
|
---|
313 | HRESULT hrc;
|
---|
314 | RTVFSFILE hVfsFile;
|
---|
315 | uint64_t fOpen = RTFILE_O_READWRITE | RTFILE_O_DENY_ALL | (0660 << RTFILE_O_CREATE_MODE_SHIFT);
|
---|
316 | if (fOverwrite)
|
---|
317 | fOpen |= RTFILE_O_CREATE_REPLACE;
|
---|
318 | else
|
---|
319 | fOpen |= RTFILE_O_OPEN;
|
---|
320 | int vrc = RTVfsFileOpenNormal(pszFilename, fOpen, &hVfsFile);
|
---|
321 | if (RT_SUCCESS(vrc))
|
---|
322 | {
|
---|
323 | /*
|
---|
324 | * Format it.
|
---|
325 | */
|
---|
326 | vrc = RTFsFatVolFormat144(hVfsFile, false /*fQuick*/);
|
---|
327 | if (RT_SUCCESS(vrc))
|
---|
328 | {
|
---|
329 | /*
|
---|
330 | * Open the FAT VFS.
|
---|
331 | */
|
---|
332 | RTERRINFOSTATIC ErrInfo;
|
---|
333 | RTVFS hVfs;
|
---|
334 | vrc = RTFsFatVolOpen(hVfsFile, false /*fReadOnly*/, 0 /*offBootSector*/, &hVfs, RTErrInfoInitStatic(&ErrInfo));
|
---|
335 | if (RT_SUCCESS(vrc))
|
---|
336 | {
|
---|
337 | *phVfs = hVfs;
|
---|
338 | RTVfsFileRelease(hVfsFile);
|
---|
339 | LogRelFlow(("UnattendedInstaller::newAuxFloppyImage: created, formatted and opened '%s'\n", pszFilename));
|
---|
340 | return S_OK;
|
---|
341 | }
|
---|
342 |
|
---|
343 | if (RTErrInfoIsSet(&ErrInfo.Core))
|
---|
344 | hrc = mpParent->setErrorBoth(E_FAIL, vrc, mpParent->tr("Failed to open newly created floppy image '%s': %Rrc: %s"),
|
---|
345 | pszFilename, vrc, ErrInfo.Core.pszMsg);
|
---|
346 | else
|
---|
347 | hrc = mpParent->setErrorBoth(E_FAIL, vrc, mpParent->tr("Failed to open newly created floppy image '%s': %Rrc"),
|
---|
348 | pszFilename, vrc);
|
---|
349 | }
|
---|
350 | else
|
---|
351 | hrc = mpParent->setErrorBoth(E_FAIL, vrc, mpParent->tr("Failed to format floppy image '%s': %Rrc"), pszFilename, vrc);
|
---|
352 | RTVfsFileRelease(hVfsFile);
|
---|
353 | RTFileDelete(pszFilename);
|
---|
354 | }
|
---|
355 | else
|
---|
356 | hrc = mpParent->setErrorBoth(E_FAIL, vrc, mpParent->tr("Failed to create floppy image '%s': %Rrc"), pszFilename, vrc);
|
---|
357 | return hrc;
|
---|
358 | }
|
---|
359 |
|
---|
360 |
|
---|
361 | HRESULT UnattendedInstaller::copyFilesToAuxFloppyImage(RTVFS hVfs)
|
---|
362 | {
|
---|
363 | HRESULT hrc = addScriptToFloppyImage(&mMainScript, hVfs);
|
---|
364 | if (SUCCEEDED(hrc))
|
---|
365 | hrc = addScriptToFloppyImage(&mPostScript, hVfs);
|
---|
366 | return hrc;
|
---|
367 | }
|
---|
368 |
|
---|
369 | HRESULT UnattendedInstaller::addScriptToFloppyImage(BaseTextScript *pEditor, RTVFS hVfs)
|
---|
370 | {
|
---|
371 | /*
|
---|
372 | * Open the destination file.
|
---|
373 | */
|
---|
374 | HRESULT hrc;
|
---|
375 | RTVFSFILE hVfsFileDst;
|
---|
376 | int vrc = RTVfsFileOpen(hVfs, pEditor->getDefaultFilename(),
|
---|
377 | RTFILE_O_WRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_ALL
|
---|
378 | | (0660 << RTFILE_O_CREATE_MODE_SHIFT),
|
---|
379 | &hVfsFileDst);
|
---|
380 | if (RT_SUCCESS(vrc))
|
---|
381 | {
|
---|
382 | /*
|
---|
383 | * Save the content to a string.
|
---|
384 | */
|
---|
385 | Utf8Str strScript;
|
---|
386 | hrc = pEditor->saveToString(strScript);
|
---|
387 | if (SUCCEEDED(hrc))
|
---|
388 | {
|
---|
389 | /*
|
---|
390 | * Write the string.
|
---|
391 | */
|
---|
392 | vrc = RTVfsFileWrite(hVfsFileDst, strScript.c_str(), strScript.length(), NULL);
|
---|
393 | if (RT_SUCCESS(vrc))
|
---|
394 | hrc = S_OK; /* done */
|
---|
395 | else
|
---|
396 | hrc = mpParent->setErrorBoth(E_FAIL, vrc,
|
---|
397 | mpParent->tr("Error writing %zu bytes to '%s' in floppy image '%s': %Rrc"),
|
---|
398 | strScript.length(), pEditor->getDefaultFilename(),
|
---|
399 | getAuxiliaryFloppyFilePath().c_str());
|
---|
400 | }
|
---|
401 | RTVfsFileRelease(hVfsFileDst);
|
---|
402 | }
|
---|
403 | else
|
---|
404 | hrc = mpParent->setErrorBoth(E_FAIL, vrc,
|
---|
405 | mpParent->tr("Error creating '%s' in floppy image '%s': %Rrc"),
|
---|
406 | pEditor->getDefaultFilename(), getAuxiliaryFloppyFilePath().c_str());
|
---|
407 | return hrc;
|
---|
408 |
|
---|
409 | }
|
---|
410 |
|
---|
411 | HRESULT UnattendedInstaller::prepareAuxIsoImage(bool fOverwrite)
|
---|
412 | {
|
---|
413 | /*
|
---|
414 | * Open the original installation ISO.
|
---|
415 | */
|
---|
416 | RTVFS hVfsOrgIso;
|
---|
417 | HRESULT hrc = openInstallIsoImage(&hVfsOrgIso);
|
---|
418 | if (SUCCEEDED(hrc))
|
---|
419 | {
|
---|
420 | /*
|
---|
421 | * The next steps depends on the kind of image we're making.
|
---|
422 | */
|
---|
423 | if (!isAuxiliaryIsoIsVISO())
|
---|
424 | {
|
---|
425 | RTFSISOMAKER hIsoMaker;
|
---|
426 | hrc = newAuxIsoImageMaker(&hIsoMaker);
|
---|
427 | if (SUCCEEDED(hrc))
|
---|
428 | {
|
---|
429 | hrc = addFilesToAuxIsoImageMaker(hIsoMaker, hVfsOrgIso);
|
---|
430 | if (SUCCEEDED(hrc))
|
---|
431 | hrc = finalizeAuxIsoImage(hIsoMaker, getAuxiliaryIsoFilePath().c_str(), fOverwrite);
|
---|
432 | RTFsIsoMakerRelease(hIsoMaker);
|
---|
433 | }
|
---|
434 | }
|
---|
435 | else
|
---|
436 | {
|
---|
437 | RTCList<RTCString> vecFiles(0);
|
---|
438 | RTCList<RTCString> vecArgs(0);
|
---|
439 | try
|
---|
440 | {
|
---|
441 | vecArgs.append() = "--iprt-iso-maker-file-marker-bourne-sh";
|
---|
442 | RTUUID Uuid;
|
---|
443 | int vrc = RTUuidCreate(&Uuid); AssertRC(vrc);
|
---|
444 | char szTmp[RTUUID_STR_LENGTH + 1];
|
---|
445 | vrc = RTUuidToStr(&Uuid, szTmp, sizeof(szTmp)); AssertRC(vrc);
|
---|
446 | vecArgs.append() = szTmp;
|
---|
447 | vecArgs.append() = "--file-mode=0444";
|
---|
448 | vecArgs.append() = "--dir-mode=0555";
|
---|
449 | }
|
---|
450 | catch (std::bad_alloc)
|
---|
451 | {
|
---|
452 | hrc = E_OUTOFMEMORY;
|
---|
453 | }
|
---|
454 | if (SUCCEEDED(hrc))
|
---|
455 | {
|
---|
456 | hrc = addFilesToAuxVisoVectors(vecArgs, vecFiles, hVfsOrgIso, fOverwrite);
|
---|
457 | if (SUCCEEDED(hrc))
|
---|
458 | hrc = finalizeAuxVisoFile(vecArgs, getAuxiliaryIsoFilePath().c_str(), fOverwrite);
|
---|
459 |
|
---|
460 | if (FAILED(hrc))
|
---|
461 | for (size_t i = 0; i < vecFiles.size(); i++)
|
---|
462 | RTFileDelete(vecFiles[i].c_str());
|
---|
463 | }
|
---|
464 | }
|
---|
465 | RTVfsRelease(hVfsOrgIso);
|
---|
466 | }
|
---|
467 | return hrc;
|
---|
468 | }
|
---|
469 |
|
---|
470 | HRESULT UnattendedInstaller::openInstallIsoImage(PRTVFS phVfsIso, uint32_t fFlags /*= 0*/)
|
---|
471 | {
|
---|
472 | /* Open the file. */
|
---|
473 | const char *pszIsoPath = mpParent->i_getIsoPath().c_str();
|
---|
474 | RTVFSFILE hOrgIsoFile;
|
---|
475 | int vrc = RTVfsFileOpenNormal(pszIsoPath, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hOrgIsoFile);
|
---|
476 | if (RT_FAILURE(vrc))
|
---|
477 | return mpParent->setErrorBoth(E_FAIL, vrc, mpParent->tr("Failed to open ISO image '%s' (%Rrc)"), pszIsoPath, vrc);
|
---|
478 |
|
---|
479 | /* Pass the file to the ISO file system interpreter. */
|
---|
480 | RTERRINFOSTATIC ErrInfo;
|
---|
481 | vrc = RTFsIso9660VolOpen(hOrgIsoFile, fFlags, phVfsIso, RTErrInfoInitStatic(&ErrInfo));
|
---|
482 | RTVfsFileRelease(hOrgIsoFile);
|
---|
483 | if (RT_SUCCESS(vrc))
|
---|
484 | return S_OK;
|
---|
485 | if (RTErrInfoIsSet(&ErrInfo.Core))
|
---|
486 | return mpParent->setErrorBoth(E_FAIL, vrc, mpParent->tr("ISO reader fail to open '%s' (%Rrc): %s"),
|
---|
487 | pszIsoPath, vrc, ErrInfo.Core.pszMsg);
|
---|
488 | return mpParent->setErrorBoth(E_FAIL, vrc, mpParent->tr("ISO reader fail to open '%s' (%Rrc)"), pszIsoPath, vrc);
|
---|
489 | }
|
---|
490 |
|
---|
491 | HRESULT UnattendedInstaller::newAuxIsoImageMaker(PRTFSISOMAKER phIsoMaker)
|
---|
492 | {
|
---|
493 | int vrc = RTFsIsoMakerCreate(phIsoMaker);
|
---|
494 | if (RT_SUCCESS(vrc))
|
---|
495 | return vrc;
|
---|
496 | return mpParent->setErrorBoth(E_FAIL, vrc, mpParent->tr("RTFsIsoMakerCreate failed (%Rrc)"), vrc);
|
---|
497 | }
|
---|
498 |
|
---|
499 | HRESULT UnattendedInstaller::addFilesToAuxIsoImageMaker(RTFSISOMAKER hIsoMaker, RTVFS hVfsOrgIso)
|
---|
500 | {
|
---|
501 | RT_NOREF(hVfsOrgIso);
|
---|
502 |
|
---|
503 | /*
|
---|
504 | * Add the two scripts to the image with default names.
|
---|
505 | */
|
---|
506 | HRESULT hrc = addScriptToIsoMaker(&mMainScript, hIsoMaker);
|
---|
507 | if (SUCCEEDED(hrc))
|
---|
508 | hrc = addScriptToIsoMaker(&mPostScript, hIsoMaker);
|
---|
509 | return hrc;
|
---|
510 | }
|
---|
511 |
|
---|
512 | HRESULT UnattendedInstaller::addScriptToIsoMaker(BaseTextScript *pEditor, RTFSISOMAKER hIsoMaker,
|
---|
513 | const char *pszDstFilename /*= NULL*/)
|
---|
514 | {
|
---|
515 | /*
|
---|
516 | * Calc default destination filename if desired.
|
---|
517 | */
|
---|
518 | RTCString strDstNameBuf;
|
---|
519 | if (!pszDstFilename)
|
---|
520 | {
|
---|
521 | try
|
---|
522 | {
|
---|
523 | strDstNameBuf = RTPATH_SLASH_STR;
|
---|
524 | strDstNameBuf.append(pEditor->getDefaultTemplateFilename());
|
---|
525 | pszDstFilename = strDstNameBuf.c_str();
|
---|
526 | }
|
---|
527 | catch (std::bad_alloc)
|
---|
528 | {
|
---|
529 | return E_OUTOFMEMORY;
|
---|
530 | }
|
---|
531 | }
|
---|
532 |
|
---|
533 | /*
|
---|
534 | * Create a memory file for the script.
|
---|
535 | */
|
---|
536 | Utf8Str strScript;
|
---|
537 | HRESULT hrc = pEditor->saveToString(strScript);
|
---|
538 | if (SUCCEEDED(hrc))
|
---|
539 | {
|
---|
540 | RTVFSFILE hVfsScriptFile;
|
---|
541 | size_t cchScript = strScript.length();
|
---|
542 | int vrc = RTVfsFileFromBuffer(RTFILE_O_READ, strScript.c_str(), strScript.length(), &hVfsScriptFile);
|
---|
543 | strScript.setNull();
|
---|
544 | if (RT_SUCCESS(vrc))
|
---|
545 | {
|
---|
546 | /*
|
---|
547 | * Add it to the ISO.
|
---|
548 | */
|
---|
549 | vrc = RTFsIsoMakerAddFileWithVfsFile(hIsoMaker, pszDstFilename, hVfsScriptFile, NULL);
|
---|
550 | RTVfsFileRelease(hVfsScriptFile);
|
---|
551 | if (RT_SUCCESS(vrc))
|
---|
552 | hrc = S_OK;
|
---|
553 | else
|
---|
554 | hrc = mpParent->setErrorBoth(E_FAIL, vrc,
|
---|
555 | mpParent->tr("RTFsIsoMakerAddFileWithVfsFile failed on the script '%s' (%Rrc)"),
|
---|
556 | pszDstFilename, vrc);
|
---|
557 | }
|
---|
558 | else
|
---|
559 | hrc = mpParent->setErrorBoth(E_FAIL, vrc,
|
---|
560 | mpParent->tr("RTVfsFileFromBuffer failed on the %zu byte script '%s' (%Rrc)"),
|
---|
561 | cchScript, pszDstFilename, vrc);
|
---|
562 | }
|
---|
563 | return hrc;
|
---|
564 | }
|
---|
565 |
|
---|
566 | HRESULT UnattendedInstaller::finalizeAuxIsoImage(RTFSISOMAKER hIsoMaker, const char *pszFilename, bool fOverwrite)
|
---|
567 | {
|
---|
568 | /*
|
---|
569 | * Finalize the image.
|
---|
570 | */
|
---|
571 | int vrc = RTFsIsoMakerFinalize(hIsoMaker);
|
---|
572 | if (RT_FAILURE(vrc))
|
---|
573 | return mpParent->setErrorBoth(E_FAIL, vrc, mpParent->tr("RTFsIsoMakerFinalize failed (%Rrc)"), vrc);
|
---|
574 |
|
---|
575 | /*
|
---|
576 | * Open the destination file.
|
---|
577 | */
|
---|
578 | uint64_t fOpen = RTFILE_O_WRITE | RTFILE_O_DENY_ALL;
|
---|
579 | if (fOverwrite)
|
---|
580 | fOpen |= RTFILE_O_CREATE_REPLACE;
|
---|
581 | else
|
---|
582 | fOpen |= RTFILE_O_CREATE;
|
---|
583 | RTVFSFILE hVfsDstFile;
|
---|
584 | vrc = RTVfsFileOpenNormal(pszFilename, fOpen, &hVfsDstFile);
|
---|
585 | if (RT_FAILURE(vrc))
|
---|
586 | {
|
---|
587 | if (vrc == VERR_ALREADY_EXISTS)
|
---|
588 | return mpParent->setErrorBoth(E_FAIL, vrc, mpParent->tr("The auxiliary ISO image file '%s' already exists"),
|
---|
589 | pszFilename);
|
---|
590 | return mpParent->setErrorBoth(E_FAIL, vrc, mpParent->tr("Failed to open the auxiliary ISO image file '%s' for writing (%Rrc)"),
|
---|
591 | pszFilename, vrc);
|
---|
592 | }
|
---|
593 |
|
---|
594 | /*
|
---|
595 | * Get the source file from the image maker.
|
---|
596 | */
|
---|
597 | HRESULT hrc;
|
---|
598 | RTVFSFILE hVfsSrcFile;
|
---|
599 | vrc = RTFsIsoMakerCreateVfsOutputFile(hIsoMaker, &hVfsSrcFile);
|
---|
600 | if (RT_SUCCESS(vrc))
|
---|
601 | {
|
---|
602 | RTVFSIOSTREAM hVfsSrcIso = RTVfsFileToIoStream(hVfsSrcFile);
|
---|
603 | RTVFSIOSTREAM hVfsDstIso = RTVfsFileToIoStream(hVfsDstFile);
|
---|
604 | if ( hVfsSrcIso != NIL_RTVFSIOSTREAM
|
---|
605 | && hVfsDstIso != NIL_RTVFSIOSTREAM)
|
---|
606 | {
|
---|
607 | vrc = RTVfsUtilPumpIoStreams(hVfsSrcIso, hVfsDstIso, 0 /*cbBufHint*/);
|
---|
608 | if (RT_SUCCESS(vrc))
|
---|
609 | hrc = S_OK;
|
---|
610 | else
|
---|
611 | hrc = mpParent->setErrorBoth(E_FAIL, vrc, mpParent->tr("Error writing auxiliary ISO image '%s' (%Rrc)"),
|
---|
612 | pszFilename, vrc);
|
---|
613 | }
|
---|
614 | else
|
---|
615 | hrc = mpParent->setErrorBoth(E_FAIL, VERR_INTERNAL_ERROR_2,
|
---|
616 | mpParent->tr("Internal Error: Failed to case VFS file to VFS I/O stream"));
|
---|
617 | RTVfsIoStrmRelease(hVfsSrcIso);
|
---|
618 | RTVfsIoStrmRelease(hVfsDstIso);
|
---|
619 | }
|
---|
620 | else
|
---|
621 | hrc = mpParent->setErrorBoth(E_FAIL, vrc, mpParent->tr("RTFsIsoMakerCreateVfsOutputFile failed (%Rrc)"), vrc);
|
---|
622 | RTVfsFileRelease(hVfsSrcFile);
|
---|
623 | RTVfsFileRelease(hVfsDstFile);
|
---|
624 | if (FAILED(hrc))
|
---|
625 | RTFileDelete(pszFilename);
|
---|
626 | return hrc;
|
---|
627 | }
|
---|
628 |
|
---|
629 | HRESULT UnattendedInstaller::addFilesToAuxVisoVectors(RTCList<RTCString> &rVecArgs, RTCList<RTCString> &rVecFiles,
|
---|
630 | RTVFS hVfsOrgIso, bool fOverwrite)
|
---|
631 | {
|
---|
632 | RT_NOREF(hVfsOrgIso);
|
---|
633 |
|
---|
634 | /*
|
---|
635 | * Save and add the scripts.
|
---|
636 | */
|
---|
637 | HRESULT hrc = addScriptToVisoVectors(&mMainScript, rVecArgs, rVecFiles, fOverwrite);
|
---|
638 | if (SUCCEEDED(hrc))
|
---|
639 | hrc = addScriptToVisoVectors(&mPostScript, rVecArgs, rVecFiles, fOverwrite);
|
---|
640 | if (SUCCEEDED(hrc))
|
---|
641 | {
|
---|
642 | try
|
---|
643 | {
|
---|
644 | /*
|
---|
645 | * If we've got additions ISO, add its content to a /vboxadditions dir.
|
---|
646 | */
|
---|
647 | if (mpParent->i_getInstallGuestAdditions())
|
---|
648 | {
|
---|
649 | rVecArgs.append().append("--push-iso=").append(mpParent->i_getAdditionsIsoPath());
|
---|
650 | rVecArgs.append() = "/vboxadditions=/";
|
---|
651 | rVecArgs.append() = "--pop";
|
---|
652 | }
|
---|
653 |
|
---|
654 | /*
|
---|
655 | * If we've got additions ISO, add its content to a /vboxadditions dir.
|
---|
656 | */
|
---|
657 | if (mpParent->i_getInstallTestExecService())
|
---|
658 | {
|
---|
659 | rVecArgs.append().append("--push-iso=").append(mpParent->i_getValidationKitIsoPath());
|
---|
660 | rVecArgs.append() = "/vboxvalidationkit=/";
|
---|
661 | rVecArgs.append() = "--pop";
|
---|
662 | }
|
---|
663 | }
|
---|
664 | catch (std::bad_alloc)
|
---|
665 | {
|
---|
666 | hrc = E_OUTOFMEMORY;
|
---|
667 | }
|
---|
668 | }
|
---|
669 | return hrc;
|
---|
670 | }
|
---|
671 |
|
---|
672 | HRESULT UnattendedInstaller::addScriptToVisoVectors(BaseTextScript *pEditor, RTCList<RTCString> &rVecArgs,
|
---|
673 | RTCList<RTCString> &rVecFiles, bool fOverwrite)
|
---|
674 | {
|
---|
675 | /*
|
---|
676 | * Calc the aux script file name.
|
---|
677 | */
|
---|
678 | RTCString strScriptName;
|
---|
679 | try
|
---|
680 | {
|
---|
681 | strScriptName = mpParent->i_getAuxiliaryBasePath();
|
---|
682 | strScriptName.append(pEditor->getDefaultFilename());
|
---|
683 | }
|
---|
684 | catch (std::bad_alloc)
|
---|
685 | {
|
---|
686 | return E_OUTOFMEMORY;
|
---|
687 | }
|
---|
688 |
|
---|
689 | /*
|
---|
690 | * Save it.
|
---|
691 | */
|
---|
692 | HRESULT hrc = pEditor->save(strScriptName.c_str(), fOverwrite);
|
---|
693 | if (SUCCEEDED(hrc))
|
---|
694 | {
|
---|
695 | /*
|
---|
696 | * Add it to the vectors.
|
---|
697 | */
|
---|
698 | try
|
---|
699 | {
|
---|
700 | rVecArgs.append().append('/').append(pEditor->getDefaultFilename()).append('=').append(strScriptName);
|
---|
701 | rVecFiles.append(strScriptName);
|
---|
702 | }
|
---|
703 | catch (std::bad_alloc)
|
---|
704 | {
|
---|
705 | RTFileDelete(strScriptName.c_str());
|
---|
706 | hrc = E_OUTOFMEMORY;
|
---|
707 | }
|
---|
708 | }
|
---|
709 | return hrc;
|
---|
710 | }
|
---|
711 |
|
---|
712 | HRESULT UnattendedInstaller::finalizeAuxVisoFile(RTCList<RTCString> const &rVecArgs, const char *pszFilename, bool fOverwrite)
|
---|
713 | {
|
---|
714 | /*
|
---|
715 | * Create a C-style argument vector and turn that into a command line string.
|
---|
716 | */
|
---|
717 | size_t const cArgs = rVecArgs.size();
|
---|
718 | const char **papszArgs = (const char **)RTMemTmpAlloc((cArgs + 1) * sizeof(const char *));
|
---|
719 | if (!papszArgs)
|
---|
720 | return E_OUTOFMEMORY;
|
---|
721 | for (size_t i = 0; i < cArgs; i++)
|
---|
722 | papszArgs[i] = rVecArgs[i].c_str();
|
---|
723 | papszArgs[cArgs] = NULL;
|
---|
724 |
|
---|
725 | char *pszCmdLine;
|
---|
726 | int vrc = RTGetOptArgvToString(&pszCmdLine, papszArgs, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH);
|
---|
727 | RTMemTmpFree(papszArgs);
|
---|
728 | if (RT_FAILURE(vrc))
|
---|
729 | return mpParent->setErrorBoth(E_FAIL, vrc, mpParent->tr("RTGetOptArgvToString failed (%Rrc)"), vrc);
|
---|
730 |
|
---|
731 | /*
|
---|
732 | * Open the file.
|
---|
733 | */
|
---|
734 | HRESULT hrc;
|
---|
735 | uint64_t fOpen = RTFILE_O_WRITE | RTFILE_O_DENY_WRITE | RTFILE_O_DENY_READ;
|
---|
736 | if (fOverwrite)
|
---|
737 | fOpen |= RTFILE_O_CREATE_REPLACE;
|
---|
738 | else
|
---|
739 | fOpen |= RTFILE_O_CREATE;
|
---|
740 | RTFILE hFile;
|
---|
741 | vrc = RTFileOpen(&hFile, pszFilename, fOpen);
|
---|
742 | if (RT_SUCCESS(vrc))
|
---|
743 | {
|
---|
744 | vrc = RTFileWrite(hFile, pszCmdLine, strlen(pszCmdLine), NULL);
|
---|
745 | if (RT_SUCCESS(vrc))
|
---|
746 | vrc = RTFileClose(hFile);
|
---|
747 | else
|
---|
748 | RTFileClose(hFile);
|
---|
749 | if (RT_SUCCESS(vrc))
|
---|
750 | hrc = S_OK;
|
---|
751 | else
|
---|
752 | hrc = mpParent->setErrorBoth(VBOX_E_FILE_ERROR, vrc, mpParent->tr("Error writing '%s' (%Rrc)"), pszFilename, vrc);
|
---|
753 | }
|
---|
754 | else
|
---|
755 | hrc = mpParent->setErrorBoth(VBOX_E_FILE_ERROR, vrc, mpParent->tr("Failed to create '%s' (%Rrc)"), pszFilename, vrc);
|
---|
756 |
|
---|
757 | RTStrFree(pszCmdLine);
|
---|
758 | return hrc;
|
---|
759 | }
|
---|
760 |
|
---|
761 | HRESULT UnattendedInstaller::loadAndParseFileFromIso(RTVFS hVfsOrgIso, const char *pszFilename, AbstractScript *pEditor)
|
---|
762 | {
|
---|
763 | HRESULT hrc;
|
---|
764 | RTVFSFILE hVfsFile;
|
---|
765 | int vrc = RTVfsFileOpen(hVfsOrgIso, pszFilename, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE, &hVfsFile);
|
---|
766 | if (RT_SUCCESS(vrc))
|
---|
767 | {
|
---|
768 | hrc = pEditor->readFromHandle(hVfsFile, pszFilename);
|
---|
769 | RTVfsFileRelease(hVfsFile);
|
---|
770 | if (SUCCEEDED(hrc))
|
---|
771 | hrc = pEditor->parse();
|
---|
772 | }
|
---|
773 | else
|
---|
774 | hrc = mpParent->setErrorBoth(VBOX_E_FILE_ERROR, vrc, mpParent->tr("Failed to open '%s' on the ISO '%s' (%Rrc)"),
|
---|
775 | pszFilename, mpParent->i_getIsoPath().c_str(), vrc);
|
---|
776 | return hrc;
|
---|
777 | }
|
---|
778 |
|
---|
779 |
|
---|
780 | //////////////////////////////////////////////////////////////////////////////////////////////////////
|
---|
781 | /*
|
---|
782 | *
|
---|
783 | *
|
---|
784 | * Implementation UnattendedLinuxInstaller functions
|
---|
785 | *
|
---|
786 | */
|
---|
787 | //////////////////////////////////////////////////////////////////////////////////////////////////////
|
---|
788 | HRESULT UnattendedLinuxInstaller::editIsoLinuxCfg(GeneralTextScript *pEditor)
|
---|
789 | {
|
---|
790 | try
|
---|
791 | {
|
---|
792 | /* Set timeouts to 10 seconds. */
|
---|
793 | std::vector<size_t> vecLineNumbers = pEditor->findTemplate("timeout", RTCString::CaseInsensitive);
|
---|
794 | for (size_t i = 0; i < vecLineNumbers.size(); ++i)
|
---|
795 | if (pEditor->getContentOfLine(vecLineNumbers[i]).startsWithWord("timeout", RTCString::CaseInsensitive))
|
---|
796 | {
|
---|
797 | HRESULT hrc = pEditor->setContentOfLine(vecLineNumbers.at(i), "timeout 10");
|
---|
798 | if (FAILED(hrc))
|
---|
799 | return hrc;
|
---|
800 | }
|
---|
801 |
|
---|
802 | /* Comment out 'display <filename>' directives that's used for displaying files at boot time. */
|
---|
803 | vecLineNumbers = pEditor->findTemplate("display", RTCString::CaseInsensitive);
|
---|
804 | for (size_t i = 0; i < vecLineNumbers.size(); ++i)
|
---|
805 | if (pEditor->getContentOfLine(vecLineNumbers[i]).startsWithWord("display", RTCString::CaseInsensitive))
|
---|
806 | {
|
---|
807 | HRESULT hrc = pEditor->prependToLine(vecLineNumbers.at(i), "#");
|
---|
808 | if (FAILED(hrc))
|
---|
809 | return hrc;
|
---|
810 | }
|
---|
811 |
|
---|
812 | /* Modify kernel parameters. */
|
---|
813 | vecLineNumbers = pEditor->findTemplate("append", RTCString::CaseInsensitive);
|
---|
814 | if (vecLineNumbers.size() > 0)
|
---|
815 | {
|
---|
816 | Utf8Str const &rStrAppend = mpParent->i_getExtraInstallKernelParameters().isNotEmpty()
|
---|
817 | ? mpParent->i_getExtraInstallKernelParameters()
|
---|
818 | : mStrDefaultExtraInstallKernelParameters;
|
---|
819 |
|
---|
820 | for (size_t i = 0; i < vecLineNumbers.size(); ++i)
|
---|
821 | if (pEditor->getContentOfLine(vecLineNumbers[i]).startsWithWord("append", RTCString::CaseInsensitive))
|
---|
822 | {
|
---|
823 | Utf8Str strLine = pEditor->getContentOfLine(vecLineNumbers[i]);
|
---|
824 |
|
---|
825 | /* Do removals. */
|
---|
826 | if (mArrStrRemoveInstallKernelParameters.size() > 0)
|
---|
827 | {
|
---|
828 | size_t offStart = strLine.find("append") + 5;
|
---|
829 | while (offStart < strLine.length() && !RT_C_IS_SPACE(strLine[offStart]))
|
---|
830 | offStart++;
|
---|
831 | while (offStart < strLine.length() && RT_C_IS_SPACE(strLine[offStart]))
|
---|
832 | offStart++;
|
---|
833 | if (offStart < strLine.length())
|
---|
834 | {
|
---|
835 | for (size_t iRemove = 0; iRemove < mArrStrRemoveInstallKernelParameters.size(); iRemove++)
|
---|
836 | {
|
---|
837 | RTCString const &rStrRemove = mArrStrRemoveInstallKernelParameters[iRemove];
|
---|
838 | for (size_t off = offStart; off < strLine.length(); )
|
---|
839 | {
|
---|
840 | Assert(!RT_C_IS_SPACE(strLine[off]));
|
---|
841 |
|
---|
842 | /* Find the end of word. */
|
---|
843 | size_t offEnd = off + 1;
|
---|
844 | while (offEnd < strLine.length() && !RT_C_IS_SPACE(strLine[offEnd]))
|
---|
845 | offEnd++;
|
---|
846 |
|
---|
847 | /* Check if it matches. */
|
---|
848 | if (RTStrSimplePatternNMatch(rStrRemove.c_str(), rStrRemove.length(),
|
---|
849 | strLine.c_str() + off, offEnd - off))
|
---|
850 | {
|
---|
851 | while (off > 0 && RT_C_IS_SPACE(strLine[off - 1]))
|
---|
852 | off--;
|
---|
853 | strLine.erase(off, offEnd - off);
|
---|
854 | }
|
---|
855 |
|
---|
856 | /* Advance to the next word. */
|
---|
857 | off = offEnd;
|
---|
858 | while (off < strLine.length() && RT_C_IS_SPACE(strLine[off]))
|
---|
859 | off++;
|
---|
860 | }
|
---|
861 | }
|
---|
862 | }
|
---|
863 | }
|
---|
864 |
|
---|
865 | /* Do the appending. */
|
---|
866 | if (rStrAppend.isNotEmpty())
|
---|
867 | {
|
---|
868 | if (!rStrAppend.startsWith(" ") && !strLine.endsWith(" "))
|
---|
869 | strLine.append(' ');
|
---|
870 | strLine.append(rStrAppend);
|
---|
871 | }
|
---|
872 |
|
---|
873 | /* Update line. */
|
---|
874 | HRESULT hrc = pEditor->setContentOfLine(vecLineNumbers.at(i), strLine);
|
---|
875 | if (FAILED(hrc))
|
---|
876 | return hrc;
|
---|
877 | }
|
---|
878 | }
|
---|
879 | }
|
---|
880 | catch (std::bad_alloc)
|
---|
881 | {
|
---|
882 | return E_OUTOFMEMORY;
|
---|
883 | }
|
---|
884 | return S_OK;
|
---|
885 | }
|
---|
886 |
|
---|
887 |
|
---|
888 | //////////////////////////////////////////////////////////////////////////////////////////////////////
|
---|
889 | /*
|
---|
890 | *
|
---|
891 | *
|
---|
892 | * Implementation UnattendedDebianInstaller functions
|
---|
893 | *
|
---|
894 | */
|
---|
895 | //////////////////////////////////////////////////////////////////////////////////////////////////////
|
---|
896 |
|
---|
897 | HRESULT UnattendedDebianInstaller::addFilesToAuxVisoVectors(RTCList<RTCString> &rVecArgs, RTCList<RTCString> &rVecFiles,
|
---|
898 | RTVFS hVfsOrgIso, bool fOverwrite)
|
---|
899 | {
|
---|
900 | /*
|
---|
901 | * VISO bits and filenames.
|
---|
902 | */
|
---|
903 | RTCString strIsoLinuxCfg;
|
---|
904 | RTCString strTxtCfg;
|
---|
905 | try
|
---|
906 | {
|
---|
907 | /* Remaster ISO. */
|
---|
908 | rVecArgs.append() = "--no-file-mode";
|
---|
909 | rVecArgs.append() = "--no-dir-mode";
|
---|
910 |
|
---|
911 | rVecArgs.append() = "--import-iso";
|
---|
912 | rVecArgs.append(mpParent->i_getIsoPath());
|
---|
913 |
|
---|
914 | rVecArgs.append() = "--file-mode=0444";
|
---|
915 | rVecArgs.append() = "--dir-mode=0555";
|
---|
916 |
|
---|
917 | /* Remove the two isolinux configure files we'll be replacing. */
|
---|
918 | rVecArgs.append() = "isolinux/isolinux.cfg=:must-remove:";
|
---|
919 | rVecArgs.append() = "isolinux/txt.cfg=:must-remove:";
|
---|
920 |
|
---|
921 | /* Add the replacement files. */
|
---|
922 | strIsoLinuxCfg = mpParent->i_getAuxiliaryBasePath();
|
---|
923 | strIsoLinuxCfg.append("isolinux-isolinux.cfg");
|
---|
924 | rVecArgs.append().append("isolinux/isolinux.cfg=").append(strIsoLinuxCfg);
|
---|
925 |
|
---|
926 | strTxtCfg = mpParent->i_getAuxiliaryBasePath();
|
---|
927 | strTxtCfg.append("isolinux-txt.cfg");
|
---|
928 | rVecArgs.append().append("isolinux/txt.cfg=").append(strTxtCfg);
|
---|
929 | }
|
---|
930 | catch (std::bad_alloc)
|
---|
931 | {
|
---|
932 | return E_OUTOFMEMORY;
|
---|
933 | }
|
---|
934 |
|
---|
935 | /*
|
---|
936 | * Edit the isolinux.cfg file.
|
---|
937 | */
|
---|
938 | {
|
---|
939 | GeneralTextScript Editor(mpParent);
|
---|
940 | HRESULT hrc = loadAndParseFileFromIso(hVfsOrgIso, "/isolinux/isolinux.cfg", &Editor);
|
---|
941 | if (SUCCEEDED(hrc))
|
---|
942 | hrc = editIsoLinuxCfg(&Editor);
|
---|
943 | if (SUCCEEDED(hrc))
|
---|
944 | {
|
---|
945 | hrc = Editor.save(strIsoLinuxCfg, fOverwrite);
|
---|
946 | if (SUCCEEDED(hrc))
|
---|
947 | {
|
---|
948 | try
|
---|
949 | {
|
---|
950 | rVecFiles.append(strIsoLinuxCfg);
|
---|
951 | }
|
---|
952 | catch (std::bad_alloc)
|
---|
953 | {
|
---|
954 | RTFileDelete(strIsoLinuxCfg.c_str());
|
---|
955 | hrc = E_OUTOFMEMORY;
|
---|
956 | }
|
---|
957 | }
|
---|
958 | }
|
---|
959 | if (FAILED(hrc))
|
---|
960 | return hrc;
|
---|
961 | }
|
---|
962 |
|
---|
963 | /*
|
---|
964 | * Edit the txt.cfg file.
|
---|
965 | */
|
---|
966 | {
|
---|
967 | GeneralTextScript Editor(mpParent);
|
---|
968 | HRESULT hrc = loadAndParseFileFromIso(hVfsOrgIso, "/isolinux/txt.cfg", &Editor);
|
---|
969 | if (SUCCEEDED(hrc))
|
---|
970 | hrc = editDebianTxtCfg(&Editor);
|
---|
971 | if (SUCCEEDED(hrc))
|
---|
972 | {
|
---|
973 | hrc = Editor.save(strTxtCfg, fOverwrite);
|
---|
974 | if (SUCCEEDED(hrc))
|
---|
975 | {
|
---|
976 | try
|
---|
977 | {
|
---|
978 | rVecFiles.append(strTxtCfg);
|
---|
979 | }
|
---|
980 | catch (std::bad_alloc)
|
---|
981 | {
|
---|
982 | RTFileDelete(strTxtCfg.c_str());
|
---|
983 | hrc = E_OUTOFMEMORY;
|
---|
984 | }
|
---|
985 | }
|
---|
986 | }
|
---|
987 | if (FAILED(hrc))
|
---|
988 | return hrc;
|
---|
989 | }
|
---|
990 |
|
---|
991 | /*
|
---|
992 | * Call parent to add the preseed file from mAlg.
|
---|
993 | */
|
---|
994 | return UnattendedLinuxInstaller::addFilesToAuxVisoVectors(rVecArgs, rVecFiles, hVfsOrgIso, fOverwrite);
|
---|
995 | }
|
---|
996 |
|
---|
997 | HRESULT UnattendedDebianInstaller::editDebianTxtCfg(GeneralTextScript *pEditor)
|
---|
998 | {
|
---|
999 | try
|
---|
1000 | {
|
---|
1001 | /** @todo r=bird: Add some comments saying wtf you're actually up to here.
|
---|
1002 | * Repeating what's clear from function calls and boasting the
|
---|
1003 | * inteligence of the code isn't helpful. */
|
---|
1004 | //find all lines with "label" inside
|
---|
1005 | std::vector<size_t> vecLineNumbers = pEditor->findTemplate("label", RTCString::CaseInsensitive);
|
---|
1006 | for (size_t i = 0; i < vecLineNumbers.size(); ++i)
|
---|
1007 | {
|
---|
1008 | RTCString const &rContent = pEditor->getContentOfLine(vecLineNumbers[i]);
|
---|
1009 |
|
---|
1010 | // ASSUME: suppose general string looks like "label install", two words separated by " ".
|
---|
1011 | RTCList<RTCString> vecPartsOfcontent = rContent.split(" ");
|
---|
1012 | if (vecPartsOfcontent.size() > 1 && vecPartsOfcontent[1].contains("install")) /** @todo r=bird: case insensitive? */
|
---|
1013 | {
|
---|
1014 | std::vector<size_t> vecDefaultLineNumbers = pEditor->findTemplate("default", RTCString::CaseInsensitive);
|
---|
1015 | //handle the lines more intelligently
|
---|
1016 | for (size_t j = 0; j < vecDefaultLineNumbers.size(); ++j)
|
---|
1017 | {
|
---|
1018 | Utf8Str strNewContent("default ");
|
---|
1019 | strNewContent.append(vecPartsOfcontent[1]);
|
---|
1020 | HRESULT hrc = pEditor->setContentOfLine(vecDefaultLineNumbers[j], strNewContent);
|
---|
1021 | if (FAILED(hrc))
|
---|
1022 | return hrc;
|
---|
1023 | }
|
---|
1024 | }
|
---|
1025 | }
|
---|
1026 | }
|
---|
1027 | catch (std::bad_alloc)
|
---|
1028 | {
|
---|
1029 | return E_OUTOFMEMORY;
|
---|
1030 | }
|
---|
1031 | return UnattendedLinuxInstaller::editIsoLinuxCfg(pEditor);
|
---|
1032 | }
|
---|
1033 |
|
---|
1034 |
|
---|
1035 | //////////////////////////////////////////////////////////////////////////////////////////////////////
|
---|
1036 | /*
|
---|
1037 | *
|
---|
1038 | *
|
---|
1039 | * Implementation UnattendedRedHat67Installer functions
|
---|
1040 | *
|
---|
1041 | */
|
---|
1042 | //////////////////////////////////////////////////////////////////////////////////////////////////////
|
---|
1043 | HRESULT UnattendedRedHat67Installer::addFilesToAuxVisoVectors(RTCList<RTCString> &rVecArgs, RTCList<RTCString> &rVecFiles,
|
---|
1044 | RTVFS hVfsOrgIso, bool fOverwrite)
|
---|
1045 | {
|
---|
1046 | Utf8Str strIsoLinuxCfg;
|
---|
1047 | try
|
---|
1048 | {
|
---|
1049 | #if 1
|
---|
1050 | /* Remaster ISO. */
|
---|
1051 | rVecArgs.append() = "--no-file-mode";
|
---|
1052 | rVecArgs.append() = "--no-dir-mode";
|
---|
1053 |
|
---|
1054 | rVecArgs.append() = "--import-iso";
|
---|
1055 | rVecArgs.append(mpParent->i_getIsoPath());
|
---|
1056 |
|
---|
1057 | rVecArgs.append() = "--file-mode=0444";
|
---|
1058 | rVecArgs.append() = "--dir-mode=0555";
|
---|
1059 |
|
---|
1060 | /* We replace isolinux.cfg with our edited version (see further down). */
|
---|
1061 | rVecArgs.append() = "isolinux/isolinux.cfg=:must-remove:";
|
---|
1062 | strIsoLinuxCfg = mpParent->i_getAuxiliaryBasePath();
|
---|
1063 | strIsoLinuxCfg.append("isolinux-isolinux.cfg");
|
---|
1064 | rVecArgs.append().append("isolinux/isolinux.cfg=").append(strIsoLinuxCfg);
|
---|
1065 |
|
---|
1066 | #else
|
---|
1067 | /** @todo Maybe we should just remaster the ISO for redhat derivatives too?
|
---|
1068 | * One less CDROM to mount. */
|
---|
1069 | /* Name the ISO. */
|
---|
1070 | rVecArgs.append() = "--volume-id=VBox Unattended Boot";
|
---|
1071 |
|
---|
1072 | /* Copy the isolinux directory from the original install ISO. */
|
---|
1073 | rVecArgs.append().append("--push-iso=").append(mpParent->i_getIsoPath());
|
---|
1074 | rVecArgs.append() = "/isolinux=/isolinux";
|
---|
1075 | rVecArgs.append() = "--pop";
|
---|
1076 |
|
---|
1077 | /* We replace isolinux.cfg with our edited version (see further down). */
|
---|
1078 | rVecArgs.append() = "/isolinux/isolinux.cfg=:must-remove:";
|
---|
1079 |
|
---|
1080 | strIsoLinuxCfg = mpParent->i_getAuxiliaryBasePath();
|
---|
1081 | strIsoLinuxCfg.append("isolinux-isolinux.cfg");
|
---|
1082 | rVecArgs.append().append("/isolinux/isolinux.cfg=").append(strIsoLinuxCfg);
|
---|
1083 |
|
---|
1084 | /* Configure booting /isolinux/isolinux.bin. */
|
---|
1085 | rVecArgs.append() = "--eltorito-boot";
|
---|
1086 | rVecArgs.append() = "/isolinux/isolinux.bin";
|
---|
1087 | rVecArgs.append() = "--no-emulation-boot";
|
---|
1088 | rVecArgs.append() = "--boot-info-table";
|
---|
1089 | rVecArgs.append() = "--boot-load-seg=0x07c0";
|
---|
1090 | rVecArgs.append() = "--boot-load-size=4";
|
---|
1091 |
|
---|
1092 | /* Make the boot catalog visible in the file system. */
|
---|
1093 | rVecArgs.append() = "--boot-catalog=/isolinux/vboxboot.cat";
|
---|
1094 | #endif
|
---|
1095 | }
|
---|
1096 | catch (std::bad_alloc)
|
---|
1097 | {
|
---|
1098 | return E_OUTOFMEMORY;
|
---|
1099 | }
|
---|
1100 |
|
---|
1101 | /*
|
---|
1102 | * Edit isolinux.cfg and save it.
|
---|
1103 | */
|
---|
1104 | {
|
---|
1105 | GeneralTextScript Editor(mpParent);
|
---|
1106 | HRESULT hrc = loadAndParseFileFromIso(hVfsOrgIso, "/isolinux/isolinux.cfg", &Editor);
|
---|
1107 | if (SUCCEEDED(hrc))
|
---|
1108 | hrc = editIsoLinuxCfg(&Editor);
|
---|
1109 | if (SUCCEEDED(hrc))
|
---|
1110 | {
|
---|
1111 | hrc = Editor.save(strIsoLinuxCfg, fOverwrite);
|
---|
1112 | if (SUCCEEDED(hrc))
|
---|
1113 | {
|
---|
1114 | try
|
---|
1115 | {
|
---|
1116 | rVecFiles.append(strIsoLinuxCfg);
|
---|
1117 | }
|
---|
1118 | catch (std::bad_alloc)
|
---|
1119 | {
|
---|
1120 | RTFileDelete(strIsoLinuxCfg.c_str());
|
---|
1121 | hrc = E_OUTOFMEMORY;
|
---|
1122 | }
|
---|
1123 | }
|
---|
1124 | }
|
---|
1125 | if (FAILED(hrc))
|
---|
1126 | return hrc;
|
---|
1127 | }
|
---|
1128 |
|
---|
1129 | /*
|
---|
1130 | * Call parent to add the ks.cfg file from mAlg.
|
---|
1131 | */
|
---|
1132 | return UnattendedLinuxInstaller::addFilesToAuxVisoVectors(rVecArgs, rVecFiles, hVfsOrgIso, fOverwrite);
|
---|
1133 | }
|
---|
1134 |
|
---|
1135 |
|
---|
1136 | //////////////////////////////////////////////////////////////////////////////////////////////////////
|
---|
1137 | /*
|
---|
1138 | *
|
---|
1139 | *
|
---|
1140 | * Implementation UnattendedSuseInstaller functions
|
---|
1141 | *
|
---|
1142 | */
|
---|
1143 | //////////////////////////////////////////////////////////////////////////////////////////////////////
|
---|
1144 | #if 0 /* doesn't work, so convert later */
|
---|
1145 | /*
|
---|
1146 | *
|
---|
1147 | * UnattendedSuseInstaller protected methods
|
---|
1148 | *
|
---|
1149 | */
|
---|
1150 | HRESULT UnattendedSuseInstaller::setUserData()
|
---|
1151 | {
|
---|
1152 | HRESULT rc = S_OK;
|
---|
1153 | //here base class function must be called first
|
---|
1154 | //because user home directory is set after user name
|
---|
1155 | rc = UnattendedInstaller::setUserData();
|
---|
1156 |
|
---|
1157 | rc = mAlg->setField(USERHOMEDIR_ID, "");
|
---|
1158 | if (FAILED(rc))
|
---|
1159 | return rc;
|
---|
1160 |
|
---|
1161 | return rc;
|
---|
1162 | }
|
---|
1163 |
|
---|
1164 | /*
|
---|
1165 | *
|
---|
1166 | * UnattendedSuseInstaller private methods
|
---|
1167 | *
|
---|
1168 | */
|
---|
1169 |
|
---|
1170 | HRESULT UnattendedSuseInstaller::iv_initialPhase()
|
---|
1171 | {
|
---|
1172 | Assert(isAuxiliaryIsoNeeded());
|
---|
1173 | if (mParent->i_isGuestOs64Bit())
|
---|
1174 | mFilesAndDirsToExtractFromIso.append("boot/x86_64/loader/ ");
|
---|
1175 | else
|
---|
1176 | mFilesAndDirsToExtractFromIso.append("boot/i386/loader/ ");
|
---|
1177 | return extractOriginalIso(mFilesAndDirsToExtractFromIso);
|
---|
1178 | }
|
---|
1179 |
|
---|
1180 |
|
---|
1181 | HRESULT UnattendedSuseInstaller::setupScriptOnAuxiliaryCD(const Utf8Str &path)
|
---|
1182 | {
|
---|
1183 | HRESULT rc = S_OK;
|
---|
1184 |
|
---|
1185 | GeneralTextScript isoSuseCfgScript(mpParent);
|
---|
1186 | rc = isoSuseCfgScript.read(path);
|
---|
1187 | rc = isoSuseCfgScript.parse();
|
---|
1188 | //fix linux core bootable parameters: add path to the preseed script
|
---|
1189 |
|
---|
1190 | std::vector<size_t> listOfLines = isoSuseCfgScript.findTemplate("append");
|
---|
1191 | for(unsigned int i=0; i<listOfLines.size(); ++i)
|
---|
1192 | {
|
---|
1193 | isoSuseCfgScript.appendToLine(listOfLines.at(i),
|
---|
1194 | " auto=true priority=critical autoyast=default instmode=cd quiet splash noprompt noshell --");
|
---|
1195 | }
|
---|
1196 |
|
---|
1197 | //find all lines with "label" inside
|
---|
1198 | listOfLines = isoSuseCfgScript.findTemplate("label");
|
---|
1199 | for(unsigned int i=0; i<listOfLines.size(); ++i)
|
---|
1200 | {
|
---|
1201 | Utf8Str content = isoSuseCfgScript.getContentOfLine(listOfLines.at(i));
|
---|
1202 |
|
---|
1203 | //suppose general string looks like "label linux", two words separated by " ".
|
---|
1204 | RTCList<RTCString> partsOfcontent = content.split(" ");
|
---|
1205 |
|
---|
1206 | if (partsOfcontent.at(1).contains("linux"))
|
---|
1207 | {
|
---|
1208 | std::vector<size_t> listOfDefault = isoSuseCfgScript.findTemplate("default");
|
---|
1209 | //handle the lines more intelligently
|
---|
1210 | for(unsigned int j=0; j<listOfDefault.size(); ++j)
|
---|
1211 | {
|
---|
1212 | Utf8Str newContent("default ");
|
---|
1213 | newContent.append(partsOfcontent.at(1));
|
---|
1214 | isoSuseCfgScript.setContentOfLine(listOfDefault.at(j), newContent);
|
---|
1215 | }
|
---|
1216 | }
|
---|
1217 | }
|
---|
1218 |
|
---|
1219 | rc = isoSuseCfgScript.save(path, true);
|
---|
1220 |
|
---|
1221 | LogRelFunc(("UnattendedSuseInstaller::setupScriptsOnAuxiliaryCD(): The file %s has been changed\n", path.c_str()));
|
---|
1222 |
|
---|
1223 | return rc;
|
---|
1224 | }
|
---|
1225 | #endif
|
---|
1226 |
|
---|