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 static int __process_request();
47 static void __print_usage();
48 static int __is_authorized();
49 static int __is_app_installed(char *pkgid);
50 static void __print_pkg_info(pkgmgr_info * pkg_info);
51 static int __return_cb(int req_id, const char *pkg_type, const char *pkgid,
52 const char *key, const char *val, const void *pmsg,
54 static int __convert_to_absolute_path(char *path);
55 static int __pkgcmd_read_proc(const char *path, char *buf, int size);
56 static int __pkgcmd_find_pid_by_cmdline(const char *dname,
57 const char *cmdline, const char *apppath);
58 static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option);
59 static int __app_list_cb(const pkgmgr_appinfo_h handle, void *user_data);
61 /* Supported options */
62 const char *short_options = "iurmcgCkaADL:lsd:p:t:n:T:S:qh";
63 const struct option long_options[] = {
64 {"install", 0, NULL, 'i'},
65 {"uninstall", 0, NULL, 'u'},
66 {"reinstall", 0, NULL, 'r'},
67 {"move", 0, NULL, 'm'},
68 {"clear", 0, NULL, 'c'},
69 {"getsize", 0, NULL, 'g'},
70 {"activate", 0, NULL, 'A'},
71 {"deactivate", 0, NULL, 'D'},
72 {"activate with Label", 1, NULL, 'L'},
73 {"check", 0, NULL, 'C'},
74 {"kill", 0, NULL, 'k'},
75 {"app-path", 0, NULL, 'a'},
76 {"list", 0, NULL, 'l'},
77 {"show", 0, NULL, 's'},
78 {"descriptor", 1, NULL, 'd'},
79 {"package-path", 1, NULL, 'p'},
80 {"package-type", 1, NULL, 't'},
81 {"package-name", 1, NULL, 'n'},
82 {"move-type", 1, NULL, 'T'},
83 {"getsize-type", 1, NULL, 'T'},
84 {"csc", 1, NULL, 'S'},
85 {"quiet", 0, NULL, 'q'},
86 {"help", 0, NULL, 'h'},
87 {0, 0, 0, 0} /* sentinel */
90 enum pm_tool_request_e {
107 typedef enum pm_tool_request_e req_type;
109 struct pm_tool_args_t {
111 char pkg_path[PKG_NAME_STRING_LEN_MAX];
112 char pkg_type[PKG_TYPE_STRING_LEN_MAX];
113 char pkgid[PKG_NAME_STRING_LEN_MAX];
114 char des_path[PKG_NAME_STRING_LEN_MAX];
115 char label[PKG_NAME_STRING_LEN_MAX];
120 typedef struct pm_tool_args_t pm_tool_args;
123 static GMainLoop *main_loop = NULL;
125 static void __error_no_to_string(int errnumber, char **errstr)
130 case PKGCMD_ERR_PACKAGE_NOT_FOUND:
131 *errstr = PKGCMD_ERR_PACKAGE_NOT_FOUND_STR;
133 case PKGCMD_ERR_PACKAGE_INVALID:
134 *errstr = PKGCMD_ERR_PACKAGE_INVALID_STR;
136 case PKGCMD_ERR_PACKAGE_LOWER_VERSION:
137 *errstr = PKGCMD_ERR_PACKAGE_LOWER_VERSION_STR;
139 case PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND:
140 *errstr = PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND_STR;
142 case PKGCMD_ERR_MANIFEST_INVALID:
143 *errstr = PKGCMD_ERR_MANIFEST_INVALID_STR;
145 case PKGCMD_ERR_CONFIG_NOT_FOUND:
146 *errstr = PKGCMD_ERR_CONFIG_NOT_FOUND_STR;
148 case PKGCMD_ERR_CONFIG_INVALID:
149 *errstr = PKGCMD_ERR_CONFIG_INVALID_STR;
151 case PKGCMD_ERR_SIGNATURE_NOT_FOUND:
152 *errstr = PKGCMD_ERR_SIGNATURE_NOT_FOUND_STR;
154 case PKGCMD_ERR_SIGNATURE_INVALID:
155 *errstr = PKGCMD_ERR_SIGNATURE_INVALID_STR;
157 case PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED:
158 *errstr = PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED_STR;
160 case PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND:
161 *errstr = PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND_STR;
163 case PKGCMD_ERR_CERTIFICATE_INVALID:
164 *errstr = PKGCMD_ERR_CERTIFICATE_INVALID_STR;
166 case PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED:
167 *errstr = PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED_STR;
169 case PKGCMD_ERR_CERTIFICATE_EXPIRED:
170 *errstr = PKGCMD_ERR_CERTIFICATE_EXPIRED_STR;
172 case PKGCMD_ERR_INVALID_PRIVILEGE:
173 *errstr = PKGCMD_ERR_INVALID_PRIVILEGE_STR;
175 case PKGCMD_ERR_MENU_ICON_NOT_FOUND:
176 *errstr = PKGCMD_ERR_MENU_ICON_NOT_FOUND_STR;
178 case PKGCMD_ERR_FATAL_ERROR:
179 *errstr = PKGCMD_ERR_FATAL_ERROR_STR;
181 case PKGCMD_ERR_OUT_OF_STORAGE:
182 *errstr = PKGCMD_ERR_OUT_OF_STORAGE_STR;
184 case PKGCMD_ERR_OUT_OF_MEMORY:
185 *errstr = PKGCMD_ERR_OUT_OF_MEMORY_STR;
187 case PKGCMD_ERR_ARGUMENT_INVALID:
188 *errstr = PKGCMD_ERR_ARGUMENT_INVALID_STR;
191 *errstr = PKGCMD_ERR_UNKNOWN_STR;
196 static int __return_cb(int req_id, const char *pkg_type,
197 const char *pkgid, const char *key, const char *val,
198 const void *pmsg, void *priv_data)
200 if (strncmp(key, "error", strlen("error")) == 0) {
203 char *extra_str = NULL;
204 char *ret_result = NULL;
207 data.result = ret_val;
210 ret_result = strtok(NULL, delims);
212 extra_str = strdup(ret_result);
213 printf("__return_cb req_id[%d] pkg_type[%s] pkgid[%s] key[%s] val[%d] error message: %s\n",
214 req_id, pkg_type, pkgid, key, ret_val, extra_str);
218 printf("__return_cb req_id[%d] pkg_type[%s] pkgid[%s] key[%s] val[%d]\n",
219 req_id, pkg_type, pkgid, key, ret_val);
221 printf("__return_cb req_id[%d] pkg_type[%s] "
222 "pkgid[%s] key[%s] val[%s]\n",
223 req_id, pkg_type, pkgid, key, val);
225 if (strncmp(key, "end", strlen("end")) == 0) {
226 if ((strncmp(val, "fail", strlen("fail")) == 0) && data.result == 0){
227 data.result = PKGCMD_ERR_FATAL_ERROR;
229 g_main_loop_quit(main_loop);
235 static int __pkgcmd_read_proc(const char *path, char *buf, int size)
239 if (buf == NULL || path == NULL)
241 fd = open(path, O_RDONLY);
244 ret = read(fd, buf, size - 1);
254 static int __pkgcmd_find_pid_by_cmdline(const char *dname,
255 const char *cmdline, const char *apppath)
259 if (strcmp(cmdline, apppath) == 0) {
261 if (pid != getpgid(pid))
267 static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option)
270 struct dirent *dentry;
273 char buf[1024] = {'\0'};
276 dp = opendir("/proc");
281 while ((dentry = readdir(dp)) != NULL) {
282 if (!isdigit(dentry->d_name[0]))
285 snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry->d_name);
286 ret = __pkgcmd_read_proc(buf, buf, sizeof(buf));
290 pid = __pkgcmd_find_pid_by_cmdline(dentry->d_name, buf, apppath);
301 if (killpg(pgid, SIGKILL) < 0) {
313 static int __app_list_cb(const pkgmgr_appinfo_h handle, void *user_data)
319 if (handle == NULL) {
320 printf("appinfo handle is NULL\n");
323 ret = pkgmgr_appinfo_get_exec(handle, &exec);
325 printf("Failed to get app exec path\n");
328 ret = pkgmgr_appinfo_get_appid(handle, &appid);
330 printf("Failed to get appid\n");
333 /*option 0 to check and option 1 to kill*/
334 switch(data.request) {
336 pid = __pkgcmd_proc_iter_kill_cmdline(exec, 0);
338 printf("Appid: %s is Running\n", appid);
340 printf("Appid: %s is Not Running\n", appid);
344 pid = __pkgcmd_proc_iter_kill_cmdline(exec, 1);
346 printf("Appid: %s is Terminated\n", appid);
354 static int __convert_to_absolute_path(char *path)
356 char abs[PKG_NAME_STRING_LEN_MAX] = {'\0'};
357 char temp[PKG_NAME_STRING_LEN_MAX] = {'\0'};
360 printf("path is NULL\n");
363 strncpy(temp, path, PKG_NAME_STRING_LEN_MAX - 1);
364 if (strchr(path, '/') == NULL) {
365 getcwd(abs, PKG_NAME_STRING_LEN_MAX - 1);
366 if (abs[0] == '\0') {
367 printf("getcwd() failed\n");
370 memset(data.pkg_path, '\0', PKG_NAME_STRING_LEN_MAX);
371 snprintf(data.pkg_path, PKG_NAME_STRING_LEN_MAX - 1, "%s/%s", abs, temp);
374 if (strncmp(path, "./", 2) == 0) {
376 getcwd(abs, PKG_NAME_STRING_LEN_MAX - 1);
377 if (abs[0] == '\0') {
378 printf("getcwd() failed\n");
382 memset(data.pkg_path, '\0', PKG_NAME_STRING_LEN_MAX);
383 snprintf(data.pkg_path, PKG_NAME_STRING_LEN_MAX - 1, "%s/%s", abs, ptr);
389 static int __is_app_installed(char *pkgid)
392 ail_appinfo_h handle;
395 ret = ail_package_get_appinfo(pkgid, &handle);
396 if (ret != AIL_ERROR_OK) {
399 ret = ail_appinfo_get_str(handle, AIL_PROP_NAME_STR, &str);
400 if (ret != AIL_ERROR_OK) {
403 ret = ail_package_destroy_appinfo(handle);
404 if (ret != AIL_ERROR_OK) {
408 pkgmgr_pkginfo_h handle;
409 int ret = pkgmgr_pkginfo_get_pkginfo(pkgid, &handle);
411 printf("package is not in pkgmgr_info DB\n");
414 pkgmgr_pkginfo_destroy_pkginfo(handle);
420 static void __print_usage()
422 printf("\nPackage Manager Tool Version: %s\n\n", PKG_TOOL_VERSION);
423 printf("-i, --install install the package\n");
424 printf("-u, --uninstall uninstall the package\n");
425 printf("-r, --reinstall reinstall the package\n");
426 printf("-c, --clear clear user data\n");
427 printf("-m, --move move package\n");
428 printf("-g, --getsize get size of given package\n");
429 printf("-T, --getsize-type get type [0 : total size /1: data size]\n");
430 printf("-l, --list display list of installed packages\n");
431 printf("-s, --show show detail package info\n");
432 printf("-a, --app-path show app installation path\n");
433 printf("-C, --check check if applications belonging to a package are running or not\n");
434 printf("-k, --kill terminate applications belonging to a package\n");
435 printf("-d, --descriptor provide descriptor path\n");
436 printf("-p, --package-path provide package path\n");
437 printf("-n, --package-name provide package name\n");
438 printf("-t, --package-type provide package type\n");
439 printf("-T, --move-type provide move type [0 : move to internal /1: move to external]\n");
440 printf("-q, --quiet quiet mode operation\n");
441 printf("-h, --help print this help\n\n");
443 printf("Usage: pkgcmd [options] (--quiet)\n");
444 printf("pkgcmd -i -t <pkg type> (-d <descriptor path>) -p <pkg path> (-q)\n");
445 printf("pkgcmd -u -n <pkgid> (-q)\n");
446 printf("pkgcmd -r -t <pkg type> -n <pkgid> \n");
447 printf("pkgcmd -l (-t <pkg type>) \n");
448 printf("pkgcmd -s -t <pkg type> -p <pkg path> (-q)\n");
449 printf("pkgcmd -s -t <pkg type> -n <pkg name> (-q)\n");
450 printf("pkgcmd -m -t <pkg type> -T <move type> -n <pkg name> (-q)\n\n");
451 printf("pkgcmd -g -T <getsize type> -n <pkgid> \n");
453 printf("Example:\n");
454 printf("pkgcmd -u -n com.samsung.calculator\n");
455 printf("pkgcmd -i -t rpm -p /mnt/nfs/com.samsung.calculator_0.1.2-95_armel.rpm\n");
456 printf("pkgcmd -r -t rpm -n com.samsung.calculator\n");
457 printf("pkgcmd -c -t rpm -n com.samsung.hello\n");
458 printf("pkgcmd -m -t rpm -T 1 -n com.samsung.hello\n");
459 printf("pkgcmd -C -t rpm -n com.samsung.hello\n");
460 printf("pkgcmd -k -t rpm -n com.samsung.hello\n");
461 printf("pkgcmd -a\n");
462 printf("pkgcmd -a -t rpm -n com.samsung.hello\n");
463 printf("pkgcmd -l\n");
464 printf("pkgcmd -l -t tpk\n");
465 printf("pkgcmd -g -T 0 -n com.samsung.calculator\n");
471 static void __print_pkg_info(pkgmgr_info *pkg_info)
475 temp = pkgmgr_info_get_string(pkg_info, "pkg_type");
477 printf("pkg_type : %s\n", temp);
481 temp = pkgmgr_info_get_string(pkg_info, "pkgid");
483 printf("pkgid : %s\n", temp);
487 temp = pkgmgr_info_get_string(pkg_info, "version");
489 printf("version : %s\n", temp);
493 temp = pkgmgr_info_get_string(pkg_info, "pkg_vendor");
495 printf("pkg_vendor : %s\n", temp);
499 temp = pkgmgr_info_get_string(pkg_info, "pkg_description");
501 printf("pkg_description : %s\n", temp);
505 temp = pkgmgr_info_get_string(pkg_info, "pkg_mimetype");
507 printf("pkg_mimetype : %s\n", temp);
511 temp = pkgmgr_info_get_string(pkg_info, "pkg_installed_path_package");
513 printf("pkg_installed_path_package : %s\n", temp);
518 pkgmgr_info_get_string(pkg_info, "pkg_installed_path_descriptor");
520 printf("pkg_installed_path_descriptor : %s\n", temp);
524 temp = pkgmgr_info_get_string(pkg_info, "category");
526 printf("category : %s\n", temp);
530 temp = pkgmgr_info_get_string(pkg_info, "min_platform_version");
532 printf("min_platform_version : %s\n", temp);
536 temp = pkgmgr_info_get_string(pkg_info, "visible");
538 printf("visible : %s\n", temp);
542 temp = pkgmgr_info_get_string(pkg_info, "removable");
544 printf("removable : %s\n", temp);
548 temp = pkgmgr_info_get_string(pkg_info, "installed_size");
550 printf("installed_size : %s\n", temp);
554 temp = pkgmgr_info_get_string(pkg_info, "installed_time");
556 printf("installed_time : %s\n", temp);
560 temp = pkgmgr_info_get_string(pkg_info, "data_size");
562 printf("data_size : %s\n", temp);
566 temp = pkgmgr_info_get_string(pkg_info, "optional_id");
568 printf("optional_id : %s\n", temp);
573 static int __pkgmgr_list_cb (const pkgmgr_pkginfo_h handle, void *user_data)
577 char *pkg_type = NULL;
578 char *pkg_version = NULL;
579 char *pkg_label = NULL;
581 ret = pkgmgr_pkginfo_get_pkgid(handle, &pkgid);
583 printf("Failed to get pkgmgr_pkginfo_get_pkgid\n");
586 ret = pkgmgr_pkginfo_get_type(handle, &pkg_type);
588 printf("Failed to get pkgmgr_pkginfo_get_type\n");
591 ret = pkgmgr_pkginfo_get_version(handle, &pkg_version);
593 printf("Failed to get pkgmgr_pkginfo_get_version\n");
596 ret = pkgmgr_pkginfo_get_label(handle, &pkg_label);
598 printf("Failed to get pkgmgr_pkginfo_get_label\n");
602 printf("pkg_type [%s]\tpkgid [%s]\tname [%s]\tversion [%s]\n", pkg_type, pkgid, pkg_label, pkg_version);
607 static int __process_request()
610 int mode = PM_DEFAULT;
611 pkgmgr_client *pc = NULL;
612 char buf[1024] = {'\0'};
613 switch (data.request) {
615 if (data.pkg_type[0] == '\0' || data.pkg_path[0] == '\0') {
616 printf("Please provide the arguments.\n");
617 printf("use -h option to see usage\n");
618 data.result = PKGCMD_ERR_ARGUMENT_INVALID;
622 main_loop = g_main_loop_new(NULL, FALSE);
623 pc = pkgmgr_client_new(PC_REQUEST);
625 printf("PkgMgr Client Creation Failed\n");
626 data.result = PKGCMD_ERR_FATAL_ERROR;
633 if (data.des_path[0] == '\0')
635 pkgmgr_client_install(pc, data.pkg_type, NULL,
636 data.pkg_path, NULL, mode,
640 pkgmgr_client_install(pc, data.pkg_type,
641 data.des_path, data.pkg_path,
642 NULL, mode, __return_cb, pc);
644 data.result = PKGCMD_ERR_FATAL_ERROR;
645 if (access(data.pkg_path, F_OK) != 0)
646 data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
649 g_main_loop_run(main_loop);
654 if (data.pkgid[0] == '\0') {
655 printf("Please provide the arguments.\n");
656 printf("use -h option to see usage\n");
657 data.result = PKGCMD_ERR_ARGUMENT_INVALID;
661 main_loop = g_main_loop_new(NULL, FALSE);
662 pc = pkgmgr_client_new(PC_REQUEST);
664 printf("PkgMgr Client Creation Failed\n");
665 data.result = PKGCMD_ERR_FATAL_ERROR;
673 ret = __is_app_installed(data.pkgid);
675 printf("package is not installed\n");
680 pkgmgr_client_uninstall(pc, data.pkg_type, data.pkgid,
681 mode, __return_cb, NULL);
683 data.result = PKGCMD_ERR_FATAL_ERROR;
684 if (access(data.pkg_path, F_OK) != 0)
685 data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
688 g_main_loop_run(main_loop);
693 if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
694 printf("Please provide the arguments.\n");
695 printf("use -h option to see usage\n");
696 data.result = PKGCMD_ERR_ARGUMENT_INVALID;
700 main_loop = g_main_loop_new(NULL, FALSE);
701 pc = pkgmgr_client_new(PC_REQUEST);
703 printf("PkgMgr Client Creation Failed\n");
704 data.result = PKGCMD_ERR_FATAL_ERROR;
709 ret = pkgmgr_client_reinstall(pc, data.pkg_type, data.pkgid, NULL, mode, __return_cb, pc);
711 data.result = PKGCMD_ERR_FATAL_ERROR;
712 if (access(data.pkg_path, F_OK) != 0)
713 data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
716 g_main_loop_run(main_loop);
721 if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
722 printf("Please provide the arguments.\n");
723 printf("use -h option to see usage\n");
728 pc = pkgmgr_client_new(PC_REQUEST);
730 printf("PkgMgr Client Creation Failed\n");
738 ret = __is_app_installed(data.pkgid);
740 printf("package is not installed\n");
743 ret = pkgmgr_client_clear_user_data(pc, data.pkg_type,
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");
765 if ( strcmp(data.pkg_type, "app") == 0 ) {
766 if (strlen(data.label) == 0) {
767 ret = pkgmgr_client_activate_app(pc, data.pkgid);
771 printf("label [%s]\n", data.label);
772 char *largv[3] = {NULL, };
774 largv[1] = data.label;
775 ret = pkgmgr_client_activate_appv(pc, data.pkgid, largv);
780 ret = pkgmgr_client_activate(pc, data.pkg_type, data.pkgid);
790 if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
791 printf("Please provide the arguments.\n");
792 printf("use -h option to see usage\n");
797 pc = pkgmgr_client_new(PC_REQUEST);
799 printf("PkgMgr Client Creation Failed\n");
804 if ( strcmp(data.pkg_type, "app") == 0 ) {
805 ret = pkgmgr_client_deactivate_app(pc, data.pkgid);
809 ret = pkgmgr_client_deactivate(pc, data.pkg_type, data.pkgid);
818 if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
819 printf("Please provide the arguments.\n");
820 printf("use -h option to see usage\n");
824 if (data.type < 0 || data.type > 1) {
825 printf("Invalid move type...See usage\n");
829 pc = pkgmgr_client_new(PC_REQUEST);
831 printf("PkgMgr Client Creation Failed\n");
836 ret = __is_app_installed(data.pkgid);
838 printf("package is not installed\n");
842 ret = pkgmgr_client_move(pc, data.pkg_type, data.pkgid, data.type, mode);
844 ret = pkgmgr_client_request_service(PM_REQUEST_MOVE, data.type, pc, NULL, data.pkgid, NULL, NULL, NULL);
846 printf("pkg[%s] move result = %d\n", data.pkgid, ret);
854 if (data.pkg_type[0] == '\0' && data.pkgid[0] == '\0') {
855 printf("Tizen Application Installation Path: %s\n", APP_INSTALLATION_PATH_RW);
859 if ((data.pkg_type[0] == '\0') || (data.pkgid[0] == '\0')) {
860 printf("Use -h option to see usage\n");
864 if (strncmp(data.pkg_type, "rpm", PKG_TYPE_STRING_LEN_MAX - 1) == 0) {
865 snprintf(buf, 1023, "%s/%s", APP_INSTALLATION_PATH_RW, data.pkgid);
866 printf("Tizen Application Installation Path: %s\n", buf);
869 } else if (strncmp(data.pkg_type, "wgt", PKG_TYPE_STRING_LEN_MAX - 1) == 0) {
870 snprintf(buf, 1023, "%s/%s/res/wgt", APP_INSTALLATION_PATH_RW, data.pkgid);
871 printf("Tizen Application Installation Path: %s\n", buf);
874 } else if (strncmp(data.pkg_type, "tpk", PKG_TYPE_STRING_LEN_MAX - 1) == 0) {
875 snprintf(buf, 1023, "%s/%s", APP_INSTALLATION_PATH_RW, data.pkgid);
876 printf("Tizen Application Installation Path: %s\n", buf);
880 printf("Invalid package type.\n");
881 printf("use -h option to see usage\n");
888 if (data.pkgid[0] == '\0') {
889 printf("Please provide the arguments.\n");
890 printf("use -h option to see usage\n");
891 data.result = PKGCMD_ERR_ARGUMENT_INVALID;
895 pc = pkgmgr_client_new(PC_REQUEST);
897 printf("PkgMgr Client Creation Failed\n");
898 data.result = PKGCMD_ERR_FATAL_ERROR;
902 ret = pkgmgr_client_request_service(PM_REQUEST_KILL_APP, NULL, pc, NULL, data.pkgid, NULL, NULL, NULL);
904 data.result = PKGCMD_ERR_FATAL_ERROR;
911 if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
912 printf("Please provide the arguments.\n");
913 printf("use -h option to see usage\n");
917 pkgmgr_pkginfo_h handle;
918 ret = pkgmgr_pkginfo_get_pkginfo(data.pkgid, &handle);
920 printf("Failed to get handle\n");
921 data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
924 ret = pkgmgr_appinfo_get_list(handle, PM_UI_APP, __app_list_cb, NULL);
926 printf("pkgmgr_appinfo_get_list() failed\n");
927 pkgmgr_pkginfo_destroy_pkginfo(handle);
928 data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
931 ret = pkgmgr_appinfo_get_list(handle, PM_SVC_APP, __app_list_cb, NULL);
933 printf("pkgmgr_appinfo_get_list() failed\n");
934 pkgmgr_pkginfo_destroy_pkginfo(handle);
935 data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
938 pkgmgr_pkginfo_destroy_pkginfo(handle);
943 if (data.pkg_type[0] == '\0') {
944 ret = pkgmgr_pkginfo_get_list(__pkgmgr_list_cb, NULL);
946 printf("Failed to get package list\n");
951 pkgmgrinfo_pkginfo_filter_h handle;
952 ret = pkgmgrinfo_pkginfo_filter_create(&handle);
954 printf("Failed to get package filter handle\n");
957 ret = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_TYPE, data.pkg_type);
959 printf("Failed to add package type filter\n");
960 pkgmgrinfo_pkginfo_filter_destroy(handle);
963 ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, __pkgmgr_list_cb, NULL);
965 printf("Failed to get package filter list\n");
966 pkgmgrinfo_pkginfo_filter_destroy(handle);
969 pkgmgrinfo_pkginfo_filter_destroy(handle);
974 if (data.pkgid[0] != '\0') {
975 pkgmgr_info *pkg_info =
976 pkgmgr_info_new(data.pkg_type, data.pkgid);
977 if (pkg_info == NULL) {
978 printf("Failed to get pkginfo handle\n");
982 __print_pkg_info(pkg_info);
983 ret = pkgmgr_info_free(pkg_info);
986 if (data.pkg_path[0] != '\0') {
987 pkgmgr_info *pkg_info =
988 pkgmgr_info_new_from_file(data.pkg_type,
990 if (pkg_info == NULL) {
991 printf("Failed to get pkginfo handle\n");
995 __print_pkg_info(pkg_info);
996 ret = pkgmgr_info_free(pkg_info);
999 printf("Either pkgid or pkgpath should be supplied\n");
1004 ret = pkgmgr_client_request_service(PM_REQUEST_CSC, 0, NULL, NULL, NULL, data.des_path, NULL, (void *)data.pkg_path);
1006 data.result = PKGCMD_ERR_FATAL_ERROR;
1010 if (data.pkgid[0] == '\0') {
1011 printf("Please provide the arguments.\n");
1012 printf("use -h option to see usage\n");
1013 data.result = PKGCMD_ERR_ARGUMENT_INVALID;
1016 if (data.type < 0 || data.type > 1) {
1017 printf("Invalid get type...See usage\n");
1022 pc = pkgmgr_client_new(PC_REQUEST);
1024 printf("PkgMgr Client Creation Failed\n");
1025 data.result = PKGCMD_ERR_FATAL_ERROR;
1029 ret = pkgmgr_client_request_service(PM_REQUEST_GET_SIZE, data.type, pc, NULL, data.pkgid, NULL, NULL, NULL);
1031 data.result = PKGCMD_ERR_FATAL_ERROR;
1035 printf("pkg[%s] size = %d\n", data.pkgid, ret);
1045 printf("Wrong Request\n");
1051 pkgmgr_client_free(pc);
1057 static int __is_authorized()
1059 /* pkgcmd needs root or developer privileges.
1060 If launched via fork/exec, the launching program
1061 must be running as root */
1063 uid_t uid = getuid();
1064 if ((uid_t) 0 == uid || (uid_t) 5100 == uid)
1070 int main(int argc, char *argv[])
1076 char *errstr = NULL;
1081 if (!__is_authorized()) {
1082 printf("You are not an authorized user!\n");
1083 return PKGCMD_ERR_FATAL_ERROR;
1089 gettimeofday(&tv, NULL);
1090 starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
1093 memset(data.des_path, '\0', PKG_NAME_STRING_LEN_MAX);
1094 memset(data.pkg_path, '\0', PKG_NAME_STRING_LEN_MAX);
1095 memset(data.pkgid, '\0', PKG_NAME_STRING_LEN_MAX);
1096 memset(data.pkg_type, '\0', PKG_TYPE_STRING_LEN_MAX);
1097 memset(data.label, '\0', PKG_TYPE_STRING_LEN_MAX);
1102 c = getopt_long(argc, argv, short_options, long_options,
1105 break; /* Parse end */
1107 case 'i': /* install */
1108 data.request = INSTALL_REQ;
1111 case 'u': /* uninstall */
1112 data.request = UNINSTALL_REQ;
1115 case 'r': /* reinstall */
1116 data.request = REINSTALL_REQ;
1119 case 'c': /* clear */
1120 data.request = CLEAR_REQ;
1123 case 'g': /* get pkg size */
1124 data.request = GETSIZE_REQ;
1127 case 'm': /* move */
1128 data.request = MOVE_REQ;
1131 case 'S': /* csc packages */
1132 data.request = CSC_REQ;
1134 strncpy(data.des_path, optarg, PKG_NAME_STRING_LEN_MAX);
1135 printf("csc file is %s\n", data.des_path);
1138 case 'A': /* activate */
1139 data.request = ACTIVATE_REQ;
1142 case 'D': /* deactivate */
1143 data.request = DEACTIVATE_REQ;
1146 case 'L': /* activate with Label */
1147 data.request = ACTIVATE_REQ;
1149 strncpy(data.label, optarg,
1150 PKG_NAME_STRING_LEN_MAX);
1153 case 'a': /* app installation path */
1154 data.request = APPPATH_REQ;
1157 case 'k': /* Terminate applications of a package */
1158 data.request = KILLAPP_REQ;
1161 case 'C': /* Check running status of applications of a package */
1162 data.request = CHECKAPP_REQ;
1165 case 'l': /* list */
1166 data.request = LIST_REQ;
1169 case 's': /* show */
1170 data.request = SHOW_REQ;
1173 case 'p': /* package path */
1175 strncpy(data.pkg_path, optarg,
1176 PKG_NAME_STRING_LEN_MAX);
1177 ret = __convert_to_absolute_path(data.pkg_path);
1179 printf("conversion of relative path to absolute path failed\n");
1182 printf("path is %s\n", data.pkg_path);
1185 case 'd': /* descriptor path */
1187 strncpy(data.des_path, optarg,
1188 PKG_NAME_STRING_LEN_MAX);
1191 case 'n': /* package name */
1193 strncpy(data.pkgid, optarg,
1194 PKG_NAME_STRING_LEN_MAX);
1197 case 't': /* package type */
1199 strncpy(data.pkg_type, optarg,
1200 PKG_TYPE_STRING_LEN_MAX);
1203 case 'T': /* move type */
1204 data.type = atoi(optarg);
1207 case 'h': /* help */
1208 data.request = HELP_REQ;
1211 case 'q': /* quiet mode */
1216 case '?': /* Not an option */
1228 ret = __process_request();
1229 if ((ret == -1) && (data.result != 0))
1230 data.result = PKGCMD_ERR_ARGUMENT_INVALID;
1233 __error_no_to_string(data.result, &errstr);
1234 printf("processing result : %s [%d] failed\n", errstr, data.result);
1236 if (data.request == INSTALL_REQ)
1241 gettimeofday(&tv, NULL);
1242 endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
1243 printf("spend time for pkgcmd is [%d]ms\n", (int)(endtime - starttime));