1 | /* $Id: VBoxManageUpdateCheck.cpp 85688 2020-08-11 12:37:34Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxManage - The 'updatecheck' command.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2020 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 VBOX_ONLY_DOCS
|
---|
19 |
|
---|
20 |
|
---|
21 | /*********************************************************************************************************************************
|
---|
22 | * Header Files *
|
---|
23 | *********************************************************************************************************************************/
|
---|
24 | #include <VBox/com/com.h>
|
---|
25 | #include <VBox/com/ErrorInfo.h>
|
---|
26 | #include <VBox/com/errorprint.h>
|
---|
27 | #include <VBox/com/VirtualBox.h>
|
---|
28 | #include <VBox/com/array.h>
|
---|
29 |
|
---|
30 | #include <iprt/buildconfig.h>
|
---|
31 | #include <VBox/version.h>
|
---|
32 |
|
---|
33 | #include <VBox/log.h>
|
---|
34 | #include <iprt/getopt.h>
|
---|
35 | #include <iprt/stream.h>
|
---|
36 | #include <iprt/ctype.h>
|
---|
37 | #include <iprt/message.h>
|
---|
38 |
|
---|
39 | #include "VBoxManage.h"
|
---|
40 |
|
---|
41 | using namespace com; // SafeArray
|
---|
42 |
|
---|
43 | // display all of the VBoxUpdate settings
|
---|
44 | static RTEXITCODE doVBoxUpdateGetSettings(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox)
|
---|
45 | {
|
---|
46 | int c;
|
---|
47 | RTGETOPTUNION ValueUnion;
|
---|
48 | RTGETOPTSTATE GetState;
|
---|
49 | /** @todo r=brent decide on the best approach for options to specify here */
|
---|
50 | static const RTGETOPTDEF s_aOptions[] =
|
---|
51 | {
|
---|
52 | { "--verbose", 'v', RTGETOPT_REQ_NOTHING }
|
---|
53 | };
|
---|
54 | int vrc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 0 /* First */, 0);
|
---|
55 | AssertRCReturn(vrc, RTEXITCODE_INIT);
|
---|
56 |
|
---|
57 | while ((c = RTGetOpt(&GetState, &ValueUnion)) != 0)
|
---|
58 | {
|
---|
59 | switch (c)
|
---|
60 | {
|
---|
61 | case 'h':
|
---|
62 | printUsage(USAGE_UPDATECHECK, RTMSGREFENTRYSTR_SCOPE_GLOBAL, g_pStdOut);
|
---|
63 | return RTEXITCODE_SUCCESS;
|
---|
64 |
|
---|
65 | default:
|
---|
66 | return errorGetOpt(USAGE_UPDATECHECK, c, &ValueUnion);
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | if (argc != 0)
|
---|
71 | return errorSyntax(USAGE_UPDATECHECK, "Incorrect number of parameters");
|
---|
72 |
|
---|
73 | ComPtr<ISystemProperties> pSystemProperties;
|
---|
74 | CHECK_ERROR2I_RET(aVirtualBox, COMGETTER(SystemProperties)(pSystemProperties.asOutParam()), RTEXITCODE_FAILURE);
|
---|
75 |
|
---|
76 | BOOL fVBoxUpdateEnabled;
|
---|
77 | CHECK_ERROR2I_RET(pSystemProperties, COMGETTER(VBoxUpdateEnabled)(&fVBoxUpdateEnabled), RTEXITCODE_FAILURE);
|
---|
78 | RTPrintf("Enabled: %s\n", fVBoxUpdateEnabled ? "yes" : "no");
|
---|
79 |
|
---|
80 | ULONG cVBoxUpdateCount;
|
---|
81 | CHECK_ERROR2I_RET(pSystemProperties, COMGETTER(VBoxUpdateCount)(&cVBoxUpdateCount), RTEXITCODE_FAILURE);
|
---|
82 | RTPrintf("Count: %u\n", cVBoxUpdateCount);
|
---|
83 |
|
---|
84 | ULONG uVBoxUpdateFrequency;
|
---|
85 | CHECK_ERROR2I_RET(pSystemProperties, COMGETTER(VBoxUpdateFrequency)(&uVBoxUpdateFrequency), RTEXITCODE_FAILURE);
|
---|
86 | if (uVBoxUpdateFrequency == 0)
|
---|
87 | RTPrintf("Frequency: never\n");
|
---|
88 | else if (uVBoxUpdateFrequency == 1)
|
---|
89 | RTPrintf("Frequency: every day\n");
|
---|
90 | else
|
---|
91 | RTPrintf("Frequency: every %u days\n", uVBoxUpdateFrequency);
|
---|
92 |
|
---|
93 | VBoxUpdateTarget_T enmVBoxUpdateTarget;
|
---|
94 | CHECK_ERROR2I_RET(pSystemProperties, COMGETTER(VBoxUpdateTarget)(&enmVBoxUpdateTarget), RTEXITCODE_FAILURE);
|
---|
95 | const char *psz;
|
---|
96 | switch (enmVBoxUpdateTarget)
|
---|
97 | {
|
---|
98 | case VBoxUpdateTarget_Stable:
|
---|
99 | psz = "Stable: new minor and maintenance releases";
|
---|
100 | break;
|
---|
101 | case VBoxUpdateTarget_AllReleases:
|
---|
102 | psz = "All releases: new minor, maintenance, and major releases";
|
---|
103 | break;
|
---|
104 | case VBoxUpdateTarget_WithBetas:
|
---|
105 | psz = "With Betas: new minor, maintenance, major, and beta releases";
|
---|
106 | break;
|
---|
107 | default:
|
---|
108 | psz = "Unset";
|
---|
109 | break;
|
---|
110 | }
|
---|
111 | RTPrintf("Target: %s\n", psz);
|
---|
112 |
|
---|
113 | Bstr strVBoxUpdateLastCheckDate;
|
---|
114 | CHECK_ERROR2I_RET(pSystemProperties, COMGETTER(VBoxUpdateLastCheckDate)(strVBoxUpdateLastCheckDate.asOutParam()),
|
---|
115 | RTEXITCODE_FAILURE);
|
---|
116 | if (!strVBoxUpdateLastCheckDate.isEmpty())
|
---|
117 | RTPrintf("Last Check Date: %ls\n", strVBoxUpdateLastCheckDate.raw());
|
---|
118 |
|
---|
119 | return RTEXITCODE_SUCCESS;
|
---|
120 | }
|
---|
121 |
|
---|
122 | static RTEXITCODE doVBoxUpdateModifySettings(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox)
|
---|
123 | {
|
---|
124 | BOOL fEnableVBoxUpdate = false;
|
---|
125 | BOOL fDisableVBoxUpdate = false;
|
---|
126 | const char *pszVBoxUpdateTarget = NULL;
|
---|
127 | uint32_t uVBoxUpdateFrequency = 0;
|
---|
128 |
|
---|
129 | int c;
|
---|
130 | RTGETOPTUNION ValueUnion;
|
---|
131 | RTGETOPTSTATE GetState;
|
---|
132 |
|
---|
133 | # define UPDATECHECK_MODSETTING_ENABLE (VINF_GETOPT_NOT_OPTION + 'e')
|
---|
134 | # define UPDATECHECK_MODSETTING_DISABLE (VINF_GETOPT_NOT_OPTION + 'd')
|
---|
135 | # define UPDATECHECK_MODSETTING_TARGET (VINF_GETOPT_NOT_OPTION + 't')
|
---|
136 | # define UPDATECHECK_MODSETTING_FREQUENCY (VINF_GETOPT_NOT_OPTION + 'f')
|
---|
137 |
|
---|
138 | static const RTGETOPTDEF s_aOptions[] =
|
---|
139 | {
|
---|
140 | { "--enable", UPDATECHECK_MODSETTING_ENABLE, RTGETOPT_REQ_NOTHING },
|
---|
141 | { "--disable", UPDATECHECK_MODSETTING_DISABLE, RTGETOPT_REQ_NOTHING },
|
---|
142 | { "--target", UPDATECHECK_MODSETTING_TARGET, RTGETOPT_REQ_STRING },
|
---|
143 | { "--frequency", UPDATECHECK_MODSETTING_FREQUENCY, RTGETOPT_REQ_UINT32 },
|
---|
144 | };
|
---|
145 | int vrc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 0 /* First */, 0);
|
---|
146 | AssertRCReturn(vrc, RTEXITCODE_INIT);
|
---|
147 |
|
---|
148 | while ((c = RTGetOpt(&GetState, &ValueUnion)) != 0)
|
---|
149 | {
|
---|
150 | switch (c)
|
---|
151 | {
|
---|
152 | case UPDATECHECK_MODSETTING_ENABLE:
|
---|
153 | fEnableVBoxUpdate = true;
|
---|
154 | break;
|
---|
155 |
|
---|
156 | case UPDATECHECK_MODSETTING_DISABLE:
|
---|
157 | fDisableVBoxUpdate = true;
|
---|
158 | break;
|
---|
159 |
|
---|
160 | case UPDATECHECK_MODSETTING_TARGET:
|
---|
161 | pszVBoxUpdateTarget = ValueUnion.psz;
|
---|
162 | break;
|
---|
163 |
|
---|
164 | case UPDATECHECK_MODSETTING_FREQUENCY:
|
---|
165 | uVBoxUpdateFrequency = ValueUnion.u32;
|
---|
166 | break;
|
---|
167 |
|
---|
168 | case 'h':
|
---|
169 | printUsage(USAGE_UPDATECHECK, RTMSGREFENTRYSTR_SCOPE_GLOBAL, g_pStdOut);
|
---|
170 | return RTEXITCODE_SUCCESS;
|
---|
171 |
|
---|
172 | default:
|
---|
173 | return errorGetOpt(USAGE_UPDATECHECK, c, &ValueUnion);
|
---|
174 | }
|
---|
175 | }
|
---|
176 |
|
---|
177 | if (argc == 0)
|
---|
178 | return errorSyntax(USAGE_UPDATECHECK, "Incorrect number of parameters");
|
---|
179 |
|
---|
180 | if (fEnableVBoxUpdate && fDisableVBoxUpdate)
|
---|
181 | return errorSyntax(USAGE_UPDATECHECK, "Invalid combination of options: --enable and --disable");
|
---|
182 |
|
---|
183 | ComPtr<ISystemProperties> pSystemProperties;
|
---|
184 | CHECK_ERROR2I_RET(aVirtualBox, COMGETTER(SystemProperties)(pSystemProperties.asOutParam()), RTEXITCODE_FAILURE);
|
---|
185 |
|
---|
186 | if (pszVBoxUpdateTarget)
|
---|
187 | {
|
---|
188 | VBoxUpdateTarget_T enmVBoxUpdateTarget;
|
---|
189 | if (!RTStrICmp(pszVBoxUpdateTarget, "stable"))
|
---|
190 | enmVBoxUpdateTarget = VBoxUpdateTarget_Stable;
|
---|
191 | else if (!RTStrICmp(pszVBoxUpdateTarget, "withbetas"))
|
---|
192 | enmVBoxUpdateTarget = VBoxUpdateTarget_WithBetas;
|
---|
193 | else if (!RTStrICmp(pszVBoxUpdateTarget, "allreleases"))
|
---|
194 | enmVBoxUpdateTarget = VBoxUpdateTarget_AllReleases;
|
---|
195 | else
|
---|
196 | return errorArgument("Unknown target specified: '%s'", pszVBoxUpdateTarget);
|
---|
197 |
|
---|
198 | CHECK_ERROR2I_RET(pSystemProperties, COMSETTER(VBoxUpdateTarget)(enmVBoxUpdateTarget), RTEXITCODE_FAILURE);
|
---|
199 | }
|
---|
200 |
|
---|
201 | if (fEnableVBoxUpdate)
|
---|
202 | {
|
---|
203 | CHECK_ERROR2I_RET(pSystemProperties, COMSETTER(VBoxUpdateEnabled)(true), RTEXITCODE_FAILURE);
|
---|
204 | }
|
---|
205 | else if (fDisableVBoxUpdate)
|
---|
206 | {
|
---|
207 | CHECK_ERROR2I_RET(pSystemProperties, COMSETTER(VBoxUpdateEnabled)(false), RTEXITCODE_FAILURE);
|
---|
208 | }
|
---|
209 |
|
---|
210 | if (uVBoxUpdateFrequency)
|
---|
211 | {
|
---|
212 | CHECK_ERROR2I_RET(pSystemProperties, COMSETTER(VBoxUpdateFrequency)(uVBoxUpdateFrequency), RTEXITCODE_FAILURE);
|
---|
213 | }
|
---|
214 |
|
---|
215 | return RTEXITCODE_SUCCESS;
|
---|
216 | }
|
---|
217 |
|
---|
218 | static RTEXITCODE doVBoxUpdate(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox)
|
---|
219 | {
|
---|
220 | int c;
|
---|
221 | RTGETOPTUNION ValueUnion;
|
---|
222 | RTGETOPTSTATE GetState;
|
---|
223 | /** @todo r=brent decide on the best approach for options to specify here */
|
---|
224 | static const RTGETOPTDEF s_aOptions[] =
|
---|
225 | {
|
---|
226 | { "--verbose", 'v', RTGETOPT_REQ_NOTHING }
|
---|
227 | };
|
---|
228 | int vrc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 0 /* First */, 0);
|
---|
229 | AssertRCReturn(vrc, RTEXITCODE_INIT);
|
---|
230 |
|
---|
231 | while ((c = RTGetOpt(&GetState, &ValueUnion)) != 0)
|
---|
232 | {
|
---|
233 | switch (c)
|
---|
234 | {
|
---|
235 | case 'h':
|
---|
236 | printUsage(USAGE_UPDATECHECK, RTMSGREFENTRYSTR_SCOPE_GLOBAL, g_pStdOut);
|
---|
237 | return RTEXITCODE_SUCCESS;
|
---|
238 |
|
---|
239 | default:
|
---|
240 | return errorGetOpt(USAGE_UPDATECHECK, c, &ValueUnion);
|
---|
241 | }
|
---|
242 | }
|
---|
243 |
|
---|
244 | ComPtr<IHost> pHost;
|
---|
245 | CHECK_ERROR2I_RET(aVirtualBox, COMGETTER(Host)(pHost.asOutParam()), RTEXITCODE_FAILURE);
|
---|
246 |
|
---|
247 | ComPtr<IHostUpdate> pHostUpdate;
|
---|
248 | CHECK_ERROR2I_RET(pHost, COMGETTER(Update)(pHostUpdate.asOutParam()), RTEXITCODE_FAILURE);
|
---|
249 |
|
---|
250 | UpdateCheckType_T updateCheckType = UpdateCheckType_VirtualBox;
|
---|
251 | BOOL updateNeeded;
|
---|
252 | ComPtr<IProgress> progress;
|
---|
253 |
|
---|
254 | RTPrintf("Checking for a new VirtualBox version...\n");
|
---|
255 |
|
---|
256 | // we don't call CHECK_ERROR2I_RET(pHostUpdate, VBoxUpdate(updateCheckType, ...); here so we can check for a specific
|
---|
257 | // return value indicating update checks are disabled.
|
---|
258 | HRESULT rc = pHostUpdate->UpdateCheck(updateCheckType, progress.asOutParam());
|
---|
259 | if (FAILED(rc))
|
---|
260 | {
|
---|
261 | if (rc == E_NOTIMPL)
|
---|
262 | {
|
---|
263 | RTPrintf("VirtualBox update checking has been disabled.\n");
|
---|
264 | return RTEXITCODE_SUCCESS;
|
---|
265 | }
|
---|
266 |
|
---|
267 | if (progress.isNull())
|
---|
268 | RTStrmPrintf(g_pStdErr, "Failed to create progress object: %Rhrc\n", rc);
|
---|
269 | else
|
---|
270 | com::GlueHandleComError(pHostUpdate, "VBoxUpdate(updateCheckType, progress.asOutParam())", rc,
|
---|
271 | __FILE__, __LINE__);
|
---|
272 | return RTEXITCODE_FAILURE;
|
---|
273 | }
|
---|
274 |
|
---|
275 | /* HRESULT hrc = */ showProgress(progress);
|
---|
276 | CHECK_PROGRESS_ERROR_RET(progress, ("Check for update failed."), RTEXITCODE_FAILURE);
|
---|
277 |
|
---|
278 | CHECK_ERROR2I_RET(pHostUpdate, COMGETTER(UpdateResponse)(&updateNeeded), RTEXITCODE_FAILURE);
|
---|
279 |
|
---|
280 | if (!updateNeeded)
|
---|
281 | {
|
---|
282 | RTPrintf("You are already running the most recent version of VirtualBox.\n");
|
---|
283 | }
|
---|
284 | else
|
---|
285 | {
|
---|
286 | Bstr updateVersion;
|
---|
287 | Bstr updateURL;
|
---|
288 |
|
---|
289 | CHECK_ERROR2I_RET(pHostUpdate, COMGETTER(UpdateVersion)(updateVersion.asOutParam()), RTEXITCODE_FAILURE);
|
---|
290 | CHECK_ERROR2I_RET(pHostUpdate, COMGETTER(UpdateURL)(updateURL.asOutParam()), RTEXITCODE_FAILURE);
|
---|
291 |
|
---|
292 | RTPrintf("A new version of VirtualBox has been released! Version %ls is available "
|
---|
293 | "at virtualbox.org.\nYou can download this version here: %ls\n", updateVersion.raw(), updateURL.raw());
|
---|
294 | }
|
---|
295 |
|
---|
296 | return RTEXITCODE_SUCCESS;
|
---|
297 | }
|
---|
298 |
|
---|
299 | /**
|
---|
300 | * Handles the 'updatecheck' command.
|
---|
301 | *
|
---|
302 | * @returns Appropriate exit code.
|
---|
303 | * @param a Handler argument.
|
---|
304 | */
|
---|
305 | RTEXITCODE handleUpdateCheck(HandlerArg *a)
|
---|
306 | {
|
---|
307 | if (!strcmp(a->argv[0], "perform"))
|
---|
308 | {
|
---|
309 | // VBoxManage updatecheck
|
---|
310 | return doVBoxUpdate(a->argc - 1, &a->argv[1], a->virtualBox);
|
---|
311 | }
|
---|
312 | else if (!strcmp(a->argv[0], "getsettings"))
|
---|
313 | {
|
---|
314 | // VBoxManage updatecheck getsettings
|
---|
315 | return doVBoxUpdateGetSettings(a->argc - 1, &a->argv[1], a->virtualBox);
|
---|
316 | }
|
---|
317 | else if (!strcmp(a->argv[0], "modifysettings"))
|
---|
318 | {
|
---|
319 | // VBoxManage updatecheck modifysettings key=value
|
---|
320 | return doVBoxUpdateModifySettings(a->argc - 1, &a->argv[1], a->virtualBox);
|
---|
321 | }
|
---|
322 | else
|
---|
323 | {
|
---|
324 | printUsage(USAGE_UPDATECHECK, RTMSGREFENTRYSTR_SCOPE_GLOBAL, g_pStdOut);
|
---|
325 | return RTEXITCODE_FAILURE;
|
---|
326 | }
|
---|
327 | }
|
---|
328 |
|
---|
329 | #endif /* !VBOX_ONLY_DOCS */
|
---|
330 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|