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:S: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 {"csc", 1, NULL, 'S'},
132 {"quiet", 0, NULL, 'q'},
133 {"help", 0, NULL, 'h'},
134 {0, 0, 0, 0} /* sentinel */
137 enum pm_tool_request_e {
153 typedef enum pm_tool_request_e req_type;
155 struct pm_tool_args_t {
157 char pkg_path[PKG_NAME_STRING_LEN_MAX];
158 char pkg_type[PKG_TYPE_STRING_LEN_MAX];
159 char pkgid[PKG_NAME_STRING_LEN_MAX];
160 char des_path[PKG_NAME_STRING_LEN_MAX];
161 char label[PKG_NAME_STRING_LEN_MAX];
166 typedef struct pm_tool_args_t pm_tool_args;
169 static GMainLoop *main_loop = NULL;
171 static void __error_no_to_string(int errnumber, char **errstr)
176 case PKGCMD_ERR_PACKAGE_NOT_FOUND:
177 *errstr = PKGCMD_ERR_PACKAGE_NOT_FOUND_STR;
179 case PKGCMD_ERR_PACKAGE_INVALID:
180 *errstr = PKGCMD_ERR_PACKAGE_INVALID_STR;
182 case PKGCMD_ERR_PACKAGE_LOWER_VERSION:
183 *errstr = PKGCMD_ERR_PACKAGE_LOWER_VERSION_STR;
185 case PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND:
186 *errstr = PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND_STR;
188 case PKGCMD_ERR_MANIFEST_INVALID:
189 *errstr = PKGCMD_ERR_MANIFEST_INVALID_STR;
191 case PKGCMD_ERR_CONFIG_NOT_FOUND:
192 *errstr = PKGCMD_ERR_CONFIG_NOT_FOUND_STR;
194 case PKGCMD_ERR_CONFIG_INVALID:
195 *errstr = PKGCMD_ERR_CONFIG_INVALID_STR;
197 case PKGCMD_ERR_SIGNATURE_NOT_FOUND:
198 *errstr = PKGCMD_ERR_SIGNATURE_NOT_FOUND_STR;
200 case PKGCMD_ERR_SIGNATURE_INVALID:
201 *errstr = PKGCMD_ERR_SIGNATURE_INVALID_STR;
203 case PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED:
204 *errstr = PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED_STR;
206 case PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND:
207 *errstr = PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND_STR;
209 case PKGCMD_ERR_CERTIFICATE_INVALID:
210 *errstr = PKGCMD_ERR_CERTIFICATE_INVALID_STR;
212 case PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED:
213 *errstr = PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED_STR;
215 case PKGCMD_ERR_CERTIFICATE_EXPIRED:
216 *errstr = PKGCMD_ERR_CERTIFICATE_EXPIRED_STR;
218 case PKGCMD_ERR_INVALID_PRIVILEGE:
219 *errstr = PKGCMD_ERR_INVALID_PRIVILEGE_STR;
221 case PKGCMD_ERR_MENU_ICON_NOT_FOUND:
222 *errstr = PKGCMD_ERR_MENU_ICON_NOT_FOUND_STR;
224 case PKGCMD_ERR_FATAL_ERROR:
225 *errstr = PKGCMD_ERR_FATAL_ERROR_STR;
227 case PKGCMD_ERR_OUT_OF_STORAGE:
228 *errstr = PKGCMD_ERR_OUT_OF_STORAGE_STR;
230 case PKGCMD_ERR_OUT_OF_MEMORY:
231 *errstr = PKGCMD_ERR_OUT_OF_MEMORY_STR;
233 case PKGCMD_ERR_ARGUMENT_INVALID:
234 *errstr = PKGCMD_ERR_ARGUMENT_INVALID_STR;
237 *errstr = PKGCMD_ERR_UNKNOWN_STR;
242 static int __return_cb(int req_id, const char *pkg_type,
243 const char *pkgid, const char *key, const char *val,
244 const void *pmsg, void *priv_data)
246 if (strncmp(key, "error", strlen("error")) == 0) {
250 char *extra_str = NULL;
251 char *ret_result = NULL;
254 __error_no_to_string(ret_val, &errstr);
255 data.result = ret_val;
257 ret_result = strtok(val, delims);
258 ret_result = strtok(NULL, delims);
260 extra_str = strdup(ret_result);
261 printf("__return_cb req_id[%d] pkg_type[%s] pkgid[%s] key[%s] val[%d] error message: %s:%s\n",
262 req_id, pkg_type, pkgid, key, ret_val, errstr, extra_str);
266 printf("__return_cb req_id[%d] pkg_type[%s] pkgid[%s] key[%s] val[%d] error message: %s\n",
267 req_id, pkg_type, pkgid, key, ret_val, errstr);
269 printf("__return_cb req_id[%d] pkg_type[%s] "
270 "pkgid[%s] key[%s] val[%s]\n",
271 req_id, pkg_type, pkgid, key, val);
273 if (strncmp(key, "end", strlen("end")) == 0) {
274 if ((strncmp(val, "fail", strlen("fail")) == 0) && data.result == 0){
275 data.result = PKGCMD_ERR_FATAL_ERROR;
277 g_main_loop_quit(main_loop);
283 static int __pkgcmd_read_proc(const char *path, char *buf, int size)
287 if (buf == NULL || path == NULL)
289 fd = open(path, O_RDONLY);
292 ret = read(fd, buf, size - 1);
302 static int __pkgcmd_find_pid_by_cmdline(const char *dname,
303 const char *cmdline, const char *apppath)
307 if (strcmp(cmdline, apppath) == 0) {
309 if (pid != getpgid(pid))
315 static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option)
318 struct dirent *dentry;
321 char buf[1024] = {'\0'};
324 dp = opendir("/proc");
329 while ((dentry = readdir(dp)) != NULL) {
330 if (!isdigit(dentry->d_name[0]))
333 snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry->d_name);
334 ret = __pkgcmd_read_proc(buf, buf, sizeof(buf));
338 pid = __pkgcmd_find_pid_by_cmdline(dentry->d_name, buf, apppath);
349 if (killpg(pgid, SIGKILL) < 0) {
361 static int __app_list_cb(const pkgmgr_appinfo_h handle, void *user_data)
367 if (handle == NULL) {
368 printf("appinfo handle is NULL\n");
371 ret = pkgmgr_appinfo_get_exec(handle, &exec);
373 printf("Failed to get app exec path\n");
376 ret = pkgmgr_appinfo_get_appid(handle, &appid);
378 printf("Failed to get appid\n");
381 /*option 0 to check and option 1 to kill*/
382 switch(data.request) {
384 pid = __pkgcmd_proc_iter_kill_cmdline(exec, 0);
386 printf("Appid: %s is Running\n", appid);
388 printf("Appid: %s is Not Running\n", appid);
392 pid = __pkgcmd_proc_iter_kill_cmdline(exec, 1);
394 printf("Appid: %s is Terminated\n", appid);
402 static int __convert_to_absolute_path(char *path)
404 char abs[PKG_NAME_STRING_LEN_MAX] = {'\0'};
405 char temp[PKG_NAME_STRING_LEN_MAX] = {'\0'};
408 printf("path is NULL\n");
411 strncpy(temp, path, PKG_NAME_STRING_LEN_MAX - 1);
412 if (strchr(path, '/') == NULL) {
413 getcwd(abs, PKG_NAME_STRING_LEN_MAX - 1);
414 if (abs[0] == '\0') {
415 printf("getcwd() failed\n");
418 memset(data.pkg_path, '\0', PKG_NAME_STRING_LEN_MAX);
419 snprintf(data.pkg_path, PKG_NAME_STRING_LEN_MAX - 1, "%s/%s", abs, temp);
422 if (strncmp(path, "./", 2) == 0) {
424 getcwd(abs, PKG_NAME_STRING_LEN_MAX - 1);
425 if (abs[0] == '\0') {
426 printf("getcwd() failed\n");
430 memset(data.pkg_path, '\0', PKG_NAME_STRING_LEN_MAX);
431 snprintf(data.pkg_path, PKG_NAME_STRING_LEN_MAX - 1, "%s/%s", abs, ptr);
437 static int __is_app_installed(char *pkgid)
440 ail_appinfo_h handle;
443 ret = ail_package_get_appinfo(pkgid, &handle);
444 if (ret != AIL_ERROR_OK) {
447 ret = ail_appinfo_get_str(handle, AIL_PROP_NAME_STR, &str);
448 if (ret != AIL_ERROR_OK) {
451 ret = ail_package_destroy_appinfo(handle);
452 if (ret != AIL_ERROR_OK) {
456 pkgmgr_pkginfo_h handle;
457 int ret = pkgmgr_pkginfo_get_pkginfo(pkgid, &handle);
459 printf("package is not in pkgmgr_info DB\n");
462 pkgmgr_pkginfo_destroy_pkginfo(handle);
468 static void __print_usage()
470 printf("\nPackage Manager Tool Version: %s\n\n", PKG_TOOL_VERSION);
471 printf("-i, --install install the package\n");
472 printf("-u, --uninstall uninstall the package\n");
473 printf("-r, --reinstall reinstall the package\n");
474 printf("-c, --clear clear user data\n");
475 printf("-m, --move move package\n");
476 printf("-l, --list display list of installed packages\n");
477 printf("-s, --show show detail package info\n");
478 printf("-a, --app-path show app installation path\n");
479 printf("-C, --check check if applications belonging to a package are running or not\n");
480 printf("-k, --kill terminate applications belonging to a package\n");
481 printf("-d, --descriptor provide descriptor path\n");
482 printf("-p, --package-path provide package path\n");
483 printf("-n, --package-name provide package name\n");
484 printf("-t, --package-type provide package type\n");
485 printf("-T, --move-type provide move type [0 : move to internal /1: move to external]\n");
486 printf("-q, --quiet quiet mode operation\n");
487 printf("-h, --help print this help\n\n");
489 printf("Usage: pkgcmd [options] (--quiet)\n");
490 printf("pkgcmd -i -t <pkg type> (-d <descriptor path>) -p <pkg path> (-q)\n");
491 printf("pkgcmd -u -t <pkg type> -n <pkgid> (-q)\n");
492 printf("pkgcmd -r -t <pkg type> -n <pkgid> \n");
493 printf("pkgcmd -l (-t <pkg type>) \n");
494 printf("pkgcmd -s -t <pkg type> -p <pkg path> (-q)\n");
495 printf("pkgcmd -s -t <pkg type> -n <pkg name> (-q)\n");
496 printf("pkgcmd -m -t <pkg type> -T <move type> -n <pkg name> (-q)\n\n");
498 printf("Example:\n");
499 printf("pkgcmd -u -t rpm -n org.tizen.calculator\n");
500 printf("pkgcmd -i -t rpm -p /mnt/nfs/org.tizen.calculator_0.1.2-95_armel.rpm\n");
501 printf("pkgcmd -r -t rpm -p org.tizen.calculator\n");
502 printf("pkgcmd -c -t rpm -n org.tizen.hello\n");
503 printf("pkgcmd -m -t rpm -T 1 -n org.tizen.hello\n");
504 printf("pkgcmd -C -t rpm -n org.tizen.hello\n");
505 printf("pkgcmd -k -t rpm -n org.tizen.hello\n");
506 printf("pkgcmd -a\n");
507 printf("pkgcmd -a -t rpm -n org.tizen.hello\n");
508 printf("pkgcmd -l\n");
509 printf("pkgcmd -l -t tpk\n");
515 static void __print_pkg_info(pkgmgr_info *pkg_info)
519 temp = pkgmgr_info_get_string(pkg_info, "pkg_type");
521 printf("pkg_type : %s\n", temp);
525 temp = pkgmgr_info_get_string(pkg_info, "pkgid");
527 printf("pkgid : %s\n", temp);
531 temp = pkgmgr_info_get_string(pkg_info, "version");
533 printf("version : %s\n", temp);
537 temp = pkgmgr_info_get_string(pkg_info, "pkg_vendor");
539 printf("pkg_vendor : %s\n", temp);
543 temp = pkgmgr_info_get_string(pkg_info, "pkg_description");
545 printf("pkg_description : %s\n", temp);
549 temp = pkgmgr_info_get_string(pkg_info, "pkg_mimetype");
551 printf("pkg_mimetype : %s\n", temp);
555 temp = pkgmgr_info_get_string(pkg_info, "pkg_installed_path_package");
557 printf("pkg_installed_path_package : %s\n", temp);
562 pkgmgr_info_get_string(pkg_info, "pkg_installed_path_descriptor");
564 printf("pkg_installed_path_descriptor : %s\n", temp);
568 temp = pkgmgr_info_get_string(pkg_info, "category");
570 printf("category : %s\n", temp);
574 temp = pkgmgr_info_get_string(pkg_info, "min_platform_version");
576 printf("min_platform_version : %s\n", temp);
580 temp = pkgmgr_info_get_string(pkg_info, "visible");
582 printf("visible : %s\n", temp);
586 temp = pkgmgr_info_get_string(pkg_info, "removable");
588 printf("removable : %s\n", temp);
592 temp = pkgmgr_info_get_string(pkg_info, "installed_size");
594 printf("installed_size : %s\n", temp);
598 temp = pkgmgr_info_get_string(pkg_info, "installed_time");
600 printf("installed_time : %s\n", temp);
604 temp = pkgmgr_info_get_string(pkg_info, "data_size");
606 printf("data_size : %s\n", temp);
610 temp = pkgmgr_info_get_string(pkg_info, "optional_id");
612 printf("optional_id : %s\n", temp);
617 static int __pkgmgr_list_cb (const pkgmgr_pkginfo_h handle, void *user_data)
621 char *pkg_type = NULL;
622 char *pkg_version = NULL;
623 char *pkg_label = NULL;
625 ret = pkgmgr_pkginfo_get_pkgid(handle, &pkgid);
627 printf("Failed to get pkgmgr_pkginfo_get_pkgid\n");
630 ret = pkgmgr_pkginfo_get_type(handle, &pkg_type);
632 printf("Failed to get pkgmgr_pkginfo_get_type\n");
635 ret = pkgmgr_pkginfo_get_version(handle, &pkg_version);
637 printf("Failed to get pkgmgr_pkginfo_get_version\n");
640 ret = pkgmgr_pkginfo_get_label(handle, &pkg_label);
642 printf("Failed to get pkgmgr_pkginfo_get_label\n");
646 printf("pkg_type [%s]\tpkgid [%s]\tname [%s]\tversion [%s]\n", pkg_type, pkgid, pkg_label, pkg_version);
651 static int __process_request()
654 int mode = PM_DEFAULT;
655 pkgmgr_client *pc = NULL;
656 char buf[1024] = {'\0'};
657 switch (data.request) {
659 if (data.pkg_type[0] == '\0' || data.pkg_path[0] == '\0') {
660 printf("Please provide the arguments.\n");
661 printf("use -h option to see usage\n");
662 data.result = PKGCMD_ERR_ARGUMENT_INVALID;
666 main_loop = g_main_loop_new(NULL, FALSE);
667 pc = pkgmgr_client_new(PC_REQUEST);
669 printf("PkgMgr Client Creation Failed\n");
670 data.result = PKGCMD_ERR_FATAL_ERROR;
677 if (data.des_path[0] == '\0')
679 pkgmgr_client_install(pc, data.pkg_type, NULL,
680 data.pkg_path, NULL, mode,
684 pkgmgr_client_install(pc, data.pkg_type,
685 data.des_path, data.pkg_path,
686 NULL, mode, __return_cb, pc);
688 data.result = PKGCMD_ERR_FATAL_ERROR;
689 if (access(data.pkg_path, F_OK) != 0)
690 data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
693 g_main_loop_run(main_loop);
698 if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
699 printf("Please provide the arguments.\n");
700 printf("use -h option to see usage\n");
701 data.result = PKGCMD_ERR_ARGUMENT_INVALID;
705 main_loop = g_main_loop_new(NULL, FALSE);
706 pc = pkgmgr_client_new(PC_REQUEST);
708 printf("PkgMgr Client Creation Failed\n");
709 data.result = PKGCMD_ERR_FATAL_ERROR;
717 ret = __is_app_installed(data.pkgid);
719 printf("package is not installed\n");
724 pkgmgr_client_uninstall(pc, data.pkg_type, data.pkgid,
725 mode, __return_cb, NULL);
727 data.result = PKGCMD_ERR_FATAL_ERROR;
728 if (access(data.pkg_path, F_OK) != 0)
729 data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
732 g_main_loop_run(main_loop);
737 if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
738 printf("Please provide the arguments.\n");
739 printf("use -h option to see usage\n");
740 data.result = PKGCMD_ERR_ARGUMENT_INVALID;
744 main_loop = g_main_loop_new(NULL, FALSE);
745 pc = pkgmgr_client_new(PC_REQUEST);
747 printf("PkgMgr Client Creation Failed\n");
748 data.result = PKGCMD_ERR_FATAL_ERROR;
753 ret = pkgmgr_client_reinstall(pc, data.pkg_type, data.pkgid, NULL, mode, __return_cb, pc);
755 data.result = PKGCMD_ERR_FATAL_ERROR;
756 if (access(data.pkg_path, F_OK) != 0)
757 data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
760 g_main_loop_run(main_loop);
765 if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
766 printf("Please provide the arguments.\n");
767 printf("use -h option to see usage\n");
772 pc = pkgmgr_client_new(PC_REQUEST);
774 printf("PkgMgr Client Creation Failed\n");
782 ret = __is_app_installed(data.pkgid);
784 printf("package is not installed\n");
787 ret = pkgmgr_client_clear_user_data(pc, data.pkg_type,
795 if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
796 printf("Please provide the arguments.\n");
797 printf("use -h option to see usage\n");
802 pc = pkgmgr_client_new(PC_REQUEST);
804 printf("PkgMgr Client Creation Failed\n");
809 if ( strcmp(data.pkg_type, "app") == 0 ) {
810 if (strlen(data.label) == 0) {
811 ret = pkgmgr_client_activate_app(pc, data.pkgid);
815 printf("label [%s]\n", data.label);
816 char *largv[3] = {NULL, };
818 largv[1] = data.label;
819 ret = pkgmgr_client_activate_appv(pc, data.pkgid, largv);
824 ret = pkgmgr_client_activate(pc, data.pkg_type, data.pkgid);
834 if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
835 printf("Please provide the arguments.\n");
836 printf("use -h option to see usage\n");
841 pc = pkgmgr_client_new(PC_REQUEST);
843 printf("PkgMgr Client Creation Failed\n");
848 if ( strcmp(data.pkg_type, "app") == 0 ) {
849 ret = pkgmgr_client_deactivate_app(pc, data.pkgid);
853 ret = pkgmgr_client_deactivate(pc, data.pkg_type, data.pkgid);
862 if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
863 printf("Please provide the arguments.\n");
864 printf("use -h option to see usage\n");
868 if (data.move_type < 0 || data.move_type > 1) {
869 printf("Invalid move type...See usage\n");
873 pc = pkgmgr_client_new(PC_REQUEST);
875 printf("PkgMgr Client Creation Failed\n");
883 ret = __is_app_installed(data.pkgid);
885 printf("package is not installed\n");
888 ret = pkgmgr_client_move(pc, data.pkg_type, data.pkgid, data.move_type, mode);
895 if (data.pkg_type[0] == '\0' && data.pkgid[0] == '\0') {
896 printf("Tizen Application Installation Path: %s\n", APP_INSTALLATION_PATH_RW);
900 if ((data.pkg_type[0] == '\0') || (data.pkgid[0] == '\0')) {
901 printf("Use -h option to see usage\n");
905 if (strncmp(data.pkg_type, "rpm", PKG_TYPE_STRING_LEN_MAX - 1) == 0) {
906 snprintf(buf, 1023, "%s/%s", APP_INSTALLATION_PATH_RW, data.pkgid);
907 printf("Tizen Application Installation Path: %s\n", buf);
910 } else if (strncmp(data.pkg_type, "wgt", PKG_TYPE_STRING_LEN_MAX - 1) == 0) {
911 snprintf(buf, 1023, "%s/%s/res/wgt", APP_INSTALLATION_PATH_RW, data.pkgid);
912 printf("Tizen Application Installation Path: %s\n", buf);
915 } else if (strncmp(data.pkg_type, "tpk", PKG_TYPE_STRING_LEN_MAX - 1) == 0) {
916 snprintf(buf, 1023, "%s/%s", APP_INSTALLATION_PATH_RW, data.pkgid);
917 printf("Tizen Application Installation Path: %s\n", buf);
921 printf("Invalid package type.\n");
922 printf("use -h option to see usage\n");
930 if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
931 printf("Please provide the arguments.\n");
932 printf("use -h option to see usage\n");
936 pkgmgr_pkginfo_h handle;
937 ret = pkgmgr_pkginfo_get_pkginfo(data.pkgid, &handle);
939 printf("Failed to get handle\n");
940 data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
943 ret = pkgmgr_appinfo_get_list(handle, PM_UI_APP, __app_list_cb, NULL);
945 printf("pkgmgr_appinfo_get_list() failed\n");
946 pkgmgr_pkginfo_destroy_pkginfo(handle);
947 data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
950 ret = pkgmgr_appinfo_get_list(handle, PM_SVC_APP, __app_list_cb, NULL);
952 printf("pkgmgr_appinfo_get_list() failed\n");
953 pkgmgr_pkginfo_destroy_pkginfo(handle);
954 data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
957 pkgmgr_pkginfo_destroy_pkginfo(handle);
962 if (data.pkg_type[0] == '\0') {
963 ret = pkgmgr_pkginfo_get_list(__pkgmgr_list_cb, NULL);
965 printf("Failed to get package list\n");
970 pkgmgrinfo_pkginfo_filter_h handle;
971 ret = pkgmgrinfo_pkginfo_filter_create(&handle);
973 printf("Failed to get package filter handle\n");
976 ret = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_TYPE, data.pkg_type);
978 printf("Failed to add package type filter\n");
979 pkgmgrinfo_pkginfo_filter_destroy(handle);
982 ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, __pkgmgr_list_cb, NULL);
984 printf("Failed to get package filter list\n");
985 pkgmgrinfo_pkginfo_filter_destroy(handle);
988 pkgmgrinfo_pkginfo_filter_destroy(handle);
993 if (data.pkgid[0] != '\0') {
994 pkgmgr_info *pkg_info =
995 pkgmgr_info_new(data.pkg_type, data.pkgid);
996 if (pkg_info == NULL) {
997 printf("Failed to get pkginfo handle\n");
1001 __print_pkg_info(pkg_info);
1002 ret = pkgmgr_info_free(pkg_info);
1005 if (data.pkg_path[0] != '\0') {
1006 pkgmgr_info *pkg_info =
1007 pkgmgr_info_new_from_file(data.pkg_type,
1009 if (pkg_info == NULL) {
1010 printf("Failed to get pkginfo handle\n");
1014 __print_pkg_info(pkg_info);
1015 ret = pkgmgr_info_free(pkg_info);
1018 printf("Either pkgid or pkgpath should be supplied\n");
1023 ret = pkgmgr_client_request_service(PM_REQUEST_CSC, NULL, NULL, NULL, data.des_path, NULL, NULL, (void *)data.pkg_path);
1025 data.result = PKGCMD_ERR_FATAL_ERROR;
1034 printf("Wrong Request\n");
1040 pkgmgr_client_free(pc);
1046 static int __is_authorized()
1048 /* pkgcmd needs root or developer privileges.
1049 If launched via fork/exec, the launching program
1050 must be running as root */
1052 uid_t uid = getuid();
1053 if ((uid_t) 0 == uid || (uid_t) 5100 == uid)
1059 int main(int argc, char *argv[])
1065 char *errstr = NULL;
1070 if (!__is_authorized()) {
1071 printf("You are not an authorized user!\n");
1072 return PKGCMD_ERR_FATAL_ERROR;
1078 gettimeofday(&tv, NULL);
1079 starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
1082 memset(data.des_path, '\0', PKG_NAME_STRING_LEN_MAX);
1083 memset(data.pkg_path, '\0', PKG_NAME_STRING_LEN_MAX);
1084 memset(data.pkgid, '\0', PKG_NAME_STRING_LEN_MAX);
1085 memset(data.pkg_type, '\0', PKG_TYPE_STRING_LEN_MAX);
1086 memset(data.label, '\0', PKG_TYPE_STRING_LEN_MAX);
1089 data.move_type = -1;
1091 c = getopt_long(argc, argv, short_options, long_options,
1094 break; /* Parse end */
1096 case 'i': /* install */
1097 data.request = INSTALL_REQ;
1100 case 'u': /* uninstall */
1101 data.request = UNINSTALL_REQ;
1104 case 'r': /* reinstall */
1105 data.request = REINSTALL_REQ;
1108 case 'c': /* clear */
1109 data.request = CLEAR_REQ;
1112 case 'm': /* move */
1113 data.request = MOVE_REQ;
1116 case 'S': /* csc packages */
1117 data.request = CSC_REQ;
1119 strncpy(data.des_path, optarg, PKG_NAME_STRING_LEN_MAX);
1120 printf("csc file is %s\n", data.des_path);
1123 case 'A': /* activate */
1124 data.request = ACTIVATE_REQ;
1127 case 'D': /* deactivate */
1128 data.request = DEACTIVATE_REQ;
1131 case 'L': /* activate with Label */
1132 data.request = ACTIVATE_REQ;
1134 strncpy(data.label, optarg,
1135 PKG_NAME_STRING_LEN_MAX);
1138 case 'a': /* app installation path */
1139 data.request = APPPATH_REQ;
1142 case 'k': /* Terminate applications of a package */
1143 data.request = KILLAPP_REQ;
1146 case 'C': /* Check running status of applications of a package */
1147 data.request = CHECKAPP_REQ;
1150 case 'l': /* list */
1151 data.request = LIST_REQ;
1154 case 's': /* show */
1155 data.request = SHOW_REQ;
1158 case 'p': /* package path */
1160 strncpy(data.pkg_path, optarg,
1161 PKG_NAME_STRING_LEN_MAX);
1162 ret = __convert_to_absolute_path(data.pkg_path);
1164 printf("conversion of relative path to absolute path failed\n");
1167 printf("path is %s\n", data.pkg_path);
1170 case 'd': /* descriptor path */
1172 strncpy(data.des_path, optarg,
1173 PKG_NAME_STRING_LEN_MAX);
1176 case 'n': /* package name */
1178 strncpy(data.pkgid, optarg,
1179 PKG_NAME_STRING_LEN_MAX);
1182 case 't': /* package type */
1184 strncpy(data.pkg_type, optarg,
1185 PKG_TYPE_STRING_LEN_MAX);
1188 case 'T': /* move type */
1189 data.move_type = atoi(optarg);
1192 case 'h': /* help */
1193 data.request = HELP_REQ;
1196 case 'q': /* quiet mode */
1201 case '?': /* Not an option */
1213 ret = __process_request();
1214 if ((ret == -1) && (data.result != 0))
1215 data.result = PKGCMD_ERR_ARGUMENT_INVALID;
1218 __error_no_to_string(data.result, &errstr);
1219 printf("processing result : %s [%d] failed\n", errstr, data.result);
1221 if (data.request == INSTALL_REQ)
1226 gettimeofday(&tv, NULL);
1227 endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
1228 printf("spend time for pkgcmd is [%d]ms\n", (int)(endtime - starttime));