blob: d904d71302e48db961220f6a5e154bbed540e820 [file] [log] [blame]
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -07001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Darin Petkov5a7f5652010-07-22 21:40:09 -07005#include <string>
6
Ben Chan46bf5c82013-06-24 11:17:41 -07007#include <dbus/dbus.h>
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -07008#include <gflags/gflags.h>
9#include <glib.h>
10
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070011#include "update_engine/marshal.glibmarshal.h"
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070012#include "update_engine/dbus_constants.h"
13#include "update_engine/subprocess.h"
14#include "update_engine/utils.h"
15
16extern "C" {
17#include "update_engine/update_engine.dbusclient.h"
18}
19
20using chromeos_update_engine::kUpdateEngineServiceName;
21using chromeos_update_engine::kUpdateEngineServicePath;
22using chromeos_update_engine::kUpdateEngineServiceInterface;
Darin Petkova0b9e772011-10-06 05:05:56 -070023using chromeos_update_engine::utils::GetAndFreeGError;
Darin Petkov5a7f5652010-07-22 21:40:09 -070024using std::string;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070025
Darin Petkov296889c2010-07-23 16:20:54 -070026DEFINE_string(app_version, "", "Force the current app version.");
Jay Srinivasanae4697c2013-03-18 17:08:08 -070027DEFINE_string(channel, "",
28 "Set the target channel. The device will be powerwashed if the target "
29 "channel is more stable than the current channel.");
Chris Sosad317e402013-06-12 13:47:09 -070030DEFINE_bool(check_for_update, false, "Initiate check for updates.");
31DEFINE_string(omaha_url, "", "The URL of the Omaha update server.");
32DEFINE_bool(reboot, false, "Initiate a reboot if needed.");
33DEFINE_bool(reset_status, false, "Sets the status in update_engine to idle.");
34DEFINE_bool(rollback, false, "Perform a rollback to the previous partition.");
35DEFINE_bool(show_channel, false, "Show the current and target channels.");
Chris Sosacb7fa882013-07-25 17:02:59 -070036DEFINE_bool(powerwash, true, "When performing rollback or channel change, "
37 "do a powerwash or allow it respectively.");
Chris Sosad317e402013-06-12 13:47:09 -070038DEFINE_bool(status, false, "Print the status to stdout.");
Darin Petkov58529db2010-08-13 09:19:47 -070039DEFINE_bool(update, false, "Forces an update and waits for its completion. "
40 "Exit status is 0 if the update succeeded, and 1 otherwise.");
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070041DEFINE_bool(watch_for_updates, false,
42 "Listen for status updates and print them to the screen.");
Alex Deymof4867c42013-06-28 14:41:39 -070043DEFINE_bool(show_update_over_cellular, false,
44 "Show the current setting for updates over cellular networks.");
45DEFINE_string(update_over_cellular, "",
46 "Enables (\"yes\") or disables (\"no\") the updates over "
47 "cellular networks.");
Alex Deymo5fdf7762013-07-17 20:01:40 -070048DEFINE_bool(show_p2p_update, false,
49 "Show the current setting for peer-to-peer update sharing.");
50DEFINE_string(p2p_update, "",
51 "Enables (\"yes\") or disables (\"no\") the peer-to-peer update "
52 "sharing.");
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070053
54namespace {
55
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070056bool GetProxy(DBusGProxy** out_proxy) {
57 DBusGConnection* bus;
Andrew de los Reyes68ab6ed2011-08-09 14:46:39 -070058 DBusGProxy* proxy = NULL;
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070059 GError* error = NULL;
Andrew de los Reyes68ab6ed2011-08-09 14:46:39 -070060 const int kTries = 4;
Darin Petkova0b9e772011-10-06 05:05:56 -070061 const int kRetrySeconds = 10;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070062
63 bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
Richard Barnetted7936062013-01-18 13:38:51 -080064 if (bus == NULL) {
65 LOG(ERROR) << "Failed to get bus: " << GetAndFreeGError(&error);
66 exit(1);
67 }
Andrew de los Reyes68ab6ed2011-08-09 14:46:39 -070068 for (int i = 0; !proxy && i < kTries; ++i) {
Darin Petkova0b9e772011-10-06 05:05:56 -070069 if (i > 0) {
70 LOG(INFO) << "Retrying to get dbus proxy. Try "
71 << (i + 1) << "/" << kTries;
Gilad Arnold8e3f1262013-01-08 14:59:54 -080072 g_usleep(kRetrySeconds * G_USEC_PER_SEC);
Darin Petkova0b9e772011-10-06 05:05:56 -070073 }
Andrew de los Reyes68ab6ed2011-08-09 14:46:39 -070074 proxy = dbus_g_proxy_new_for_name_owner(bus,
75 kUpdateEngineServiceName,
76 kUpdateEngineServicePath,
77 kUpdateEngineServiceInterface,
78 &error);
Darin Petkova0b9e772011-10-06 05:05:56 -070079 LOG_IF(WARNING, !proxy) << "Error getting dbus proxy for "
80 << kUpdateEngineServiceName << ": "
81 << GetAndFreeGError(&error);
Andrew de los Reyes68ab6ed2011-08-09 14:46:39 -070082 }
Richard Barnetted7936062013-01-18 13:38:51 -080083 if (proxy == NULL) {
84 LOG(ERROR) << "Giving up -- unable to get dbus proxy for "
85 << kUpdateEngineServiceName;
86 exit(1);
87 }
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070088 *out_proxy = proxy;
89 return true;
90}
91
92static void StatusUpdateSignalHandler(DBusGProxy* proxy,
93 int64_t last_checked_time,
94 double progress,
95 gchar* current_operation,
96 gchar* new_version,
97 int64_t new_size,
98 void* user_data) {
99 LOG(INFO) << "Got status update:";
100 LOG(INFO) << " last_checked_time: " << last_checked_time;
101 LOG(INFO) << " progress: " << progress;
102 LOG(INFO) << " current_operation: " << current_operation;
103 LOG(INFO) << " new_version: " << new_version;
104 LOG(INFO) << " new_size: " << new_size;
105}
106
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -0700107bool ResetStatus() {
108 DBusGProxy* proxy;
109 GError* error = NULL;
110
111 CHECK(GetProxy(&proxy));
112
113 gboolean rc =
114 org_chromium_UpdateEngineInterface_reset_status(proxy, &error);
115 return rc;
116}
117
118
Darin Petkov58529db2010-08-13 09:19:47 -0700119// If |op| is non-NULL, sets it to the current operation string or an
120// empty string if unable to obtain the current status.
121bool GetStatus(string* op) {
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700122 DBusGProxy* proxy;
123 GError* error = NULL;
Andrew de los Reyesada42202010-07-15 22:23:20 -0700124
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700125 CHECK(GetProxy(&proxy));
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700126
127 gint64 last_checked_time = 0;
128 gdouble progress = 0.0;
129 char* current_op = NULL;
130 char* new_version = NULL;
131 gint64 new_size = 0;
132
133 gboolean rc = org_chromium_UpdateEngineInterface_get_status(
134 proxy,
135 &last_checked_time,
136 &progress,
137 &current_op,
138 &new_version,
139 &new_size,
140 &error);
141 if (rc == FALSE) {
Darin Petkova0b9e772011-10-06 05:05:56 -0700142 LOG(INFO) << "Error getting status: " << GetAndFreeGError(&error);
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700143 }
144 printf("LAST_CHECKED_TIME=%" PRIi64 "\nPROGRESS=%f\nCURRENT_OP=%s\n"
145 "NEW_VERSION=%s\nNEW_SIZE=%" PRIi64 "\n",
146 last_checked_time,
147 progress,
148 current_op,
149 new_version,
150 new_size);
Darin Petkov58529db2010-08-13 09:19:47 -0700151 if (op) {
152 *op = current_op ? current_op : "";
153 }
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700154 return true;
155}
156
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700157// Should never return.
158void WatchForUpdates() {
159 DBusGProxy* proxy;
Andrew de los Reyesada42202010-07-15 22:23:20 -0700160
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700161 CHECK(GetProxy(&proxy));
Andrew de los Reyesada42202010-07-15 22:23:20 -0700162
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700163 // Register marshaller
164 dbus_g_object_register_marshaller(
165 update_engine_VOID__INT64_DOUBLE_STRING_STRING_INT64,
166 G_TYPE_NONE,
167 G_TYPE_INT64,
168 G_TYPE_DOUBLE,
169 G_TYPE_STRING,
170 G_TYPE_STRING,
171 G_TYPE_INT64,
172 G_TYPE_INVALID);
Andrew de los Reyesada42202010-07-15 22:23:20 -0700173
174 static const char kStatusUpdate[] = "StatusUpdate";
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700175 dbus_g_proxy_add_signal(proxy,
Andrew de los Reyesada42202010-07-15 22:23:20 -0700176 kStatusUpdate,
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700177 G_TYPE_INT64,
178 G_TYPE_DOUBLE,
179 G_TYPE_STRING,
180 G_TYPE_STRING,
181 G_TYPE_INT64,
182 G_TYPE_INVALID);
183 GMainLoop* loop = g_main_loop_new (NULL, TRUE);
184 dbus_g_proxy_connect_signal(proxy,
Andrew de los Reyesada42202010-07-15 22:23:20 -0700185 kStatusUpdate,
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700186 G_CALLBACK(StatusUpdateSignalHandler),
187 NULL,
188 NULL);
189 g_main_loop_run(loop);
190 g_main_loop_unref(loop);
191}
192
Chris Sosad317e402013-06-12 13:47:09 -0700193bool Rollback(bool rollback) {
194 DBusGProxy* proxy;
195 GError* error = NULL;
196
197 CHECK(GetProxy(&proxy));
198
199 gboolean rc =
200 org_chromium_UpdateEngineInterface_attempt_rollback(proxy,
201 rollback,
202 &error);
203 CHECK_EQ(rc, TRUE) << "Error with rollback request: "
204 << GetAndFreeGError(&error);
205 return true;
206}
207
Darin Petkov58529db2010-08-13 09:19:47 -0700208bool CheckForUpdates(const string& app_version, const string& omaha_url) {
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700209 DBusGProxy* proxy;
210 GError* error = NULL;
Andrew de los Reyesada42202010-07-15 22:23:20 -0700211
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700212 CHECK(GetProxy(&proxy));
213
214 gboolean rc =
Darin Petkov5a7f5652010-07-22 21:40:09 -0700215 org_chromium_UpdateEngineInterface_attempt_update(proxy,
216 app_version.c_str(),
217 omaha_url.c_str(),
218 &error);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700219 CHECK_EQ(rc, TRUE) << "Error checking for update: "
Darin Petkova0b9e772011-10-06 05:05:56 -0700220 << GetAndFreeGError(&error);
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700221 return true;
222}
223
Darin Petkov296889c2010-07-23 16:20:54 -0700224bool RebootIfNeeded() {
225 DBusGProxy* proxy;
226 GError* error = NULL;
227
228 CHECK(GetProxy(&proxy));
229
230 gboolean rc =
231 org_chromium_UpdateEngineInterface_reboot_if_needed(proxy, &error);
232 // Reboot error code doesn't necessarily mean that a reboot
233 // failed. For example, D-Bus may be shutdown before we receive the
234 // result.
Darin Petkova0b9e772011-10-06 05:05:56 -0700235 LOG_IF(INFO, !rc) << "Reboot error message: " << GetAndFreeGError(&error);
Darin Petkov296889c2010-07-23 16:20:54 -0700236 return true;
237}
238
Chris Sosacb7fa882013-07-25 17:02:59 -0700239void SetTargetChannel(const string& target_channel, bool allow_powerwash) {
Darin Petkov8daa3242010-10-25 13:28:47 -0700240 DBusGProxy* proxy;
241 GError* error = NULL;
242
243 CHECK(GetProxy(&proxy));
244
245 gboolean rc =
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700246 org_chromium_UpdateEngineInterface_set_channel(proxy,
247 target_channel.c_str(),
Chris Sosacb7fa882013-07-25 17:02:59 -0700248 allow_powerwash,
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700249 &error);
250 CHECK_EQ(rc, true) << "Error setting the channel: "
Darin Petkova0b9e772011-10-06 05:05:56 -0700251 << GetAndFreeGError(&error);
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700252 LOG(INFO) << "Channel permanently set to: " << target_channel;
Darin Petkov8daa3242010-10-25 13:28:47 -0700253}
254
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700255string GetChannel(bool get_current_channel) {
Satoru Takabayashi583667b2010-10-27 13:09:57 +0900256 DBusGProxy* proxy;
257 GError* error = NULL;
258
259 CHECK(GetProxy(&proxy));
260
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700261 char* channel = NULL;
Satoru Takabayashi583667b2010-10-27 13:09:57 +0900262 gboolean rc =
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700263 org_chromium_UpdateEngineInterface_get_channel(proxy,
264 get_current_channel,
265 &channel,
266 &error);
267 CHECK_EQ(rc, true) << "Error getting the channel: "
268 << GetAndFreeGError(&error);
269 string output = channel;
270 g_free(channel);
Satoru Takabayashi583667b2010-10-27 13:09:57 +0900271 return output;
272}
273
Alex Deymo5fdf7762013-07-17 20:01:40 -0700274void SetUpdateOverCellularPermission(gboolean allowed) {
Alex Deymof4867c42013-06-28 14:41:39 -0700275 DBusGProxy* proxy;
276 GError* error = NULL;
277
278 CHECK(GetProxy(&proxy));
279
280 gboolean rc =
281 org_chromium_UpdateEngineInterface_set_update_over_cellular_permission(
282 proxy,
283 allowed,
284 &error);
285 CHECK_EQ(rc, true) << "Error setting the update over cellular setting: "
286 << GetAndFreeGError(&error);
Alex Deymof4867c42013-06-28 14:41:39 -0700287}
288
289bool GetUpdateOverCellularPermission() {
290 DBusGProxy* proxy;
291 GError* error = NULL;
292
293 CHECK(GetProxy(&proxy));
294
295 gboolean allowed;
296 gboolean rc =
297 org_chromium_UpdateEngineInterface_get_update_over_cellular_permission(
298 proxy,
299 &allowed,
300 &error);
301 CHECK_EQ(rc, true) << "Error getting the update over cellular setting: "
302 << GetAndFreeGError(&error);
303 return allowed;
304}
305
Alex Deymo5fdf7762013-07-17 20:01:40 -0700306void SetP2PUpdatePermission(gboolean enabled) {
307 DBusGProxy* proxy;
308 GError* error = NULL;
309
310 CHECK(GetProxy(&proxy));
311
312 gboolean rc =
313 org_chromium_UpdateEngineInterface_set_p2_pupdate_permission(
314 proxy,
315 enabled,
316 &error);
317 CHECK_EQ(rc, true) << "Error setting the peer-to-peer update setting: "
318 << GetAndFreeGError(&error);
319}
320
321bool GetP2PUpdatePermission() {
322 DBusGProxy* proxy;
323 GError* error = NULL;
324
325 CHECK(GetProxy(&proxy));
326
327 gboolean enabled;
328 gboolean rc =
329 org_chromium_UpdateEngineInterface_get_p2_pupdate_permission(
330 proxy,
331 &enabled,
332 &error);
333 CHECK_EQ(rc, true) << "Error getting the peer-to-peer update setting: "
334 << GetAndFreeGError(&error);
335 return enabled;
336}
337
Darin Petkov58529db2010-08-13 09:19:47 -0700338static gboolean CompleteUpdateSource(gpointer data) {
339 string current_op;
340 if (!GetStatus(&current_op) || current_op == "UPDATE_STATUS_IDLE") {
341 LOG(ERROR) << "Update failed.";
342 exit(1);
343 }
344 if (current_op == "UPDATE_STATUS_UPDATED_NEED_REBOOT") {
345 LOG(INFO) << "Update succeeded -- reboot needed.";
346 exit(0);
347 }
348 return TRUE;
349}
350
351// This is similar to watching for updates but rather than registering
352// a signal watch, activelly poll the daemon just in case it stops
353// sending notifications.
354void CompleteUpdate() {
355 GMainLoop* loop = g_main_loop_new (NULL, TRUE);
356 g_timeout_add_seconds(5, CompleteUpdateSource, NULL);
357 g_main_loop_run(loop);
358 g_main_loop_unref(loop);
359}
360
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700361} // namespace {}
362
363int main(int argc, char** argv) {
364 // Boilerplate init commands.
365 g_type_init();
Ben Chan46bf5c82013-06-24 11:17:41 -0700366 dbus_threads_init_default();
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700367 chromeos_update_engine::Subprocess::Init();
368 google::ParseCommandLineFlags(&argc, &argv, true);
Andrew de los Reyesada42202010-07-15 22:23:20 -0700369
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -0700370 // Update the status if requested.
371 if (FLAGS_reset_status) {
372 LOG(INFO) << "Setting Update Engine status to idle ...";
373 if (!ResetStatus()) {
374 LOG(ERROR) << "ResetStatus failed.";
375 return 1;
376 }
377
Gilad Arnold50c60632013-01-25 10:27:19 -0800378 LOG(INFO) << "ResetStatus succeeded; to undo partition table changes run:\n"
379 "(D=$(rootdev -d) P=$(rootdev -s); cgpt p -i$(($(echo ${P#$D} "
380 "| sed 's/^[^0-9]*//')-1)) $D;)";
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -0700381 return 0;
382 }
383
384
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700385 if (FLAGS_status) {
386 LOG(INFO) << "Querying Update Engine status...";
Darin Petkov58529db2010-08-13 09:19:47 -0700387 if (!GetStatus(NULL)) {
388 LOG(FATAL) << "GetStatus failed.";
389 return 1;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700390 }
391 return 0;
392 }
Darin Petkov58529db2010-08-13 09:19:47 -0700393
Alex Deymof4867c42013-06-28 14:41:39 -0700394 // Changes the current update over cellular network setting.
395 if (!FLAGS_update_over_cellular.empty()) {
396 gboolean allowed = FLAGS_update_over_cellular == "yes";
397 if (!allowed && FLAGS_update_over_cellular != "no") {
398 LOG(ERROR) << "Unknown option: \"" << FLAGS_update_over_cellular
399 << "\". Please specify \"yes\" or \"no\".";
400 } else {
401 SetUpdateOverCellularPermission(allowed);
402 }
403 }
404
405 // Show the current update over cellular network setting.
406 if (FLAGS_show_update_over_cellular) {
407 bool allowed = GetUpdateOverCellularPermission();
408 LOG(INFO) << "Current update over cellular network setting: "
409 << (allowed ? "ENABLED" : "DISABLED");
410 }
411
Chris Sosacb7fa882013-07-25 17:02:59 -0700412 if (!FLAGS_powerwash && !FLAGS_rollback && FLAGS_channel.empty()) {
413 LOG(FATAL) << "powerwash flag only makes sense rollback or channel change";
414 return 1;
415 }
416
Alex Deymo5fdf7762013-07-17 20:01:40 -0700417 // Change the P2P enabled setting.
418 if (!FLAGS_p2p_update.empty()) {
419 gboolean enabled = FLAGS_p2p_update == "yes";
420 if (!enabled && FLAGS_p2p_update != "no") {
421 LOG(ERROR) << "Unknown option: \"" << FLAGS_p2p_update
422 << "\". Please specify \"yes\" or \"no\".";
423 } else {
424 SetP2PUpdatePermission(enabled);
425 }
426 }
427
428 // Show the current P2P enabled setting.
429 if (FLAGS_show_p2p_update) {
430 bool enabled = GetP2PUpdatePermission();
431 LOG(INFO) << "Current update using P2P setting: "
432 << (enabled ? "ENABLED" : "DISABLED");
433 }
434
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700435 // First, update the target channel if requested.
436 if (!FLAGS_channel.empty())
Chris Sosacb7fa882013-07-25 17:02:59 -0700437 SetTargetChannel(FLAGS_channel, FLAGS_powerwash);
Darin Petkov8daa3242010-10-25 13:28:47 -0700438
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700439 // Show the current and target channels if requested.
440 if (FLAGS_show_channel) {
441 string current_channel = GetChannel(true);
442 LOG(INFO) << "Current Channel: " << current_channel;
443
444 string target_channel = GetChannel(false);
445 if (!target_channel.empty())
446 LOG(INFO) << "Target Channel (pending update): " << target_channel;
Satoru Takabayashi583667b2010-10-27 13:09:57 +0900447 }
448
Chris Sosad317e402013-06-12 13:47:09 -0700449 bool do_update_request = FLAGS_check_for_update | FLAGS_update |
450 !FLAGS_app_version.empty() | !FLAGS_omaha_url.empty();
451
Chris Sosad317e402013-06-12 13:47:09 -0700452 if (do_update_request && FLAGS_rollback) {
453 LOG(FATAL) << "Update should not be requested with rollback!";
454 return 1;
455 }
456
457 if(FLAGS_rollback) {
458 LOG(INFO) << "Requesting rollback.";
459 CHECK(Rollback(FLAGS_powerwash)) << "Request for rollback failed.";
460 return 0;
461 }
462
Darin Petkov58529db2010-08-13 09:19:47 -0700463 // Initiate an update check, if necessary.
Chris Sosad317e402013-06-12 13:47:09 -0700464 if (do_update_request) {
Darin Petkov296889c2010-07-23 16:20:54 -0700465 LOG_IF(WARNING, FLAGS_reboot) << "-reboot flag ignored.";
Darin Petkov58529db2010-08-13 09:19:47 -0700466 string app_version = FLAGS_app_version;
467 if (FLAGS_update && app_version.empty()) {
468 app_version = "ForcedUpdate";
469 LOG(INFO) << "Forcing an update by setting app_version to ForcedUpdate.";
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700470 }
Darin Petkov58529db2010-08-13 09:19:47 -0700471 LOG(INFO) << "Initiating update check and install.";
472 CHECK(CheckForUpdates(app_version, FLAGS_omaha_url))
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700473 << "Update check/initiate update failed.";
Darin Petkov58529db2010-08-13 09:19:47 -0700474
475 // Wait for an update to complete.
476 if (FLAGS_update) {
Darin Petkov9d911fa2010-08-19 09:36:08 -0700477 LOG(INFO) << "Waiting for update to complete.";
Darin Petkov58529db2010-08-13 09:19:47 -0700478 CompleteUpdate(); // Should never return.
479 return 1;
480 }
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700481 return 0;
482 }
Darin Petkov58529db2010-08-13 09:19:47 -0700483
484 // Start watching for updates.
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700485 if (FLAGS_watch_for_updates) {
Darin Petkov296889c2010-07-23 16:20:54 -0700486 LOG_IF(WARNING, FLAGS_reboot) << "-reboot flag ignored.";
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700487 LOG(INFO) << "Watching for status updates.";
488 WatchForUpdates(); // Should never return.
489 return 1;
490 }
Darin Petkov58529db2010-08-13 09:19:47 -0700491
Darin Petkov296889c2010-07-23 16:20:54 -0700492 if (FLAGS_reboot) {
493 LOG(INFO) << "Requesting a reboot...";
494 CHECK(RebootIfNeeded());
495 return 0;
496 }
Andrew de los Reyesada42202010-07-15 22:23:20 -0700497
Darin Petkov8daa3242010-10-25 13:28:47 -0700498 LOG(INFO) << "Done.";
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700499 return 0;
500}