From 78426f79987c45ebfad874edf7240d2703149576 Mon Sep 17 00:00:00 2001 From: Jinkun Jang Date: Wed, 13 Mar 2013 01:46:57 +0900 Subject: [PATCH] Tizen 2.1 base --- CMakeLists.txt | 26 + LICENSE | 204 ++++++++ backend-lib/CMakeLists.txt | 54 ++ backend-lib/inc/librpminternals.h | 58 ++ backend-lib/src/librpm.c | 243 +++++++++ backend-lib/src/librpminternals.c | 332 ++++++++++++ backend/inc/rpm-installer.h | 106 ++++ backend/scripts/install_rpm_package.sh.in | 43 ++ backend/scripts/query_rpm_package.sh.in | 45 ++ backend/scripts/uninstall_rpm_package.sh.in | 34 ++ backend/scripts/upgrade_rpm_package.sh.in | 44 ++ backend/src/core/rpm-installer-core.c | 570 ++++++++++++++++++++ backend/src/core/rpm-installer-tool.c | 649 +++++++++++++++++++++++ backend/src/rpm/rpm-installer.c | 786 ++++++++++++++++++++++++++++ backend/src/vconf/rpm-vconf-intf.c | 177 +++++++ common/CMakeLists.txt | 46 ++ common/rpm-installer-util.c | 354 +++++++++++++ debian/changelog | 55 ++ debian/compat | 1 + debian/control | 18 + debian/control.slp | 3 + debian/desktop.slp | 11 + debian/dirs | 2 + debian/docs | 1 + debian/rpm-installer-dbg.postinst | 5 + debian/rpm-installer.install.in | 7 + debian/rpm-installer.postinst | 14 + debian/rules | 115 ++++ frontend/CMakeLists.txt | 111 ++++ frontend/inc/rpm-frontend.h | 89 ++++ frontend/src/rpm-appcore-intf.c | 243 +++++++++ frontend/src/rpm-cmdline.c | 352 +++++++++++++ frontend/ui/include/rpm-homeview.h | 37 ++ frontend/ui/src/rpm-homeview.c | 234 +++++++++ inc/rpm-installer-util.h | 112 ++++ packaging/rpm-installer.spec | 78 +++ po/CMakeLists.txt | 24 + po/POTFILES.in | 3 + po/en_GB.po | 42 ++ po/en_US.po | 42 ++ po/ja_JP.po | 42 ++ po/ko_KR.po | 42 ++ po/update-po.sh | 59 +++ po/zh_CN.po | 42 ++ rpm-installer.manifest | 5 + 45 files changed, 5560 insertions(+) create mode 100755 CMakeLists.txt create mode 100755 LICENSE create mode 100755 backend-lib/CMakeLists.txt create mode 100755 backend-lib/inc/librpminternals.h create mode 100755 backend-lib/src/librpm.c create mode 100755 backend-lib/src/librpminternals.c create mode 100755 backend/inc/rpm-installer.h create mode 100755 backend/scripts/install_rpm_package.sh.in create mode 100755 backend/scripts/query_rpm_package.sh.in create mode 100755 backend/scripts/uninstall_rpm_package.sh.in create mode 100755 backend/scripts/upgrade_rpm_package.sh.in create mode 100755 backend/src/core/rpm-installer-core.c create mode 100755 backend/src/core/rpm-installer-tool.c create mode 100755 backend/src/rpm/rpm-installer.c create mode 100755 backend/src/vconf/rpm-vconf-intf.c create mode 100755 common/CMakeLists.txt create mode 100755 common/rpm-installer-util.c create mode 100755 debian/changelog create mode 100755 debian/compat create mode 100755 debian/control create mode 100755 debian/control.slp create mode 100755 debian/desktop.slp create mode 100755 debian/dirs create mode 100755 debian/docs create mode 100755 debian/rpm-installer-dbg.postinst create mode 100755 debian/rpm-installer.install.in create mode 100755 debian/rpm-installer.postinst create mode 100755 debian/rules create mode 100755 frontend/CMakeLists.txt create mode 100755 frontend/inc/rpm-frontend.h create mode 100755 frontend/src/rpm-appcore-intf.c create mode 100755 frontend/src/rpm-cmdline.c create mode 100755 frontend/ui/include/rpm-homeview.h create mode 100755 frontend/ui/src/rpm-homeview.c create mode 100755 inc/rpm-installer-util.h create mode 100755 packaging/rpm-installer.spec create mode 100755 po/CMakeLists.txt create mode 100755 po/POTFILES.in create mode 100755 po/en_GB.po create mode 100755 po/en_US.po create mode 100755 po/ja_JP.po create mode 100755 po/ko_KR.po create mode 100755 po/update-po.sh create mode 100755 po/zh_CN.po create mode 100755 rpm-installer.manifest diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..7a2b4b3 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,26 @@ +# +# Copyright (c) 2008 ~ 2010 Samsung Electronics Co., Ltd. +# All rights reserved +# + +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) + +PROJECT(rpm-installer C) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "\${prefix}") +SET(LIBDIR "\${prefix}/lib") +SET(INCLUDEDIR "\${prefix}/include") +SET(VERSION 1.0) + +set(CMAKE_SKIP_BUILD_RPATH true) + +################## +## build comm libraries +add_subdirectory(common) +add_subdirectory(frontend) +add_subdirectory(po) +add_subdirectory(backend-lib) +################## + diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..a06208b --- /dev/null +++ b/LICENSE @@ -0,0 +1,204 @@ +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/backend-lib/CMakeLists.txt b/backend-lib/CMakeLists.txt new file mode 100755 index 0000000..caf9db3 --- /dev/null +++ b/backend-lib/CMakeLists.txt @@ -0,0 +1,54 @@ +# +# Copyright (c) 2008 ~ 2010 Samsung Electronics Co., Ltd. +# All rights reserved +# + +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +set(CMAKE_SKIP_BUILD_RPATH true) + +#Verbose +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc ${CMAKE_CURRENT_SOURCE_DIR}/inc ) + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED dbus-glib-1 pkgmgr-types vconf) +#pkg_check_modules(pkgs REQUIRED pkgmgr-installer-status-broadcast-server security-server vconf sqlite3 dbus-glib-1 glib-2.0 db-util ) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +pkg_check_modules(libpkgs REQUIRED dbus-glib-1 pkgmgr-types vconf) + +FOREACH(flag ${libpkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +pkg_check_modules(STATUS pkgmgr-installer-status-broadcast-server pkgmgr-types vconf) + +link_directories ("${STATUS_LIBRARY_DIRS} /usr/lib") +include_directories (${STATUS_INCLUDE_DIRS}) +find_library(RPM_LIBRARY rpm "/usr/lib") + +SET(backend_lib_dir "${CMAKE_CURRENT_SOURCE_DIR}") +SET(backend_lib_inc_dir "${backend_lib_dir}/inc") +SET(backend_lib_c_src_dir "${backend_lib_dir}/src") + +## Additional flag +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +################################################################################################### +## for backend_lib (binary) +SET(backend_lib_SOURCES ${backend_lib_c_src_dir}/librpminternals.c ${backend_lib_c_src_dir}/librpm.c) +SET(backend_lib_CFLAGS " -I. -I/usr/include/rpm -I${backend_lib_inc_dir} ${pkg_CFLAGS}") +SET(backend_lib_LDFLAGS ${pkgs_LDFLAGS}) + +ADD_LIBRARY(nativerpm SHARED ${backend_lib_SOURCES}) +#TARGET_LINK_LIBRARIES(nativerpm ${RPM_LIB}) +TARGET_LINK_LIBRARIES(nativerpm "rpm") +SET_TARGET_PROPERTIES(nativerpm PROPERTIES COMPILE_FLAGS "${backend_lib_CFLAGS}") +#################################################################################################### + +INSTALL(TARGETS nativerpm DESTINATION lib COMPONENT RuntimeLibraries) + +#################################################################################################### diff --git a/backend-lib/inc/librpminternals.h b/backend-lib/inc/librpminternals.h new file mode 100755 index 0000000..acdd4d2 --- /dev/null +++ b/backend-lib/inc/librpminternals.h @@ -0,0 +1,58 @@ +/* + * rpm-installer + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , + * Jaeho Lee , Shobhit Srivastava + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#include +#include +#include +#include +#include +#include + +#define API __attribute__ ((visibility("default"))) +#define DEBUG_ERR 0x0001 +#define DEBUG_INFO 0x0002 +#define DEBUG_RESULT 0x0004 +#define LIBRPM_LOG 1 +#define LIBRPM_SUCCESS 0 +#define LIBRPM_ERROR -1 + +#define BLOCK_SIZE 4096 /*in bytes*/ +#define LIKELY(expr) __builtin_expect((expr), 1) +#define UNLIKELY(expr) __builtin_expect((expr), 0) + +void _librpm_print_msg(int type, int exetype, char *format, ...); +#define _librpm_print(type, fmtstr, args...) { \ +_librpm_print_msg(type, LIBRPM_LOG, "%s():%d: " fmtstr, \ +__func__, __LINE__, ##args); \ +} + +int _librpm_get_package_header_info(char *pkg_path, + package_manager_pkg_detail_info_t *pkg_detail_info); +int _librpm_get_installed_package_info(char *pkgid, + package_manager_pkg_detail_info_t *pkg_detail_info); +int _librpm_app_is_installed(char *pkgid); +long long _librpm_calculate_dir_size(char *dirname); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ diff --git a/backend-lib/src/librpm.c b/backend-lib/src/librpm.c new file mode 100755 index 0000000..8810422 --- /dev/null +++ b/backend-lib/src/librpm.c @@ -0,0 +1,243 @@ +/* + * rpm-installer + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , + * Jaeho Lee , Shobhit Srivastava + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + + +#include +#include +#include +/*rpm specific headers*/ +#include +#include +#include +#include +#include + +#include "librpminternals.h" + +#define BASEDIR "/opt/share" +#define BUFFSIZE 256 + +void pkg_native_plugin_on_unload(void) +{ + return; +} + +int pkg_plugin_app_is_installed(const char *pkgid) +{ + _librpm_print(DEBUG_INFO, + "pkg_plugin_app_is_installed() is called\n"); + /* Check for valid arguments */ + if (pkgid == NULL) { + _librpm_print(DEBUG_ERR, + "[pkg_plugin_get_app_detail_info_from_package] " + "args supplied is NULL\n"); + return LIBRPM_ERROR; + } + int ret = -1; + ret = _librpm_app_is_installed(pkgid); + if (ret == -1) { + _librpm_print(DEBUG_ERR, "_librpm_app_is_installed() failed\n"); + return LIBRPM_ERROR; + } + /*1 for installed, 0 for not installed*/ + if (ret == 1) + return LIBRPM_SUCCESS; + else + return LIBRPM_ERROR; +} + +int pkg_plugin_get_installed_apps_list(const char *category, + const char *option, + package_manager_pkg_info_t **list, + int *count) +{ + return LIBRPM_SUCCESS; +} + +int pkg_plugin_get_app_detail_info(const char *pkgid, + package_manager_pkg_detail_info_t + *pkg_detail_info) +{ + _librpm_print(DEBUG_INFO, + "pkg_plugin_get_app_detail_info() is called\n"); + /* Check for valid arguments */ + if (pkgid == NULL || pkg_detail_info == NULL) { + _librpm_print(DEBUG_ERR, + "[pkg_plugin_get_app_detail_info_from_package] " + "args supplied is NULL\n"); + return LIBRPM_ERROR; + } + char dirname[BUFFSIZE] = { '\0' }; + int ret = 0; + long long data_size = 0; + char buff[256] = {'\0'}; + time_t install_time = 0; + + /* pkgtype is by default rpm */ + strncpy(pkg_detail_info->pkg_type, "rpm", sizeof(pkg_detail_info->pkg_type)); + + /* Get the installed package info from rpm db */ + ret = _librpm_get_installed_package_info(pkgid, pkg_detail_info); + if (ret) { + return LIBRPM_ERROR; + } + + /*get data_size*/ + snprintf(dirname, BUFFSIZE-1, "/opt/usr/apps/%s/data", pkgid); + data_size = _librpm_calculate_dir_size(dirname); + if (data_size < 0) { + _librpm_print(DEBUG_ERR, + "Calculate dir size failed\n"); + pkg_detail_info->data_size = 0 ; + } + else { + data_size += BLOCK_SIZE; /* the function does not adds 4096 + bytes for the directory size itself*/ + pkg_detail_info->data_size = data_size/1024 ; + } + + /* Min Platform Version */ + pkg_detail_info->min_platform_version[0] = '\0'; + + /* Optional ID*/ + pkg_detail_info->optional_id[0] = '\0'; + + /* Total Installed Size*/ + pkg_detail_info->installed_size = pkg_detail_info->app_size + + pkg_detail_info->data_size; + /* Installed Time*/ + snprintf(buff, 256, "db/app-info/%s/installed-time", pkgid); + ret = vconf_get_int(buff, (int *)&install_time); + if (ret) { + _librpm_print(DEBUG_ERR, "get installed time failed\n"); + pkg_detail_info->installed_time = 0; + } + else + pkg_detail_info->installed_time = install_time; + + + return LIBRPM_SUCCESS; +} + +int pkg_plugin_get_app_detail_info_from_package(const char *pkg_path, + package_manager_pkg_detail_info_t + *pkg_detail_info) +{ + _librpm_print(DEBUG_INFO, + "pkg_plugin_get_app_detail_info_from_package() is called\n"); + + /* Check for valid arguments */ + if (pkg_path == NULL || pkg_detail_info == NULL) { + _librpm_print(DEBUG_ERR, + "[pkg_plugin_get_app_detail_info_from_package]" + "args supplied is NULL\n"); + return LIBRPM_ERROR; + } + + int ret = 0; + long long data_size = 0; + char *str = NULL; + char dirname[BUFFSIZE] = { '\0' }; + char buff[256] = {'\0'}; + time_t install_time = 0; + + /* populate pkg type */ + str = strrchr(pkg_path, 46); /* 46 is ASCII for . */ + strncpy(pkg_detail_info->pkg_type, (str + 1), strlen(str + 1)); + + /* populate rpm header specific info (name, version, description, size)*/ + ret = _librpm_get_package_header_info(pkg_path, pkg_detail_info); + if (ret) { + return LIBRPM_ERROR; + } + + /*get data_size. If pkg is not installed it will be 0*/ + snprintf(dirname, BUFFSIZE-1, "/opt/usr/apps/%s/data", + pkg_detail_info->pkgid); + + data_size = _librpm_calculate_dir_size(dirname); + if (data_size < 0) { + _librpm_print(DEBUG_ERR, + "Calculate dir size failed\n"); + pkg_detail_info->data_size = 0 ; + } + else { + data_size += BLOCK_SIZE; /* the function does not adds 4096 + bytes for the directory size itself*/ + + pkg_detail_info->data_size = data_size/1024 ; + } + + /* Min Platform Version */ + pkg_detail_info->min_platform_version[0] = '\0'; + + /* Optional ID*/ + pkg_detail_info->optional_id[0] = '\0'; + + /* Total Installed Size*/ + pkg_detail_info->installed_size = pkg_detail_info->app_size + + pkg_detail_info->data_size; + + /* Installed Time */ + snprintf(buff, 256, "db/app-info/%s/installed-time", pkg_detail_info->pkgid); + ret = vconf_get_int(buff, (int *)&install_time); + if (ret) { + _librpm_print(DEBUG_ERR, "get installed time failed\n"); + pkg_detail_info->installed_time = 0; + } + else + pkg_detail_info->installed_time = install_time; + + + return LIBRPM_SUCCESS; +} + +API int pkg_plugin_on_load(pkg_plugin_set *set) +{ + static int initialized = 0; + rpmRC rc; + if (set == NULL) { + return LIBRPM_ERROR; + } + + memset(set, 0x00, sizeof(pkg_plugin_set)); + if (!initialized) { + rc = rpmReadConfigFiles(NULL, NULL); + if (rc == RPMRC_OK) + initialized = 1; + else { + _librpm_print(DEBUG_ERR, "Unable to read RPM configuration.\n"); + initialized = 0; + return LIBRPM_ERROR; + } + } + + set->plugin_on_unload = pkg_native_plugin_on_unload; + set->pkg_is_installed = pkg_plugin_app_is_installed; + set->get_installed_pkg_list = pkg_plugin_get_installed_apps_list; + set->get_pkg_detail_info = pkg_plugin_get_app_detail_info; + set->get_pkg_detail_info_from_package = + pkg_plugin_get_app_detail_info_from_package; + + return LIBRPM_SUCCESS; +} diff --git a/backend-lib/src/librpminternals.c b/backend-lib/src/librpminternals.c new file mode 100755 index 0000000..4525c46 --- /dev/null +++ b/backend-lib/src/librpminternals.c @@ -0,0 +1,332 @@ +/* + * rpm-installer + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , + * Jaeho Lee , Shobhit Srivastava + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/*rpm specific headers*/ +#include +#include +#include +#include +#include +#include "librpminternals.h" + +/* This is backend lib's filter string for dlogutil*/ +#define LOCAL_LOG_TAG "librpm" +int logging = 0x0004; +#ifdef LOG_IN_FILE +#define RPM_INSTALLER_LIBRPM_LOG_FILE "/tmp/librpm" +FILE *logfile = NULL; +#endif + +void _librpm_print_msg(int type, int exetype, char *format, ...) +{ + char buffer[FILENAME_MAX] = { 0 }; + char tbuffer[FILENAME_MAX] = { 0 }; + + int nbuffer; + va_list args; + va_start(args, format); + nbuffer = vsnprintf(tbuffer, FILENAME_MAX, format, args); + va_end(args); + + switch (type) { + case DEBUG_ERR: + LOG(LOG_ERROR, LOCAL_LOG_TAG, tbuffer); + break; + case DEBUG_RESULT: + LOG(LOG_WARN, LOCAL_LOG_TAG, tbuffer); + break; + case DEBUG_INFO: + LOG(LOG_DEBUG, LOCAL_LOG_TAG, tbuffer); + default: + break; + } + + if (logging == 0) + return; + + if (DEBUG_ERR == (logging & type)) { + nbuffer = snprintf(buffer, FILENAME_MAX, "ERROR:%s", tbuffer); + vfprintf(stderr, format, args); + } else if (DEBUG_INFO == (logging & type)) { + nbuffer = snprintf(buffer, FILENAME_MAX, "INFO:%s", tbuffer); + vfprintf(stdout, format, args); + } else if (DEBUG_RESULT == (logging & type)) { + nbuffer = snprintf(buffer, FILENAME_MAX, "RESULT:%s", tbuffer); + vfprintf(stdout, format, args); + } else { + return; + } + +#ifdef LOG_IN_FILE + if (logfile != NULL) + fwrite(buffer, sizeof(char), strlen(buffer), logfile); +#endif /*LOG_IN_FILE */ +} + +int _librpm_app_is_installed(char *pkgid) +{ + rpmts ts = NULL; + int ret = 0; + Header hdr = NULL; + int found = 0; + rpmdbMatchIterator mi; + rpmtd tn = NULL; + rpmRC rc; + + tn = rpmtdNew(); + ts = rpmtsCreate(); +/* + hdr = headerNew(); +*/ + + mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES, NULL, 0); + while (NULL != (hdr = rpmdbNextIterator(mi))) { + + hdr = headerLink(hdr); + rc = headerGet(hdr, RPMTAG_NAME, tn, HEADERGET_MINMEM); + if (strcmp(pkgid, rpmtdGetString(tn) ) == 0) { + found = 1; + break; + } else { + rpmtdReset(tn); + headerFree(hdr); + } + + } + if (found == 0) { + _librpm_print(DEBUG_INFO, "Package not found in DB\n"); + ret = 0; + goto err; + } + else { + _librpm_print(DEBUG_INFO, "Package found in DB\n"); + ret = 1; + goto err; + } +err: + rpmtdFreeData(tn); + rpmtdFree(tn); + headerFree(hdr); + rpmtsFree(ts); + rpmdbFreeIterator(mi); + return ret; + +} + +int _librpm_get_installed_package_info(char *pkgid, + package_manager_pkg_detail_info_t *pkg_detail_info) +{ + rpmts ts = NULL; + Header hdr = NULL; + int found = 0; + int ret = 0; + rpmdbMatchIterator mi; + rpmtd td, tn, tv, ta; + rpmRC rc; + + td = rpmtdNew(); + tn = rpmtdNew(); + tv = rpmtdNew(); + ta = rpmtdNew(); + ts = rpmtsCreate(); +/* + hdr = headerNew(); +*/ + mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES, NULL, 0); + while (NULL != (hdr = rpmdbNextIterator(mi))) { + + hdr = headerLink(hdr); + rc = headerGet(hdr, RPMTAG_NAME, tn, HEADERGET_MINMEM); + if (strcmp(pkgid, rpmtdGetString(tn) ) == 0) { + found = 1; + break; + } else { + rpmtdReset(tn); + headerFree(hdr); + } + + } + + /*Print the header info */ + if (found == 0) { + _librpm_print(DEBUG_ERR, "Package not found in DB\n"); + ret = LIBRPM_ERROR; + goto err; + } + /*Name*/ + headerGet(hdr, RPMTAG_NAME, tn, HEADERGET_MINMEM); + strncpy(pkg_detail_info->pkgid, rpmtdGetString(tn), PKG_NAME_STRING_LEN_MAX-1); + /*Version*/ + headerGet(hdr, RPMTAG_VERSION, tv, HEADERGET_MINMEM); + strncpy(pkg_detail_info->version, rpmtdGetString(tv), PKG_VERSION_STRING_LEN_MAX-1); + /*Description*/ + headerGet(hdr, RPMTAG_DESCRIPTION, td, HEADERGET_MINMEM); + strncpy(pkg_detail_info->pkg_description, rpmtdGetString(td), PKG_VALUE_STRING_LEN_MAX-1); + /*Size*/ + headerGet(hdr, RPMTAG_SIZE, ta, HEADERGET_MINMEM); + pkg_detail_info->app_size = rpmtdGetNumber(ta); + ret = LIBRPM_SUCCESS; + +err: + headerFree(hdr); + rpmtdFreeData(tn); + rpmtdFree(tn); + rpmtdFreeData(td); + rpmtdFree(td); + rpmtdFreeData(ta); + rpmtdFree(ta); + rpmtdFreeData(tv); + rpmtdFree(tv); + rpmdbFreeIterator(mi); + rpmtsFree(ts); + + return ret; + +} + +int _librpm_get_package_header_info(char *pkg_path, + package_manager_pkg_detail_info_t *pkg_detail_info) +{ + int i; + int ret = 0; + rpmts ts = NULL; + rpmtd td = NULL; + FD_t fd; + rpmRC rc; + Header hdr = NULL; + rpmVSFlags vsflags = 0; + + fd = Fopen(pkg_path, "r.ufdio"); + if ((!fd) || Ferror(fd)) { + _librpm_print(DEBUG_ERR, "Failed to open package file (%s)\n", Fstrerror(fd)); + ret = LIBRPM_ERROR; + goto err; + } + + ts = rpmtsCreate(); + td = rpmtdNew(); + hdr = headerNew(); + + vsflags |= _RPMVSF_NODIGESTS; + vsflags |= _RPMVSF_NOSIGNATURES; + vsflags |= RPMVSF_NOHDRCHK; + (void) rpmtsSetVSFlags(ts, vsflags); + + rc = rpmReadPackageFile(ts, fd, pkg_path, &hdr); + if (rc != RPMRC_OK) { + _librpm_print(DEBUG_ERR, "Could not read package file\n"); + ret = LIBRPM_ERROR; + goto err; + } + Fclose(fd); + /*Name*/ + headerGet(hdr, RPMTAG_NAME, td, HEADERGET_MINMEM); + strncpy(pkg_detail_info->pkgid, rpmtdGetString(td), PKG_NAME_STRING_LEN_MAX-1); + rpmtdReset(td); + /*Version*/ + headerGet(hdr, RPMTAG_VERSION, td, HEADERGET_MINMEM); + strncpy(pkg_detail_info->version, rpmtdGetString(td), PKG_VERSION_STRING_LEN_MAX-1); + rpmtdReset(td); + /*Description*/ + headerGet(hdr, RPMTAG_DESCRIPTION, td, HEADERGET_MINMEM); + strncpy(pkg_detail_info->pkg_description, rpmtdGetString(td), PKG_VALUE_STRING_LEN_MAX-1); + rpmtdReset(td); + /*Size*/ + headerGet(hdr, RPMTAG_SIZE, td, HEADERGET_MINMEM); + pkg_detail_info->app_size = rpmtdGetNumber(td); + + ret = LIBRPM_SUCCESS; +err: + rpmtdFreeData(td); + rpmtdFree(td); + headerFree(hdr); + rpmtsFree(ts); + return ret; + +} + +long long _librpm_calculate_dir_size(char *dirname) +{ + long long total = 0; + long long ret = 0; + int q = 0; /*quotient*/ + int r = 0; /*remainder*/ + DIR *dp = NULL; + struct dirent *ep = NULL; + struct stat fileinfo; + char abs_filename[FILENAME_MAX] = { 0, }; + if (dirname == NULL) { + _librpm_print(DEBUG_ERR, + "dirname is NULL"); + return LIBRPM_ERROR; + } + dp = opendir(dirname); + if (dp != NULL) { + while ((ep = readdir(dp)) != NULL) { + if (!strcmp(ep->d_name, ".") || + !strcmp(ep->d_name, "..")) { + continue; + } + snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname, + ep->d_name); + if (stat(abs_filename, &fileinfo) < 0) + perror(abs_filename); + else { + if (S_ISDIR(fileinfo.st_mode)) { + total += fileinfo.st_size; + if (strcmp(ep->d_name, ".") + && strcmp(ep->d_name, "..")) { + ret = _librpm_calculate_dir_size + (abs_filename); + total = total + ret; + } + } else { + /*It is a file. Calculate the actual + size occupied (in terms of 4096 blocks)*/ + q = (fileinfo.st_size / BLOCK_SIZE); + r = (fileinfo.st_size % BLOCK_SIZE); + if (r) { + q = q + 1; + } + total += q * BLOCK_SIZE; + } + } + } + (void)closedir(dp); + } else { + _librpm_print(DEBUG_ERR, + "Couldn't open the directory\n"); + return -1; + } + return total; + +} diff --git a/backend/inc/rpm-installer.h b/backend/inc/rpm-installer.h new file mode 100755 index 0000000..706d4c6 --- /dev/null +++ b/backend/inc/rpm-installer.h @@ -0,0 +1,106 @@ +/* + * rpm-installer + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , + * Jaeho Lee , Shobhit Srivastava + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef __RPM_INSTALLER_H_ +#define __RPM_INSTALLER_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include "rpm-installer-util.h" +#include + +#define PM_UNLIKELY(expr) __builtin_expect((expr), 0) +#define PM_LIKELY(expr) __builtin_expect((expr), 1) + + enum backend_state { + REQUEST_ACCEPTED = 1, + GOT_PACKAGE_INFO_SUCCESSFULLY, + REQUEST_PENDING, + REQUEST_COMPLETED + }; + typedef enum backend_state backend_state; + struct pkginfo_t { + char package_name[128]; + char version[11]; + }; + + typedef struct pkginfo_t pkginfo; + +/** + * Install the package + * @in :pkgfilepath : Package file path + * @in :force_install: Whether we need to forceful overwrite. + * If package already installed then reinstall the application + * @in :install_options: install options + */ + int _rpm_installer_package_install(char *pkgfilepath, + bool force_install, + char *install_options); + +/** + * get the package information from package name + * return the package information + * @in :pkgid : package id for which information is requested + */ + pkginfo *_rpm_installer_get_pkgname_info(char *pkgid); + +/** + * get the package information from package file + * return the package information + * @in :pkgfile : package file for which information is requested + */ + pkginfo *_rpm_installer_get_pkgfile_info(char *pkgfile); + +/** + * Uninstall the Application + * @in :pkgid : package id to be uninstalled + */ + int _rpm_installer_package_uninstall(char *pkgid); + +/* Dbus related prototype */ + void _ri_broadcast_status_notification(char *pkgid, char *key, + char *val); + int _rpm_backend_interface(char *keyid, char *pkgid, + char *reqcommand); + +/* RPM operations prototype */ + int _rpm_uninstall_pkg(char *pkgid); + int _rpm_install_pkg(char *pkgfilepath, char *installoptions); + int _rpm_upgrade_pkg(char *pkgfilepath, char *installoptions); + int _ri_set_backend_state(int state); + int _ri_get_backend_state(); + int _ri_get_backend_state_info(); + int _ri_set_backend_state_info(int state); + int _ri_get_last_input_info(char **pkgid, int *preqcommand, + int *poptions); + void _ri_save_last_input_info(char *pkgid, int reqcommand, + int options); + void _ri_package_downgrade_information(const char *message); + int _rpm_installer_clear_private_data(char *pkgid); + int _rpm_move_pkg(char *pkgid, int move_type); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* __RPM_INSTALLER_H_ */ diff --git a/backend/scripts/install_rpm_package.sh.in b/backend/scripts/install_rpm_package.sh.in new file mode 100755 index 0000000..5a6fdfc --- /dev/null +++ b/backend/scripts/install_rpm_package.sh.in @@ -0,0 +1,43 @@ +#!/bin/sh + +E_WRONG_ARGS=17 +E_FILE_NOT_FOUND=11 +E_RPM_ERROR=15 + +PKG_LOG_DIR=/var/pkgmgr/rpm + + +debug () { + echo ">>$DEBUG" >> /tmp/rpmscriptlog +} + +NOARG=$# + +if [ $NOARG -lt 1 ] || [ $NOARG -gt 2 ] ; then + DEBUG="Usage: install.sh PKG_FILE";debug + exit $E_WRONG_ARGS +elif [ $NOARG -eq 2 ] ; then + OPTIONS_FLAGS=$2 +fi +PKGFILE_PATH="$1" + +if [ ! -f "$1" ];then + DEBUG="File not found";debug + exit $E_FILE_NOT_FOUND +fi + +if [ ! -d $PKG_LOG_DIR ];then + DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug + mkdir -p $PKG_LOG_DIR +fi + + +rpm --install --percent --nodeps $OPTION_FLAGS "$PKGFILE_PATH" +rpmretval=$? +if [ $rpmretval -ne 0 ]; then + DEBUG="rpm returned error ";debug + exit $E_RPM_ERROR +else + DEBUG="rpm success ";debug +fi + diff --git a/backend/scripts/query_rpm_package.sh.in b/backend/scripts/query_rpm_package.sh.in new file mode 100755 index 0000000..84e4123 --- /dev/null +++ b/backend/scripts/query_rpm_package.sh.in @@ -0,0 +1,45 @@ +#!/bin/sh +E_RPM_NOT_INSTALLED=1 +E_RPM_ALREADY_INSTALLED=2 +E_WRONG_ARGS=17 +E_FILE_NOT_FOUND=11 + +echo "find pakcage $1" >> /tmp/rpmscriptlog + +CURDIR=`pwd` +echo $CURDIR >> /tmp/rpmscriptlog + +debug () { + echo ">>$DEBUG" >> /tmp/rpmscriptlog +} + +if [ $# -ne 1 ];then + DEBUG="Usage: query_package.sh PKG_FILE";debug + exit $E_WRONG_ARGS +fi + +PKGNAME=$1 +echo "pkg name = $PKGNAME" >> /tmp/rpmscriptlog + +PKG_LOG_DIR=/var/pkgmgr/$PKGNAME +if [ ! -d $PKG_LOG_DIR ];then + DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug + mkdir -p $PKG_LOG_DIR +fi + +if [ -f $PKGNAME ]; then + rpm -qpi $PKGNAME + retval=$? +else + rpm -qi $PKGNAME + retval=$? +fi +echo "retval = $retval" >> /tmp/rpmscriptlog + +if [ $retval -ne 0 ];then + DEBUG="pakcage not exist";debug + cd $CURDIR + exit $E_RPM_NOT_INSTALLED +else + exit $E_RPM_ALREADY_INSTALLED +fi diff --git a/backend/scripts/uninstall_rpm_package.sh.in b/backend/scripts/uninstall_rpm_package.sh.in new file mode 100755 index 0000000..623b4af --- /dev/null +++ b/backend/scripts/uninstall_rpm_package.sh.in @@ -0,0 +1,34 @@ +#!/bin/sh + +E_WRONG_ARGS=17 +E_FILE_NOT_FOUND=11 +E_RPM_ERROR=15 + +PKG_LOG_DIR=/var/pkgmgr/rpm + +debug () { + echo ">>$DEBUG" >> /tmp/rpmscriptlog +} + +NOARG=$# + +if [ $NOARG -lt 1 ] || [ $NOARG -gt 2 ]; then + DEBUG="Usage: uninstall.sh ";debug + exit $E_WRONG_ARGS +fi + + +if [ ! -d $PKG_LOG_DIR ];then + DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug + mkdir -p $PKG_LOG_DIR +fi + +PKGNAME=$1 + +# 3. DELETE FILES +rpm --erase --nodeps $PKGNAME +ret=$? +if [ $ret -ne 0 ];then + DEBUG="rpm error";debug + exit $E_RPM_ERROR +fi diff --git a/backend/scripts/upgrade_rpm_package.sh.in b/backend/scripts/upgrade_rpm_package.sh.in new file mode 100755 index 0000000..9fb8523 --- /dev/null +++ b/backend/scripts/upgrade_rpm_package.sh.in @@ -0,0 +1,44 @@ +#!/bin/sh + +E_WRONG_ARGS=17 +E_FILE_NOT_FOUND=11 +E_RPM_ERROR=15 + +PKG_LOG_DIR=/var/pkgmgr/rpm + + +debug () { + echo ">>$DEBUG" >> /tmp/rpmscriptlog +} + +NOARG=$# + +if [ $NOARG -lt 1 ] || [ $NOARG -gt 2 ] ; then + DEBUG="Usage: install.sh PKG_FILE";debug + exit $E_WRONG_ARGS +elif [ $NOARG -eq 2 ] ; then + OPTIONS_FLAGS=$2 +fi +PKGFILE_PATH="$1" + +if [ ! -f "$1" ];then + DEBUG="File not found";debug + exit $E_FILE_NOT_FOUND +fi + +if [ ! -d $PKG_LOG_DIR ];then + DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug + mkdir -p $PKG_LOG_DIR +fi + + +#rpm --upgrade --percent --nodeps --replacepkgs $OPTION_FLAGS "$PKGFILE_PATH" +rpm --upgrade --percent --nodeps --replacepkgs --force "$PKGFILE_PATH" +rpmretval=$? +if [ $rpmretval -ne 0 ]; then + DEBUG="rpm returned error ";debug + exit $E_RPM_ERROR +else + DEBUG="rpm success ";debug +fi + diff --git a/backend/src/core/rpm-installer-core.c b/backend/src/core/rpm-installer-core.c new file mode 100755 index 0000000..455b82a --- /dev/null +++ b/backend/src/core/rpm-installer-core.c @@ -0,0 +1,570 @@ +/* + * rpm-installer + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , + * Jaeho Lee , Shobhit Srivastava + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/* System Include files */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* SLP include files */ +#include "rpm-installer.h" +#include "rpm-installer-util.h" +#include "db-util.h" + +#define QUERY_PACKAGE "/usr/bin/query_rpm_package.sh" +#define RPM_PKG_INFO "/var/rpmpkg.info" + +struct pkgfile_info_t { + char *pkg_filename; + char *pkg_type; +}; +typedef struct pkgfile_info_t pkgfile_info; + +extern char *gpkgname; +extern int do_upgrade; +static int __ri_xsystem_with_dup(char *pkgid, int fd); +static int __ri_recursive_delete_dir(char *dirname); + +static int __ri_recursive_delete_dir(char *dirname) +{ + DIR *dp; + struct dirent *ep; + char abs_filename[FILENAME_MAX]; + struct stat stFileInfo; + dp = opendir(dirname); + if (dp != NULL) { + while (ep = readdir(dp)) { + snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname, + ep->d_name); + if (lstat(abs_filename, &stFileInfo) < 0) + perror(abs_filename); + if (S_ISDIR(stFileInfo.st_mode)) { + if (strcmp(ep->d_name, ".") && + strcmp(ep->d_name, "..")) { + __ri_recursive_delete_dir(abs_filename); + remove(abs_filename); + } + } else { + remove(abs_filename); + } + } + (void)closedir(dp); + } else { + _d_msg(DEBUG_ERR, "Couldn't open the directory\n"); + return RPM_INSTALLER_ERR_CLEAR_DATA_FAILED; + } + + return RPM_INSTALLER_SUCCESS; +} + +pkginfo *_rpm_installer_get_pkgfile_info(char *pkgfile) +{ + int i; + int ret = 0; + rpmts ts; + rpmtd td; + FD_t fd; + rpmRC rc; + Header hdr = NULL; + rpmVSFlags vsflags = 0; + pkginfo *info = NULL; + if (pkgfile == NULL) + return NULL; + info = malloc(sizeof(pkginfo)); + if (info == NULL) { + _d_msg(DEBUG_ERR, "Malloc Failed\n"); + return NULL; + } + ts = rpmtsCreate(); + td = rpmtdNew(); + hdr = headerNew(); + + fd = Fopen(pkgfile, "r.ufdio"); + if ((!fd) || Ferror(fd)) { + _d_msg(DEBUG_ERR, "Failed to open package file (%s)\n", Fstrerror(fd)); + if (fd) { + Fclose(fd); + } + free(info); + info = NULL; + goto err; + } + + vsflags |= _RPMVSF_NODIGESTS; + vsflags |= _RPMVSF_NOSIGNATURES; + vsflags |= RPMVSF_NOHDRCHK; + (void) rpmtsSetVSFlags(ts, vsflags); + + rc = rpmReadPackageFile(ts, fd, pkgfile, &hdr); + if (rc != RPMRC_OK) { + _d_msg(DEBUG_ERR, "Could not read package file\n"); + free(info); + info = NULL; + goto err; + } + Fclose(fd); + /*Name*/ + headerGet(hdr, RPMTAG_NAME, td, HEADERGET_MINMEM); + strncpy(info->package_name, rpmtdGetString(td), sizeof(info->package_name) - 1); + _d_msg(DEBUG_INFO, "Package Name : %s\n", info->package_name); + rpmtdReset(td); + /*Version*/ + headerGet(hdr, RPMTAG_VERSION, td, HEADERGET_MINMEM); + strncpy(info->version, rpmtdGetString(td), sizeof(info->version) - 1); + _d_msg(DEBUG_INFO, "Version : %s\n", info->version); + rpmtdReset(td); + + +err: + rpmtdFreeData(td); + rpmtdFree(td); + headerFree(hdr); + rpmtsFree(ts); + return info; + +} + +pkginfo *_rpm_installer_get_pkgname_info(char *pkgid) +{ + rpmts ts = NULL; + Header hdr = NULL; + int found = 0; + rpmdbMatchIterator mi; + rpmtd tn, tv; + rpmRC rc; + pkginfo *info = NULL; + if (pkgid == NULL) + return NULL; + info = malloc(sizeof(pkginfo)); + if (info == NULL) { + _d_msg(DEBUG_ERR, "Malloc Failed\n"); + return NULL; + } + + tn = rpmtdNew(); + tv = rpmtdNew(); + ts = rpmtsCreate(); + + mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES, NULL, 0); + while (NULL != (hdr = rpmdbNextIterator(mi))) { + + hdr = headerLink(hdr); + rc = headerGet(hdr, RPMTAG_NAME, tn, HEADERGET_MINMEM); + if (strcmp(pkgid, rpmtdGetString(tn)) == 0) { + found = 1; + break; + } else { + rpmtdReset(tn); + headerFree(hdr); + } + + } + + if (found == 0) { + _d_msg(DEBUG_ERR, "Package not found in DB\n"); + free(info); + info = NULL; + goto err; + } + /*Name */ + headerGet(hdr, RPMTAG_NAME, tn, HEADERGET_MINMEM); + strncpy(info->package_name, rpmtdGetString(tn), + sizeof(info->package_name)-1); + _d_msg(DEBUG_INFO, "Package Name : %s\n", info->package_name); + /*Version */ + headerGet(hdr, RPMTAG_VERSION, tv, HEADERGET_MINMEM); + strncpy(info->version, rpmtdGetString(tv), sizeof(info->version)-1); + _d_msg(DEBUG_INFO, "Version : %s\n", info->version); + + + err: + headerFree(hdr); + rpmtdFreeData(tn); + rpmtdFree(tn); + rpmtdFreeData(tv); + rpmtdFree(tv); + rpmdbFreeIterator(mi); + rpmtsFree(ts); + + return info; + +} + +#if 0 + +static int __ri_xsystem_with_dup(char *pkgname, int fd) +{ + int pid; + int status = 0; + const char *argv[] = { QUERY_PACKAGE, pkgname, NULL }; + pid = fork(); + switch (pid) { + case -1: + perror("fork failed"); + return -1; + case 0: /* child */ + close(1); + close(2); + dup(fd); + dup(fd); /* dup called twice to create copy of fd 1 and fd 2 */ + execvp(argv[0], (char *const *)argv); + exit(-1); + default: /*parent */ + break; + } + if (waitpid(pid, &status, 0) == -1) { + perror("waitpid failed"); + return -1; + } + if (WIFSIGNALED(status)) { + perror("signal"); + printf("sig no. %d\n", WTERMSIG(status)); + return -1; + } + if (!WIFEXITED(status)) { + perror("should not happen"); + return -1; + } + + return WEXITSTATUS(status); +} + +pkginfo *_rpm_installer_get_pkg_info(char *pkgname) +{ + pkginfo *info = NULL; + int err = 0; + int fd = -1; + FILE *fp = NULL; + char *line = NULL; + size_t len = 0; + ssize_t read; + char *saveptr = NULL; + char *tok = NULL; + + if (pkgname == NULL) + return NULL; + + fd = open(RPM_PKG_INFO, O_CREAT | O_RDWR, 0644); + if (fd == -1) { + _d_msg(DEBUG_ERR, "open failed\n"); + return NULL; + } + + err = __ri_xsystem_with_dup(pkgname, fd); + _d_msg(DEBUG_INFO, + "[_rpm_installer_get_pkg_info] _xsystem returns %d\n", err); + if (err == 1) { + _d_msg(DEBUG_INFO, + "[_rpm_installer_get_pkg_info] " + "Package Not installed \n"); + close(fd); + return NULL; + } else if (err == 2) { + _d_msg(DEBUG_INFO, + "[_rpm_installer_get_pkg_info] " + "package already install\n"); + info = malloc(sizeof(pkginfo)); + if (info == NULL) { + _d_msg(DEBUG_ERR, "Malloc Failed\n"); + close(fd); + return NULL; + } + memset(info, 0x00, sizeof(pkginfo)); + close(fd); + fp = fopen(RPM_PKG_INFO, "r"); + if (fp == NULL) { + _d_msg(DEBUG_ERR, "fopen failed\n"); + return NULL; + } + + /* Now open file and get pkgname and version */ + while ((read = getline(&line, &len, fp)) != -1) { + int len = strlen(line); + line[len - 1] = '\0'; + + _d_msg(DEBUG_INFO, "line[%s]\n", line); + + tok = strtok_r(line, " ", &saveptr); /*Name */ + if (tok && strncmp(tok, "Name", 4) == 0) { + /* : */ + tok = strtok_r(NULL, " ", &saveptr); + /* */ + tok = strtok_r(NULL, " ", &saveptr); + if (tok) { + strncpy(info->package_name, tok, + sizeof(info->package_name)); + } + } else if (tok && strncmp(tok, "Version", 7) == 0) { + /* : */ + tok = strtok_r(NULL, " ", &saveptr); + /* */ + tok = strtok_r(NULL, " ", &saveptr); + if (tok) { + strncpy(info->version, tok, + sizeof(info->version)); + } + break; + } else + continue; + } + if (line) { + free(line); + line = NULL; + } + fclose(fp); + remove(RPM_PKG_INFO); + return info; + + } else { + _d_msg(DEBUG_ERR, + "[_rpm_installer_get_pkg_info] " + "_xsystem returns error = %d\n", err); + close(fd); + return NULL; + } + remove(RPM_PKG_INFO); + return info; + +} + +#endif + +int _rpm_installer_package_install(char *pkgfilepath, bool forceinstall, + char *installoptions) +{ + int err = 0; + if (forceinstall == true && installoptions == NULL) + return RPM_INSTALLER_ERR_WRONG_PARAM; + pkginfo *info = NULL; + pkginfo *tmpinfo = NULL; + /*Check to see if the package is already installed or not + If it is installed, compare the versions. If the current version + is higher than the installed version, upgrade it automatically + else ask for user confirmation before downgrading */ + + info = _rpm_installer_get_pkgfile_info(pkgfilepath); + if (info == NULL) { + /* failed to get pkg info */ + return RPM_INSTALLER_ERR_UNKNOWN; + } + + _ri_set_backend_state_info(GOT_PACKAGE_INFO_SUCCESSFULLY); + if (gpkgname) { + free(gpkgname); + gpkgname = NULL; + } + gpkgname = strdup(info->package_name); + + tmpinfo = _rpm_installer_get_pkgname_info(info->package_name); + if (tmpinfo == NULL) { + /* package is not installed. Go for installation. */ + if (info) { + free(info); + info = NULL; + } + err = _rpm_install_pkg(pkgfilepath, installoptions); + if (err != 0) { + _d_msg(DEBUG_ERR, + "install complete with error(%d)\n", err); + return err; + } else { + _ri_set_backend_state_info(REQUEST_COMPLETED); + return RPM_INSTALLER_SUCCESS; + } + } else if (strcmp(info->version, tmpinfo->version) > 0) { + /*upgrade */ + err = _rpm_upgrade_pkg(pkgfilepath, "--force"); + if (err != 0) { + _d_msg(DEBUG_ERR, + "upgrade complete with error(%d)\n", err); + if (info) { + free(info); + info = NULL; + } + if (tmpinfo) { + free(tmpinfo); + tmpinfo = NULL; + } + return err; + } else { + _ri_set_backend_state_info(REQUEST_COMPLETED); + if (info) { + free(info); + info = NULL; + } + if (tmpinfo) { + free(tmpinfo); + tmpinfo = NULL; + } + return RPM_INSTALLER_SUCCESS; + } + } else if (strcmp(info->version, tmpinfo->version) < 0) { + /*show popup and confirm from user */ + switch (do_upgrade) { + case -1: + _ri_set_backend_state_info(REQUEST_PENDING); + if (info) { + free(info); + info = NULL; + } + if (tmpinfo) { + free(tmpinfo); + tmpinfo = NULL; + } + return RPM_INSTALLER_ERR_NEED_USER_CONFIRMATION; + case 0: + /*return */ + if (info) { + free(info); + info = NULL; + } + if (tmpinfo) { + free(tmpinfo); + tmpinfo = NULL; + } + _ri_set_backend_state_info(REQUEST_COMPLETED); + return RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED; + case 1: + /*continue with downgrade */ + _ri_set_backend_state_info + (GOT_PACKAGE_INFO_SUCCESSFULLY); + err = _rpm_upgrade_pkg(pkgfilepath, "--force"); + if (err != 0) { + _d_msg(DEBUG_ERR, + "upgrade complete with error(%d)\n", + err); + if (info) { + free(info); + info = NULL; + } + if (tmpinfo) { + free(tmpinfo); + tmpinfo = NULL; + } + return err; + } + _ri_set_backend_state_info(REQUEST_COMPLETED); + if (info) { + free(info); + info = NULL; + } + if (tmpinfo) { + free(tmpinfo); + tmpinfo = NULL; + } + return RPM_INSTALLER_SUCCESS; + + } + + } else { + /*same package. Reinstall it. Manifest should be parsed again */ + err = _rpm_upgrade_pkg(pkgfilepath, "--force"); + if (err != 0) { + _d_msg(DEBUG_ERR, + "upgrade complete with error(%d)\n", err); + if (info) { + free(info); + info = NULL; + } + if (tmpinfo) { + free(tmpinfo); + tmpinfo = NULL; + } + return err; + } else { + _ri_set_backend_state_info(REQUEST_COMPLETED); + if (info) { + free(info); + info = NULL; + } + if (tmpinfo) { + free(tmpinfo); + tmpinfo = NULL; + } + return RPM_INSTALLER_SUCCESS; + } + } + if (info) { + free(info); + info = NULL; + } + if (tmpinfo) { + free(tmpinfo); + tmpinfo = NULL; + } + return RPM_INSTALLER_SUCCESS; + +} + +int _rpm_installer_package_uninstall(char *pkgid) +{ + int ret = 0; + pkginfo *tmppkginfo = _rpm_installer_get_pkgname_info(pkgid); + if (tmppkginfo == NULL) + return RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED; + if (tmppkginfo) { + free(tmppkginfo); + tmppkginfo = NULL; + } +#ifndef SEND_PKGPATH + if (gpkgname) { + free(gpkgname); + gpkgname = NULL; + } + gpkgname = strdup(pkgid); + _ri_broadcast_status_notification(pkgid, "start", "uninstall"); + _ri_broadcast_status_notification(pkgid, "command", "Uninstall"); +#endif + _ri_set_backend_state_info(GOT_PACKAGE_INFO_SUCCESSFULLY); + ret = _rpm_uninstall_pkg(pkgid); + + _ri_set_backend_state_info(REQUEST_COMPLETED); + + return ret; +} + +int _rpm_installer_clear_private_data(char *pkgid) +{ + if (pkgid == NULL) + return RPM_INSTALLER_ERR_WRONG_PARAM; + char dir_path[256] = { '\0' }; + int ret = -1; + snprintf(dir_path, 255, "/opt/usr/apps/%s/data/", pkgid); + ret = __ri_recursive_delete_dir(dir_path); + return ret; +} diff --git a/backend/src/core/rpm-installer-tool.c b/backend/src/core/rpm-installer-tool.c new file mode 100755 index 0000000..e396e69 --- /dev/null +++ b/backend/src/core/rpm-installer-tool.c @@ -0,0 +1,649 @@ +/* + * rpm-installer + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , + * Jaeho Lee , Shobhit Srivastava + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "rpm-installer.h" +#include "rpm-frontend.h" +#include + +#define RPM "/usr/etc/package-manager/backend/rpm" + +char *gpkgname = NULL; +extern char scrolllabel[256]; +extern int move_type; +enum optionsflags { + INVALID_OPTIONS = 0, + FORCE_OVERWITE = 1, + IGNORE_DEPENDS = 2, +}; + +struct ri_backend_data_t { + int req_cmd; + char *cmd_string; + char *pkgid; + int force_overwrite; +}; + +typedef struct ri_backend_data_t ri_backend_data; +static int __ri_native_recovery(int lastbackstate); +static int __ri_uninstall_package(char *pkgid); +static int __ri_clear_private_data(char *pkgid); +static int __ri_move_package(char *pkgid, int move_type); +static inline int __ri_read_proc(const char *path, char *buf, int size); +static inline int __ri_find_pid_by_cmdline(const char *dname, + const char *cmdline, + const char *priv); +static bool __ri_is_another_instance_running(const char *exepath); + +static int __ri_uninstall_package(char *pkgid) +{ + + if (pkgid == NULL) + return RPM_INSTALLER_ERR_WRONG_PARAM; + int ret = 0; + ret = _rpm_installer_package_uninstall(pkgid); + if (ret == RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED) { + _d_msg(DEBUG_ERR, "[__ri_uninstall_package]%s " + "not installed\n", pkgid); + } else if (ret != 0) { + _d_msg(DEBUG_ERR, + "[__ri_uninstall_package]%s uninstall failed(%d)\n", + pkgid, ret); + } else { + _d_msg(DEBUG_ERR, + "[__ri_uninstall_package]%s successfully uninstalled\n", + pkgid); + } + return ret; +} + +static int __ri_clear_private_data(char *pkgid) +{ + if (pkgid == NULL) + return RPM_INSTALLER_ERR_WRONG_PARAM; + int ret = 0; + ret = _rpm_installer_clear_private_data(pkgid); + if (ret == RPM_INSTALLER_SUCCESS) { + _d_msg(DEBUG_ERR, + "[__clear_private_data]%s clear data successful\n", + pkgid); + } else { + _d_msg(DEBUG_ERR, + "[__clear_private_data]%s clear data failed(%d)\n", + pkgid, ret); + } + return ret; +} + +static int __ri_move_package(char *pkgid, int move_type) +{ + if (pkgid == NULL) + return RPM_INSTALLER_ERR_WRONG_PARAM; + int ret = 0; + ret = _rpm_move_pkg(pkgid, move_type); + if (ret == RPM_INSTALLER_SUCCESS) { + _d_msg(DEBUG_ERR, + "[__ri_move_package]%s move successful\n", + pkgid); + } else { + _d_msg(DEBUG_ERR, + "[__ri_move_package]%s move failed(%d)\n", + pkgid, ret); + } + return ret; +} + +static inline int __ri_read_proc(const char *path, char *buf, int size) +{ + int fd; + int ret; + + if (buf == NULL || path == NULL) + return -1; + + fd = open(path, O_RDONLY); + if (fd < 0) + return -1; + + ret = read(fd, buf, size - 1); + if (ret <= 0) { + close(fd); + return -1; + } else + buf[ret] = 0; + + close(fd); + + return ret; +} + +static inline int __ri_find_pid_by_cmdline(const char *dname, + const char *cmdline, + const char *priv) +{ + int pid = 0; + if (strncmp(cmdline, priv, strlen(RPM)) == 0) { + pid = atoi(dname); + if (pid != getpgid(pid)) + pid = 0; + if (pid == getpid()) + pid = 0; + } + + return pid; +} + +static bool __ri_is_another_instance_running(const char *exepath) +{ + DIR *dp; + struct dirent *dentry; + int pid; + int ret; + char buf[256] = { 0, }; + char buf1[256] = { 0, }; + dp = opendir("/proc"); + if (dp == NULL) { + return 0; + } + while ((dentry = readdir(dp)) != NULL) { + if (!isdigit(dentry->d_name[0])) + continue; + snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry->d_name); + ret = __ri_read_proc(buf, buf1, sizeof(buf)); + if (ret <= 0) + continue; + pid = __ri_find_pid_by_cmdline(dentry->d_name, buf1, exepath); + if (pid > 0) { + closedir(dp); + return 1; + } + } + + closedir(dp); + return 0; + +} + +static int __ri_native_recovery(int lastbackstate) +{ + char *pn = NULL; + int lreq; + int opt; + int err = 0; + char *installoptions = NULL; + + _d_msg(DEBUG_INFO, "Rpm Installer Recovery Entry \n"); + + /* which package it was installing and what was state at that time */ + _ri_get_last_input_info(&pn, &lreq, &opt); + + switch (lastbackstate) { + case REQUEST_ACCEPTED: + case GOT_PACKAGE_INFO_SUCCESSFULLY: + /* + * restart the last operation + */ + _d_msg(DEBUG_INFO, + "Rpm Installer Recovery started. state=%d \n", lastbackstate); + switch (lreq) { + case INSTALL_CMD: + err = + _rpm_installer_package_install(pn, true, "--force"); + if (err) + goto RECOVERYERROR; + break; + + case DELETE_CMD: + err = _rpm_installer_package_uninstall(pn); + if (err) + goto RECOVERYERROR; + break; + + case CLEARDATA_CMD: + case MOVE_CMD: + case RECOVER_CMD: + /*TODO*/ + _d_msg(DEBUG_INFO, + "Recovery of command(%d) is to be implemented\n", lreq); + return 0; + } + _d_msg(DEBUG_INFO, + " Rpm Installer Recovery Ended \n"); + break; + case REQUEST_COMPLETED: + _d_msg(DEBUG_INFO, + " Rpm Installer Recovery. Nothing To Be Done\n"); + _ri_set_backend_state_info(REQUEST_COMPLETED); + break; + + case REQUEST_PENDING: + _d_msg(DEBUG_INFO, + "Rpm Installer Recovery started. state=%d\n", lastbackstate); + /*Only package downgradation can be the case*/ + err = _rpm_installer_package_install(pn, true, "--force"); + if (err != RPM_INSTALLER_SUCCESS && + err != RPM_INSTALLER_ERR_NEED_USER_CONFIRMATION) { + goto RECOVERYERROR; + } + _d_msg(DEBUG_INFO, + " Rpm Installer Recovery ended \n"); + _ri_set_backend_state_info(REQUEST_COMPLETED); + break; + + default: + /* + * Unknown state + * No need to recover + */ + _d_msg(DEBUG_INFO, + " Rpm Installer Recovery Default state \n"); + break; + + } + return 0; + + RECOVERYERROR: + _d_msg(DEBUG_ERR, "Error in Recovery error number = (%d)\n", + err); + return err; + +} + +int _rpm_backend_interface(char *keyid, char *pkgid, char *reqcommand) +{ + int ret = -1; + ri_backend_data data = { 0 }; + int backendstate; + rpmRC rc; + if (reqcommand == NULL) { + _d_msg(DEBUG_ERR, "reqcommand is NULL\n"); + return RPM_INSTALLER_ERR_WRONG_PARAM; + } + if (keyid == NULL || pkgid == NULL) { + if (strncmp(reqcommand, "recover", strlen("recover"))) { + _d_msg(DEBUG_ERR, " Either keyid/pkgid is NULL\n"); + return RPM_INSTALLER_ERR_WRONG_PARAM; + } + } + + if (strncmp(reqcommand, "install", strlen("install")) == 0) { + data.req_cmd = INSTALL_CMD; + data.cmd_string = strdup("install"); + if (data.cmd_string == NULL) { + _d_msg(DEBUG_ERR, + "strdup failed due to insufficient memory\n"); + } + } else if (strncmp(reqcommand, "remove", strlen("remove")) == 0) { + data.req_cmd = DELETE_CMD; + data.cmd_string = strdup("uninstall"); + if (data.cmd_string == NULL) { + _d_msg(DEBUG_ERR, + "strdup failed due to insufficient memory\n"); + } + } else if (strncmp(reqcommand, "recover", strlen("recover")) == 0) { + data.req_cmd = RECOVER_CMD; + data.cmd_string = strdup("recover"); + if (data.cmd_string == NULL) { + _d_msg(DEBUG_ERR, + "strdup failed due to insufficient memory\n"); + } + } else if (strncmp(reqcommand, "cleardata", strlen("cleardata")) == 0) { + data.req_cmd = CLEARDATA_CMD; + data.cmd_string = strdup("cleardata"); + if (data.cmd_string == NULL) { + _d_msg(DEBUG_ERR, + "strdup failed due to insufficient memory\n"); + } + } else if (strncmp(reqcommand, "move", strlen("move")) == 0) { + data.req_cmd = MOVE_CMD; + data.cmd_string = strdup("move"); + if (data.cmd_string == NULL) { + _d_msg(DEBUG_ERR, + "strdup failed due to insufficient memory\n"); + } + } else { + _d_msg(DEBUG_INFO, "wrong input parameter\n"); + _d_msg(DEBUG_RESULT, "%d\n", RPM_INSTALLER_ERR_WRONG_PARAM); + return RPM_INSTALLER_ERR_WRONG_PARAM; + } + + data.pkgid = pkgid; + backendstate = _ri_get_backend_state(); + + rc = rpmReadConfigFiles(NULL, NULL); + if (rc == RPMRC_OK) { + _d_msg(DEBUG_INFO, "Successfully read rpm configuration\n"); + } else { + _d_msg(DEBUG_ERR, "Unable to read RPM configuration.\n"); + return RPM_INSTALLER_ERR_INTERNAL; + } + + if (RECOVER_CMD == data.req_cmd) { + if (0 == backendstate) { + int lastbackstate; + + /* check the current state of backend */ + lastbackstate = _ri_get_backend_state_info(); + + if (REQUEST_COMPLETED == lastbackstate) { + _d_msg(DEBUG_INFO, + " Rpm Installer recovery is in REQUEST_COMPLETED \n"); + snprintf(scrolllabel, sizeof(scrolllabel), + "No Recovery Needed"); + } else + ret = __ri_native_recovery(lastbackstate); + if (ret == 0) + snprintf(scrolllabel, sizeof(scrolllabel), + "Recovery Success"); + else + snprintf(scrolllabel, sizeof(scrolllabel), + "Recovery Failed"); + + /* set the backend state as completed */ + _ri_set_backend_state(1); + } else { + /* nothing to recover */ + _d_msg(DEBUG_INFO, + " Rpm Installer recovery Nothing to be done\n"); + ret = 0; + snprintf(scrolllabel, sizeof(scrolllabel), + "No Recovery Needed"); + } + _d_msg(DEBUG_RESULT, "%d\n", ret); + return ret; + + } + if (backendstate == 0) { + + /* Non Recovery case + * + * Another Instance may be running + * or something went wrong in last execution + * Check for it + */ + if (__ri_is_another_instance_running(RPM)) { + if (data.pkgid) { + _ri_broadcast_status_notification + (data.pkgid, "error", + "Another Instance Running"); + _ri_stat_cb(data.pkgid, "error", + "Another Instance Running"); + _ri_broadcast_status_notification + (data.pkgid, "end", "fail"); + _ri_stat_cb(data.pkgid, "end", + "fail"); + } else { + _ri_broadcast_status_notification + ("unknown", "error", + "Another Instance Running"); + _ri_stat_cb("unknown", "error", + "Another Instance Running"); + _ri_broadcast_status_notification + ("unknown", "end", "fail"); + _ri_stat_cb("unknown", "end", "fail"); + } + _d_msg(DEBUG_INFO, + "Request Failed as " + "Another Instance is running \n"); + ret = RPM_INSTALLER_ERR_RESOURCE_BUSY; + return ret; + } else { + int lastbackstate; + + /* check the current state of backend */ + lastbackstate = _ri_get_backend_state_info(); + /* Publish Notification that backend has started */ + _ri_broadcast_status_notification(data.pkgid, + "start", + data.cmd_string); + _ri_broadcast_status_notification(data.pkgid, + "command", + data.cmd_string); + if (REQUEST_COMPLETED == lastbackstate) { + _d_msg(DEBUG_INFO, + " Rpm Installer recovery" + " is in REQUEST_COMPLETED \n"); + ret = 0; + } else + ret = __ri_native_recovery(lastbackstate); + if (ret != 0) { + _d_msg(DEBUG_INFO, + "recovery of last request failed\n"); + } else { + _d_msg(DEBUG_INFO, + "recovery of last request success\n"); + } + + /* set the backend state as completed */ + _ri_set_backend_state(1); + } + } + + /* set the backend state as started for the current request*/ + _ri_set_backend_state(0); + +#ifdef SEND_PKGPATH + gpkgname = strdup(data.pkgid); + + /* Publish Notification that backend has started */ + if (data.pkgid) + _ri_broadcast_status_notification(data.pkgid, "start", + data.cmd_string); + else + _ri_broadcast_status_notification("unknown", "start", + data.cmd_string); +#endif + + _ri_set_backend_state_info(REQUEST_ACCEPTED); + + /* Set the input request info */ + _ri_save_last_input_info(data.pkgid, data.req_cmd, + data.force_overwrite); + + switch (data.req_cmd) { + case INSTALL_CMD: + { + _d_msg(DEBUG_INFO, "[%s] --install %s\n", + "backend", data.pkgid); +#ifdef SEND_PKGPATH + _ri_broadcast_status_notification(data.pkgid, + "command", "Install"); +#endif + if (data.force_overwrite == FORCE_OVERWITE) { + _d_msg(DEBUG_INFO, + "[%s] --install %s --force-overwrite\n", + "backend", data.pkgid); + ret = + _rpm_installer_package_install + (data.pkgid, true, "--force"); + } else { + _d_msg(DEBUG_INFO, "[%s] --install %s\n", + "backend", data.pkgid); + ret = + _rpm_installer_package_install + (data.pkgid, false, NULL); + } + if (ret == RPM_INSTALLER_ERR_NEED_USER_CONFIRMATION) { + break; + } else if (ret == RPM_INSTALLER_SUCCESS) { + _d_msg(DEBUG_INFO, "install success\n"); + _ri_broadcast_status_notification(data.pkgid, + "end", "ok"); + _ri_stat_cb(data.pkgid, "end", "ok"); + } else { + + char *errstr = NULL; + _ri_error_no_to_string(ret, &errstr); + _ri_broadcast_status_notification(data.pkgid, + "error", + errstr); + _ri_stat_cb(data.pkgid, "error", errstr); + _ri_broadcast_status_notification(data.pkgid, + "end", + "fail"); + sleep(2); + _ri_stat_cb(data.pkgid, "end", "fail"); + _d_msg(DEBUG_ERR, + "install failed with err(%d) (%s)\n", + ret, errstr); + } + } + break; + case DELETE_CMD: + { + _d_msg(DEBUG_INFO, "[%s] uninstall %s\n", + "backend", data.pkgid); +#ifdef SEND_PKGPATH + _ri_broadcast_status_notification(data.pkgid, + "command", "Remove"); +#endif + ret = __ri_uninstall_package(data.pkgid); + if (ret != 0) { + char *errstr = NULL; + _ri_error_no_to_string(ret, &errstr); + _ri_broadcast_status_notification(data.pkgid, + "error", + errstr); + _ri_stat_cb(data.pkgid, "error", errstr); + sleep(2); + _ri_broadcast_status_notification(data.pkgid, + "end", + "fail"); + _ri_stat_cb(data.pkgid, "end", "fail"); + _d_msg(DEBUG_ERR, + "remove failed with err(%d) (%s)\n", + ret, errstr); + } else { + _d_msg(DEBUG_INFO, "remove success\n"); + _ri_broadcast_status_notification(data.pkgid, + "end", "ok"); + _ri_stat_cb(data.pkgid, "end", "ok"); + } + } + break; + case CLEARDATA_CMD: + { + _d_msg(DEBUG_INFO, "[%s] clear data %s\n", + "backend", data.pkgid); +#ifdef SEND_PKGPATH + _ri_broadcast_status_notification(data.pkgid, + "command", "clear"); +#endif + ret = __ri_clear_private_data(data.pkgid); + if (ret != 0) { + char *errstr = NULL; + _ri_error_no_to_string(ret, &errstr); + _ri_broadcast_status_notification(data.pkgid, + "error", + errstr); + _ri_stat_cb(data.pkgid, "error", errstr); + _ri_broadcast_status_notification(data.pkgid, + "end", + "fail"); + _ri_stat_cb(data.pkgid, "end", "fail"); + _d_msg(DEBUG_ERR, + "clear data failed with err(%d) (%s)\n", + ret, errstr); + } else { + _d_msg(DEBUG_INFO, "clear data success\n"); + _ri_broadcast_status_notification(data.pkgid, + "end", "ok"); + _ri_stat_cb(data.pkgid, "end", "ok"); + } + break; + } + case MOVE_CMD: + { + _d_msg(DEBUG_INFO, "[%s] move %s\n", + "backend", data.pkgid); +#ifdef SEND_PKGPATH + _ri_broadcast_status_notification(data.pkgid, + "command", "move"); +#endif + ret = __ri_move_package(data.pkgid, move_type); + if (ret != 0) { + char *errstr = NULL; + _ri_error_no_to_string(ret, &errstr); + _ri_broadcast_status_notification(data.pkgid, + "error", + errstr); + _ri_stat_cb(data.pkgid, "error", errstr); + _ri_broadcast_status_notification(data.pkgid, + "end", + "fail"); + _ri_stat_cb(data.pkgid, "end", "fail"); + _d_msg(DEBUG_ERR, + "move failed with err(%d) (%s)\n", + ret, errstr); + } else { + _d_msg(DEBUG_INFO, "move success\n"); + _ri_broadcast_status_notification(data.pkgid, + "end", "ok"); + _ri_stat_cb(data.pkgid, "end", "ok"); + } + break; + } + default: + { + _ri_broadcast_status_notification("unknown", "command", + "unknown"); + _ri_broadcast_status_notification("unknown", "error", + "not supported"); + _ri_stat_cb("unknown", "error", "not supported"); + _ri_broadcast_status_notification("unknown", + "end", "fail"); + _ri_stat_cb("unknown", "end", "fail"); + _d_msg(DEBUG_ERR, "unknown command \n"); + ret = RPM_INSTALLER_ERR_WRONG_PARAM; + } + } + + if (gpkgname) { + free(gpkgname); + gpkgname = NULL; + } + + if (data.cmd_string) { + free(data.cmd_string); + data.cmd_string = NULL; + } + + if (_ri_get_backend_state_info() != REQUEST_PENDING) { + _ri_set_backend_state_info(REQUEST_COMPLETED); + /* set the backend state as completed */ + _ri_set_backend_state(1); + _d_msg(DEBUG_RESULT, "%d\n", ret); + _d_msg_deinit(); + } + return ret; +} diff --git a/backend/src/rpm/rpm-installer.c b/backend/src/rpm/rpm-installer.c new file mode 100755 index 0000000..a2aae62 --- /dev/null +++ b/backend/src/rpm/rpm-installer.c @@ -0,0 +1,786 @@ +/* + * rpm-installer + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , + * Jaeho Lee , Shobhit Srivastava + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#define __USE_GNU +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* for isspace () */ +#include +#include +#include + +#include "rpm-installer-util.h" +#include "rpm-installer.h" +#include "rpm-frontend.h" + +#define PRE_CHECK_FOR_MANIFEST +#define INSTALL_SCRIPT "/usr/bin/install_rpm_package.sh" +#define UNINSTALL_SCRIPT "/usr/bin/uninstall_rpm_package.sh" +#define UPGRADE_SCRIPT "/usr/bin/upgrade_rpm_package.sh" +#define RPM2CPIO "/usr/bin/rpm2cpio" + +enum rpm_request_type { + INSTALL_REQ, + UNINSTALL_REQ, + UPGRADE_REQ, +}; + +#define APP2EXT_ENABLE +#ifdef APP2EXT_ENABLE +#include +#endif + +typedef enum rpm_request_type rpm_request_type; +extern char *gpkgname; + +static int __rpm_xsystem(const char *argv[]); +static void __rpm_process_line(char *line); +static void __rpm_perform_read(int fd); +static void __rpm_clear_dir_list(GList* dir_list); +static GList * __rpm_populate_dir_list(); + +static void __rpm_process_line(char *line) +{ + char *tok = NULL; + tok = strtok(line, " "); + if (tok) { + if (!strncmp(tok, "%%", 2)) { + tok = strtok(NULL, " "); + if (tok) { + _d_msg(DEBUG_INFO, "Install percentage is %s\n", + tok); + _ri_broadcast_status_notification(gpkgname, + "install_percent", + tok); + _ri_stat_cb(gpkgname, "install_percent", tok); + } + return; + } + } + return; +} + +static void __rpm_perform_read(int fd) +{ + char *buf_ptr = NULL; + char *tmp_ptr = NULL; + int size = 0; + static char buffer[1024] = { 0, }; + static int buffer_position; + + size = read(fd, &buffer[buffer_position], + sizeof(buffer) - buffer_position); + buffer_position += size; + if (size <= 0) + return; + + /* Process each line of the recieved buffer */ + buf_ptr = tmp_ptr = buffer; + while ((tmp_ptr = (char *)memchr(buf_ptr, '\n', + buffer + buffer_position - buf_ptr)) != + NULL) { + *tmp_ptr = 0; + __rpm_process_line(buf_ptr); + /* move to next line and continue */ + buf_ptr = tmp_ptr + 1; + } + + /*move the remaining bits at the start of the buffer + and update the buffer position */ + buf_ptr = (char *)memrchr(buffer, 0, buffer_position); + if (buf_ptr == NULL) + return; + + /* we have processed till the last \n which has now become + 0x0. So we increase the pointer to next position */ + buf_ptr++; + + memmove(buffer, buf_ptr, buf_ptr - buffer); + buffer_position = buffer + buffer_position - buf_ptr; +} + +static int __rpm_xsystem(const char *argv[]) +{ + int err = 0; + int status = 0; + pid_t pid; + int pipefd[2]; + + if (pipe(pipefd) == -1) { + _d_msg(DEBUG_ERR, "pipe creation failed\n"); + return -1; + } + /*Read progress info via pipe */ + pid = fork(); + + switch (pid) { + case -1: + _d_msg(DEBUG_ERR, "fork failed\n"); + return -1; + case 0: + /* child */ + { + close(pipefd[0]); + close(1); + close(2); + dup(pipefd[1]); + dup(pipefd[1]); + if (execvp(argv[0], (char *const *)argv) == -1) { + _d_msg(DEBUG_ERR, "execvp failed\n"); + } + _exit(100); + } + default: + /* parent */ + break; + } + + close(pipefd[1]); + + while ((err = waitpid(pid, &status, WNOHANG)) != pid) { + if (err < 0) { + if (errno == EINTR) + continue; + _d_msg(DEBUG_ERR, "waitpid failed\n"); + close(pipefd[0]); + return -1; + } + + int select_ret; + fd_set rfds; + struct timespec tv; + FD_ZERO(&rfds); + FD_SET(pipefd[0], &rfds); + tv.tv_sec = 1; + tv.tv_nsec = 0; + select_ret = + pselect(pipefd[0] + 1, &rfds, NULL, NULL, &tv, NULL); + if (select_ret == 0) + continue; + + else if (select_ret < 0 && errno == EINTR) + continue; + else if (select_ret < 0) { + _d_msg(DEBUG_ERR, "select() returned error\n"); + continue; + } + if (FD_ISSET(pipefd[0], &rfds)) + __rpm_perform_read(pipefd[0]); + } + + close(pipefd[0]); + /* Check for an error code. */ + if (WIFEXITED(status) == 0 || WEXITSTATUS(status) != 0) { + + if (WIFSIGNALED(status) != 0 && WTERMSIG(status) == SIGSEGV) { + printf + ("Sub-process %s received a segmentation fault. \n", + argv[0]); + } else if (WIFEXITED(status) != 0) { + printf("Sub-process %s returned an error code (%u)\n", + argv[0], WEXITSTATUS(status)); + } else { + printf("Sub-process %s exited unexpectedly\n", argv[0]); + } + } + return WEXITSTATUS(status); +} + +static void __rpm_clear_dir_list(GList* dir_list) +{ + GList *list = NULL; + app2ext_dir_details* dir_detail = NULL; + if (dir_list) { + list = g_list_first(dir_list); + while (list) { + dir_detail = (app2ext_dir_details *)list->data; + if (dir_detail && dir_detail->name) { + free(dir_detail->name); + } + list = g_list_next(list); + } + g_list_free(dir_list); + } +} + +static GList * __rpm_populate_dir_list() +{ + GList *dir_list = NULL; + GList *list = NULL; + app2ext_dir_details* dir_detail = NULL; + int i; + char pkg_ro_content_rpm[3][5] = { "bin", "res", "lib" }; + + + for (i=0; i<3; i++) { + dir_detail = (app2ext_dir_details*) calloc(1, sizeof(app2ext_dir_details)); + if (dir_detail == NULL) { + printf("\nMemory allocation failed\n"); + goto FINISH_OFF; + } + dir_detail->name = (char*) calloc(1, sizeof(char)*(strlen(pkg_ro_content_rpm[i])+2)); + if (dir_detail->name == NULL) { + printf("\nMemory allocation failed\n"); + free(dir_detail); + goto FINISH_OFF; + } + snprintf(dir_detail->name, (strlen(pkg_ro_content_rpm[i])+1), "%s", pkg_ro_content_rpm[i]); + dir_detail->type = APP2EXT_DIR_RO; + dir_list = g_list_append(dir_list, dir_detail); + } + if (dir_list) { + list = g_list_first(dir_list); + while (list) { + dir_detail = (app2ext_dir_details *)list->data; + list = g_list_next(list); + } + } + return dir_list; +FINISH_OFF: + if (dir_list) { + list = g_list_first(dir_list); + while (list) { + dir_detail = (app2ext_dir_details *)list->data; + if (dir_detail && dir_detail->name) { + free(dir_detail->name); + } + list = g_list_next(list); + } + g_list_free(dir_list); + } + return NULL; +} + +int _rpm_uninstall_pkg(char *pkgid) +{ + int ret = 0; + int err = 0; + char buff[256] = {'\0'}; + pkgmgr_install_location location = 1; + int size = -1; +#ifdef APP2EXT_ENABLE + app2ext_handle *handle = NULL; +#endif + char *manifest = NULL; + pkgmgr_pkginfo_h pkghandle; + const char *argv[] = { UNINSTALL_SCRIPT, pkgid, NULL }; + +#ifdef APP2EXT_ENABLE + ret = pkgmgr_pkginfo_get_pkginfo(pkgid, &pkghandle); + if (ret < 0) { + _d_msg(DEBUG_ERR, "Failed to get pkginfo handle\n"); +// return RPM_INSTALLER_ERR_INTERNAL; + } else { + ret = pkgmgr_pkginfo_get_install_location(pkghandle, &location); + if (ret < 0) { + _d_msg(DEBUG_ERR, "Failed to get install location\n"); + pkgmgr_pkginfo_destroy_pkginfo(pkghandle); + return RPM_INSTALLER_ERR_INTERNAL; + } + pkgmgr_pkginfo_destroy_pkginfo(pkghandle); + if (location == PM_INSTALL_LOCATION_PREFER_EXTERNAL) { + handle = app2ext_init(APP2EXT_SD_CARD); + if (handle == NULL) { + _d_msg(DEBUG_ERR, "app2ext init failed\n"); + return RPM_INSTALLER_ERR_INTERNAL; + } + if ((&(handle->interface) != NULL) && (handle->interface.pre_uninstall != NULL) && (handle->interface.post_uninstall != NULL)){ + ret = app2ext_get_app_location(pkgid); + if (ret == APP2EXT_INTERNAL_MEM){ + _d_msg(DEBUG_ERR, "app2xt APP is not in MMC, go internal (%d)\n", ret); + } + else { + ret = handle->interface.pre_uninstall(pkgid); + if (ret == APP2EXT_ERROR_MMC_STATUS || ret == APP2EXT_SUCCESS ) { + _d_msg(DEBUG_ERR, "app2xt MMC is not here, go internal (%d)\n", ret); + } + else { + _d_msg(DEBUG_ERR, "app2xt pre uninstall API failed (%d)\n", ret); + handle->interface.post_uninstall(pkgid); + return RPM_INSTALLER_ERR_INTERNAL; + } + } + } + } + } +#endif + +#ifdef PRE_CHECK_FOR_MANIFEST + /*Manifest info should be removed first because after installation manifest + file is uninstalled. If uninstallation fails, we need to re-insert manifest info for consistency*/ + manifest = pkgmgr_parser_get_manifest_file(pkgid); + if (manifest == NULL) { + _d_msg(DEBUG_ERR, "manifest name is NULL\n"); + return RPM_INSTALLER_ERR_INTERNAL; + } + _d_msg(DEBUG_INFO, "manifest name is %s\n", manifest); + pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL); +#endif + + ret = __rpm_xsystem(argv); + if (ret != 0) { + _d_msg(DEBUG_ERR, "uninstall failed with error(%d)\n", ret); + #ifdef PRE_CHECK_FOR_MANIFEST + err = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL); + if (err < 0) { + _d_msg(DEBUG_ERR, "Parsing Manifest Failed\n"); + } + if (manifest) { + free(manifest); + manifest = NULL; + } + #endif + #ifdef APP2EXT_ENABLE + if ((handle != NULL) && (handle->interface.post_uninstall != NULL)){ + handle->interface.post_uninstall(pkgid); + } + #endif + return ret; + } + +#ifdef APP2EXT_ENABLE + if ((handle != NULL) && (handle->interface.post_uninstall != NULL)){ + handle->interface.post_uninstall(pkgid); + app2ext_deinit(handle); + } +#endif + +#ifdef PRE_CHECK_FOR_MANIFEST + if (manifest) { + free(manifest); + manifest = NULL; + } +#endif + /* Uninstallation Success. Remove the installation time key from vconf*/ + snprintf(buff, 256, "db/app-info/%s/installed-time", pkgid); + err = vconf_unset(buff); + if (err) { + _d_msg(DEBUG_ERR, "unset installation time failed\n"); + } + return ret; +} + +int _rpm_install_pkg(char *pkgfilepath, char *installoptions) +{ + int err = 0; + int ret = 0; + time_t cur_time; + char buff[256] = {'\0'}; + char manifest[1024] = { '\0'}; + char *mfst = NULL; + pkgmgrinfo_install_location location = 1; + int size = -1; +#ifdef APP2EXT_ENABLE + app2ext_handle *handle = NULL; + GList *dir_list = NULL; +#endif + pkgmgr_pkginfo_h pkghandle; + const char *argv[] = { + INSTALL_SCRIPT, pkgfilepath, installoptions, NULL + }; + +#ifdef PRE_CHECK_FOR_MANIFEST + char cwd[1024] = {'\0'}; + char query[1024] = {'\0'}; + int m_exist = 0; + getcwd(cwd, 1024); + if (cwd[0] == '\0') { + _d_msg(DEBUG_ERR, "getcwd() Failed\n"); + return RPM_INSTALLER_ERR_INTERNAL; + } + _d_msg(DEBUG_ERR, "Current working directory is %s\n", cwd); + err = chdir("/tmp"); + if (err != 0) { + _d_msg(DEBUG_ERR, "chdir() failed\n"); + return RPM_INSTALLER_ERR_INTERNAL; + } + _d_msg(DEBUG_ERR, "Switched to /tmp\n"); + snprintf(query, 1024, "/usr/bin/rpm2cpio %s | cpio -idmv", pkgfilepath); + _d_msg(DEBUG_INFO, "query= %s\n", query); + system(query); + snprintf(manifest, 1024, "/tmp/opt/share/packages/%s.xml", gpkgname); + _d_msg(DEBUG_ERR, "Manifest name is %s\n", manifest); + if (access(manifest, F_OK)) { + _d_msg(DEBUG_ERR, "No rw Manifest File Found\n"); + + snprintf(manifest, 1024, "/tmp/usr/share/packages/%s.xml", gpkgname); + _d_msg(DEBUG_ERR, "Manifest ro name is %s\n", manifest); + + if (access(manifest, F_OK)) { + _d_msg(DEBUG_ERR, "No ro Manifest File Found\n"); +// unlink(manifest); +// return RPM_INSTALLER_ERR_NO_MANIFEST; + } else + m_exist = 1; + } else + m_exist = 1; + + _d_msg(DEBUG_ERR, "Manifest exists\n"); + + err = chdir(cwd); + if (err != 0) { + _d_msg(DEBUG_ERR, "chdir() failed\n"); +// unlink(manifest); +// return RPM_INSTALLER_ERR_INTERNAL; + } + + if (m_exist) { + err = pkgmgr_parser_check_manifest_validation(manifest); + if(err < 0) { + _d_msg(DEBUG_ERR, "Invalid manifest\n"); + unlink(manifest); + return RPM_INSTALLER_ERR_INVALID_MANIFEST; + } + } +#endif + +#ifdef APP2EXT_ENABLE + ret = pkgmgrinfo_pkginfo_get_location_from_xml(manifest, &location); + + if (ret < 0) { + _d_msg(DEBUG_ERR, "Failed to get install location\n"); + return RPM_INSTALLER_ERR_INTERNAL; + } else { + if (location == PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL) { + ret = pkgmgrinfo_pkginfo_get_size_from_xml(manifest, &size); + if (ret < 0) { + _d_msg(DEBUG_ERR, "Failed to get package size\n"); + return RPM_INSTALLER_ERR_INTERNAL; + } + } + } + + if ((location == PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL) && size > 0) { + handle = app2ext_init(APP2EXT_SD_CARD); + if (handle == NULL) { + _d_msg(DEBUG_ERR, "app2ext init failed\n"); + return RPM_INSTALLER_ERR_INTERNAL; + } + if ((&(handle->interface) != NULL) && (handle->interface.pre_install != NULL) && (handle->interface.post_install != NULL)){ + dir_list = __rpm_populate_dir_list(); + if (dir_list == NULL) { + _d_msg(DEBUG_ERR, "\nError in populating the directory list\n"); + app2ext_deinit(handle); + return RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS; + } + ret = handle->interface.pre_install(gpkgname, dir_list, size); + if (ret == APP2EXT_ERROR_MMC_STATUS) { + _d_msg(DEBUG_ERR, "app2xt MMC is not here, go internal\n"); + } else if (ret == APP2EXT_SUCCESS){ + _d_msg(DEBUG_ERR, "pre_install done, go internal\n"); + } + else { + _d_msg(DEBUG_ERR, "app2xt pre install API failed (%d)\n", ret); + __rpm_clear_dir_list(dir_list); + handle->interface.post_install(gpkgname, APP2EXT_STATUS_FAILED); + app2ext_deinit(handle); + return RPM_INSTALLER_ERR_INTERNAL; + } + } + } +#endif + + err = __rpm_xsystem(argv); + + if (err != 0) { + _d_msg(DEBUG_ERR, "install complete with error(%d)\n", err); + + #ifdef APP2EXT_ENABLE + if ((handle != NULL) && (handle->interface.post_install != NULL)){ + __rpm_clear_dir_list(dir_list); + handle->interface.post_install(gpkgname, APP2EXT_STATUS_FAILED); + } + #endif + + return err; + } + +#ifdef APP2EXT_ENABLE + if ((handle != NULL) && (handle->interface.post_install != NULL)){ + __rpm_clear_dir_list(dir_list); + handle->interface.post_install(gpkgname, APP2EXT_STATUS_SUCCESS); + app2ext_deinit(handle); + } +#endif + + /*Parse the manifest to get install location and size. If installation fails, remove manifest info from DB*/ + err = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL); + if (err < 0) { + _d_msg(DEBUG_ERR, "Parsing Manifest Failed\n"); +// unlink(manifest); +// return RPM_INSTALLER_ERR_INTERNAL; + } else { + _d_msg(DEBUG_ERR, "Parsing Manifest Success\n"); + return err; + } + +#ifndef PRE_CHECK_FOR_MANIFEST + mfst = pkgmgr_parser_get_manifest_file(gpkgname); + if (mfst == NULL) { + _d_msg(DEBUG_ERR, "manifest name is NULL\n"); + unlink(manifest); + return RPM_INSTALLER_ERR_INTERNAL; + } + pkgmgr_parser_parse_manifest_for_installation(mfst, NULL); + if (mfst) { + free(mfst); + mfst = NULL; + } +#endif + /* Install Success. Store the installation time*/ + cur_time = time(NULL); + snprintf(buff, 256, "db/app-info/%s/installed-time", gpkgname); + /* The time is stored in time_t format. It can be converted to + local time or GMT time as per the need by the apps*/ + ret = vconf_set_int(buff, cur_time); + if(ret) { + _d_msg(DEBUG_ERR, "setting installation time failed\n"); + vconf_unset(buff); + } + unlink(manifest); + return err; +} + +int _rpm_upgrade_pkg(char *pkgfilepath, char *installoptions) +{ + int err = 0; + int ret = 0; + time_t cur_time; + char buff[256] = {'\0'}; + char manifest[1024] = { '\0'}; + char *mfst = NULL; + pkgmgr_install_location location = 1; + int size = -1; +#ifdef APP2EXT_ENABLE + app2ext_handle *handle = NULL; + GList *dir_list = NULL; +#endif + pkgmgr_pkginfo_h pkghandle; + const char *argv[] = { + UPGRADE_SCRIPT, pkgfilepath, installoptions, NULL + }; + +#ifdef PRE_CHECK_FOR_MANIFEST + char cwd[1024] = {'\0'}; + char query[1024] = {'\0'}; + int m_exist = 0; + getcwd(cwd, 1024); + if (cwd[0] == '\0') { + _d_msg(DEBUG_ERR, "getcwd() Failed\n"); + return RPM_INSTALLER_ERR_INTERNAL; + } + _d_msg(DEBUG_ERR, "Current working directory is %s\n", cwd); + err = chdir("/tmp"); + if (err != 0) { + _d_msg(DEBUG_ERR, "chdir() failed\n"); + return RPM_INSTALLER_ERR_INTERNAL; + } + _d_msg(DEBUG_ERR, "Switched to /tmp\n"); + snprintf(query, 1024, "/usr/bin/rpm2cpio %s | cpio -idmv", pkgfilepath); + _d_msg(DEBUG_INFO, "query= %s\n", query); + system(query); + snprintf(manifest, 1024, "/tmp/opt/share/packages/%s.xml", gpkgname); + _d_msg(DEBUG_ERR, "Manifest name is %s\n", manifest); + if (access(manifest, F_OK)) { + _d_msg(DEBUG_ERR, "No rw Manifest File Found\n"); + + snprintf(manifest, 1024, "/tmp/usr/share/packages/%s.xml", gpkgname); + _d_msg(DEBUG_ERR, "Manifest ro name is %s\n", manifest); + + if (access(manifest, F_OK)) { + _d_msg(DEBUG_ERR, "No ro Manifest File Found\n"); +// unlink(manifest); +// return RPM_INSTALLER_ERR_NO_MANIFEST; + } else + m_exist = 1; + } else + m_exist = 1; + + _d_msg(DEBUG_ERR, "Manifest exists\n"); + + err = chdir(cwd); + if (err != 0) { + _d_msg(DEBUG_ERR, "chdir() failed\n"); +// unlink(manifest); +// return RPM_INSTALLER_ERR_INTERNAL; + } + + if (m_exist) { + err = pkgmgr_parser_check_manifest_validation(manifest); + if(err < 0) { + _d_msg(DEBUG_ERR, "Invalid manifest\n"); + unlink(manifest); + return RPM_INSTALLER_ERR_INVALID_MANIFEST; + } + } + /*Parse the manifest to get install location and size. If upgradation fails, remove manifest info from DB*/ + err = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL); + if (err < 0) { + _d_msg(DEBUG_ERR, "Parsing Manifest Failed\n"); +// unlink(manifest); +// return RPM_INSTALLER_ERR_INTERNAL; + } else { + _d_msg(DEBUG_ERR, "Parsing Manifest Success\n"); + } +#endif + +#ifdef APP2EXT_ENABLE + ret = pkgmgr_pkginfo_get_pkginfo(gpkgname, &pkghandle); + if (ret < 0) { + _d_msg(DEBUG_ERR, "Failed to get pkginfo handle\n"); +// unlink(manifest); +// return RPM_INSTALLER_ERR_INTERNAL; + } else { + ret = pkgmgr_pkginfo_get_install_location(pkghandle, &location); + if (ret < 0) { + _d_msg(DEBUG_ERR, "Failed to get install location\n"); + pkgmgr_pkginfo_destroy_pkginfo(pkghandle); + unlink(manifest); + return RPM_INSTALLER_ERR_INTERNAL; + } else { + if (location == PM_INSTALL_LOCATION_PREFER_EXTERNAL) { + ret = pkgmgr_pkginfo_get_package_size(pkghandle, &size); + if (ret < 0) { + _d_msg(DEBUG_ERR, "Failed to get package size\n"); + pkgmgr_pkginfo_destroy_pkginfo(pkghandle); + unlink(manifest); + return RPM_INSTALLER_ERR_INTERNAL; + } + } + } + pkgmgr_pkginfo_destroy_pkginfo(pkghandle); + if ((location == PM_INSTALL_LOCATION_PREFER_EXTERNAL) && size > 0) { + handle = app2ext_init(APP2EXT_SD_CARD); + if (handle == NULL) { + _d_msg(DEBUG_ERR, "app2ext init failed\n"); + unlink(manifest); + return RPM_INSTALLER_ERR_INTERNAL; + } + if ((&(handle->interface) != NULL) && (handle->interface.pre_upgrade != NULL) && (handle->interface.post_upgrade != NULL)){ + dir_list = __rpm_populate_dir_list(); + if (dir_list == NULL) { + _d_msg(DEBUG_ERR, "\nError in populating the directory list\n"); + return RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS; + } + ret = handle->interface.pre_upgrade(gpkgname, dir_list, size); + if (ret == APP2EXT_ERROR_MMC_STATUS || ret == APP2EXT_SUCCESS ) { + _d_msg(DEBUG_ERR, "app2xt MMC is not here, go internal (%d)\n", ret); + } + else { + _d_msg(DEBUG_ERR, "app2xt pre upgrade API failed (%d)\n", ret); + __rpm_clear_dir_list(dir_list); + handle->interface.post_upgrade(gpkgname, APP2EXT_STATUS_FAILED); + unlink(manifest); + return RPM_INSTALLER_ERR_INTERNAL; + } + } + } + } +#endif + + err = __rpm_xsystem(argv); + if (err != 0) { + _d_msg(DEBUG_ERR, "upgrade complete with error(%d)\n", err); + /*remove manifest info*/ + #ifdef PRE_CHECK_FOR_MANIFEST + pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL); + #endif + #ifdef APP2EXT_ENABLE + if ((handle != NULL) && (handle->interface.post_upgrade != NULL)){ + __rpm_clear_dir_list(dir_list); + handle->interface.post_upgrade(gpkgname, APP2EXT_STATUS_FAILED); + } + #endif + unlink(manifest); + return err; + } +#ifdef APP2EXT_ENABLE + if ((handle != NULL) && (handle->interface.post_upgrade != NULL)){ + __rpm_clear_dir_list(dir_list); + handle->interface.post_upgrade(gpkgname, APP2EXT_STATUS_SUCCESS); + app2ext_deinit(handle); + } +#endif +#ifndef PRE_CHECK_FOR_MANIFEST + mfst = pkgmgr_parser_get_manifest_file(gpkgname); + if (mfst == NULL) { + _d_msg(DEBUG_ERR, "manifest name is NULL\n"); + unlink(manifest); + return RPM_INSTALLER_ERR_INTERNAL; + } + pkgmgr_parser_parse_manifest_for_upgrade(mfst, NULL); + if (mfst) { + free(mfst); + mfst = NULL; + } +#endif + unlink(manifest); + return err; +} + +int _rpm_move_pkg(char *pkgid, int move_type) +{ + app2ext_handle *hdl = NULL; + int ret = 0; + int movetype = -1; + GList *dir_list = NULL; + + if (move_type == PM_MOVE_TO_INTERNAL) + movetype = APP2EXT_MOVE_TO_PHONE; + else if (move_type == PM_MOVE_TO_SDCARD) + movetype = APP2EXT_MOVE_TO_EXT; + else + return RPM_INSTALLER_ERR_WRONG_PARAM; + + hdl = app2ext_init(APP2EXT_SD_CARD); + if ((hdl != NULL) && (hdl->interface.move != NULL)){ + dir_list = __rpm_populate_dir_list(); + if (dir_list == NULL) { + _d_msg(DEBUG_ERR, "\nError in populating the directory list\n"); + return RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS; + } + ret = hdl->interface.move(pkgid, dir_list, movetype); + __rpm_clear_dir_list(dir_list); + if (ret != 0) { + _d_msg(DEBUG_ERR, "Failed to move app\n"); + return RPM_INSTALLER_ERR_INTERNAL; + } + app2ext_deinit(hdl); + return RPM_INSTALLER_SUCCESS; + } else { + _d_msg(DEBUG_ERR,"Failed to get app2ext handle\n"); + return RPM_INSTALLER_ERR_INTERNAL; + } +} + diff --git a/backend/src/vconf/rpm-vconf-intf.c b/backend/src/vconf/rpm-vconf-intf.c new file mode 100755 index 0000000..3dab0d9 --- /dev/null +++ b/backend/src/vconf/rpm-vconf-intf.c @@ -0,0 +1,177 @@ +/* + * rpm-installer + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , + * Jaeho Lee , Shobhit Srivastava + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include + +#include "rpm-installer-util.h" +#include "rpm-installer.h" + +#define VCONF_LOCATION "db" +#define VCONF_RPM_INSTALLER VCONF_LOCATION"/private/rpm-installer" + +#define VCONF_RPM_INSTALLER_BACKEND_STATE \ + VCONF_RPM_INSTALLER"/state" +#define VCONF_RPM_INSTALLER_BACKEND_STATEINFO \ + VCONF_RPM_INSTALLER"/stateinfo" + +#define VCONF_RPM_INSTALLER_LAST_REQUESTINFO_COMMAND \ + VCONF_RPM_INSTALLER"/requestinfo/command" +#define VCONF_RPM_INSTALLER_LAST_REQUESTINFO_PKGNAME \ + VCONF_RPM_INSTALLER"/requestinfo/pkgname" +#define VCONF_RPM_INSTALLER_LAST_REQUESTINFO_OPTIONS \ + VCONF_RPM_INSTALLER"/requestinfo/options" + +extern pkgmgr_installer *pi; +extern char *gpkgname; + +int _ri_get_backend_state() +{ + int ret = -1; + int state = -1; + + _d_msg(DEBUG_INFO,"_ri_get_backend_state\n"); + ret = vconf_get_int(VCONF_RPM_INSTALLER_BACKEND_STATE, &state); + if (ret == -1) { + _d_msg(DEBUG_ERR, + "_ri_get_backend_state: vconf_get_int FAIL\n"); + } else { + ret = state; + } + return ret; +} + +int _ri_set_backend_state(int state) +{ + int ret = -1; + + if (state == 0) { + vconf_unset_recursive(VCONF_RPM_INSTALLER); + } + + _d_msg(DEBUG_INFO,"_ri_set_backend_state\n"); + ret = vconf_set_int(VCONF_RPM_INSTALLER_BACKEND_STATE, state); + if (ret == -1) { + _d_msg(DEBUG_ERR, + "_ri_set_backend_state: vconf_set_int FAIL\n"); + } + + return ret; +} + +int _ri_get_backend_state_info() +{ + int ret = -1; + int state = -1; + ret = vconf_get_int(VCONF_RPM_INSTALLER_BACKEND_STATEINFO, &state); + if (ret == -1) { + _d_msg(DEBUG_ERR, + "_ri_get_backend_state_info: vconf_get_int FAIL\n"); + } else { + ret = state; + /* _d_msg(DEBUG_INFO,"_ri_get_backend_state_info state[%d]\n", state);*/ + } + return ret; +} + +int _ri_set_backend_state_info(int state) +{ + int ret = -1; + _d_msg(DEBUG_INFO,"_ri_set_backend_state_info %d\n", state); + ret = vconf_set_int(VCONF_RPM_INSTALLER_BACKEND_STATEINFO, state); + if (ret == -1) + _d_msg(DEBUG_ERR, + "_ri_set_backend_state_info: vconf_set_int FAIL\n"); + + return ret; +} + +int _ri_get_last_input_info(char **pkgid, int *preqcommand, int *poptions) +{ + int ret = -1; + if (!pkgid || !preqcommand || !poptions) + return -1; + ret = vconf_get_int(VCONF_RPM_INSTALLER_LAST_REQUESTINFO_COMMAND, + preqcommand); + if (ret == -1) + _d_msg(DEBUG_ERR, + "_ri_get_last_input_info: VCONF_RPM_INSTALLER_LAST_REQUESTINFO_COMMAND: vconf_get_int FAIL\n"); + + ret = vconf_get_int(VCONF_RPM_INSTALLER_LAST_REQUESTINFO_OPTIONS, + poptions); + if (ret == -1) + _d_msg(DEBUG_ERR, + "_ri_get_last_input_info: VCONF_RPM_INSTALLER_LAST_REQUESTINFO_OPTIONS: vconf_get_int FAIL\n"); + + *pkgid = vconf_get_str(VCONF_RPM_INSTALLER_LAST_REQUESTINFO_PKGNAME); + return 0; +} + +void _ri_save_last_input_info(char *pkgid, int reqcommand, int options) +{ + keylist_t *kl = NULL; + kl = vconf_keylist_new(); + int ret = -1; + + ret = vconf_keylist_add_int(kl, + VCONF_RPM_INSTALLER_LAST_REQUESTINFO_COMMAND, + reqcommand); + if (ret == -1) + _d_msg(DEBUG_ERR, "vconf_keylist_add_int FAIL\n"); + ret = vconf_keylist_add_str(kl, + VCONF_RPM_INSTALLER_LAST_REQUESTINFO_PKGNAME, + pkgid); + if (ret == -1) + _d_msg(DEBUG_ERR, "vconf_keylist_add_str FAIL\n"); + ret = vconf_keylist_add_int(kl, + VCONF_RPM_INSTALLER_LAST_REQUESTINFO_OPTIONS, + options); + if (ret == -1) + _d_msg(DEBUG_ERR, "vconf_keylist_add_int FAIL\n"); + + if (vconf_set(kl)) + _d_msg(DEBUG_ERR, + "_ri_save_last_input_info: Failure in writing vconf\n"); + + ret = vconf_keylist_free(kl); + if (ret == -1) + _d_msg(DEBUG_ERR, "vconf_keylist_free FAIL\n"); +} + +void _ri_broadcast_status_notification(char *pkgid, char *key, char *val) +{ + char *pkgid_tmp = NULL; + + if (gpkgname != NULL) + pkgid_tmp = gpkgname; + else + pkgid_tmp = pkgid; + + _d_msg(DEBUG_INFO, "pkgid = %s, key = %s, val = %s\n", + pkgid_tmp, key, val); + + if (pi != NULL) + pkgmgr_installer_send_signal(pi, PKGTYPE, pkgid_tmp, key, val); + else + _d_msg(DEBUG_ERR, "Failure in sending broadcast message\n"); +} diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt new file mode 100755 index 0000000..b12b2ef --- /dev/null +++ b/common/CMakeLists.txt @@ -0,0 +1,46 @@ +# +# Copyright (c) 2008 ~ 2010 Samsung Electronics Co., Ltd. +# All rights reserved +# + +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +set(CMAKE_SKIP_BUILD_RPATH true) + +#Verbose +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/inc) + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED glib-2.0) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(pkgs_CFLAGS_str "${pkgs_CFLAGS_str} ${flag}") +ENDFOREACH(flag) + +pkg_check_modules(libpkgs REQUIRED dbus-glib-1 db-util vconf sqlite3 dlog) + +FOREACH(flag ${libpkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(comm_dir "${CMAKE_SOURCE_DIR}") +SET(comm_c_src_dir "${comm_dir}") + +## Additional flag +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") + +################################################################################################### +## for librpm-util.so (library) + +add_library(rpm-util STATIC + ${CMAKE_CURRENT_SOURCE_DIR}/rpm-installer-util.c + ) +set_target_properties(rpm-util PROPERTIES COMPILE_FLAGS "${pkgs_CFLAGS_str}") +target_link_libraries(rpm-util ${libpkg_LDFLAGS}) +################################################################################################### + +INSTALL(TARGETS + rpm-util + DESTINATION lib/rpm-installer + COMPONENT RuntimeLibraries) diff --git a/common/rpm-installer-util.c b/common/rpm-installer-util.c new file mode 100755 index 0000000..0c5fd26 --- /dev/null +++ b/common/rpm-installer-util.c @@ -0,0 +1,354 @@ +/* + * rpm-installer + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , + * Jaeho Lee , Shobhit Srivastava + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include /* for isspace () */ +#include +#include +#include +#include +#include + +#include +#include "rpm-installer-util.h" + +#include + +#define LOG_TAG "rpminstaller" + +int logging = 0x0004; +#ifdef LOG_IN_FILE +#define RPM_INSTALLER_LOG_FILE "/tmp/rpm-installer" +FILE *logfile = NULL; +#endif + +/** + * This is intended to be a faster splitter, it does not use dynamic + * memories. Input is changed to insert nulls at each token location. + */ +int _ri_tok_split_string(char tok, char *input, char **list, + unsigned long listmax) +{ + /* Strip any leading spaces */ + char *start = input; + char *stop = start + strlen(start); + for (; *start != 0 && isspace(*start) != 0; start++) ; + + unsigned long count = 0; + char *pos = start; + while (pos != stop) { + /* Skip to the next Token */ + for (; pos != stop && *pos != tok; pos++) ; + + /* Back remove spaces */ + char *end = pos; + for (; + end > start && (end[-1] == tok || isspace(end[-1]) != 0); + end--) ; + + *end = 0; + + list[count++] = start; + if (count >= listmax) { + list[count - 1] = 0; + return -1; + } + /* Advance pos */ + for (; + pos != stop && (*pos == tok || isspace(*pos) != 0 + || *pos == 0); pos++) ; + + start = pos; + } + + list[count] = 0; + return 0; +} + +void _d_msg_init(char *program) +{ + if (logging == 0) + return; + +#ifdef LOG_IN_FILE + char logfilename[64] = { 0, }; + char buffer[256] = { 0 }; + snprintf(logfilename, 64, "%s-%s", RPM_INSTALLER_LOG_FILE, program); + logfile = fopen(logfilename, "a+"); + + if (logfile == NULL) + printf("Error opening log file\n"); + else { + snprintf(buffer, 64, "\nLog File %s Created", logfilename); + fwrite(buffer, sizeof(char), strlen(buffer), logfile); + snprintf(buffer, 64, "\nLog Started\n"); + fwrite(buffer, sizeof(char), strlen(buffer), logfile); + } +#endif +} + +void _d_msg_deinit() +{ + if (logging == 0) + return; + +#ifdef LOG_IN_FILE + if (logfile != NULL) + fclose(logfile); +#endif +} + +void _print_msg(int type, int exetype, char *format, ...) +{ + char buffer[1024] = { 0 }; + char tbuffer[1024] = { 0 }; + int nbuffer = 0; + va_list args; + va_start(args, format); + nbuffer = vsnprintf(tbuffer, 1024, format, args); + va_end(args); + + switch (type) { + case DEBUG_ERR: + LOG(LOG_ERROR, LOG_TAG, tbuffer); + break; + case DEBUG_RESULT: + LOG(LOG_WARN, LOG_TAG, tbuffer); + break; + case DEBUG_INFO: + LOG(LOG_DEBUG, LOG_TAG, tbuffer); + default: + break; + } + + if (logging == 0) + return; + + if (DEBUG_ERR == (logging & type)) { + nbuffer = snprintf(buffer, 1024, "ERROR:%s", tbuffer); + vfprintf(stderr, format, args); + } else if (DEBUG_INFO == (logging & type)) { + nbuffer = snprintf(buffer, 1024, "INFO:%s", tbuffer); + vfprintf(stdout, format, args); + } else if (DEBUG_RESULT == (logging & type)) { + nbuffer = snprintf(buffer, 1024, "RESULT:%s", tbuffer); + vfprintf(stdout, format, args); + } else { + return; + } + +#ifdef LOG_IN_FILE + if (logfile != NULL) + fwrite(buffer, sizeof(char), strlen(buffer), logfile); +#endif /*LOG_IN_FILE */ +} + +/* Like system(3), but with error messages printed if the fork fails + or if the child process dies due to an uncaught signal. Also, the + return value is a bit simpler: + + -1 if there was any problem + Otherwise, the 8-bit return value of the program ala WEXITSTATUS + as defined in . + */ +int _ri_xsystem(const char *argv[]) +{ + int status; + pid_t pid; + pid = vfork(); + switch (pid) { + case -1: + perror("fork failed"); + return -1; + case 0: + /* child */ + execvp(argv[0], (char *const *)argv); + _exit(-1); + default: + /* parent */ + break; + } + + _d_msg(DEBUG_INFO, "parent\n"); + if (waitpid(pid, &status, 0) == -1) { + perror("waitpid failed"); + return -1; + } + + if (WIFSIGNALED(status)) { + perror("signal"); + return -1; + } + + if (!WIFEXITED(status)) { + /* shouldn't happen */ + perror("should not happen"); + return -1; + } + + return WEXITSTATUS(status); +} + +char *_ri_substring(const char *str, size_t begin, size_t len) +{ + if (str == 0 || strlen(str) == 0 || strlen(str) < (begin + len)) + return 0; + return strndup(str + begin, len); +} + +void _ri_error_no_to_string(int errnumber, char **errstr) +{ + if (errstr == NULL) + return; + switch (errnumber) { + case RPM_INSTALLER_SUCCESS: + *errstr = RPM_INSTALLER_SUCCESS_STR; + break; + case RPM_INSTALLER_ERR_WRONG_PARAM: + *errstr = RPM_INSTALLER_ERR_WRONG_PARAM_STR; + break; + case RPM_INSTALLER_ERR_DBUS_PROBLEM: + *errstr = RPM_INSTALLER_ERR_DBUS_PROBLEM_STR; + break; + case RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY: + *errstr = RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY_STR; + break; + case RPM_INSTALLER_ERR_PACKAGE_EXIST: + *errstr = RPM_INSTALLER_ERR_PACKAGE_EXIST_STR; + break; + case RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED: + *errstr = RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED_STR; + break; + case RPM_INSTALLER_ERR_RESOURCE_BUSY: + *errstr = RPM_INSTALLER_ERR_RESOURCE_BUSY_STR; + break; + case RPM_INSTALLER_ERR_UNKNOWN: + *errstr = RPM_INSTALLER_ERR_UNKNOWN_STR; + break; + case RPM_INSTALLER_ERR_PKG_NOT_FOUND: + *errstr = RPM_INSTALLER_ERR_PKG_NOT_FOUND_STR; + break; + case RPM_INSTALLER_ERR_NOT_SUPPOTED_VERSION: + *errstr = RPM_INSTALLER_ERR_NOT_SUPPOTED_VERSION_STR; + break; + case RPM_INSTALLER_ERR_NO_RPM_FILE: + *errstr = RPM_INSTALLER_ERR_NO_RPM_FILE_STR; + break; + case RPM_INSTALLER_ERR_DB_ACCESS_FAILED: + *errstr = RPM_INSTALLER_ERR_DB_ACCESS_FAILED_STR; + break; + case RPM_INSTALLER_ERR_RPM_OPERATION_FAILED: + *errstr = RPM_INSTALLER_ERR_RPM_OPERATION_FAILED_STR; + break; + case RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED: + *errstr = RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED_STR; + break; + case RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS: + *errstr = RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS_STR; + break; + case RPM_INSTALLER_ERR_PACKAGE_INSTALLATION_DISABLED: + *errstr = RPM_INSTALLER_ERR_PACKAGE_INSTALLATION_DISABLED_STR; + break; + case RPM_INSTALLER_ERR_PACKAGE_UNINSTALLATION_DISABLED: + *errstr = RPM_INSTALLER_ERR_PACKAGE_UNINSTALLATION_DISABLED_STR; + break; + case RPM_INSTALLER_ERR_CLEAR_DATA_FAILED: + *errstr = RPM_INSTALLER_ERR_CLEAR_DATA_FAILED_STR; + break; + case RPM_INSTALLER_ERR_INTERNAL: + *errstr = RPM_INSTALLER_ERR_INTERNAL_STR; + break; + case RPM_INSTALLER_ERR_NO_MANIFEST: + *errstr = RPM_INSTALLER_ERR_NO_MANIFEST_STR; + break; + case RPM_INSTALLER_ERR_INVALID_MANIFEST: + *errstr = RPM_INSTALLER_ERR_INVALID_MANIFEST_STR; + break; + default: + *errstr = RPM_INSTALLER_ERR_UNKNOWN_STR; + break; + } +} + +int _ri_string_to_error_no(char *errstr) +{ + int errnumber = RPM_INSTALLER_ERR_UNKNOWN; + if (errstr == NULL) + return errnumber; + + if (strcmp(errstr, RPM_INSTALLER_SUCCESS_STR) == 0) + errnumber = RPM_INSTALLER_SUCCESS; + else if (strcmp(errstr, RPM_INSTALLER_ERR_WRONG_PARAM_STR) == 0) + errnumber = RPM_INSTALLER_ERR_WRONG_PARAM; + else if (strcmp(errstr, RPM_INSTALLER_ERR_DBUS_PROBLEM_STR) == 0) + errnumber = RPM_INSTALLER_ERR_DBUS_PROBLEM; + else if (strcmp(errstr, RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY_STR) == 0) + errnumber = RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY; + else if (strcmp(errstr, RPM_INSTALLER_ERR_PACKAGE_EXIST_STR) == 0) + errnumber = RPM_INSTALLER_ERR_PACKAGE_EXIST; + else if (strcmp(errstr, RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED_STR) + == 0) + errnumber = RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED; + else if (strcmp(errstr, RPM_INSTALLER_ERR_RESOURCE_BUSY_STR) == 0) + errnumber = RPM_INSTALLER_ERR_RESOURCE_BUSY; + else if (strcmp(errstr, RPM_INSTALLER_ERR_UNKNOWN_STR) == 0) + errnumber = RPM_INSTALLER_ERR_UNKNOWN; + else if (strcmp(errstr, RPM_INSTALLER_ERR_PKG_NOT_FOUND_STR) == 0) + errnumber = RPM_INSTALLER_ERR_PKG_NOT_FOUND; + else if (strcmp(errstr, RPM_INSTALLER_ERR_NOT_SUPPOTED_VERSION_STR) == + 0) + errnumber = RPM_INSTALLER_ERR_NOT_SUPPOTED_VERSION; + else if (strcmp(errstr, RPM_INSTALLER_ERR_NO_RPM_FILE_STR) == 0) + errnumber = RPM_INSTALLER_ERR_NO_RPM_FILE; + else if (strcmp(errstr, RPM_INSTALLER_ERR_DB_ACCESS_FAILED_STR) == 0) + errnumber = RPM_INSTALLER_ERR_DB_ACCESS_FAILED; + else if (strcmp(errstr, RPM_INSTALLER_ERR_RPM_OPERATION_FAILED_STR) + == 0) + errnumber = RPM_INSTALLER_ERR_RPM_OPERATION_FAILED; + else if (strcmp(errstr, RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED_STR) == + 0) + errnumber = RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED; + else if (strcmp(errstr, RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS_STR) == + 0) + errnumber = RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS; + else if (strcmp(errstr, RPM_INSTALLER_ERR_PACKAGE_INSTALLATION_DISABLED_STR) == 0) + errnumber = RPM_INSTALLER_ERR_PACKAGE_INSTALLATION_DISABLED; + else if (strcmp(errstr, RPM_INSTALLER_ERR_PACKAGE_UNINSTALLATION_DISABLED_STR) == 0) + errnumber = RPM_INSTALLER_ERR_PACKAGE_UNINSTALLATION_DISABLED; + else if (strcmp(errstr, RPM_INSTALLER_ERR_CLEAR_DATA_FAILED_STR) == 0) + errnumber = RPM_INSTALLER_ERR_CLEAR_DATA_FAILED; + else if (strcmp(errstr, RPM_INSTALLER_ERR_INTERNAL_STR) == 0) + errnumber = RPM_INSTALLER_ERR_INTERNAL; + else if (strcmp(errstr, RPM_INSTALLER_ERR_NO_MANIFEST_STR) == 0) + errnumber = RPM_INSTALLER_ERR_NO_MANIFEST; + else if (strcmp(errstr, RPM_INSTALLER_ERR_INVALID_MANIFEST_STR) == 0) + errnumber = RPM_INSTALLER_ERR_INVALID_MANIFEST; + else + _d_msg(DEBUG_ERR, "Unsupported Error\n"); + return errnumber; +} diff --git a/debian/changelog b/debian/changelog new file mode 100755 index 0000000..2f84da8 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,55 @@ +rpm-installer (0.1.7) unstable; urgency=low + + * Changed vconf key according to the guide + * Git: 165.213.149.219:slp/pkgs/r/rpm-installer + * Tag: rpm-installer_0.1.7 + + -- Sewook Park Thu, 17 May 2012 21:17:15 +0900 + +rpm-installer (0.1.6) unstable; urgency=low + + * Fixed memory consumption bug + * Git: 165.213.149.219:slp/pkgs/r/rpm-installer + * Tag: rpm-installer_0.1.6 + + -- Sewook Park Mon, 09 Apr 2012 17:52:35 +0900 + +rpm-installer (0.1.5) unstable; urgency=low + + * Fixed install bug + * Git: 165.213.149.219:slp/pkgs/r/rpm-installer + * Tag: rpm-installer_0.1.5 + + -- Sewook Park Tue, 27 Mar 2012 18:19:14 +0900 + +rpm-installer (0.1.4) unstable; urgency=low + + * Implemented backend-lib, localization, recovery and clear data + * Git: 165.213.149.219:slp/pkgs/r/rpm-installer + * Tag: rpm-installer_0.1.4 + + -- Sewook Park Fri, 16 Mar 2012 18:08:10 +0900 + +rpm-installer (0.1.3) unstable; urgency=low + + * Fixed bug for elementary modification + * Git: 165.213.149.219:slp/pkgs/r/rpm-installer + * Tag: rpm-installer_0.1.3 + + -- Sewook Park Thu, 15 Mar 2012 15:11:14 +0900 + +rpm-installer (0.1.2) unstable; urgency=low + + * Fixed code for elementary 1.0 + * Git: 165.213.149.219:slp/pkgs/r/rpm-installer + * Tag: rpm-installer_0.1.2 + + -- Sewook Park Wed, 14 Mar 2012 18:27:21 +0900 + +rpm-installer (0.1.1) unstable; urgency=low + + * First release + * Git: 165.213.149.219:slp/pkgs/r/rpm-installer + * Tag: rpm-installer_0.1.1 + + -- Sewook Park Fri, 03 Feb 2012 15:30:00 +0900 diff --git a/debian/compat b/debian/compat new file mode 100755 index 0000000..7ed6ff8 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +5 diff --git a/debian/control b/debian/control new file mode 100755 index 0000000..9db9fce --- /dev/null +++ b/debian/control @@ -0,0 +1,18 @@ +Source: rpm-installer +Section: base +Priority: extra +Maintainer: Shobhit Srivastava , Sewook Park +Build-Depends: debhelper (>= 5), libslp-setting-dev, libsqlite3-dev, libslp-db-util-dev, libdbus-glib-1-dev, libglib2.0-dev, libpkgmgr-installer-dev, libsecurity-server-client-dev, libelm-dev, libappcore-efl-dev, dlog-dev, libpkgmgr-types-dev, libevas-dev, libecore-dev, libedje-dev +Standards-Version: 3.7.2 + +Package: rpm-installer +Section: base +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: rpm installer package + +Package: rpm-installer-dbg +Section: debug +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} rpm-installer +Description: rpm installer debug package diff --git a/debian/control.slp b/debian/control.slp new file mode 100755 index 0000000..36defa5 --- /dev/null +++ b/debian/control.slp @@ -0,0 +1,3 @@ +#Fri Feb 03 19:14:26 KST 2012 +Package=rpm-installer +AppInstallPath=/usr diff --git a/debian/desktop.slp b/debian/desktop.slp new file mode 100755 index 0000000..f48a64d --- /dev/null +++ b/debian/desktop.slp @@ -0,0 +1,11 @@ +#Fri Feb 03 17:26:45 KST 2012 +Name=rpm-installer +Type=Application +Exec=/usr/etc/package-manager/backend/rpm +Icon= +Comment= +MimeType=application/x-rpm +Hidden=true +Version=0.1.1 +X-SLP-TaskManage=true +X-SLP-Multiple=true diff --git a/debian/dirs b/debian/dirs new file mode 100755 index 0000000..ca882bb --- /dev/null +++ b/debian/dirs @@ -0,0 +1,2 @@ +usr/bin +usr/sbin diff --git a/debian/docs b/debian/docs new file mode 100755 index 0000000..a0f0008 --- /dev/null +++ b/debian/docs @@ -0,0 +1 @@ +CMakeLists.txt diff --git a/debian/rpm-installer-dbg.postinst b/debian/rpm-installer-dbg.postinst new file mode 100755 index 0000000..ed02837 --- /dev/null +++ b/debian/rpm-installer-dbg.postinst @@ -0,0 +1,5 @@ +#!/bin/sh + +mkdir -p /usr/etc/package-manager/backend +chmod 755 /usr/lib/rpm-installer/librpm-util.a +chmod 755 /usr/lib/debug/usr/bin/rpm-backend diff --git a/debian/rpm-installer.install.in b/debian/rpm-installer.install.in new file mode 100755 index 0000000..b9b05ac --- /dev/null +++ b/debian/rpm-installer.install.in @@ -0,0 +1,7 @@ +@PREFIX@/lib/rpm-installer/librpm-util.a +@PREFIX@/bin/rpm-backend +@PREFIX@/bin/install_rpm_package.sh +@PREFIX@/bin/uninstall_rpm_package.sh +@PREFIX@/bin/upgrade_rpm_package.sh +@PREFIX@/bin/query_rpm_package.sh +@PREFIX@/usr/share/data diff --git a/debian/rpm-installer.postinst b/debian/rpm-installer.postinst new file mode 100755 index 0000000..1c82b7b --- /dev/null +++ b/debian/rpm-installer.postinst @@ -0,0 +1,14 @@ +#!/bin/sh + +mkdir -p /usr/etc/package-manager/backend +ln -sf /usr/bin/rpm-backend /usr/etc/package-manager/backend/rpm +ln -sf /usr/lib/libnativerpm.so /usr/etc/package-manager/backendlib/librpm.so +if [ "${USER}" = "root" ] +then + chown 5000:5000 /usr/lib/rpm-installer/librpm-util.a + chown 5000:5000 /usr/bin/rpm-backend +fi + +chmod 755 /usr/lib/rpm-installer/librpm-util.a +chmod 755 /usr/bin/rpm-backend + diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..1b29587 --- /dev/null +++ b/debian/rules @@ -0,0 +1,115 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +include debian/desktop.slp +include debian/control.slp + +PKGDIR = debian/$(Package) +DESKTOPFILE = debian/desktop.slp +DESKTOPDIR = usr/share/install-info/application + +CFLAGS = -Wall -g + +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) + CFLAGS += -O0 +else + CFLAGS += -O2 +endif + +configure: configure-stamp +configure-stamp: + dh_testdir + # Add here commands to configure the package. + rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb + cmake . -DCMAKE_INSTALL_PREFIX=/usr + rm -rf CMakeFiles/CompilerIdC* + touch configure-stamp + + +build: build-stamp + +build-stamp: configure-stamp + dh_testdir + + # Add here commands to compile the package. + $(MAKE) + #docbook-to-man debian/native-installer.sgml > native-installer.1 + + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + # Add here commands to clean up after the build process. + -$(MAKE) clean + dh_clean + rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb + cd backend && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb + cd backend-lib && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb + rm -f backend/install_rpm_package.sh backend/uninstall_rpm_package.sh backend/upgrade_rpm_package.sh backend/query_rpm__package.sh + cd frontend && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb *.sh rpm-backend + cd common && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb *.a + cd frontend && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb + cd po && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb *.mo + rm -rf $(CURDIR)/debian/rpm-installer + rm -rf $(CURDIR)/debian/rpm-installer-dbg + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/rpm-installer. + $(MAKE) DESTDIR=$(CURDIR)/$(PKGDIR) install +# mkdir -p $(CURDIR)/$(PKGDIR)/$(DESKTOPDIR) +# cp $(DESKTOPFILE) $(CURDIR)/$(PKGDIR)/$(DESKTOPDIR)/$(Package).desktop + + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples +# cp $(DESKTOPFILE) $(CURDIR)/debian/native-installer/$(DESKTOPDIR)/$(Package).desktop +# dh_install +# dh_installmenu +# dh_installdebconf +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_python +# dh_installinit +# dh_installcron +# dh_installinfo + dh_installman + dh_link + dh_strip --dbg-package=$(Package)-dbg + dh_compress + dh_fixperms +# dh_perl +# dh_makeshlibs + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/frontend/CMakeLists.txt b/frontend/CMakeLists.txt new file mode 100755 index 0000000..883a849 --- /dev/null +++ b/frontend/CMakeLists.txt @@ -0,0 +1,111 @@ +# +# Copyright (c) 2008 ~ 2010 Samsung Electronics Co., Ltd. +# All rights reserved +# + +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +set(CMAKE_SKIP_BUILD_RPATH true) + +#Verbose +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc ${CMAKE_SOURCE_DIR}/backend/inc ${CMAKE_CURRENT_SOURCE_DIR}/inc) + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED pkgmgr pkgmgr-installer pkgmgr-parser pkgmgr-info pkgmgr-installer-status-broadcast-server security-server vconf sqlite3 dbus-glib-1 glib-2.0 db-util elementary appcore-efl libxml-2.0 app2sd) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +pkg_check_modules(libpkgs REQUIRED security-server pkgmgr pkgmgr-installer pkgmgr-parser pkgmgr-info pkgmgr-installer-status-broadcast-server vconf sqlite3 dbus-glib-1 glib-2.0 db-util elementary appcore-efl libxml-2.0 app2sd) + +FOREACH(flag ${libpkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +pkg_check_modules(STATUS pkgmgr-installer-status-broadcast-server pkgmgr pkgmgr-installer pkgmgr-parser libxml-2.0 app2sd pkgmgr-info) +link_directories (${STATUS_LIBRARY_DIRS}) +include_directories (${STATUS_INCLUDE_DIRS}) + +pkg_check_modules(COMMCLIENT pkgmgr-installer-client) +link_directories (${COMMCLIENT_LIBRARY_DIRS}) +include_directories (${COMMCLIENT_INCLUDE_DIRS}) + +pkg_check_modules(APPCODEEFL appcore-efl evas ecore edje ecore-input ecore-x) +link_directories (${APPCODEEFL_LIBRARY_DIRS}) +include_directories (${APPCODEEFL_INCLUDE_DIRS}) + +pkg_check_modules(SECURITYSERVER security-server) +link_directories (${SECURITYSERVER_LIBRARY_DIRS}) +include_directories (${SECURITYSERVER_INCLUDE_DIRS}) + +## DEFINITIONS +ADD_DEFINITIONS("-DAPP_DIR=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DPACKAGE=\"${PROJECT_NAME}\"") + +link_directories ("${STATUS_LIBRARY_DIRS} /usr/lib") +include_directories (${STATUS_INCLUDE_DIRS}) +find_library(RPM_LIBRARY rpm "/usr/lib") + + +SET(backend_dir "${CMAKE_CURRENT_SOURCE_DIR}/../backend") +SET(backend_inc_dir "${backend_dir}/include") +SET(backend_c_src_dir "${backend_dir}/src") +SET(backend_script_dir "${backend_dir}/scripts") +SET(SCRIPTS_DIR "${backend_script_dir}") + +SET(frontend_dir "${CMAKE_CURRENT_SOURCE_DIR}") +SET(frontend_inc_dir "${frontend_dir}/inc") +SET(frontend_c_src_dir "${frontend_dir}/src") +SET(frontend_c_ui_src_dir "${frontend_dir}/ui/src") +SET(frontend_c_ui_inc_dir "${frontend_dir}/ui/include") + + + +## Additional flag +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall -rdynamic") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") + +#################################################################################################### +## for rpm-backend (binary) +SET(rpm-backend_SOURCES ${backend_c_src_dir}/core/rpm-installer-core.c ${backend_c_src_dir}/core/rpm-installer-tool.c ${backend_c_src_dir}/rpm/rpm-installer.c ${backend_c_src_dir}/vconf/rpm-vconf-intf.c ${frontend_c_src_dir}/rpm-appcore-intf.c ${frontend_c_src_dir}/rpm-cmdline.c ${frontend_c_ui_src_dir}/rpm-homeview.c) + +SET(rpm-backend_CFLAGS " -I. -I/usr/include/rpm -I${backend_inc_dir} -I${frontend_inc_dir} -I${frontend_c_ui_inc_dir} ${pkg_CFLAGS}") +SET(rpm-backend_LDFLAGS ${pkgs_LDFLAGS}) + +ADD_EXECUTABLE(rpm-backend ${rpm-backend_SOURCES}) +TARGET_LINK_LIBRARIES(rpm-backend rpm-util "rpm" "rpmio") +TARGET_LINK_LIBRARIES(rpm-backend ${libpkgs_LDFLAGS}) +TARGET_LINK_LIBRARIES(rpm-backend ${COMMCLIENT_LIBRARIES}) +TARGET_LINK_LIBRARIES(rpm-backend ${APPCODEEFL_LIBRARIES}) +TARGET_LINK_LIBRARIES(rpm-backend ${SECURITYSERVER_LIBRARIES}) +TARGET_LINK_LIBRARIES(rpm-backend ${STATUS_LIBRARIES}) + +SET_TARGET_PROPERTIES(rpm-backend PROPERTIES COMPILE_FLAGS "${rpm-backend_CFLAGS}") +#################################################################################################### + +#SET(RESOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ui/res") + +# INSTALL + +MESSAGE("${CLEAN_FILE_LIST}") +SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${CLEAN_FILE_LIST}") + + + +###################################################################################################i +configure_file(${backend_script_dir}/install_rpm_package.sh.in ${CMAKE_CURRENT_BINARY_DIR}/install_rpm_package.sh @ONLY) +configure_file(${backend_script_dir}/uninstall_rpm_package.sh.in ${CMAKE_CURRENT_BINARY_DIR}/uninstall_rpm_package.sh @ONLY) +configure_file(${backend_script_dir}/upgrade_rpm_package.sh.in ${CMAKE_CURRENT_BINARY_DIR}/upgrade_rpm_package.sh @ONLY) +configure_file(${backend_script_dir}/query_rpm_package.sh.in ${CMAKE_CURRENT_BINARY_DIR}/query_rpm_package.sh @ONLY) + +INSTALL(FILES + ${CMAKE_CURRENT_BINARY_DIR}/install_rpm_package.sh + ${CMAKE_CURRENT_BINARY_DIR}/uninstall_rpm_package.sh + ${CMAKE_CURRENT_BINARY_DIR}/upgrade_rpm_package.sh + ${CMAKE_CURRENT_BINARY_DIR}/query_rpm_package.sh + DESTINATION bin) + + +INSTALL(TARGETS rpm-backend DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE) + diff --git a/frontend/inc/rpm-frontend.h b/frontend/inc/rpm-frontend.h new file mode 100755 index 0000000..6a39cb8 --- /dev/null +++ b/frontend/inc/rpm-frontend.h @@ -0,0 +1,89 @@ +/* + * rpm-installer + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , + * Jaeho Lee , Shobhit Srivastava + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef __RPM_FRONTEND_H_ +#define __RPM_FRONTEND_H_ + +#include +#include +#include + +#ifndef APP_DIR +#define APP_DIR "/usr" +#endif /* APP_DIR */ + +#ifndef LOCALE_PATH +#define LOCALE_PATH APP_DIR"/share/locale" +#endif /* LOCALE_PATH */ + +#ifndef PACKAGE +#define PACKAGE "rpm-installer" +#endif /* PACKAGE */ + +enum command { + INVALID_CMD = -1, + INSTALL_CMD = 1, + DELETE_CMD = 2, + UPDATE_CMD = 3, + RECOVER_CMD = 4, + CLEARDATA_CMD = 5, + MOVE_CMD = 6, +}; + +struct ri_frontend_cmdline_arg_t { + int req_cmd; + char *pkgid; + char *keyid; + int quiet; + int move_type; +}; +typedef struct ri_frontend_cmdline_arg_t ri_frontend_cmdline_arg; + +struct ri_frontend_data_t { + ri_frontend_cmdline_arg *args; + char *security_cookie; + char *error; +}; +typedef struct ri_frontend_data_t ri_frontend_data; + +struct appdata { + Evas *evas; + Evas_Object *win_main; + Evas_Coord root_w; + Evas_Coord root_h; + Evas_Object *main_view; /* for main view layout */ + Evas_Object *scrollbar_label; +}; + +int app_create(void *user_data); +int app_terminate(void *user_data); +int app_pause(void *user_data); +int app_resume(void *user_data); +int app_reset(bundle *b, void *user_data); +int app_rotation(enum appcore_rm, void *user_data); + +int _ri_cmdline_destroy(ri_frontend_data *data); +int _ri_cmdline_process(ri_frontend_data *data); +int _ri_parse_cmdline(int argc, char **argv, ri_frontend_cmdline_arg *data); +void _ri_stat_cb(const char *pkgid, const char *key, const char *val); + +#endif /* __RPM_FRONTEND_H_ */ diff --git a/frontend/src/rpm-appcore-intf.c b/frontend/src/rpm-appcore-intf.c new file mode 100755 index 0000000..bc92dca --- /dev/null +++ b/frontend/src/rpm-appcore-intf.c @@ -0,0 +1,243 @@ +/* + * rpm-installer + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , + * Jaeho Lee , Shobhit Srivastava + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include + +#include +#include +#include +#include + +#include "rpm-frontend.h" +#include "rpm-homeview.h" +#include "rpm-installer-util.h" +#include "rpm-installer.h" +#include + +static void __ri_start_processing(void *user_data); +static Eina_Bool __ri_elm_exit_cb(void *data); + +int ret_val = -1; +struct appdata ad; +extern char scrolllabel[256]; +extern ri_frontend_data front_data; +pkgmgr_installer *pi = NULL; + +/**< Called before main loop */ +int app_create(void *user_data) +{ + + int ret = 0; + struct appdata *data = (struct appdata *)user_data; + ri_frontend_cmdline_arg *fdata = front_data.args; + /*In case of downgrade, popup should be shown even if quiet mode*/ + ret = _ri_frontend_launch_main_view(data); + return ret; +} + +/**< Called after main loop */ +int app_terminate(void *user_data) +{ + struct appdata *data = (struct appdata *)user_data; + ri_frontend_cmdline_arg *fdata = front_data.args; + if (fdata->quiet == 0) { + _ri_destroy_home_view(data); + } + return 0; +} + +/**< Called when every window goes back */ +int app_pause(void *user_data) +{ + return 0; +} + +/**< Called when any window comes on top */ +int app_resume(void *user_data) +{ + return 0; +} + +/**< Called at the first idler*/ +int app_reset(bundle *b, void *user_data) +{ + return 0; +} + +/**< Called at rotate device*/ +int app_rotation(enum appcore_rm mode, void *user_data) +{ + if (user_data == NULL) { + _d_msg(DEBUG_ERR, "arg supplied is NULL \n"); + return -1; + } + struct appdata *data = (struct appdata *)user_data; + int angle; + switch (mode) { + case APPCORE_RM_LANDSCAPE_NORMAL: + angle = -90; + break; + + case APPCORE_RM_LANDSCAPE_REVERSE: + angle = 90; + break; + + case APPCORE_RM_PORTRAIT_REVERSE: + angle = 180; + break; + + case APPCORE_RM_UNKNOWN: + case APPCORE_RM_PORTRAIT_NORMAL: + default: + angle = 0; + break; + } + elm_win_rotation_with_resize_set(data->win_main, angle); + return 0; +} + +Eina_Bool show_popup_cb(void *data) +{ + /*Avoid log printing as it is an idler function*/ + int state = -1; + int ret = -1; + const char message[256] = {'\0'}; + state = _ri_get_backend_state_info(); + switch (state) { + case REQUEST_ACCEPTED: + break; + case GOT_PACKAGE_INFO_SUCCESSFULLY: + break; + case REQUEST_PENDING: + strncpy(message, _("Continue Downgrade?"), 255); + _ri_package_downgrade_information(message); + /*request is not completed yet. We just got confirmation + from user whether to downgrade or not*/ + _ri_set_backend_state_info(REQUEST_ACCEPTED); + break; + case REQUEST_COMPLETED: + default: + if (front_data.args->quiet == 0) { + _ri_frontend_update_progress_info(&ad, scrolllabel); + return 0; + } else + elm_exit(); + break; + } + + return 1; +} + +static void __ri_start_processing(void *user_data) +{ + int ret = 0; + if (user_data == NULL) { + _d_msg(DEBUG_ERR, "arg supplied is NULL \n"); + return -1; + } + ri_frontend_data *data = (ri_frontend_data *) user_data; + g_type_init(); + ret = _ri_cmdline_process(data); + ret_val = ret; + _ri_cmdline_destroy(data); + +} + +int main(int argc, char *argv[]) +{ + int ret = 0; + ri_frontend_cmdline_arg *data = NULL; + struct appcore_ops ops; + ops.create = app_create; + ops.terminate = app_terminate; + ops.pause = app_pause; + ops.resume = app_resume; + ops.reset = app_reset; + ops.data = &ad; + ecore_init(); + appcore_set_i18n(PACKAGE, LOCALE_PATH); + _d_msg_init("rpm-installer"); + data = (ri_frontend_cmdline_arg *) calloc(1, + sizeof + (ri_frontend_cmdline_arg)); + if (data == NULL) { + _d_msg(DEBUG_ERR, "Not Enough Memory\n"); + ret = RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY; + goto ERROR; + } + data->keyid = NULL; + data->pkgid = NULL; + data->quiet = 0; + data->req_cmd = INVALID_CMD; + data->move_type = -1; + + /* We need to use pkgmgr_installer_receive request() + to parse the arguments */ + if ((ret = + _ri_parse_cmdline(argc, argv, data)) != RPM_INSTALLER_SUCCESS) { + _d_msg(DEBUG_ERR, "_ri_parse_cmdline failed \n"); + goto ERROR; + } + + front_data.args = data; + front_data.security_cookie = NULL; + front_data.error = NULL; + + __ri_start_processing(&front_data); + + /*The installer has finished the installation/uninstallation. + Now, if it was a non quiet operation we need to show the popup. */ + ecore_idler_add(show_popup_cb, NULL); + + _d_msg(DEBUG_RESULT, "About to run EFL Main Loop"); + appcore_efl_main(PACKAGE, &argc, &argv, &ops); + _d_msg(DEBUG_RESULT, "%d\n", ret_val); + + _d_msg_deinit(); + if (pi) { + pkgmgr_installer_free(pi); + pi = NULL; + } + if(!ret_val) + sync(); + + return ret_val; + + ERROR: + if (data) { + if (data->pkgid) { + free(data->pkgid); + data->pkgid = NULL; + } + if (data->keyid) { + free(data->keyid); + data->keyid = NULL; + } + free(data); + data = NULL; + } + _d_msg(DEBUG_RESULT, "%d\n", ret); + _d_msg_deinit(); + return ret; + +} diff --git a/frontend/src/rpm-cmdline.c b/frontend/src/rpm-cmdline.c new file mode 100755 index 0000000..794fd15 --- /dev/null +++ b/frontend/src/rpm-cmdline.c @@ -0,0 +1,352 @@ +/* + * rpm-installer + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , + * Jaeho Lee , Shobhit Srivastava + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "rpm-frontend.h" +#include "rpm-installer-util.h" +#include "rpm-installer.h" +#include "rpm-homeview.h" + +#define _FIX_POP_UP_ +extern struct appdata ad; +extern int ret_val; +extern pkgmgr_installer *pi; +ri_frontend_data front_data; +char scrolllabel[256]; +int move_type; + +static void __ri_show_usage(char **arg); +static int __ri_process_request(ri_frontend_cmdline_arg *fdata); + +static void __ri_show_usage(char **arg) +{ + + int i = 0; + char buffer[256]; + char buff[256] = ""; + while (arg[i] != NULL) { + snprintf(buffer, 256, "%s %s", buff, arg[i]); + strncpy(buff, buffer, 255); + i++; + } + + _d_msg(DEBUG_INFO, "%s\n", buffer); + _d_msg(DEBUG_INFO, + "\nrpm-backend usage\n rpm-backend -k [-q] \n\n"); + _d_msg(DEBUG_INFO, " \n"); + _d_msg(DEBUG_INFO, + "\t -i : install package file \n"); + _d_msg(DEBUG_INFO, + "\t -k : key id file \n"); + _d_msg(DEBUG_INFO, + "\t -r : (recover). Must ignore specific package name or path \n"); + _d_msg(DEBUG_INFO, + "\t -d : delete a package with package name \n"); + _d_msg(DEBUG_INFO, + "\t -q : (quiet) run in background without any user interaction \n"); +} + +int _ri_parse_cmdline(int argc, char **argv, ri_frontend_cmdline_arg *data) +{ + int req_cmd = INVALID_CMD; + const char *pkgid = NULL; + int quiet = 0; + const char *pkeyid = NULL; + int ret = 0; + int move_type = -1; + pi = pkgmgr_installer_new(); + if (!pi) { + _d_msg(DEBUG_ERR, + "Failure in creating the pkgmgr_installer object \n"); + return RPM_INSTALLER_ERR_WRONG_PARAM; + } + ret = pkgmgr_installer_receive_request(pi, argc, argv); + if (ret) { + _d_msg(DEBUG_ERR, "pkgmgr_installer_receive_request failed \n"); + return RPM_INSTALLER_ERR_WRONG_PARAM; + } + ret = pkgmgr_installer_get_request_type(pi); + switch (ret) { + case PKGMGR_REQ_INSTALL: + req_cmd = INSTALL_CMD; + break; + case PKGMGR_REQ_UNINSTALL: + req_cmd = DELETE_CMD; + break; + case PKGMGR_REQ_RECOVER: + req_cmd = RECOVER_CMD; + break; + case PKGMGR_REQ_CLEAR: + req_cmd = CLEARDATA_CMD; + break; + case PKGMGR_REQ_MOVE: + req_cmd = MOVE_CMD; + break; + case PKGMGR_REQ_PERM: + goto PARSEERROR; + case PKGMGR_REQ_INVALID: + req_cmd = INVALID_CMD; + goto PARSEERROR; + default: + goto PARSEERROR; + } + if (req_cmd != RECOVER_CMD) { + pkgid = pkgmgr_installer_get_request_info(pi); + if (!pkgid) { + _d_msg(DEBUG_ERR, + "pkgmgr_installer_get_request_info failed \n"); + return RPM_INSTALLER_ERR_WRONG_PARAM; + } + pkeyid = pkgmgr_installer_get_session_id(pi); + if (!pkeyid) { + _d_msg(DEBUG_ERR, "pkgmgr_installer_get_session_id failed \n"); + return RPM_INSTALLER_ERR_WRONG_PARAM; + } + + quiet = pkgmgr_installer_is_quiet(pi); + if (quiet != 0 && quiet != 1) { + _d_msg(DEBUG_ERR, "pkgmgr_installer_is_quiet failed \n"); + return RPM_INSTALLER_ERR_WRONG_PARAM; + } + + move_type = pkgmgr_installer_get_move_type(pi); + } + if ((req_cmd < INSTALL_CMD) ||(req_cmd > MOVE_CMD)) { + _d_msg(DEBUG_ERR, "invalid command \n"); + goto PARSEERROR; + } + + data->req_cmd = req_cmd; + data->pkgid = (char *)pkgid; + data->quiet = quiet; + data->keyid = (char *)pkeyid; + data->move_type = move_type; + return RPM_INSTALLER_SUCCESS; + + PARSEERROR: + _d_msg(DEBUG_ERR, "Error in parsing input parameter\n"); + __ri_show_usage(argv); + return RPM_INSTALLER_ERR_WRONG_PARAM; + +} + +static int __ri_process_request(ri_frontend_cmdline_arg *data) +{ + int ret = 0; + if (!data) + return RPM_INSTALLER_ERR_WRONG_PARAM; + char *pkgid = NULL; + char *keyid = NULL; + if (data->req_cmd != RECOVER_CMD) { + pkgid = strdup(data->pkgid); + if (PM_UNLIKELY(pkgid == NULL)) { + _d_msg(DEBUG_ERR, "strdup failed\n"); + return RPM_INSTALLER_ERR_WRONG_PARAM; + } + keyid = strdup(data->keyid); + if (PM_UNLIKELY(keyid == NULL)) { + _d_msg(DEBUG_ERR, "strdup failed\n"); + free(pkgid); + return RPM_INSTALLER_ERR_WRONG_PARAM; + } + } + switch (data->req_cmd) { + case INSTALL_CMD: + _d_msg(DEBUG_INFO, "rpm-backend -i %s\n", pkgid); + ret = _rpm_backend_interface(keyid, pkgid, "install"); + break; + case DELETE_CMD: + _d_msg(DEBUG_INFO, "rpm-backend -d %s\n", pkgid); + ret = _rpm_backend_interface(keyid, pkgid, "remove"); + break; + case CLEARDATA_CMD: + _d_msg(DEBUG_INFO, "rpm-backend -c %s\n", pkgid); + ret = _rpm_backend_interface(keyid, pkgid, "cleardata"); + break; + case MOVE_CMD: + _d_msg(DEBUG_INFO, "rpm-backend -m %s -t %d\n", pkgid, data->move_type); + move_type = data->move_type; + ret = _rpm_backend_interface(keyid, pkgid, "move"); + break; + case RECOVER_CMD: + _d_msg(DEBUG_INFO, "rpm-backend -r \n"); + ret = _rpm_backend_interface(keyid, pkgid, "recover"); + break; + default: + _d_msg(DEBUG_ERR, + "Error Never Come Here as Error is already checked\n"); + + } + if (keyid) { + free(keyid); + keyid = NULL; + } + if (pkgid) { + free(pkgid); + pkgid = NULL; + } + + return ret; +} + +void _ri_stat_cb(const char *pkgid, const char *key, const char *val) +{ + + if (NULL == pkgid || NULL == key || NULL == val) { + _d_msg(DEBUG_ERR, "Either pkgid/key/val is NULL\n"); + return; /*TODO: handle error. */ + } + + char *pkgid_modified = NULL; + char delims[] = "/"; + char *result = NULL; + char *pkgid_tmp = NULL; + char *saveptr = NULL; + + pkgid_modified = (char *)malloc(strlen(pkgid) + 1); + if (pkgid_modified == NULL) { + _d_msg(DEBUG_ERR, "pkgid_modified is NULL. Malloc failed\n"); + return; + } + memset(pkgid_modified, '\0', strlen(pkgid) + 1); + memcpy(pkgid_modified, pkgid, strlen(pkgid)); + + result = strtok_r(pkgid_modified, delims, &saveptr); + while (result != NULL) { + pkgid_tmp = result; + result = strtok_r(NULL, delims, &saveptr); + } + + if (strcmp(key, "install_percent") == 0) { + return; + } else if (strcmp(key, "error") == 0) { + /* Store the error to be display to the user */ + front_data.error = strdup(val); + } else if (strcmp(key, "end") == 0) { + + char requesttype[32]; + switch (front_data.args->req_cmd) { + case INSTALL_CMD: + snprintf(requesttype, sizeof(requesttype), + _("Installation")); + break; + case DELETE_CMD: + snprintf(requesttype, sizeof(requesttype), _("Deletion")); + break; + case CLEARDATA_CMD: + snprintf(requesttype, sizeof(requesttype), + _("Clear Data")); + break; + case MOVE_CMD: + snprintf(requesttype, sizeof(requesttype), + _("Move")); + break; + default: + snprintf(requesttype, sizeof(requesttype), _("Recovery")); + break; + } + + if (front_data.error) { + /* Error Happened */ + snprintf(scrolllabel, sizeof(scrolllabel), + "%s :: %s:: %s:: %s", requesttype, pkgid_tmp, + dgettext("sys_string", "IDS_COM_POP_ERROR"), + front_data.error); + _d_msg(DEBUG_ERR, "%s\n", scrolllabel); + ret_val = _ri_string_to_error_no(front_data.error); + _d_msg(DEBUG_ERR, "%d\n", ret_val); + + } else { + snprintf(scrolllabel, sizeof(scrolllabel), + " %s :: %s :: %s", requesttype, pkgid_tmp, + dgettext("sys_string", "IDS_COM_POP_SUCCESS")); + _d_msg(DEBUG_INFO, "%s\n", scrolllabel); + ret_val = 0; + } + } +} + +int _ri_cmdline_process(ri_frontend_data *data) +{ + char *cookie = NULL; + int cookie_size = 0; + int cookie_ret = 0; + + int ret = 0; + ri_frontend_cmdline_arg *fdata = data->args; + + cookie_size = security_server_get_cookie_size(); + /* If security server is down or some other + error occured, raise failure */ + if (0 >= cookie_size) { + /* TODO: raise error */ + _d_msg(DEBUG_ERR, + "security_server_get_cookie_size: Security server down \n"); + } else { + cookie = calloc(cookie_size, sizeof(char)); + cookie_ret = + security_server_request_cookie(cookie, cookie_size); + /* TODO: Check cookie_ret... + (See security-server.h to check return code) */ + } + + if (cookie != NULL) + _d_msg(DEBUG_INFO, "Got Cookie with size = %d\n", cookie_size); + + data->security_cookie = cookie; + + ret = __ri_process_request(fdata); + if (ret != RPM_INSTALLER_SUCCESS) { + _d_msg(DEBUG_ERR, "__ri_process_request: Error\n"); + goto RETURN; + } + + return RPM_INSTALLER_SUCCESS; + + RETURN: + + if (data->security_cookie) { + free(data->security_cookie); + data->security_cookie = NULL; + } + + return ret; +} + +int _ri_cmdline_destroy(ri_frontend_data *data) +{ + if (data == NULL) + return 0; + + if (data->security_cookie) + free(data->security_cookie); + + return 0; + +} diff --git a/frontend/ui/include/rpm-homeview.h b/frontend/ui/include/rpm-homeview.h new file mode 100755 index 0000000..49c1599 --- /dev/null +++ b/frontend/ui/include/rpm-homeview.h @@ -0,0 +1,37 @@ +/* + * rpm-installer + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , + * Jaeho Lee , Shobhit Srivastava + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef HOME_VIEW_H_ +#define HOME_VIEW_H_ + +void _ri_information_popup(Evas_Smart_Cb func, const char *output, + void *user_param); +void _ri_package_downgrade_popup(Evas_Smart_Cb func1, Evas_Smart_Cb func2, const char *output, + void *user_param); +Eina_Bool _ri_init_appdata(struct appdata *ad); +Eina_Bool _ri_init_home_view(struct appdata *ad); +void _ri_destroy_home_view(struct appdata *ad); +int _ri_frontend_launch_main_view(struct appdata *data); +void _ri_frontend_update_progress_info(struct appdata *data, + char *progressinfo); + +#endif /* HOME_VIEW_H_ */ diff --git a/frontend/ui/src/rpm-homeview.c b/frontend/ui/src/rpm-homeview.c new file mode 100755 index 0000000..afc80ac --- /dev/null +++ b/frontend/ui/src/rpm-homeview.c @@ -0,0 +1,234 @@ +/* + * rpm-installer + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , + * Jaeho Lee , Shobhit Srivastava + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include "rpm-frontend.h" +#include "rpm-installer-util.h" +#include "rpm-homeview.h" +#include "rpm-installer.h" + +#define DESKTOP_W 720.0 + +extern struct appdata ad; +int do_upgrade = -1; +extern ri_frontend_data front_data; +Evas_Object *popup_global; + +static void __ri_response_cb1(void *data, Evas_Object *obj, void *event); +static void __ri_response_cb2(void *data, Evas_Object *obj, void *event); +static void __ri_win_del(void *data, Evas_Object *obj, void *event); +static Eina_Bool __ri_perform_downgrade(void *data); + +void _ri_information_popup(Evas_Smart_Cb func, const char *output, + void *user_param) +{ + if (!ad.win_main) + return; + evas_object_show(ad.win_main); + Evas_Object *popup = NULL; + popup = elm_popup_add(ad.win_main); + if (!popup) + return; + elm_object_part_text_set(popup, dgettext("sys_string", + "IDS_COM_BODY_INFORMATION"), NULL); + evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, + EVAS_HINT_EXPAND); + elm_object_text_set(popup, output); + Evas_Object *button = NULL; + button = elm_button_add(popup); + elm_object_text_set(button, dgettext("sys_string", "IDS_COM_SK_OK")); + elm_object_part_content_set(popup, "button1", button); + evas_object_smart_callback_add(button, "clicked", func, user_param); + evas_object_show(popup); +} + +void _ri_package_downgrade_popup(Evas_Smart_Cb func1, + Evas_Smart_Cb func2, + const char *output, void *user_param) +{ + if (!ad.win_main) + return; + evas_object_show(ad.win_main); + Evas_Object *popup = NULL; + popup = elm_popup_add(ad.win_main); + if (!popup) + return; + elm_object_part_text_set(popup, dgettext("sys_string", + "IDS_COM_BODY_INFORMATION"), NULL); + evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, + EVAS_HINT_EXPAND); + elm_object_text_set(popup, output); + Evas_Object *button1 = NULL; + Evas_Object *button2 = NULL; + button1 = elm_button_add(popup); + elm_object_text_set(button1, dgettext("sys_string", "IDS_COM_SK_YES")); + elm_object_part_content_set(popup, "button1", button1); + evas_object_smart_callback_add(button1, "clicked", func1, user_param); + + button2 = elm_button_add(popup); + elm_object_text_set(button2, dgettext("sys_string", "IDS_COM_SK_NO")); + elm_object_part_content_set(popup, "button2", button2); + evas_object_smart_callback_add(button2, "clicked", func2, user_param); + popup_global = popup; + evas_object_show(popup); +} + +static void __ri_win_del(void *data, Evas_Object *obj, void *event) +{ + elm_exit(); +} + +static Eina_Bool __ri_perform_downgrade(void *data) +{ + int ret = -1; + ret = _rpm_installer_package_install(front_data.args->pkgid, + true, "--force"); + if (ret != 0) { + char *errstr = NULL; + _ri_error_no_to_string(ret, &errstr); + _ri_broadcast_status_notification(front_data.args->pkgid, + "error", errstr); + _ri_stat_cb(front_data.args->pkgid, "error", errstr); + _ri_broadcast_status_notification(front_data.args->pkgid, + "end", "fail"); + _ri_stat_cb(front_data.args->pkgid, "end", "fail"); + _d_msg(DEBUG_ERR, + "install failed with err(%d) (%s)\n", ret, errstr); + } else { + _d_msg(DEBUG_INFO, "install success\n"); + _ri_broadcast_status_notification(front_data.args->pkgid, + "end", "ok"); + _ri_stat_cb(front_data.args->pkgid, "end", "ok"); + } + _ri_set_backend_state_info(REQUEST_COMPLETED); + _ri_set_backend_state(1); + return 0; +} + +static void __ri_response_cb1(void *data, Evas_Object *obj, void *event) +{ + printf("\nresponse callback=%d\n", (int)event); + do_upgrade = 1; + + ecore_idler_add(__ri_perform_downgrade, NULL); + _d_msg(DEBUG_INFO, "doUpgrade is %d\n", do_upgrade); + evas_object_del(obj); + evas_object_del(popup_global); + obj = NULL; +} +static void __ri_response_cb2(void *data, Evas_Object *obj, void *event) +{ + printf("\nresponse callback=%d\n", (int)event); + do_upgrade = 0; + + ecore_idler_add(__ri_perform_downgrade, NULL); + evas_object_del(obj); + evas_object_del(popup_global); + _d_msg(DEBUG_INFO, "doUpgrade is %d\n", do_upgrade); + obj = NULL; +} + +Eina_Bool _ri_init_appdata(struct appdata *user_data) +{ + unsigned char *prop_data = NULL; + int rotation = 0; + int w; + int h; + int x; + int y; + int count = 0; + user_data->win_main = elm_win_add(NULL, PACKAGE, ELM_WIN_DIALOG_BASIC); + if (!user_data->win_main) + return EINA_FALSE; + + elm_win_title_set(user_data->win_main, PACKAGE); + elm_win_alpha_set(user_data->win_main, EINA_TRUE); + elm_win_borderless_set(user_data->win_main, EINA_TRUE); + elm_win_raise(user_data->win_main); + ecore_x_window_geometry_get(ecore_x_window_root_get + (ecore_x_window_focus_get()), &x, &y, &w, + &h); + int ret = + ecore_x_window_prop_property_get(ecore_x_window_root_get + (ecore_x_window_focus_get()), + ECORE_X_ATOM_E_ILLUME_ROTATE_ROOT_ANGLE, + ECORE_X_ATOM_CARDINAL, 32, + &prop_data, &count); + if (ret && prop_data) + memcpy(&rotation, prop_data, sizeof(int)); + if (prop_data) + free(prop_data); + evas_object_resize(user_data->win_main, w, h); + evas_object_move(user_data->win_main, x, y); + /*evas_object_show(user_data->win_main); + evas_object_smart_callback_add(user_data->win_main, "delete,request", + __ri_win_del, NULL); + elm_win_indicator_state_set(user_data->win_main, EINA_TRUE);*/ + double s; + s = w / DESKTOP_W; + elm_config_scale_set(s); + user_data->evas = evas_object_evas_get(user_data->win_main); + if (!user_data->evas) + return EINA_FALSE; + + return EINA_TRUE; +} + +Eina_Bool _ri_init_home_view(struct appdata *user_data) +{ + return EINA_TRUE; + +} + +void _ri_destroy_home_view(struct appdata *user_data) +{ + + if (!user_data) { + return; + } + evas_object_del(user_data->main_view); +} + +int _ri_frontend_launch_main_view(struct appdata *data) +{ + /* create UI */ + if (!_ri_init_appdata(data)) { + return 0; + } + if (!_ri_init_home_view(data)) { + return 0; + } + return 0; +} + +void _ri_frontend_update_progress_info(struct appdata *data, char *progressinfo) +{ + elm_object_text_set(data->scrollbar_label, progressinfo); + _ri_information_popup(__ri_win_del, progressinfo, data); +} + +void _ri_package_downgrade_information(const char *message) +{ + _ri_package_downgrade_popup(__ri_response_cb1, __ri_response_cb2, message, &ad); +} diff --git a/inc/rpm-installer-util.h b/inc/rpm-installer-util.h new file mode 100755 index 0000000..0218632 --- /dev/null +++ b/inc/rpm-installer-util.h @@ -0,0 +1,112 @@ +/* + * rpm-installer + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , + * Jaeho Lee , Shobhit Srivastava + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef __RPM_INSTALLER_UTIL_H_ +#define __RPM_INSTALLER_UTIL_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define RPM_BACKEND_EXEC "rpm-backend" + +#define PKGTYPE "rpm" + +#define RPM_INSTALLER_SUCCESS 0 +#define RPM_INSTALLER_ERR_WRONG_PARAM 3 +#define RPM_INSTALLER_ERR_DBUS_PROBLEM 4 +#define RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY 5 +#define RPM_INSTALLER_ERR_PACKAGE_EXIST 7 +#define RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED 8 +#define RPM_INSTALLER_ERR_RESOURCE_BUSY 9 +#define RPM_INSTALLER_ERR_UNKNOWN 10 +#define RPM_INSTALLER_ERR_PKG_NOT_FOUND 11 +#define RPM_INSTALLER_ERR_NOT_SUPPOTED_VERSION 12 +#define RPM_INSTALLER_ERR_NO_RPM_FILE 13 +#define RPM_INSTALLER_ERR_DB_ACCESS_FAILED 14 +#define RPM_INSTALLER_ERR_RPM_OPERATION_FAILED 15 +#define RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED 16 +#define RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS 17 +#define RPM_INSTALLER_ERR_NEED_USER_CONFIRMATION 18 +#define RPM_INSTALLER_ERR_PACKAGE_INSTALLATION_DISABLED 19 +#define RPM_INSTALLER_ERR_PACKAGE_UNINSTALLATION_DISABLED 20 +#define RPM_INSTALLER_ERR_CLEAR_DATA_FAILED 21 +#define RPM_INSTALLER_ERR_INTERNAL 22 +#define RPM_INSTALLER_ERR_NO_MANIFEST 23 +#define RPM_INSTALLER_ERR_INVALID_MANIFEST 24 + +#define RPM_INSTALLER_SUCCESS_STR "Success" +#define RPM_INSTALLER_ERR_WRONG_PARAM_STR "Wrong Input Param" +#define RPM_INSTALLER_ERR_DBUS_PROBLEM_STR "DBUS Error" +#define RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY_STR "Not Enough Memory" +#define RPM_INSTALLER_ERR_PACKAGE_EXIST_STR "Package Already Installed" +#define RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED_STR "Package Not Installed" +#define RPM_INSTALLER_ERR_RESOURCE_BUSY_STR "Resource Busy" +#define RPM_INSTALLER_ERR_UNKNOWN_STR "Unknown Error" +#define RPM_INSTALLER_ERR_PKG_NOT_FOUND_STR "Package file not found" +#define RPM_INSTALLER_ERR_NOT_SUPPOTED_VERSION_STR "Version Not supported" +#define RPM_INSTALLER_ERR_NO_RPM_FILE_STR "No RPM Package" +#define RPM_INSTALLER_ERR_DB_ACCESS_FAILED_STR "DB Access Failed" +#define RPM_INSTALLER_ERR_RPM_OPERATION_FAILED_STR "RPM operation failed" +#define RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED_STR "Package Not Upgraded" +#define RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS_STR "Wrong Args to Script" +#define RPM_INSTALLER_ERR_PACKAGE_INSTALLATION_DISABLED_STR "Installation Disabled" +#define RPM_INSTALLER_ERR_PACKAGE_UNINSTALLATION_DISABLED_STR "Uninstallation Disabled" +#define RPM_INSTALLER_ERR_CLEAR_DATA_FAILED_STR "Clear Data Failed" +#define RPM_INSTALLER_ERR_INTERNAL_STR "Internal Error" +#define RPM_INSTALLER_ERR_NO_MANIFEST_STR "Manifest File Not Found" +#define RPM_INSTALLER_ERR_INVALID_MANIFEST_STR "Manifest Validation Failed" + +#define DEBUG_ERR 0x0001 +#define DEBUG_INFO 0x0002 +#define DEBUG_RESULT 0x0004 + +#define RPM_LOG 1 + + void _print_msg(int type, int exetype, char *format, ...); +#define _d_msg(type, fmtstr, args...) { \ +_print_msg(type, RPM_LOG, "%s:%d:%s(): " fmtstr, basename(__FILE__), \ +__LINE__, __func__, ##args); \ +} + + void _d_msg_init(char *program); + void _d_msg_deinit(); + int _ri_xsystem(const char *argv[]); + char *_ri_substring(const char *str, size_t begin, size_t len); + int _ri_tok_split_string(char tok, char *input, char **list, + unsigned long listmax); + void _ri_error_no_to_string(int errnumber, char **errstr); + int _ri_string_to_error_no(char *errstr); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* __RPM_INSTALLER_UTIL_H_ */ diff --git a/packaging/rpm-installer.spec b/packaging/rpm-installer.spec new file mode 100755 index 0000000..d9cc2ca --- /dev/null +++ b/packaging/rpm-installer.spec @@ -0,0 +1,78 @@ +Name: rpm-installer +Summary: Native rpm installer +Version: 0.1.25 +Release: 1 +Group: System/Libraries +License: Apache License, Version 2.0 +Source0: %{name}-%{version}.tar.gz +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig +BuildRequires: cmake +BuildRequires: edje-bin +BuildRequires: rpm-devel +BuildRequires: popt-devel +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(dbus-glib-1) +BuildRequires: pkgconfig(sqlite3) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(db-util) +BuildRequires: pkgconfig(pkgmgr-types) +BuildRequires: pkgconfig(pkgmgr-installer) +BuildRequires: pkgconfig(pkgmgr-parser) +BuildRequires: pkgconfig(pkgmgr) +BuildRequires: pkgconfig(pkgmgr-info) +BuildRequires: pkgconfig(app2sd) +BuildRequires: pkgconfig(libxml-2.0) +BuildRequires: pkgconfig(security-server) +BuildRequires: pkgconfig(elementary) +BuildRequires: pkgconfig(appcore-efl) +BuildRequires: pkgconfig(evas) +BuildRequires: pkgconfig(ecore) +BuildRequires: pkgconfig(edje) +BuildRequires: gettext-tools +Requires: /bin/cpio + +%description +Native rpm installer + +%prep +%setup -q + +%build +CFLAGS+=" -fpic" +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install + +%post +mkdir -p /usr/etc/package-manager/backend +mkdir -p /usr/etc/package-manager/backendlib +ln -sf /usr/bin/rpm-backend /usr/etc/package-manager/backend/rpm +ln -sf /usr/lib/libnativerpm.so /usr/etc/package-manager/backendlib/librpm.so + +chmod 700 /usr/bin/rpm-backend + +vconftool set -t int db/private/rpm-installer/state "0" +vconftool set -t int db/private/rpm-installer/stateinfo "0" +vconftool set -t int db/private/rpm-installer/requestinfo/command "0" +vconftool set -t string db/private/rpm-installer/requestinfo/pkgname "" +vconftool set -t int db/private/rpm-installer/requestinfo/options "0" + +%files +%manifest rpm-installer.manifest +%attr(0700,-,-) /usr/bin/rpm-backend +%attr(0700,-,-) /usr/bin/install_rpm_package.sh +%attr(0755,-,-) /usr/bin/query_rpm_package.sh +%attr(0700,-,-) /usr/bin/uninstall_rpm_package.sh +%attr(0700,-,-) /usr/bin/upgrade_rpm_package.sh +%attr(0644,-,-) /usr/share/locale/en_GB/LC_MESSAGES/rpm-installer.mo +%attr(0644,-,-) /usr/share/locale/ja_JP/LC_MESSAGES/rpm-installer.mo +%attr(0644,-,-) /usr/share/locale/zh_CN/LC_MESSAGES/rpm-installer.mo +%attr(0644,-,-) /usr/share/locale/en_US/LC_MESSAGES/rpm-installer.mo +%attr(0644,-,-) /usr/share/locale/ko_KR/LC_MESSAGES/rpm-installer.mo +%attr(0644,-,-) /usr/lib/libnativerpm.so diff --git a/po/CMakeLists.txt b/po/CMakeLists.txt new file mode 100755 index 0000000..e3aebb4 --- /dev/null +++ b/po/CMakeLists.txt @@ -0,0 +1,24 @@ +# for i18n + +SET(POFILES en_US.po en_GB.po ja_JP.po ko_KR.po zh_CN.po) + +SET(MSGFMT "/usr/bin/msgfmt") + +FOREACH(pofile ${POFILES}) + SET(pofile ${CMAKE_CURRENT_SOURCE_DIR}/${pofile}) + MESSAGE("PO: ${pofile}") + GET_FILENAME_COMPONENT(absPofile ${pofile} ABSOLUTE) + GET_FILENAME_COMPONENT(lang ${absPofile} NAME_WE) + SET(moFile ${CMAKE_CURRENT_BINARY_DIR}/${lang}.mo) + ADD_CUSTOM_COMMAND( + OUTPUT ${moFile} + COMMAND ${MSGFMT} -o ${moFile} ${absPofile} + DEPENDS ${absPofile} + ) + INSTALL(FILES ${moFile} + DESTINATION share/locale/${lang}/LC_MESSAGES RENAME ${PROJECT_NAME}.mo) + SET(moFiles ${moFiles} ${moFile}) +ENDFOREACH(pofile) + +MESSAGE(".mo files: ${moFiles}") +ADD_CUSTOM_TARGET(po ALL DEPENDS ${moFiles}) diff --git a/po/POTFILES.in b/po/POTFILES.in new file mode 100755 index 0000000..d657f08 --- /dev/null +++ b/po/POTFILES.in @@ -0,0 +1,3 @@ +# List of source files containing translatable strings. +frontend/src/rpm-cmdline.c +frontend/src/rpm-appcore-intf.c diff --git a/po/en_GB.po b/po/en_GB.po new file mode 100755 index 0000000..a04a042 --- /dev/null +++ b/po/en_GB.po @@ -0,0 +1,42 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-01-03 15:32+0900\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: frontend/src/rpm-appcore-intf.c:129 +#, c-format +msgid "Continue Downgrade?" +msgstr "" + +#: frontend/src/rpm-cmdline.c:245 +#, c-format +msgid "Installation" +msgstr "" + +#: frontend/src/rpm-cmdline.c:248 +#, c-format +msgid "Deletion" +msgstr "" + +#: frontend/src/rpm-cmdline.c:255 +#, c-format +msgid "Recovery" +msgstr "" + +#: frontend/src/rpm-cmdline.c:252 +#, c-format +msgid "Clear Data" +msgstr "" diff --git a/po/en_US.po b/po/en_US.po new file mode 100755 index 0000000..a04a042 --- /dev/null +++ b/po/en_US.po @@ -0,0 +1,42 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-01-03 15:32+0900\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: frontend/src/rpm-appcore-intf.c:129 +#, c-format +msgid "Continue Downgrade?" +msgstr "" + +#: frontend/src/rpm-cmdline.c:245 +#, c-format +msgid "Installation" +msgstr "" + +#: frontend/src/rpm-cmdline.c:248 +#, c-format +msgid "Deletion" +msgstr "" + +#: frontend/src/rpm-cmdline.c:255 +#, c-format +msgid "Recovery" +msgstr "" + +#: frontend/src/rpm-cmdline.c:252 +#, c-format +msgid "Clear Data" +msgstr "" diff --git a/po/ja_JP.po b/po/ja_JP.po new file mode 100755 index 0000000..41544d5 --- /dev/null +++ b/po/ja_JP.po @@ -0,0 +1,42 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-01-03 15:32+0900\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: frontend/src/rpm-appcore-intf.c:129 +#, c-format +msgid "Continue Downgrade?" +msgstr "ダウングレード を続行しますか?" + +#: frontend/src/rpm-cmdline.c:245 +#, c-format +msgid "Installation" +msgstr "インストール" + +#: frontend/src/rpm-cmdline.c:248 +#, c-format +msgid "Deletion" +msgstr "削除" + +#: frontend/src/rpm-cmdline.c:255 +#, c-format +msgid "Recovery" +msgstr "回復" + +#: frontend/src/rpm-cmdline.c:252 +#, c-format +msgid "Clear Data" +msgstr "明確な データ" diff --git a/po/ko_KR.po b/po/ko_KR.po new file mode 100755 index 0000000..521011d --- /dev/null +++ b/po/ko_KR.po @@ -0,0 +1,42 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-01-03 15:32+0900\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: frontend/src/rpm-appcore-intf.c:129 +#, c-format +msgid "Continue Downgrade?" +msgstr "다운 그레이드 를 계속하시겠습니까?" + +#: frontend/src/rpm-cmdline.c:245 +#, c-format +msgid "Installation" +msgstr "설치" + +#: frontend/src/rpm-cmdline.c:248 +#, c-format +msgid "Deletion" +msgstr "삭제" + +#: frontend/src/rpm-cmdline.c:255 +#, c-format +msgid "Recovery" +msgstr "회복" + +#: frontend/src/rpm-cmdline.c:252 +#, c-format +msgid "Clear Data" +msgstr "삭제 데이터" diff --git a/po/update-po.sh b/po/update-po.sh new file mode 100755 index 0000000..39ae5d5 --- /dev/null +++ b/po/update-po.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +PACKAGE=rpm-installer +SRCROOT=.. +POTFILES=POTFILES.in + +#ALL_LINGUAS= am az be ca cs da de el en_CA en_GB es et fi fr hr hu it ja ko lv mk ml ms nb ne nl pa pl pt pt_BR ru rw sk sl sr sr@Latn sv ta tr uk vi zh_CN zh_TW +ALL_LINGUAS="en_US en_GB ja_JP ko_KR zh_CN" + +XGETTEXT=/usr/bin/xgettext +MSGMERGE=/usr/bin/msgmerge + +echo -n "Make ${PACKAGE}.pot " +if [ ! -e $POTFILES ] ; then + echo "$POTFILES not found" + exit 1 +fi + +$XGETTEXT --default-domain=${PACKAGE} --directory=${SRCROOT} \ + --add-comments --keyword=_ --keyword=N_ --files-from=$POTFILES +if [ $? -ne 0 ]; then + echo "xgettext error" + exit 1 +fi + +if [ ! -f ${PACKAGE}.po ]; then + echo "No such file: ${PACKAGE}.po" + exit 1 +fi + +rm -f ${PACKAGE}.pot && mv ${PACKAGE}.po ${PACKAGE}.pot +echo "done" + +for LANG in $ALL_LINGUAS; do + echo "$LANG : " + + if [ ! -e $LANG.po ] ; then + sed 's/CHARSET/UTF-8/g' ${PACKAGE}.pot > ${LANG}.po + echo "${LANG}.po created" + else + if $MSGMERGE ${LANG}.po ${PACKAGE}.pot -o ${LANG}.new.po ; then + if cmp ${LANG}.po ${LANG}.new.po > /dev/null 2>&1; then + rm -f ${LANG}.new.po + else + if mv -f ${LANG}.new.po ${LANG}.po; then + echo "" + else + echo "msgmerge for $LANG.po failed: cannot move $LANG.new.po to $LANG.po" 1>&2 + rm -f ${LANG}.new.po + exit 1 + fi + fi + else + echo "msgmerge for $LANG failed!" + rm -f ${LANG}.new.po + fi + fi + echo "" +done diff --git a/po/zh_CN.po b/po/zh_CN.po new file mode 100755 index 0000000..e2b11d6 --- /dev/null +++ b/po/zh_CN.po @@ -0,0 +1,42 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-01-03 15:32+0900\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: frontend/src/rpm-appcore-intf.c:129 +#, c-format +msgid "Continue Downgrade?" +msgstr "繼續 降級?" + +#: frontend/src/rpm-cmdline.c:245 +#, c-format +msgid "Installation" +msgstr "安裝" + +#: frontend/src/rpm-cmdline.c:248 +#, c-format +msgid "Deletion" +msgstr "刪除" + +#: frontend/src/rpm-cmdline.c:255 +#, c-format +msgid "Recovery" +msgstr "恢復" + +#: frontend/src/rpm-cmdline.c:252 +#, c-format +msgid "Clear Data" +msgstr "清除數據" diff --git a/rpm-installer.manifest b/rpm-installer.manifest new file mode 100755 index 0000000..97e8c31 --- /dev/null +++ b/rpm-installer.manifest @@ -0,0 +1,5 @@ + + + + + -- 2.7.4