OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include <string> |
| 6 |
5 #include <gflags/gflags.h> | 7 #include <gflags/gflags.h> |
6 #include <glib.h> | 8 #include <glib.h> |
7 | 9 |
8 #include "update_engine/marshal.glibmarshal.h" | 10 #include "update_engine/marshal.glibmarshal.h" |
9 #include "update_engine/dbus_constants.h" | 11 #include "update_engine/dbus_constants.h" |
10 #include "update_engine/subprocess.h" | 12 #include "update_engine/subprocess.h" |
11 #include "update_engine/utils.h" | 13 #include "update_engine/utils.h" |
12 | 14 |
13 extern "C" { | 15 extern "C" { |
14 #include "update_engine/update_engine.dbusclient.h" | 16 #include "update_engine/update_engine.dbusclient.h" |
15 } | 17 } |
16 | 18 |
17 using chromeos_update_engine::kUpdateEngineServiceName; | 19 using chromeos_update_engine::kUpdateEngineServiceName; |
18 using chromeos_update_engine::kUpdateEngineServicePath; | 20 using chromeos_update_engine::kUpdateEngineServicePath; |
19 using chromeos_update_engine::kUpdateEngineServiceInterface; | 21 using chromeos_update_engine::kUpdateEngineServiceInterface; |
20 using chromeos_update_engine::utils::GetGErrorMessage; | 22 using chromeos_update_engine::utils::GetGErrorMessage; |
| 23 using std::string; |
21 | 24 |
22 DEFINE_bool(status, false, "Print the status to stdout."); | 25 DEFINE_string(app_version, "", |
| 26 "Force the current app version."); |
| 27 DEFINE_bool(check_for_update, false, |
| 28 "Initiate check for updates."); |
23 DEFINE_bool(force_update, false, | 29 DEFINE_bool(force_update, false, |
24 "Force an update, even over an expensive network."); | 30 "Force an update, even over an expensive network."); |
25 DEFINE_bool(check_for_update, false, | 31 DEFINE_string(omaha_url, "", |
26 "Initiate check for updates."); | 32 "The URL of the Omaha update server."); |
| 33 DEFINE_bool(status, false, "Print the status to stdout."); |
27 DEFINE_bool(watch_for_updates, false, | 34 DEFINE_bool(watch_for_updates, false, |
28 "Listen for status updates and print them to the screen."); | 35 "Listen for status updates and print them to the screen."); |
29 | 36 |
30 namespace { | 37 namespace { |
31 | 38 |
32 bool GetProxy(DBusGProxy** out_proxy) { | 39 bool GetProxy(DBusGProxy** out_proxy) { |
33 DBusGConnection* bus; | 40 DBusGConnection* bus; |
34 DBusGProxy* proxy; | 41 DBusGProxy* proxy; |
35 GError* error = NULL; | 42 GError* error = NULL; |
36 | 43 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 GMainLoop* loop = g_main_loop_new (NULL, TRUE); | 134 GMainLoop* loop = g_main_loop_new (NULL, TRUE); |
128 dbus_g_proxy_connect_signal(proxy, | 135 dbus_g_proxy_connect_signal(proxy, |
129 kStatusUpdate, | 136 kStatusUpdate, |
130 G_CALLBACK(StatusUpdateSignalHandler), | 137 G_CALLBACK(StatusUpdateSignalHandler), |
131 NULL, | 138 NULL, |
132 NULL); | 139 NULL); |
133 g_main_loop_run(loop); | 140 g_main_loop_run(loop); |
134 g_main_loop_unref(loop); | 141 g_main_loop_unref(loop); |
135 } | 142 } |
136 | 143 |
137 bool CheckForUpdates(bool force) { | 144 bool CheckForUpdates(bool force, const string& app_version, |
| 145 const string& omaha_url) { |
138 DBusGProxy* proxy; | 146 DBusGProxy* proxy; |
139 GError* error = NULL; | 147 GError* error = NULL; |
140 | 148 |
141 CHECK(GetProxy(&proxy)); | 149 CHECK(GetProxy(&proxy)); |
142 | 150 |
143 gboolean rc = | 151 gboolean rc = |
144 org_chromium_UpdateEngineInterface_check_for_update(proxy, &error); | 152 org_chromium_UpdateEngineInterface_attempt_update(proxy, |
| 153 app_version.c_str(), |
| 154 omaha_url.c_str(), |
| 155 &error); |
145 CHECK_EQ(rc, TRUE) << "Error checking for update: " | 156 CHECK_EQ(rc, TRUE) << "Error checking for update: " |
146 << GetGErrorMessage(error); | 157 << GetGErrorMessage(error); |
147 return true; | 158 return true; |
148 } | 159 } |
149 | 160 |
150 } // namespace {} | 161 } // namespace {} |
151 | 162 |
152 int main(int argc, char** argv) { | 163 int main(int argc, char** argv) { |
153 // Boilerplate init commands. | 164 // Boilerplate init commands. |
154 g_type_init(); | 165 g_type_init(); |
155 g_thread_init(NULL); | 166 g_thread_init(NULL); |
156 dbus_g_thread_init(); | 167 dbus_g_thread_init(); |
157 chromeos_update_engine::Subprocess::Init(); | 168 chromeos_update_engine::Subprocess::Init(); |
158 google::ParseCommandLineFlags(&argc, &argv, true); | 169 google::ParseCommandLineFlags(&argc, &argv, true); |
159 | 170 |
160 if (FLAGS_status) { | 171 if (FLAGS_status) { |
161 LOG(INFO) << "Querying Update Engine status..."; | 172 LOG(INFO) << "Querying Update Engine status..."; |
162 if (!GetStatus()) { | 173 if (!GetStatus()) { |
163 LOG(FATAL) << "GetStatus() failed."; | 174 LOG(FATAL) << "GetStatus() failed."; |
164 } | 175 } |
165 return 0; | 176 return 0; |
166 } | 177 } |
167 if (FLAGS_force_update || FLAGS_check_for_update) { | 178 if (FLAGS_force_update || FLAGS_check_for_update || |
| 179 !FLAGS_app_version.empty() || !FLAGS_omaha_url.empty()) { |
168 LOG(INFO) << "Initiating update check and install."; | 180 LOG(INFO) << "Initiating update check and install."; |
169 if (FLAGS_force_update) { | 181 if (FLAGS_force_update) { |
170 LOG(INFO) << "Will not abort due to being on expensive network."; | 182 LOG(INFO) << "Will not abort due to being on expensive network."; |
171 } | 183 } |
172 CHECK(CheckForUpdates(FLAGS_force_update)) | 184 CHECK(CheckForUpdates(FLAGS_force_update, FLAGS_app_version, |
| 185 FLAGS_omaha_url)) |
173 << "Update check/initiate update failed."; | 186 << "Update check/initiate update failed."; |
174 return 0; | 187 return 0; |
175 } | 188 } |
176 if (FLAGS_watch_for_updates) { | 189 if (FLAGS_watch_for_updates) { |
177 LOG(INFO) << "Watching for status updates."; | 190 LOG(INFO) << "Watching for status updates."; |
178 WatchForUpdates(); // Should never return. | 191 WatchForUpdates(); // Should never return. |
179 return 1; | 192 return 1; |
180 } | 193 } |
181 | 194 |
182 LOG(INFO) << "No flags specified. Exiting."; | 195 LOG(INFO) << "No flags specified. Exiting."; |
183 return 0; | 196 return 0; |
184 } | 197 } |
OLD | NEW |