1 | /* $Id: VBoxManageUpdateCheck.cpp 85778 2020-08-14 20:54:43Z 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 | /**
|
---|
44 | * updatecheck getsettings
|
---|
45 | */
|
---|
46 | static RTEXITCODE doVBoxUpdateGetSettings(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox)
|
---|
47 | {
|
---|
48 | /*
|
---|
49 | * Parse options.
|
---|
50 | */
|
---|
51 | static const RTGETOPTDEF s_aOptions[] =
|
---|
52 | {
|
---|
53 | { "--verbose", 'v', RTGETOPT_REQ_NOTHING }
|
---|
54 | };
|
---|
55 | RTGETOPTSTATE GetState;
|
---|
56 | int vrc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 0 /* First */, 0);
|
---|
57 | AssertRCReturn(vrc, RTEXITCODE_INIT);
|
---|
58 |
|
---|
59 | int c;
|
---|
60 | RTGETOPTUNION ValueUnion;
|
---|
61 | while ((c = RTGetOpt(&GetState, &ValueUnion)) != 0)
|
---|
62 | {
|
---|
63 | switch (c)
|
---|
64 | {
|
---|
65 | default:
|
---|
66 | return errorGetOpt(c, &ValueUnion);
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | /*
|
---|
71 | * Do the work.
|
---|
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 | /**
|
---|
123 | * updatecheck modifysettings
|
---|
124 | */
|
---|
125 | static RTEXITCODE doVBoxUpdateModifySettings(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox)
|
---|
126 | {
|
---|
127 | /*
|
---|
128 | * Parse options.
|
---|
129 | */
|
---|
130 | static const RTGETOPTDEF s_aOptions[] =
|
---|
131 | {
|
---|
132 | { "--enable", 'e', RTGETOPT_REQ_NOTHING },
|
---|
133 | { "--disable", 'd', RTGETOPT_REQ_NOTHING },
|
---|
134 | { "--target", 't', RTGETOPT_REQ_STRING },
|
---|
135 | { "--frequency", 'f', RTGETOPT_REQ_UINT32 },
|
---|
136 | };
|
---|
137 |
|
---|
138 | RTGETOPTSTATE GetState;
|
---|
139 | int vrc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 0 /* First */, 0);
|
---|
140 | AssertRCReturn(vrc, RTEXITCODE_INIT);
|
---|
141 |
|
---|
142 | int fEnabled = -1; /* tristate: -1 (not modified), false, true */
|
---|
143 | VBoxUpdateTarget_T const enmVBoxUpdateTargetNil = (VBoxUpdateTarget_T)-999;
|
---|
144 | VBoxUpdateTarget_T enmVBoxUpdateTarget = enmVBoxUpdateTargetNil;
|
---|
145 | uint32_t cDaysUpdateFrequency = 0;
|
---|
146 |
|
---|
147 | int c;
|
---|
148 | RTGETOPTUNION ValueUnion;
|
---|
149 | while ((c = RTGetOpt(&GetState, &ValueUnion)) != 0)
|
---|
150 | {
|
---|
151 | switch (c)
|
---|
152 | {
|
---|
153 | case 'e':
|
---|
154 | fEnabled = true;
|
---|
155 | break;
|
---|
156 |
|
---|
157 | case 'd':
|
---|
158 | fEnabled = false;
|
---|
159 | break;
|
---|
160 |
|
---|
161 | case 't':
|
---|
162 | if (!RTStrICmp(ValueUnion.psz, "stable"))
|
---|
163 | enmVBoxUpdateTarget = VBoxUpdateTarget_Stable;
|
---|
164 | else if (!RTStrICmp(ValueUnion.psz, "withbetas"))
|
---|
165 | enmVBoxUpdateTarget = VBoxUpdateTarget_WithBetas;
|
---|
166 | else if (!RTStrICmp(ValueUnion.psz, "allreleases"))
|
---|
167 | enmVBoxUpdateTarget = VBoxUpdateTarget_AllReleases;
|
---|
168 | else
|
---|
169 | return errorArgument("Unknown target specified: '%s'", ValueUnion.psz);
|
---|
170 | break;
|
---|
171 |
|
---|
172 | case 'f':
|
---|
173 | cDaysUpdateFrequency = ValueUnion.u32;
|
---|
174 | if (cDaysUpdateFrequency == 0)
|
---|
175 | return errorArgument("The update frequency cannot be zero");
|
---|
176 | break;
|
---|
177 |
|
---|
178 | default:
|
---|
179 | return errorGetOpt(c, &ValueUnion);
|
---|
180 | }
|
---|
181 | }
|
---|
182 |
|
---|
183 | if ( fEnabled == -1
|
---|
184 | && enmVBoxUpdateTarget != enmVBoxUpdateTargetNil
|
---|
185 | && cDaysUpdateFrequency == 0)
|
---|
186 | return errorSyntax("No change requested");
|
---|
187 |
|
---|
188 | /*
|
---|
189 | * Make the changes.
|
---|
190 | */
|
---|
191 | ComPtr<ISystemProperties> pSystemProperties;
|
---|
192 | CHECK_ERROR2I_RET(aVirtualBox, COMGETTER(SystemProperties)(pSystemProperties.asOutParam()), RTEXITCODE_FAILURE);
|
---|
193 |
|
---|
194 | if (enmVBoxUpdateTarget != enmVBoxUpdateTargetNil)
|
---|
195 | {
|
---|
196 | CHECK_ERROR2I_RET(pSystemProperties, COMSETTER(VBoxUpdateTarget)(enmVBoxUpdateTarget), RTEXITCODE_FAILURE);
|
---|
197 | }
|
---|
198 |
|
---|
199 | if (fEnabled != -1)
|
---|
200 | {
|
---|
201 | CHECK_ERROR2I_RET(pSystemProperties, COMSETTER(VBoxUpdateEnabled)((BOOL)fEnabled), RTEXITCODE_FAILURE);
|
---|
202 | }
|
---|
203 |
|
---|
204 | if (cDaysUpdateFrequency)
|
---|
205 | {
|
---|
206 | CHECK_ERROR2I_RET(pSystemProperties, COMSETTER(VBoxUpdateFrequency)(cDaysUpdateFrequency), RTEXITCODE_FAILURE);
|
---|
207 | }
|
---|
208 |
|
---|
209 | return RTEXITCODE_SUCCESS;
|
---|
210 | }
|
---|
211 |
|
---|
212 | /**
|
---|
213 | * updatecheck perform
|
---|
214 | */
|
---|
215 | static RTEXITCODE doVBoxUpdate(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox)
|
---|
216 | {
|
---|
217 | /*
|
---|
218 | * Parse arguments.
|
---|
219 | */
|
---|
220 | static const RTGETOPTDEF s_aOptions[] =
|
---|
221 | {
|
---|
222 | { "--verbose", 'v', RTGETOPT_REQ_NOTHING }
|
---|
223 | };
|
---|
224 | RTGETOPTSTATE GetState;
|
---|
225 | int vrc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 0 /* First */, 0);
|
---|
226 | AssertRCReturn(vrc, RTEXITCODE_INIT);
|
---|
227 |
|
---|
228 | int c;
|
---|
229 | RTGETOPTUNION ValueUnion;
|
---|
230 | while ((c = RTGetOpt(&GetState, &ValueUnion)) != 0)
|
---|
231 | {
|
---|
232 | switch (c)
|
---|
233 | {
|
---|
234 | default:
|
---|
235 | return errorGetOpt(c, &ValueUnion);
|
---|
236 | }
|
---|
237 | }
|
---|
238 |
|
---|
239 | /*
|
---|
240 | * Do the work.
|
---|
241 | */
|
---|
242 | ComPtr<IHost> pHost;
|
---|
243 | CHECK_ERROR2I_RET(aVirtualBox, COMGETTER(Host)(pHost.asOutParam()), RTEXITCODE_FAILURE);
|
---|
244 |
|
---|
245 | ComPtr<IHostUpdate> pHostUpdate;
|
---|
246 | CHECK_ERROR2I_RET(pHost, COMGETTER(Update)(pHostUpdate.asOutParam()), RTEXITCODE_FAILURE);
|
---|
247 |
|
---|
248 | UpdateCheckType_T updateCheckType = UpdateCheckType_VirtualBox;
|
---|
249 | ComPtr<IProgress> ptrProgress;
|
---|
250 |
|
---|
251 | RTPrintf("Checking for a new VirtualBox version...\n");
|
---|
252 |
|
---|
253 | // we don't call CHECK_ERROR2I_RET(pHostUpdate, VBoxUpdate(updateCheckType, ...); here so we can check for a specific
|
---|
254 | // return value indicating update checks are disabled.
|
---|
255 | HRESULT rc = pHostUpdate->UpdateCheck(updateCheckType, ptrProgress.asOutParam());
|
---|
256 | if (FAILED(rc))
|
---|
257 | {
|
---|
258 | /** @todo r=bird: WTF? This makes no sense. I've commented upon this in the
|
---|
259 | * HostUpdateImpl.cpp code too. */
|
---|
260 | if (rc == E_NOTIMPL)
|
---|
261 | {
|
---|
262 | RTPrintf("VirtualBox update checking has been disabled.\n");
|
---|
263 | return RTEXITCODE_SUCCESS;
|
---|
264 | }
|
---|
265 |
|
---|
266 | if (ptrProgress.isNull())
|
---|
267 | RTStrmPrintf(g_pStdErr, "Failed to create ptrProgress object: %Rhrc\n", rc);
|
---|
268 | else
|
---|
269 | com::GlueHandleComError(pHostUpdate, "VBoxUpdate(updateCheckType, ptrProgress.asOutParam())", rc, __FILE__, __LINE__);
|
---|
270 | return RTEXITCODE_FAILURE;
|
---|
271 | }
|
---|
272 |
|
---|
273 | /* HRESULT hrc = */ showProgress(ptrProgress);
|
---|
274 | CHECK_PROGRESS_ERROR_RET(ptrProgress, ("Check for update failed."), RTEXITCODE_FAILURE);
|
---|
275 |
|
---|
276 | BOOL fUpdateNeeded = FALSE;
|
---|
277 | CHECK_ERROR2I_RET(pHostUpdate, COMGETTER(UpdateResponse)(&fUpdateNeeded), RTEXITCODE_FAILURE);
|
---|
278 |
|
---|
279 | if (!fUpdateNeeded)
|
---|
280 | RTPrintf("You are already running the most recent version of VirtualBox.\n");
|
---|
281 | else
|
---|
282 | {
|
---|
283 | Bstr bstrUpdateVersion;
|
---|
284 | CHECK_ERROR2I_RET(pHostUpdate, COMGETTER(UpdateVersion)(bstrUpdateVersion.asOutParam()), RTEXITCODE_FAILURE);
|
---|
285 | Bstr bstrUpdateURL;
|
---|
286 | CHECK_ERROR2I_RET(pHostUpdate, COMGETTER(UpdateURL)(bstrUpdateURL.asOutParam()), RTEXITCODE_FAILURE);
|
---|
287 |
|
---|
288 | RTPrintf("A new version of VirtualBox has been released! Version %ls is available at virtualbox.org.\n"
|
---|
289 | "You can download this version here: %ls\n", bstrUpdateVersion.raw(), bstrUpdateURL.raw());
|
---|
290 | }
|
---|
291 |
|
---|
292 | return RTEXITCODE_SUCCESS;
|
---|
293 | }
|
---|
294 |
|
---|
295 | /**
|
---|
296 | * Handles the 'updatecheck' command.
|
---|
297 | *
|
---|
298 | * @returns Appropriate exit code.
|
---|
299 | * @param a Handler argument.
|
---|
300 | */
|
---|
301 | RTEXITCODE handleUpdateCheck(HandlerArg *a)
|
---|
302 | {
|
---|
303 | if (a->argc < 1)
|
---|
304 | return errorNoSubcommand();
|
---|
305 | if (!strcmp(a->argv[0], "perform"))
|
---|
306 | {
|
---|
307 | setCurrentSubcommand(HELP_SCOPE_UPDATECHECK_PERFORM);
|
---|
308 | return doVBoxUpdate(a->argc - 1, &a->argv[1], a->virtualBox);
|
---|
309 | }
|
---|
310 | if (!strcmp(a->argv[0], "getsettings"))
|
---|
311 | {
|
---|
312 | setCurrentSubcommand(HELP_SCOPE_UPDATECHECK_GETSETTINGS);
|
---|
313 | return doVBoxUpdateGetSettings(a->argc - 1, &a->argv[1], a->virtualBox);
|
---|
314 | }
|
---|
315 | if (!strcmp(a->argv[0], "modifysettings"))
|
---|
316 | {
|
---|
317 | setCurrentSubcommand(HELP_SCOPE_UPDATECHECK_MODIFYSETTINGS);
|
---|
318 | return doVBoxUpdateModifySettings(a->argc - 1, &a->argv[1], a->virtualBox);
|
---|
319 | }
|
---|
320 | return errorUnknownSubcommand(a->argv[0]);
|
---|
321 | }
|
---|
322 |
|
---|
323 | #endif /* !VBOX_ONLY_DOCS */
|
---|
324 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|