VirtualBox

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

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

Main: export Unattended* source files.

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