VirtualBox

source: vbox/trunk/src/VBox/Main/include/UnattendedInstaller.h@ 68222

Last change on this file since 68222 was 68222, checked in by vboxsync, 7 years ago

Main: Squeeze the validation kit and additions onto the aux image when installing windows vista+. Implemented setting up vboxtxs.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 22.3 KB
Line 
1/* $Id: UnattendedInstaller.h 68222 2017-08-01 19:05:50Z vboxsync $ */
2/** @file
3 * UnattendedInstaller class header
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#ifndef ____H_UNATTENDEDINSTALLER
19#define ____H_UNATTENDEDINSTALLER
20
21#include "UnattendedScript.h"
22
23/* Forward declarations */
24class Unattended;
25class UnattendedInstaller;
26class BaseTextScript;
27
28
29/**
30 * The abstract UnattendedInstaller class declaration
31 *
32 * The class is intended to service a new VM that this VM will be able to
33 * execute an unattended installation
34 */
35class UnattendedInstaller : public RTCNonCopyable
36{
37/*data*/
38protected:
39 /** Main unattended installation script. */
40 UnattendedScriptTemplate mMainScript;
41 /** Full path to the main template file (set by initInstaller). */
42 Utf8Str mStrMainScriptTemplate;
43
44 /** Post installation (shell) script. */
45 UnattendedScriptTemplate mPostScript;
46 /** Full path to the post template file (set by initInstaller). */
47 Utf8Str mStrPostScriptTemplate;
48
49 /** Pointer to the parent object.
50 * We use this for setting errors and querying attributes. */
51 Unattended *mpParent;
52 /** The path of the extra ISO image we create (set by initInstaller).
53 * This is only valid when isAdditionsIsoNeeded() returns true. */
54 Utf8Str mStrAuxiliaryIsoFilePath;
55 /** The path of the extra floppy image we create (set by initInstaller)
56 * This is only valid when isAdditionsFloppyNeeded() returns true. */
57 Utf8Str mStrAuxiliaryFloppyFilePath;
58 /** The boot device. */
59 DeviceType_T const meBootDevice;
60 /** Default extra install kernel parameters (set by constructor).
61 * This can be overridden by the extraInstallKernelParameters attribute of
62 * IUnattended. */
63 Utf8Str mStrDefaultExtraInstallKernelParameters;
64
65private:
66 UnattendedInstaller(); /* no default constructors */
67
68public:
69 /**
70 * Regular constructor.
71 *
72 * @param pParent The parent object. Used for setting
73 * errors and querying attributes.
74 * @param pszMainScriptTemplateName The name of the template file (no path)
75 * for the main unattended installer
76 * script.
77 * @param pszPostScriptTemplateName The name of the template file (no path)
78 * for the post installation script.
79 * @param pszMainScriptFilename The main unattended installer script
80 * filename (on aux media).
81 * @param pszPostScriptFilename The post installation script filename
82 * (on aux media).
83 * @param enmBootDevice The boot device type.
84 */
85 UnattendedInstaller(Unattended *pParent,
86 const char *pszMainScriptTemplateName, const char *pszPostScriptTemplateName,
87 const char *pszMainScriptFilename, const char *pszPostScriptFilename,
88 DeviceType_T enmBootDevice = DeviceType_DVD);
89 virtual ~UnattendedInstaller();
90
91 /**
92 * Instantiates the appropriate child class.
93 *
94 * @returns Pointer to the new instance, NULL if no appropriate installer.
95 * @param enmOsType The guest OS type value.
96 * @param strGuestOsType The guest OS type string
97 * @param pParent The parent object. Used for setting errors and
98 * querying attributes.
99 * @throws std::bad_alloc
100 */
101 static UnattendedInstaller *createInstance(VBOXOSTYPE enmOsType, const Utf8Str &strGuestOsType, Unattended *pParent);
102
103 /**
104 * Initialize the installer.
105 *
106 * @note This is called immediately after instantiation and the caller will
107 * always destroy the unattended installer instance on failure, so it
108 * is not necessary to keep track of whether this succeeded or not.
109 */
110 virtual HRESULT initInstaller();
111
112#if 0 /* These are now in the AUX VISO. */
113 /**
114 * Whether the VBox guest additions ISO is needed or not.
115 *
116 * The default implementation always returns false when a VISO is used, see
117 * UnattendedInstaller::addFilesToAuxVisoVectors.
118 */
119 virtual bool isAdditionsIsoNeeded() const;
120
121 /**
122 * Whether the VBox validation kit ISO is needed or not.
123 *
124 * The default implementation always returns false when a VISO is used, see
125 * UnattendedInstaller::addFilesToAuxVisoVectors.
126 */
127 virtual bool isValidationKitIsoNeeded() const;
128#endif
129
130 /**
131 * Indicates whether an original installation ISO is needed or not.
132 */
133 virtual bool isOriginalIsoNeeded() const { return true; }
134
135 /**
136 * Indicates whether a floppy image is needed or not.
137 */
138 virtual bool isAuxiliaryFloppyNeeded() const { return false; }
139
140 /**
141 * Indicates whether an additional or replacement ISO image is needed or not.
142 */
143 virtual bool isAuxiliaryIsoNeeded() const;
144
145 /**
146 * Indicates whether we should boot from the auxiliary ISO image.
147 *
148 * Will boot from installation ISO if false.
149 */
150 virtual bool bootFromAuxiliaryIso() const { return isAuxiliaryIsoNeeded(); }
151
152 /**
153 * Indicates whether a the auxiliary ISO is a .viso-file rather than an
154 * .iso-file.
155 *
156 * Different worker methods are used depending on the return value. A
157 * .viso-file is generally only used when the installation media needs to
158 * be remastered with small changes and additions.
159 */
160 virtual bool isAuxiliaryIsoIsVISO() const { return true; }
161
162 /*
163 * Getters
164 */
165 DeviceType_T getBootableDeviceType() const { return meBootDevice; }
166 const Utf8Str &getTemplateFilePath() const { return mStrMainScriptTemplate; }
167 const Utf8Str &getPostTemplateFilePath() const { return mStrPostScriptTemplate; }
168 const Utf8Str &getAuxiliaryIsoFilePath() const { return mStrAuxiliaryIsoFilePath; }
169 const Utf8Str &getAuxiliaryFloppyFilePath() const { return mStrAuxiliaryFloppyFilePath; }
170 const Utf8Str &getDefaultExtraInstallKernelParameters() const { return mStrDefaultExtraInstallKernelParameters; }
171
172 /*
173 * Setters
174 */
175 void setTemplatePath(const Utf8Str& data); /**< @todo r=bird: This is confusing as heck. Dir for a while, then it's a file. Not a comment about it. Brilliant. */
176
177 /**
178 * Prepares the unattended scripts, does all but write them to the installation
179 * media.
180 */
181 HRESULT prepareUnattendedScripts();
182
183 /**
184 * Prepares the media - floppy image, ISO image.
185 *
186 * This method calls prepareAuxFloppyImage() and prepareAuxIsoImage(), child
187 * classes may override these methods or methods they call.
188 *
189 * @returns COM status code.
190 * @param fOverwrite Whether to overwrite media files or fail if they
191 * already exist.
192 */
193 HRESULT prepareMedia(bool fOverwrite = true);
194
195protected:
196 /**
197 * Prepares (creates) the auxiliary floppy image.
198 *
199 * This is called by the base class prepareMedia() when
200 * isAuxiliaryFloppyNeeded() is true. The base class implementation puts the
201 * edited unattended script onto it.
202 */
203 HRESULT prepareAuxFloppyImage(bool fOverwrite);
204
205 /**
206 * Creates and formats (FAT12) a floppy image, then opens a VFS for it.
207 *
208 * @returns COM status code.
209 * @param pszFilename The path to the image file.
210 * @param fOverwrite Whether to overwrite the file.
211 * @param phVfs Where to return a writable VFS handle to the newly
212 * created image.
213 */
214 HRESULT newAuxFloppyImage(const char *pszFilename, bool fOverwrite, PRTVFS phVfs);
215
216 /**
217 * Copies files to the auxiliary floppy image.
218 *
219 * The base class implementation copies the main and post scripts to the root of
220 * the floppy using the default script names. Child classes may override this
221 * to add additional or different files.
222 *
223 * @returns COM status code.
224 * @param hVfs The floppy image VFS handle.
225 */
226 virtual HRESULT copyFilesToAuxFloppyImage(RTVFS hVfs);
227
228 /**
229 * Adds the given script to the root of the floppy image under the default
230 * script filename.
231 *
232 * @returns COM status code.
233 * @param pEditor The script to add.
234 * @param hVfs The VFS to add it to.
235 */
236 HRESULT addScriptToFloppyImage(BaseTextScript *pEditor, RTVFS hVfs);
237
238 /**
239 * Prepares (creates) the auxiliary ISO image.
240 *
241 * This is called by the base class prepareMedia() when isAuxiliaryIsoNeeded()
242 * is true. The base class implementation puts the edited unattended script
243 * onto it.
244 */
245 virtual HRESULT prepareAuxIsoImage(bool fOverwrite);
246
247 /**
248 * Opens the installation ISO image.
249 *
250 * @returns COM status code.
251 * @param phVfsIso Where to return the VFS handle for the ISO.
252 * @param fFlags RTFSISO9660_F_XXX flags to pass to the
253 * RTFsIso9660VolOpen API.
254 */
255 virtual HRESULT openInstallIsoImage(PRTVFS phVfsIso, uint32_t fFlags = 0);
256
257 /**
258 * Creates and configures the ISO maker instance.
259 *
260 * This can be overridden to set configure options.
261 *
262 * @returns COM status code.
263 * @param phIsoMaker Where to return the ISO maker.
264 */
265 virtual HRESULT newAuxIsoImageMaker(PRTFSISOMAKER phIsoMaker);
266
267 /**
268 * Adds files to the auxiliary ISO image maker.
269 *
270 * The base class implementation copies just the mMainScript and mPostScript
271 * files to root directory using the default filenames.
272 *
273 * @returns COM status code.
274 * @param hIsoMaker The ISO maker handle.
275 * @param hVfsOrgIso The VFS handle to the original ISO in case files
276 * needs to be added from it.
277 */
278 virtual HRESULT addFilesToAuxIsoImageMaker(RTFSISOMAKER hIsoMaker, RTVFS hVfsOrgIso);
279
280 /**
281 * Adds the given script to the ISO maker.
282 *
283 * @returns COM status code.
284 * @param pEditor The script to add.
285 * @param hIsoMaker The ISO maker to add it to.
286 * @param pszDstFilename The file name (w/ path) to add it under. If NULL,
287 * the default script filename is used to add it to the
288 * root.
289 */
290 HRESULT addScriptToIsoMaker(BaseTextScript *pEditor, RTFSISOMAKER hIsoMaker, const char *pszDstFilename = NULL);
291
292 /**
293 * Writes the ISO image to disk.
294 *
295 * @returns COM status code.
296 * @param hIsoMaker The ISO maker handle.
297 * @param pszFilename The filename.
298 * @param fOverwrite Whether to overwrite the destination file or not.
299 */
300 HRESULT finalizeAuxIsoImage(RTFSISOMAKER hIsoMaker, const char *pszFilename, bool fOverwrite);
301
302 /**
303 * Adds files to the .viso-file vectors.
304 *
305 * The base class implementation adds the script from mAlg, additions ISO
306 * content to '/vboxadditions', and validation kit ISO to '/vboxvalidationkit'.
307 *
308 * @returns COM status code.
309 * @param rVecArgs The ISO maker argument list that will be turned into
310 * a .viso-file.
311 * @param rVecFiles The list of files we've created. This is for
312 * cleaning up at the end.
313 * @param hVfsOrgIso The VFS handle to the original ISO in case files
314 * needs to be added from it.
315 * @param fOverwrite Whether to overwrite files or not.
316 */
317 virtual HRESULT addFilesToAuxVisoVectors(RTCList<RTCString> &rVecArgs, RTCList<RTCString> &rVecFiles,
318 RTVFS hVfsOrgIso, bool fOverwrite);
319
320 /**
321 * Saves the given script to disk and adds it to the .viso-file vectors.
322 *
323 * @returns COM status code.
324 * @param pEditor The script to add.
325 * @param rVecArgs The ISO maker argument list that will be turned into
326 * a .viso-file.
327 * @param rVecFiles The list of files we've created. This is for
328 * cleaning up at the end.
329 * @param fOverwrite Whether to overwrite files or not.
330 */
331 HRESULT addScriptToVisoVectors(BaseTextScript *pEditor, RTCList<RTCString> &rVecArgs,
332 RTCList<RTCString> &rVecFiles, bool fOverwrite);
333
334 /**
335 * Writes out the .viso-file to disk.
336 *
337 * @returns COM status code.
338 * @param rVecArgs The ISO maker argument list to write out.
339 * @param pszFilename The filename.
340 * @param fOverwrite Whether to overwrite the destination file or not.
341 */
342 HRESULT finalizeAuxVisoFile(RTCList<RTCString> const &rVecArgs, const char *pszFilename, bool fOverwrite);
343
344 /**
345 * Loads @a pszFilename from @a hVfsOrgIso into @a pEditor and parses it.
346 *
347 * @returns COM status code.
348 * @param hVfsOrgIso The handle to the original installation ISO.
349 * @param pszFilename The filename to open and load from the ISO.
350 * @param pEditor The editor instance to load the file into and
351 * do the parseing with.
352 */
353 HRESULT loadAndParseFileFromIso(RTVFS hVfsOrgIso, const char *pszFilename, AbstractScript *pEditor);
354};
355
356
357/**
358 * Windows installer, for versions up to xp 64 / w2k3.
359 */
360class UnattendedWindowsSifInstaller : public UnattendedInstaller
361{
362public:
363 UnattendedWindowsSifInstaller(Unattended *pParent)
364 : UnattendedInstaller(pParent,
365 "win_nt5_unattended.sif", "win_postinstall.cmd",
366 "WINNT.SIF", "VBOXPOST.CMD")
367 { Assert(isOriginalIsoNeeded()); Assert(isAuxiliaryFloppyNeeded()); Assert(isAuxiliaryIsoIsVISO()); Assert(!bootFromAuxiliaryIso()); }
368 ~UnattendedWindowsSifInstaller() {}
369
370 bool isAuxiliaryFloppyNeeded() const { return true; }
371 bool bootFromAuxiliaryIso() const { return false; }
372
373};
374
375/**
376 * Windows installer, for versions starting with Vista.
377 */
378class UnattendedWindowsXmlInstaller : public UnattendedInstaller
379{
380public:
381 UnattendedWindowsXmlInstaller(Unattended *pParent)
382 : UnattendedInstaller(pParent,
383 "win_nt6_unattended.xml", "win_postinstall.cmd",
384 "autounattend.xml", "VBOXPOST.CMD")
385 { Assert(isOriginalIsoNeeded()); Assert(isAuxiliaryFloppyNeeded()); Assert(isAuxiliaryIsoIsVISO()); Assert(!bootFromAuxiliaryIso()); }
386 ~UnattendedWindowsXmlInstaller() {}
387
388 bool isAuxiliaryFloppyNeeded() const { return true; }
389 bool bootFromAuxiliaryIso() const { return false; }
390};
391
392
393/**
394 * Base class for the unattended linux installers.
395 */
396class UnattendedLinuxInstaller : public UnattendedInstaller
397{
398protected:
399 /** Array of linux parameter patterns that should be removed by editIsoLinuxCfg.
400 * The patterns are proceed by RTStrSimplePatternNMatch. */
401 RTCList<RTCString, RTCString *> mArrStrRemoveInstallKernelParameters;
402
403public:
404 UnattendedLinuxInstaller(Unattended *pParent,
405 const char *pszMainScriptTemplateName, const char *pszPostScriptTemplateName,
406 const char *pszMainScriptFilename, const char *pszPostScriptFilename = "vboxpostinstall.sh")
407 : UnattendedInstaller(pParent,
408 pszMainScriptTemplateName, pszPostScriptTemplateName,
409 pszMainScriptFilename, pszPostScriptFilename) {}
410 ~UnattendedLinuxInstaller() {}
411
412 bool isAuxiliaryIsoNeeded() const { return true; }
413
414protected:
415 /**
416 * Performs basic edits on a isolinux.cfg file.
417 *
418 * @returns COM status code
419 * @param pEditor Editor with the isolinux.cfg file loaded and parsed.
420 */
421 virtual HRESULT editIsoLinuxCfg(GeneralTextScript *pEditor);
422};
423
424
425/**
426 * Debian installer.
427 *
428 * This will remaster the orignal ISO and therefore be producing a .viso-file.
429 */
430class UnattendedDebianInstaller : public UnattendedLinuxInstaller
431{
432public:
433 UnattendedDebianInstaller(Unattended *pParent,
434 const char *pszMainScriptTemplateName = "debian_preseed.cfg",
435 const char *pszPostScriptTemplateName = "debian_postinstall.sh",
436 const char *pszMainScriptFilename = "preseed.cfg")
437 : UnattendedLinuxInstaller(pParent, pszMainScriptTemplateName, pszPostScriptTemplateName, pszMainScriptFilename)
438 {
439 Assert(!isOriginalIsoNeeded()); Assert(isAuxiliaryIsoNeeded());
440 Assert(!isAuxiliaryFloppyNeeded()); Assert(isAuxiliaryIsoIsVISO());
441 mStrDefaultExtraInstallKernelParameters.setNull();
442 mStrDefaultExtraInstallKernelParameters += " auto=true";
443 mStrDefaultExtraInstallKernelParameters.append(" preseed/file=/cdrom/").append(pszMainScriptFilename);
444 mStrDefaultExtraInstallKernelParameters += " priority=critical";
445 mStrDefaultExtraInstallKernelParameters += " quiet";
446 mStrDefaultExtraInstallKernelParameters += " splash";
447 mStrDefaultExtraInstallKernelParameters += " noprompt"; /* no questions about things like CD/DVD ejections */
448 mStrDefaultExtraInstallKernelParameters += " noshell"; /* No shells on VT1-3 (debian, not ubuntu). */
449 mStrDefaultExtraInstallKernelParameters += " automatic-ubiquity"; // ubiquity
450 // the following can probably go into the preseed.cfg:
451 mStrDefaultExtraInstallKernelParameters.append(" debian-installer/locale=").append(pParent->i_getLocale());
452 mStrDefaultExtraInstallKernelParameters += " keyboard-configuration/layoutcode=us";
453 mStrDefaultExtraInstallKernelParameters += " languagechooser/language-name=English"; /** @todo fixme */
454 mStrDefaultExtraInstallKernelParameters.append(" localechooser/supported-locales=").append(pParent->i_getLocale()).append(".UTF-8");
455 mStrDefaultExtraInstallKernelParameters.append(" countrychooser/shortlist=").append(pParent->i_getCountry()); // ubiquity?
456 mStrDefaultExtraInstallKernelParameters += " --";
457 }
458 ~UnattendedDebianInstaller() {}
459
460 bool isOriginalIsoNeeded() const { return false; }
461
462protected:
463 HRESULT addFilesToAuxVisoVectors(RTCList<RTCString> &rVecArgs, RTCList<RTCString> &rVecFiles,
464 RTVFS hVfsOrgIso, bool fOverwrite);
465 HRESULT editDebianTxtCfg(GeneralTextScript *pEditor);
466
467};
468
469
470/**
471 * Ubuntu installer (same as debian, except for the template).
472 */
473class UnattendedUbuntuInstaller : public UnattendedDebianInstaller
474{
475public:
476 UnattendedUbuntuInstaller(Unattended *pParent)
477 : UnattendedDebianInstaller(pParent, "ubuntu_preseed.cfg")
478 { Assert(!isOriginalIsoNeeded()); Assert(isAuxiliaryIsoNeeded()); Assert(!isAuxiliaryFloppyNeeded()); Assert(isAuxiliaryIsoIsVISO()); }
479 ~UnattendedUbuntuInstaller() {}
480};
481
482
483/**
484 * RedHat 6/7 installer.
485 *
486 * This serves as a base for the kickstart based installers.
487 */
488class UnattendedRedHat67Installer : public UnattendedLinuxInstaller
489{
490public:
491 UnattendedRedHat67Installer(Unattended *pParent,
492 const char *pszMainScriptTemplateName = "redhat67_ks.cfg",
493 const char *pszPostScriptTemplateName = "redhat_postinstall.sh",
494 const char *pszMainScriptFilename = "ks.cfg")
495 : UnattendedLinuxInstaller(pParent, pszMainScriptTemplateName, pszPostScriptTemplateName, pszMainScriptFilename)
496 {
497 Assert(!isOriginalIsoNeeded()); Assert(isAuxiliaryIsoNeeded());
498 Assert(!isAuxiliaryFloppyNeeded()); Assert(isAuxiliaryIsoIsVISO());
499 mStrDefaultExtraInstallKernelParameters.assign(" ks=cdrom:/").append(pszMainScriptFilename).append(' ');
500 mArrStrRemoveInstallKernelParameters.append("rd.live.check"); /* Disables the checkisomd5 step. Required for VISO. */
501 }
502 ~UnattendedRedHat67Installer() {}
503
504 bool isAuxiliaryIsoIsVISO() { return true; }
505 bool isOriginalIsoNeeded() const { return false; }
506
507protected:
508 HRESULT addFilesToAuxVisoVectors(RTCList<RTCString> &rVecArgs, RTCList<RTCString> &rVecFiles,
509 RTVFS hVfsOrgIso, bool fOverwrite);
510};
511
512
513/**
514 * Fedora installer (same as RedHat 6/7, except for the template).
515 */
516class UnattendedFedoraInstaller : public UnattendedRedHat67Installer
517{
518public:
519 UnattendedFedoraInstaller(Unattended *pParent)
520 : UnattendedRedHat67Installer(pParent, "fedora_ks.cfg")
521 { Assert(!isOriginalIsoNeeded()); Assert(isAuxiliaryIsoNeeded()); Assert(!isAuxiliaryFloppyNeeded()); Assert(isAuxiliaryIsoIsVISO()); }
522 ~UnattendedFedoraInstaller() {}
523};
524
525
526/**
527 * Oracle Linux installer (same as RedHat 6/7, except for the template).
528 */
529class UnattendedOracleLinuxInstaller : public UnattendedRedHat67Installer
530{
531public:
532 UnattendedOracleLinuxInstaller(Unattended *pParent)
533 : UnattendedRedHat67Installer(pParent, "ol_ks.cfg")
534 { Assert(!isOriginalIsoNeeded()); Assert(isAuxiliaryIsoNeeded()); Assert(!isAuxiliaryFloppyNeeded()); Assert(isAuxiliaryIsoIsVISO()); }
535 ~UnattendedOracleLinuxInstaller() {}
536};
537
538
539#if 0 /* fixme */
540/**
541 * SUSE linux installer.
542 *
543 * @todo needs fixing.
544 */
545class UnattendedSuseInstaller : public UnattendedLinuxInstaller
546{
547public:
548 UnattendedSuseInstaller(BaseTextScript *pAlg, Unattended *pParent)
549 : UnattendedLinuxInstaller(pAlg, pParent, "suse_autoinstall.xml")
550 { Assert(isOriginalIsoNeeded()); Assert(isAuxiliaryIsoNeeded()); Assert(!isAuxiliaryFloppyNeeded()); Assert(!isAuxiliaryIsoIsVISO()); }
551 ~UnattendedSuseInstaller() {}
552
553 HRESULT setupScriptOnAuxiliaryCD(const Utf8Str &path);
554};
555#endif
556
557#endif // !____H_UNATTENDEDINSTALLER
558
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