1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
6 // On Tizen installing applications requires super-user powers primarily because
7 // some pieces of information of the application are put on globally accessible
8 // locations. This helper will run with super-user powers (via suid) and will
9 // be called by Crosswalk (now running as a normal user) so all the activities
10 // that required 'root' access are done by a small code base.
17 #include "base/files/file_path.h"
18 #include "base/file_util.h"
19 #include "xwalk/application/tools/tizen/xwalk_package_installer_helper.h"
23 char* install_option = NULL;
24 char* update_option = NULL;
25 char* uninstall_option = NULL;
26 char* reinstall_option = NULL;
27 char* operation_key = NULL;
28 char* xml_path = NULL;
29 char* icon_path = NULL;
32 GOptionEntry entries[] = {
33 { "install", 'i', 0, G_OPTION_ARG_STRING, &install_option,
34 "Path of the application to be installed", "APPID" },
35 { "update", 'u', 0, G_OPTION_ARG_STRING, &update_option,
36 "Path of the application to be updated", "APPID" },
37 { "uninstall", 'd', 0, G_OPTION_ARG_STRING, &uninstall_option,
38 "Uninstall the application with this appid", "APPID" },
39 { "reinstall", 'r', 0, G_OPTION_ARG_STRING, &reinstall_option,
40 "Path of the application to be reinstalled", "APPID" },
41 { "key", 'k', 0, G_OPTION_ARG_STRING, &operation_key,
42 "Unique operation key", "KEY" },
43 { "quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet,
45 { "xml", 'x', 0, G_OPTION_ARG_STRING, &xml_path,
46 "Xml file", "XML_FILE" },
47 { "icon", 'y', 0, G_OPTION_ARG_STRING, &icon_path,
48 "Icon file", "ICON_FILE" },
54 int main(int argc, char *argv[]) {
56 GOptionContext* context;
58 #if !GLIB_CHECK_VERSION(2, 36, 0)
59 // g_type_init() is deprecated on GLib since 2.36, Tizen has 2.32.
63 context = g_option_context_new(
64 " - Crosswalk Tizen Application Installation helper");
66 fprintf(stderr, "g_option_context_new failed\n");
69 g_option_context_add_main_entries(context, entries, NULL);
70 if (!g_option_context_parse(context, &argc, &argv, &error)) {
71 fprintf(stderr, "option parsing failed: %s\n", error->message);
72 g_option_context_free(context);
75 g_option_context_free(context);
80 const char* pkgmgr_argv[5];
81 pkgmgr_argv[2] = "-k";
82 pkgmgr_argv[3] = operation_key;
83 pkgmgr_argv[4] = "-q";
87 appId = install_option;
88 } else if (uninstall_option) {
89 appId = uninstall_option;
90 } else if (update_option) {
91 appId = update_option;
92 } else if (reinstall_option) {
93 appId = reinstall_option;
95 fprintf(stderr, "Use: --install, --uninstall, --update or --reinstall\n");
99 PackageInstallerHelper helper(appId);
101 if (install_option) {
102 if (!xml_path || !icon_path) {
103 fprintf(stdout, "missing --xml or --icon option\n");
108 pkgmgr_argv[0] = "-i";
109 pkgmgr_argv[1] = install_option; // this value is ignored by pkgmgr
110 helper.InitializePkgmgrSignal((quiet ? 5 : 4), pkgmgr_argv);
113 result = helper.InstallApplication(xml_path, icon_path);
114 } else if (uninstall_option) {
116 pkgmgr_argv[0] = "-d";
117 pkgmgr_argv[1] = uninstall_option; // this value is ignored by pkgmgr
118 helper.InitializePkgmgrSignal((quiet ? 5 : 4), pkgmgr_argv);
121 result = helper.UninstallApplication();
122 } else if (update_option) {
123 if (!xml_path || !icon_path) {
124 fprintf(stderr, "missing --xml or --icon option\n");
129 pkgmgr_argv[0] = "-i";
130 pkgmgr_argv[1] = update_option; // this value is ignored by pkgmgr
131 helper.InitializePkgmgrSignal((quiet ? 5 : 4), pkgmgr_argv);
134 result = helper.UpdateApplication(xml_path, icon_path);
135 } else if (reinstall_option) {
137 pkgmgr_argv[0] = "-r";
138 pkgmgr_argv[1] = reinstall_option; // this value is ignored by pkgmgr
139 helper.InitializePkgmgrSignal((quiet ? 5 : 4), pkgmgr_argv);
142 result = helper.ReinstallApplication();
145 // Convention is to return 0 on success.
146 return result ? 0 : 1;