blob: bed72056f073283c57caea08210f6cc7e5a75b2a [file] [log] [blame]
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -07001// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <gflags/gflags.h>
6#include <glib.h>
7
8#include "update_engine/dbus_constants.h"
9#include "update_engine/subprocess.h"
10#include "update_engine/utils.h"
11
12extern "C" {
13#include "update_engine/update_engine.dbusclient.h"
14}
15
16using chromeos_update_engine::kUpdateEngineServiceName;
17using chromeos_update_engine::kUpdateEngineServicePath;
18using chromeos_update_engine::kUpdateEngineServiceInterface;
Andrew de los Reyesc7020782010-04-28 10:46:04 -070019using chromeos_update_engine::utils::GetGErrorMessage;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070020
21DEFINE_bool(status, false, "Print the status to stdout.");
22DEFINE_bool(force_update, false,
23 "Force an update, even over an expensive network.");
24DEFINE_bool(check_for_update, false,
25 "Initiate check for updates.");
26
27namespace {
28
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070029bool GetStatus() {
30 DBusGConnection *bus;
31 DBusGProxy *proxy;
32 GError *error = NULL;
33
34 bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
35 if (!bus) {
36 LOG(FATAL) << "Failed to get bus";
37 }
38 proxy = dbus_g_proxy_new_for_name_owner(bus,
39 kUpdateEngineServiceName,
40 kUpdateEngineServicePath,
41 kUpdateEngineServiceInterface,
42 &error);
43 if (!proxy) {
Andrew de los Reyesc7020782010-04-28 10:46:04 -070044 LOG(FATAL) << "Error getting proxy: " << GetGErrorMessage(error);
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070045 }
46
47 gint64 last_checked_time = 0;
48 gdouble progress = 0.0;
49 char* current_op = NULL;
50 char* new_version = NULL;
51 gint64 new_size = 0;
52
53 gboolean rc = org_chromium_UpdateEngineInterface_get_status(
54 proxy,
55 &last_checked_time,
56 &progress,
57 &current_op,
58 &new_version,
59 &new_size,
60 &error);
61 if (rc == FALSE) {
Andrew de los Reyesc7020782010-04-28 10:46:04 -070062 LOG(INFO) << "Error getting status: " << GetGErrorMessage(error);
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070063 }
64 printf("LAST_CHECKED_TIME=%" PRIi64 "\nPROGRESS=%f\nCURRENT_OP=%s\n"
65 "NEW_VERSION=%s\nNEW_SIZE=%" PRIi64 "\n",
66 last_checked_time,
67 progress,
68 current_op,
69 new_version,
70 new_size);
71 return true;
72}
73
74bool CheckForUpdates(bool force) {
75 return true;
76}
77
78} // namespace {}
79
80int main(int argc, char** argv) {
81 // Boilerplate init commands.
82 g_type_init();
83 g_thread_init(NULL);
84 dbus_g_thread_init();
85 chromeos_update_engine::Subprocess::Init();
86 google::ParseCommandLineFlags(&argc, &argv, true);
87
88 if (FLAGS_status) {
89 LOG(INFO) << "Querying Update Engine status...";
90 if (!GetStatus()) {
91 LOG(FATAL) << "GetStatus() failed.";
92 }
93 return 0;
94 }
95 if (FLAGS_force_update || FLAGS_check_for_update) {
96 LOG(INFO) << "Initiating update check and install.";
97 if (FLAGS_force_update) {
98 LOG(INFO) << "Will not abort due to being on expensive network.";
99 }
100 CHECK(CheckForUpdates(FLAGS_force_update))
101 << "Update check/initiate update failed.";
102 return 0;
103 }
104
105 LOG(INFO) << "No flags specified. Exiting.";
106 return 0;
107}