5 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
7 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
8 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
35 #include <sys/types.h>
38 #include <glib-object.h>
39 #include <pkgmgr-info.h>
40 #include "package-manager.h"
41 #include "package-manager-types.h"
43 #define PKG_TOOL_VERSION "0.1"
44 #define APP_INSTALLATION_PATH_RW "/opt/usr/apps"
46 /* 1 -100 : Package command errors */
47 /* 101-120 : reserved for Core installer */
48 /* 121-140 : reserved for Web installer */
49 /* 141-160 : reserved for Native installer */
50 #define PKGCMD_ERR_PACKAGE_NOT_FOUND 1
51 #define PKGCMD_ERR_PACKAGE_INVALID 2
52 #define PKGCMD_ERR_PACKAGE_LOWER_VERSION 3
53 #define PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND 4
54 #define PKGCMD_ERR_MANIFEST_NOT_FOUND 11
55 #define PKGCMD_ERR_MANIFEST_INVALID 12
56 #define PKGCMD_ERR_CONFIG_NOT_FOUND 13
57 #define PKGCMD_ERR_CONFIG_INVALID 14
58 #define PKGCMD_ERR_SIGNATURE_NOT_FOUND 21
59 #define PKGCMD_ERR_SIGNATURE_INVALID 22
60 #define PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED 23
61 #define PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND 31
62 #define PKGCMD_ERR_CERTIFICATE_INVALID 32
63 #define PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED 33
64 #define PKGCMD_ERR_CERTIFICATE_EXPIRED 34
65 #define PKGCMD_ERR_INVALID_PRIVILEGE 41
66 #define PKGCMD_ERR_MENU_ICON_NOT_FOUND 51
67 #define PKGCMD_ERR_FATAL_ERROR 61
68 #define PKGCMD_ERR_OUT_OF_STORAGE 62
69 #define PKGCMD_ERR_OUT_OF_MEMORY 63
70 #define PKGCMD_ERR_ARGUMENT_INVALID 64
72 #define PKGCMD_ERR_PACKAGE_NOT_FOUND_STR "PACKAGE_NOT_FOUND"
73 #define PKGCMD_ERR_PACKAGE_INVALID_STR "PACKAGE_INVALID"
74 #define PKGCMD_ERR_PACKAGE_LOWER_VERSION_STR "PACKAGE_LOWER_VERSION"
75 #define PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND_STR "PACKAGE_EXECUTABLE_NOT_FOUND"
76 #define PKGCMD_ERR_MANIFEST_NOT_FOUND_STR "MANIFEST_NOT_FOUND"
77 #define PKGCMD_ERR_MANIFEST_INVALID_STR "MANIFEST_INVALID"
78 #define PKGCMD_ERR_CONFIG_NOT_FOUND_STR "CONFIG_NOT_FOUND"
79 #define PKGCMD_ERR_CONFIG_INVALID_STR "CONFIG_INVALID"
80 #define PKGCMD_ERR_SIGNATURE_NOT_FOUND_STR "SIGNATURE_NOT_FOUND"
81 #define PKGCMD_ERR_SIGNATURE_INVALID_STR "SIGNATURE_INVALID"
82 #define PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED_STR "SIGNATURE_VERIFICATION_FAILED"
83 #define PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND_STR "ROOT_CERTIFICATE_NOT_FOUND"
84 #define PKGCMD_ERR_CERTIFICATE_INVALID_STR "CERTIFICATE_INVALID"
85 #define PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED_STR "CERTIFICATE_CHAIN_VERIFICATION_FAILED"
86 #define PKGCMD_ERR_CERTIFICATE_EXPIRED_STR "CERTIFICATE_EXPIRED"
87 #define PKGCMD_ERR_INVALID_PRIVILEGE_STR "INVALID_PRIVILEGE"
88 #define PKGCMD_ERR_MENU_ICON_NOT_FOUND_STR "MENU_ICON_NOT_FOUND"
89 #define PKGCMD_ERR_FATAL_ERROR_STR "FATAL_ERROR"
90 #define PKGCMD_ERR_OUT_OF_STORAGE_STR "OUT_OF_STORAGE"
91 #define PKGCMD_ERR_OUT_OF_MEMORY_STR "OUT_OF_MEMORY"
92 #define PKGCMD_ERR_ARGUMENT_INVALID_STR "ARGUMENT_INVALID"
93 #define PKGCMD_ERR_UNKNOWN_STR "Unknown Error"
95 static int __process_request();
96 static void __print_usage();
97 static int __is_authorized();
98 static int __is_app_installed(char *pkgid);
99 static void __print_pkg_info(pkgmgr_info * pkg_info);
100 static int __return_cb(int req_id, const char *pkg_type, const char *pkgid,
101 const char *key, const char *val, const void *pmsg,
103 static int __convert_to_absolute_path(char *path);
104 static int __pkgcmd_read_proc(const char *path, char *buf, int size);
105 static int __pkgcmd_find_pid_by_cmdline(const char *dname,
106 const char *cmdline, const char *apppath);
107 static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option);
108 static int __app_list_cb(const pkgmgr_appinfo_h handle, void *user_data);
110 /* Supported options */
111 const char *short_options = "iurmcCkaADL:lsd:p:t:n:T:qh";
112 const struct option long_options[] = {
113 {"install", 0, NULL, 'i'},
114 {"uninstall", 0, NULL, 'u'},
115 {"reinstall", 0, NULL, 'r'},
116 {"move", 0, NULL, 'm'},
117 {"clear", 0, NULL, 'c'},
118 {"activate", 0, NULL, 'A'},
119 {"deactivate", 0, NULL, 'D'},
120 {"activate with Label", 1, NULL, 'L'},
121 {"check", 0, NULL, 'C'},
122 {"kill", 0, NULL, 'k'},
123 {"app-path", 0, NULL, 'a'},
124 {"list", 0, NULL, 'l'},
125 {"show", 0, NULL, 's'},
126 {"descriptor", 1, NULL, 'd'},
127 {"package-path", 1, NULL, 'p'},
128 {"package-type", 1, NULL, 't'},
129 {"package-name", 1, NULL, 'n'},
130 {"move-type", 1, NULL, 'T'},
131 {"quiet", 0, NULL, 'q'},
132 {"help", 0, NULL, 'h'},
133 {0, 0, 0, 0} /* sentinel */
136 enum pm_tool_request_e {
151 typedef enum pm_tool_request_e req_type;
153 struct pm_tool_args_t {
155 char pkg_path[PKG_NAME_STRING_LEN_MAX];
156 char pkg_type[PKG_TYPE_STRING_LEN_MAX];
157 char pkgid[PKG_NAME_STRING_LEN_MAX];
158 char des_path[PKG_NAME_STRING_LEN_MAX];
159 char label[PKG_NAME_STRING_LEN_MAX];
164 typedef struct pm_tool_args_t pm_tool_args;
167 static GMainLoop *main_loop = NULL;
169 static void __error_no_to_string(int errnumber, char **errstr)
174 case PKGCMD_ERR_PACKAGE_NOT_FOUND:
175 *errstr = PKGCMD_ERR_PACKAGE_NOT_FOUND_STR;
177 case PKGCMD_ERR_PACKAGE_INVALID:
178 *errstr = PKGCMD_ERR_PACKAGE_INVALID_STR;
180 case PKGCMD_ERR_PACKAGE_LOWER_VERSION:
181 *errstr = PKGCMD_ERR_PACKAGE_LOWER_VERSION_STR;
183 case PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND:
184 *errstr = PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND_STR;
186 case PKGCMD_ERR_MANIFEST_INVALID:
187 *errstr = PKGCMD_ERR_MANIFEST_INVALID_STR;
189 case PKGCMD_ERR_CONFIG_NOT_FOUND:
190 *errstr = PKGCMD_ERR_CONFIG_NOT_FOUND_STR;
192 case PKGCMD_ERR_CONFIG_INVALID:
193 *errstr = PKGCMD_ERR_CONFIG_INVALID_STR;
195 case PKGCMD_ERR_SIGNATURE_NOT_FOUND:
196 *errstr = PKGCMD_ERR_SIGNATURE_NOT_FOUND_STR;
198 case PKGCMD_ERR_SIGNATURE_INVALID:
199 *errstr = PKGCMD_ERR_SIGNATURE_INVALID_STR;
201 case PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED:
202 *errstr = PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED_STR;
204 case PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND:
205 *errstr = PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND_STR;
207 case PKGCMD_ERR_CERTIFICATE_INVALID:
208 *errstr = PKGCMD_ERR_CERTIFICATE_INVALID_STR;
210 case PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED:
211 *errstr = PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED_STR;
213 case PKGCMD_ERR_CERTIFICATE_EXPIRED:
214 *errstr = PKGCMD_ERR_CERTIFICATE_EXPIRED_STR;
216 case PKGCMD_ERR_INVALID_PRIVILEGE:
217 *errstr = PKGCMD_ERR_INVALID_PRIVILEGE_STR;
219 case PKGCMD_ERR_MENU_ICON_NOT_FOUND:
220 *errstr = PKGCMD_ERR_MENU_ICON_NOT_FOUND_STR;
222 case PKGCMD_ERR_FATAL_ERROR:
223 *errstr = PKGCMD_ERR_FATAL_ERROR_STR;
225 case PKGCMD_ERR_OUT_OF_STORAGE:
226 *errstr = PKGCMD_ERR_OUT_OF_STORAGE_STR;
228 case PKGCMD_ERR_OUT_OF_MEMORY:
229 *errstr = PKGCMD_ERR_OUT_OF_MEMORY_STR;
231 case PKGCMD_ERR_ARGUMENT_INVALID:
232 *errstr = PKGCMD_ERR_ARGUMENT_INVALID_STR;
235 *errstr = PKGCMD_ERR_UNKNOWN_STR;
240 static int __return_cb(int req_id, const char *pkg_type,
241 const char *pkgid, const char *key, const char *val,
242 const void *pmsg, void *priv_data)
244 if (strncmp(key, "error", strlen("error")) == 0) {
249 __error_no_to_string(ret_val, &errstr);
250 data.result = ret_val;
252 printf("__return_cb req_id[%d] pkg_type[%s] pkgid[%s] key[%s] val[%d] error_message[%s]\n",
253 req_id, pkg_type, pkgid, key, ret_val, errstr);
255 printf("__return_cb req_id[%d] pkg_type[%s] "
256 "pkgid[%s] key[%s] val[%s]\n",
257 req_id, pkg_type, pkgid, key, val);
259 if (strncmp(key, "end", strlen("end")) == 0) {
260 if ((strncmp(val, "fail", strlen("fail")) == 0) && data.result == 0){
261 data.result = PKGCMD_ERR_FATAL_ERROR;
263 g_main_loop_quit(main_loop);
269 static int __pkgcmd_read_proc(const char *path, char *buf, int size)
273 if (buf == NULL || path == NULL)
275 fd = open(path, O_RDONLY);
278 ret = read(fd, buf, size - 1);
288 static int __pkgcmd_find_pid_by_cmdline(const char *dname,
289 const char *cmdline, const char *apppath)
293 if (strcmp(cmdline, apppath) == 0) {
295 if (pid != getpgid(pid))
301 static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option)
304 struct dirent *dentry;
307 char buf[1024] = {'\0'};
310 dp = opendir("/proc");
315 while ((dentry = readdir(dp)) != NULL) {
316 if (!isdigit(dentry->d_name[0]))
319 snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry->d_name);
320 ret = __pkgcmd_read_proc(buf, buf, sizeof(buf));
324 pid = __pkgcmd_find_pid_by_cmdline(dentry->d_name, buf, apppath);
335 if (killpg(pgid, SIGKILL) < 0) {
347 static int __app_list_cb(const pkgmgr_appinfo_h handle, void *user_data)
353 if (handle == NULL) {
354 printf("appinfo handle is NULL\n");
357 ret = pkgmgr_appinfo_get_exec(handle, &exec);
359 printf("Failed to get app exec path\n");
362 ret = pkgmgr_appinfo_get_appid(handle, &appid);
364 printf("Failed to get appid\n");
367 /*option 0 to check and option 1 to kill*/
368 switch(data.request) {
370 pid = __pkgcmd_proc_iter_kill_cmdline(exec, 0);
372 printf("Appid: %s is Running\n", appid);
374 printf("Appid: %s is Not Running\n", appid);
378 pid = __pkgcmd_proc_iter_kill_cmdline(exec, 1);
380 printf("Appid: %s is Terminated\n", appid);
388 static int __convert_to_absolute_path(char *path)
390 char abs[PKG_NAME_STRING_LEN_MAX] = {'\0'};
391 char temp[PKG_NAME_STRING_LEN_MAX] = {'\0'};
394 printf("path is NULL\n");
397 strncpy(temp, path, PKG_NAME_STRING_LEN_MAX - 1);
398 if (strchr(path, '/') == NULL) {
399 getcwd(abs, PKG_NAME_STRING_LEN_MAX - 1);
400 if (abs[0] == '\0') {
401 printf("getcwd() failed\n");
404 memset(data.pkg_path, '\0', PKG_NAME_STRING_LEN_MAX);
405 snprintf(data.pkg_path, PKG_NAME_STRING_LEN_MAX - 1, "%s/%s", abs, temp);
408 if (strncmp(path, "./", 2) == 0) {
410 getcwd(abs, PKG_NAME_STRING_LEN_MAX - 1);
411 if (abs[0] == '\0') {
412 printf("getcwd() failed\n");
416 memset(data.pkg_path, '\0', PKG_NAME_STRING_LEN_MAX);
417 snprintf(data.pkg_path, PKG_NAME_STRING_LEN_MAX - 1, "%s/%s", abs, ptr);
423 static int __is_app_installed(char *pkgid)
426 ail_appinfo_h handle;
429 ret = ail_package_get_appinfo(pkgid, &handle);
430 if (ret != AIL_ERROR_OK) {
433 ret = ail_appinfo_get_str(handle, AIL_PROP_NAME_STR, &str);
434 if (ret != AIL_ERROR_OK) {
437 ret = ail_package_destroy_appinfo(handle);
438 if (ret != AIL_ERROR_OK) {
442 pkgmgr_pkginfo_h handle;
443 int ret = pkgmgr_pkginfo_get_pkginfo(pkgid, &handle);
445 printf("package is not in pkgmgr_info DB\n");
448 pkgmgr_pkginfo_destroy_pkginfo(handle);
454 static void __print_usage()
456 printf("\nPackage Manager Tool Version: %s\n\n", PKG_TOOL_VERSION);
457 printf("-i, --install install the package\n");
458 printf("-u, --uninstall uninstall the package\n");
459 printf("-r, --reinstall reinstall the package\n");
460 printf("-c, --clear clear user data\n");
461 printf("-m, --move move package\n");
462 printf("-l, --list display list of installed packages\n");
463 printf("-s, --show show detail package info\n");
464 printf("-a, --app-path show app installation path\n");
465 printf("-C, --check check if applications belonging to a package are running or not\n");
466 printf("-k, --kill terminate applications belonging to a package\n");
467 printf("-d, --descriptor provide descriptor path\n");
468 printf("-p, --package-path provide package path\n");
469 printf("-n, --package-name provide package name\n");
470 printf("-t, --package-type provide package type\n");
471 printf("-T, --move-type provide move type [0 : move to internal /1: move to external]\n");
472 printf("-q, --quiet quiet mode operation\n");
473 printf("-h, --help print this help\n\n");
475 printf("Usage: pkgcmd [options] (--quiet)\n");
476 printf("pkgcmd -i -t <pkg type> (-d <descriptor path>) -p <pkg path> (-q)\n");
477 printf("pkgcmd -u -t <pkg type> -n <pkgid> (-q)\n");
478 printf("pkgcmd -r -t <pkg type> -n <pkgid> \n");
479 printf("pkgcmd -l (-t <pkg type>) \n");
480 printf("pkgcmd -s -t <pkg type> -p <pkg path> (-q)\n");
481 printf("pkgcmd -s -t <pkg type> -n <pkg name> (-q)\n");
482 printf("pkgcmd -m -t <pkg type> -T <move type> -n <pkg name> (-q)\n\n");
484 printf("Example:\n");
485 printf("pkgcmd -u -t rpm -n org.tizen.calculator\n");
486 printf("pkgcmd -i -t rpm -p /mnt/nfs/org.tizen.calculator_0.1.2-95_armel.rpm\n");
487 printf("pkgcmd -r -t rpm -p org.tizen.calculator\n");
488 printf("pkgcmd -c -t rpm -n org.tizen.hello\n");
489 printf("pkgcmd -m -t rpm -T 1 -n org.tizen.hello\n");
490 printf("pkgcmd -C -t rpm -n org.tizen.hello\n");
491 printf("pkgcmd -k -t rpm -n org.tizen.hello\n");
492 printf("pkgcmd -a\n");
493 printf("pkgcmd -a -t rpm -n org.tizen.hello\n");
494 printf("pkgcmd -l\n");
495 printf("pkgcmd -l -t tpk\n");
501 static void __print_pkg_info(pkgmgr_info *pkg_info)
505 temp = pkgmgr_info_get_string(pkg_info, "pkg_type");
507 printf("pkg_type : %s\n", temp);
511 temp = pkgmgr_info_get_string(pkg_info, "pkgid");
513 printf("pkgid : %s\n", temp);
517 temp = pkgmgr_info_get_string(pkg_info, "version");
519 printf("version : %s\n", temp);
523 temp = pkgmgr_info_get_string(pkg_info, "pkg_vendor");
525 printf("pkg_vendor : %s\n", temp);
529 temp = pkgmgr_info_get_string(pkg_info, "pkg_description");
531 printf("pkg_description : %s\n", temp);
535 temp = pkgmgr_info_get_string(pkg_info, "pkg_mimetype");
537 printf("pkg_mimetype : %s\n", temp);
541 temp = pkgmgr_info_get_string(pkg_info, "pkg_installed_path_package");
543 printf("pkg_installed_path_package : %s\n", temp);
548 pkgmgr_info_get_string(pkg_info, "pkg_installed_path_descriptor");
550 printf("pkg_installed_path_descriptor : %s\n", temp);
554 temp = pkgmgr_info_get_string(pkg_info, "category");
556 printf("category : %s\n", temp);
560 temp = pkgmgr_info_get_string(pkg_info, "min_platform_version");
562 printf("min_platform_version : %s\n", temp);
566 temp = pkgmgr_info_get_string(pkg_info, "visible");
568 printf("visible : %s\n", temp);
572 temp = pkgmgr_info_get_string(pkg_info, "removable");
574 printf("removable : %s\n", temp);
578 temp = pkgmgr_info_get_string(pkg_info, "installed_size");
580 printf("installed_size : %s\n", temp);
584 temp = pkgmgr_info_get_string(pkg_info, "installed_time");
586 printf("installed_time : %s\n", temp);
590 temp = pkgmgr_info_get_string(pkg_info, "data_size");
592 printf("data_size : %s\n", temp);
596 temp = pkgmgr_info_get_string(pkg_info, "optional_id");
598 printf("optional_id : %s\n", temp);
603 static int __pkgmgr_list_cb (const pkgmgr_pkginfo_h handle, void *user_data)
607 char *pkg_type = NULL;
608 char *pkg_version = NULL;
609 char *pkg_label = NULL;
611 ret = pkgmgr_pkginfo_get_pkgid(handle, &pkgid);
613 printf("Failed to get pkgmgr_pkginfo_get_pkgid\n");
616 ret = pkgmgr_pkginfo_get_type(handle, &pkg_type);
618 printf("Failed to get pkgmgr_pkginfo_get_type\n");
621 ret = pkgmgr_pkginfo_get_version(handle, &pkg_version);
623 printf("Failed to get pkgmgr_pkginfo_get_version\n");
626 ret = pkgmgr_pkginfo_get_label(handle, &pkg_label);
628 printf("Failed to get pkgmgr_pkginfo_get_label\n");
632 printf("pkg_type [%s]\tpkgid [%s]\tname [%s]\tversion [%s]\n", pkg_type, pkgid, pkg_label, pkg_version);
637 static int __process_request()
640 int mode = PM_DEFAULT;
641 pkgmgr_client *pc = NULL;
642 char buf[1024] = {'\0'};
643 switch (data.request) {
645 if (data.pkg_type[0] == '\0' || data.pkg_path[0] == '\0') {
646 printf("Please provide the arguments.\n");
647 printf("use -h option to see usage\n");
648 data.result = PKGCMD_ERR_ARGUMENT_INVALID;
652 main_loop = g_main_loop_new(NULL, FALSE);
653 pc = pkgmgr_client_new(PC_REQUEST);
655 printf("PkgMgr Client Creation Failed\n");
656 data.result = PKGCMD_ERR_FATAL_ERROR;
663 if (data.des_path[0] == '\0')
665 pkgmgr_client_install(pc, data.pkg_type, NULL,
666 data.pkg_path, NULL, mode,
670 pkgmgr_client_install(pc, data.pkg_type,
671 data.des_path, data.pkg_path,
672 NULL, mode, __return_cb, pc);
674 data.result = PKGCMD_ERR_FATAL_ERROR;
675 if (access(data.pkg_path, F_OK) != 0)
676 data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
679 g_main_loop_run(main_loop);
684 if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
685 printf("Please provide the arguments.\n");
686 printf("use -h option to see usage\n");
687 data.result = PKGCMD_ERR_ARGUMENT_INVALID;
691 main_loop = g_main_loop_new(NULL, FALSE);
692 pc = pkgmgr_client_new(PC_REQUEST);
694 printf("PkgMgr Client Creation Failed\n");
695 data.result = PKGCMD_ERR_FATAL_ERROR;
703 ret = __is_app_installed(data.pkgid);
705 printf("package is not installed\n");
710 pkgmgr_client_uninstall(pc, data.pkg_type, data.pkgid,
711 mode, __return_cb, NULL);
713 data.result = PKGCMD_ERR_FATAL_ERROR;
714 if (access(data.pkg_path, F_OK) != 0)
715 data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
718 g_main_loop_run(main_loop);
723 if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
724 printf("Please provide the arguments.\n");
725 printf("use -h option to see usage\n");
726 data.result = PKGCMD_ERR_ARGUMENT_INVALID;
730 main_loop = g_main_loop_new(NULL, FALSE);
731 pc = pkgmgr_client_new(PC_REQUEST);
733 printf("PkgMgr Client Creation Failed\n");
734 data.result = PKGCMD_ERR_FATAL_ERROR;
739 ret = pkgmgr_client_reinstall(pc, data.pkg_type, data.pkgid, NULL, mode, __return_cb, pc);
741 data.result = PKGCMD_ERR_FATAL_ERROR;
742 if (access(data.pkg_path, F_OK) != 0)
743 data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
746 g_main_loop_run(main_loop);
751 if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
752 printf("Please provide the arguments.\n");
753 printf("use -h option to see usage\n");
758 pc = pkgmgr_client_new(PC_REQUEST);
760 printf("PkgMgr Client Creation Failed\n");
768 ret = __is_app_installed(data.pkgid);
770 printf("package is not installed\n");
773 ret = pkgmgr_client_clear_user_data(pc, data.pkg_type,
781 if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
782 printf("Please provide the arguments.\n");
783 printf("use -h option to see usage\n");
788 pc = pkgmgr_client_new(PC_REQUEST);
790 printf("PkgMgr Client Creation Failed\n");
795 if ( strcmp(data.pkg_type, "app") == 0 ) {
796 if (strlen(data.label) == 0) {
797 ret = pkgmgr_client_activate_app(pc, data.pkgid);
801 printf("label [%s]\n", data.label);
802 char *largv[3] = {NULL, };
804 largv[1] = data.label;
805 ret = pkgmgr_client_activate_appv(pc, data.pkgid, largv);
810 ret = pkgmgr_client_activate(pc, data.pkg_type, data.pkgid);
820 if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
821 printf("Please provide the arguments.\n");
822 printf("use -h option to see usage\n");
827 pc = pkgmgr_client_new(PC_REQUEST);
829 printf("PkgMgr Client Creation Failed\n");
834 if ( strcmp(data.pkg_type, "app") == 0 ) {
835 ret = pkgmgr_client_deactivate_app(pc, data.pkgid);
839 ret = pkgmgr_client_deactivate(pc, data.pkg_type, data.pkgid);
848 if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
849 printf("Please provide the arguments.\n");
850 printf("use -h option to see usage\n");
854 if (data.move_type < 0 || data.move_type > 1) {
855 printf("Invalid move type...See usage\n");
859 pc = pkgmgr_client_new(PC_REQUEST);
861 printf("PkgMgr Client Creation Failed\n");
869 ret = __is_app_installed(data.pkgid);
871 printf("package is not installed\n");
874 ret = pkgmgr_client_move(pc, data.pkg_type, data.pkgid, data.move_type, mode);
881 if (data.pkg_type[0] == '\0' && data.pkgid[0] == '\0') {
882 printf("Tizen Application Installation Path: %s\n", APP_INSTALLATION_PATH_RW);
886 if ((data.pkg_type[0] == '\0') || (data.pkgid[0] == '\0')) {
887 printf("Use -h option to see usage\n");
891 if (strncmp(data.pkg_type, "rpm", PKG_TYPE_STRING_LEN_MAX - 1) == 0) {
892 snprintf(buf, 1023, "%s/%s", APP_INSTALLATION_PATH_RW, data.pkgid);
893 printf("Tizen Application Installation Path: %s\n", buf);
896 } else if (strncmp(data.pkg_type, "wgt", PKG_TYPE_STRING_LEN_MAX - 1) == 0) {
897 snprintf(buf, 1023, "%s/%s/res/wgt", APP_INSTALLATION_PATH_RW, data.pkgid);
898 printf("Tizen Application Installation Path: %s\n", buf);
901 } else if (strncmp(data.pkg_type, "tpk", PKG_TYPE_STRING_LEN_MAX - 1) == 0) {
902 snprintf(buf, 1023, "%s/%s", APP_INSTALLATION_PATH_RW, data.pkgid);
903 printf("Tizen Application Installation Path: %s\n", buf);
907 printf("Invalid package type.\n");
908 printf("use -h option to see usage\n");
916 if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
917 printf("Please provide the arguments.\n");
918 printf("use -h option to see usage\n");
922 pkgmgr_pkginfo_h handle;
923 ret = pkgmgr_pkginfo_get_pkginfo(data.pkgid, &handle);
925 printf("Failed to get handle\n");
928 ret = pkgmgr_appinfo_get_list(handle, PM_UI_APP, __app_list_cb, NULL);
930 printf("pkgmgr_appinfo_get_list() failed\n");
931 pkgmgr_pkginfo_destroy_pkginfo(handle);
934 ret = pkgmgr_appinfo_get_list(handle, PM_SVC_APP, __app_list_cb, NULL);
936 printf("pkgmgr_appinfo_get_list() failed\n");
937 pkgmgr_pkginfo_destroy_pkginfo(handle);
940 pkgmgr_pkginfo_destroy_pkginfo(handle);
945 if (data.pkg_type[0] == '\0') {
946 ret = pkgmgr_pkginfo_get_list(__pkgmgr_list_cb, NULL);
948 printf("Failed to get package list\n");
953 pkgmgrinfo_pkginfo_filter_h handle;
954 ret = pkgmgrinfo_pkginfo_filter_create(&handle);
956 printf("Failed to get package filter handle\n");
959 ret = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_TYPE, data.pkg_type);
961 printf("Failed to add package type filter\n");
962 pkgmgrinfo_pkginfo_filter_destroy(handle);
965 ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, __pkgmgr_list_cb, NULL);
967 printf("Failed to get package filter list\n");
968 pkgmgrinfo_pkginfo_filter_destroy(handle);
971 pkgmgrinfo_pkginfo_filter_destroy(handle);
976 if (data.pkgid[0] != '\0') {
977 pkgmgr_info *pkg_info =
978 pkgmgr_info_new(data.pkg_type, data.pkgid);
979 if (pkg_info == NULL) {
980 printf("Failed to get pkginfo handle\n");
984 __print_pkg_info(pkg_info);
985 ret = pkgmgr_info_free(pkg_info);
988 if (data.pkg_path[0] != '\0') {
989 pkgmgr_info *pkg_info =
990 pkgmgr_info_new_from_file(data.pkg_type,
992 if (pkg_info == NULL) {
993 printf("Failed to get pkginfo handle\n");
997 __print_pkg_info(pkg_info);
998 ret = pkgmgr_info_free(pkg_info);
1001 printf("Either pkgid or pkgpath should be supplied\n");
1011 printf("Wrong Request\n");
1017 pkgmgr_client_free(pc);
1023 static int __is_authorized()
1025 /* pkgcmd needs root or developer privileges.
1026 If launched via fork/exec, the launching program
1027 must be running as root */
1029 uid_t uid = getuid();
1030 if ((uid_t) 0 == uid || (uid_t) 5100 == uid)
1036 int main(int argc, char *argv[])
1042 char *errstr = NULL;
1047 if (!__is_authorized()) {
1048 printf("You are not an authorized user!\n");
1049 return PKGCMD_ERR_FATAL_ERROR;
1055 gettimeofday(&tv, NULL);
1056 starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
1059 memset(data.des_path, '\0', PKG_NAME_STRING_LEN_MAX);
1060 memset(data.pkg_path, '\0', PKG_NAME_STRING_LEN_MAX);
1061 memset(data.pkgid, '\0', PKG_NAME_STRING_LEN_MAX);
1062 memset(data.pkg_type, '\0', PKG_TYPE_STRING_LEN_MAX);
1063 memset(data.label, '\0', PKG_TYPE_STRING_LEN_MAX);
1066 data.move_type = -1;
1068 c = getopt_long(argc, argv, short_options, long_options,
1071 break; /* Parse end */
1073 case 'i': /* install */
1074 data.request = INSTALL_REQ;
1077 case 'u': /* uninstall */
1078 data.request = UNINSTALL_REQ;
1081 case 'r': /* reinstall */
1082 data.request = REINSTALL_REQ;
1085 case 'c': /* clear */
1086 data.request = CLEAR_REQ;
1089 case 'm': /* move */
1090 data.request = MOVE_REQ;
1093 case 'A': /* activate */
1094 data.request = ACTIVATE_REQ;
1097 case 'D': /* deactivate */
1098 data.request = DEACTIVATE_REQ;
1101 case 'L': /* activate with Label */
1102 data.request = ACTIVATE_REQ;
1104 strncpy(data.label, optarg,
1105 PKG_NAME_STRING_LEN_MAX);
1108 case 'a': /* app installation path */
1109 data.request = APPPATH_REQ;
1112 case 'k': /* Terminate applications of a package */
1113 data.request = KILLAPP_REQ;
1116 case 'C': /* Check running status of applications of a package */
1117 data.request = CHECKAPP_REQ;
1120 case 'l': /* list */
1121 data.request = LIST_REQ;
1124 case 's': /* show */
1125 data.request = SHOW_REQ;
1128 case 'p': /* package path */
1130 strncpy(data.pkg_path, optarg,
1131 PKG_NAME_STRING_LEN_MAX);
1132 ret = __convert_to_absolute_path(data.pkg_path);
1134 printf("conversion of relative path to absolute path failed\n");
1137 printf("package path is %s\n", data.pkg_path);
1140 case 'd': /* descriptor path */
1142 strncpy(data.des_path, optarg,
1143 PKG_NAME_STRING_LEN_MAX);
1146 case 'n': /* package name */
1148 strncpy(data.pkgid, optarg,
1149 PKG_NAME_STRING_LEN_MAX);
1152 case 't': /* package type */
1154 strncpy(data.pkg_type, optarg,
1155 PKG_TYPE_STRING_LEN_MAX);
1158 case 'T': /* move type */
1159 data.move_type = atoi(optarg);
1162 case 'h': /* help */
1163 data.request = HELP_REQ;
1166 case 'q': /* quiet mode */
1171 case '?': /* Not an option */
1183 ret = __process_request();
1185 data.result = PKGCMD_ERR_ARGUMENT_INVALID;
1188 __error_no_to_string(data.result, &errstr);
1189 printf("processing result : %s [%d] failed\n", errstr, data.result);
1191 if (data.request == INSTALL_REQ)
1196 gettimeofday(&tv, NULL);
1197 endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
1198 printf("spend time for pkgcmd is [%d]ms\n", (int)(endtime - starttime));