Pkg-install-manifest helper binary 25/55225/21
authorTomasz Iwanek <t.iwanek@samsung.com>
Mon, 21 Dec 2015 10:37:34 +0000 (11:37 +0100)
committerPawel Sikorski <p.sikorski@samsung.com>
Fri, 22 Jan 2016 12:37:39 +0000 (04:37 -0800)
Requires:
 - https://review.tizen.org/gerrit/#/c/55055/
 - https://review.tizen.org/gerrit/#/c/56244/
 - https://review.tizen.org/gerrit/#/c/56245/

Change-Id: I32402533583a2f7b12705b2d8bb97a977f09e025

CMakeLists.txt
packaging/app-installers.manifest
packaging/app-installers.spec
src/CMakeLists.txt
src/common/pkgmgr_interface.cc
src/common/request.cc
src/common/step/step_configure.cc
src/pkg_install_manifest/CMakeLists.txt [new file with mode: 0644]
src/pkg_install_manifest/pkg_install_manifest.cc [new file with mode: 0644]

index 72edc95..e86a679 100644 (file)
@@ -24,6 +24,7 @@ SET(CMAKE_CXX_FLAGS_CCOV       "-O0 -std=c++11 -g --coverage")
 # Targets
 SET(TARGET_LIBNAME_COMMON "app-installers")
 SET(TARGET_PKGDIR_TOOL "pkgdir-tool")
+SET(TARGET_PKG_INSTALL_MANIFEST "pkg-install-manifest")
 
 ADD_DEFINITIONS("-Wall")
 ADD_DEFINITIONS("-Wextra")
@@ -42,6 +43,7 @@ PKG_CHECK_MODULES(ZLIB_DEPS REQUIRED zlib)
 PKG_CHECK_MODULES(TZPLATFORM_CONFIG_DEPS REQUIRED libtzplatform-config)
 PKG_CHECK_MODULES(SECURITY_MANAGER_DEPS REQUIRED security-manager)
 PKG_CHECK_MODULES(DELTA_MANIFEST_HANDLERS_DEPS REQUIRED delta-manifest-handlers)
+PKG_CHECK_MODULES(TPK_MANIFEST_HANDLERS_DEPS REQUIRED tpk-manifest-handlers)
 PKG_CHECK_MODULES(MANIFEST_PARSER_UTILS_DEPS REQUIRED manifest-parser-utils)
 PKG_CHECK_MODULES(CERT_SVC_DEPS_VCORE_DEPS REQUIRED cert-svc-vcore)
 PKG_CHECK_MODULES(PKGMGR_PARSER_DEPS REQUIRED pkgmgr-parser)
index d50f44a..0502b63 100644 (file)
@@ -4,5 +4,6 @@
         </request>
         <assign>
                 <filesystem path="/usr/bin/pkgdir-tool" exec_label="User" />
+                <filesystem path="/usr/bin/pkg-install-manifest" exec_label="User" />
         </assign>
 </manifest>
index 0fc9088..662bfd6 100644 (file)
@@ -80,6 +80,7 @@ ln -sf %{_bindir}/pkgdir-tool %{_bindir}/pkgdir_maker
 %manifest app-installers.manifest
 %{_libdir}/libapp-installers.so*
 %attr(6750,root,users) %{_bindir}/pkgdir-tool
+%{_bindir}/pkg-install-manifest
 %license LICENSE
 
 %files devel
index d1a2d79..a8d55ef 100644 (file)
@@ -1,3 +1,4 @@
 ADD_SUBDIRECTORY(common)
+ADD_SUBDIRECTORY(pkg_install_manifest)
 ADD_SUBDIRECTORY(pkgdir_tool)
 ADD_SUBDIRECTORY(unit_tests)
index 38593a2..61630d8 100644 (file)
@@ -38,8 +38,14 @@ int PkgMgrInterface::InitInternal(int argc, char** argv) {
   pi_ = pkgmgr_installer_new();
 
   if (!pi_) {
-    LOG(ERROR) << "Cannot create pkgmgr_installer object";
-    return ENOMEM;
+    LOG(WARNING) << "Cannot create pkgmgr_installer object. Will try offline";
+    // TODO(t.iwanek): app-installer should recognize offline installation and
+    // this information should be accesible in installation context
+    pi_ = pkgmgr_installer_offline_new();
+    if (!pi_) {
+      LOG(ERROR) << "Cannot create pkgmgr_installer object. Aborting.";
+      return ENOMEM;
+    }
   }
 
   int result = pkgmgr_installer_receive_request(pi_, argc, argv);
index 6f9bbf5..6934077 100644 (file)
@@ -9,7 +9,8 @@
 namespace common_installer {
 
 RequestMode GetRequestMode() {
-  return (getuid() == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)) ?
+  return (getuid() == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) ||
+          getuid() == 0) ?
       RequestMode::GLOBAL : RequestMode::USER;
 }
 
index 98df6e9..ee45cd4 100644 (file)
@@ -86,7 +86,6 @@ Step::Status StepConfigure::process() {
       context_->unpacked_dir_path.set(package_directory);
       context_->pkg_path.set(package_directory);
       context_->xml_path.set(xml_path);
-      context_->privilege_level.set(common_installer::PrivilegeLevel::PUBLIC);
       context_->pkg_type.set(kRpmPackageType);  // temporary fix as rpm
       break;
     }
@@ -121,9 +120,15 @@ Step::Status StepConfigure::process() {
 }
 
 Step::Status StepConfigure::precheck() {
-  if (getuid() == 0) {
-    LOG(ERROR) << "App-installer should not run with superuser!";
-    return Status::OPERATION_NOT_ALLOWED;
+  if (pkgmgr_->GetRequestType() != RequestType::ManifestDirectInstall &&
+      pkgmgr_->GetRequestType() != RequestType::ManifestDirectUpdate) {
+    if (getuid() == 0) {
+      LOG(ERROR) << "App-installer should not run with superuser!";
+      return Status::OPERATION_NOT_ALLOWED;
+    }
+  } else {
+    LOG(INFO) << "Allowing installation from root user for"
+                 "manifest direct installation mode.";
   }
   return Status::OK;
 }
diff --git a/src/pkg_install_manifest/CMakeLists.txt b/src/pkg_install_manifest/CMakeLists.txt
new file mode 100644 (file)
index 0000000..d4e4bf0
--- /dev/null
@@ -0,0 +1,20 @@
+# Target - sources
+SET(SRCS
+  pkg_install_manifest.cc
+)
+
+# Target - definition
+ADD_EXECUTABLE(${TARGET_PKG_INSTALL_MANIFEST} "pkg_install_manifest.cc")
+# Target - includes
+TARGET_INCLUDE_DIRECTORIES(${TARGET_PKG_INSTALL_MANIFEST} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../")
+# Target - deps
+APPLY_PKG_CONFIG(${TARGET_PKG_INSTALL_MANIFEST} PUBLIC
+  TPK_MANIFEST_HANDLERS_DEPS
+  PKGMGR_DEPS
+  Boost
+)
+# Target - in-package deps
+TARGET_LINK_LIBRARIES(${TARGET_PKG_INSTALL_MANIFEST} PUBLIC ${TARGET_LIBNAME_COMMON})
+
+# Install
+INSTALL(TARGETS ${TARGET_PKG_INSTALL_MANIFEST} DESTINATION ${BINDIR})
diff --git a/src/pkg_install_manifest/pkg_install_manifest.cc b/src/pkg_install_manifest/pkg_install_manifest.cc
new file mode 100644 (file)
index 0000000..57e4391
--- /dev/null
@@ -0,0 +1,75 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include <boost/filesystem/path.hpp>
+#include <boost/program_options.hpp>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+#include <manifest_parser/utils/logging.h>
+#include <tpk_manifest_handlers/package_handler.h>
+#include <tpk_manifest_handlers/tpk_config_parser.h>
+
+#include <iostream>
+
+#include "common/request.h"
+#include "common/utils/subprocess.h"
+
+namespace bf = boost::filesystem;
+namespace bpo = boost::program_options;
+namespace ci = common_installer;
+
+namespace {
+
+const char kBackendDirectoryPath[] = "/etc/package-manager/backend/";
+
+int InstallManifestOffline(const std::string& pkgid,
+                           const std::string& type) {
+  bf::path backend_path(kBackendDirectoryPath);
+  backend_path /= type;
+  ci::Subprocess backend(backend_path.string());
+  backend.Run("-y", pkgid.c_str());
+  return backend.Wait();
+}
+
+}  // namespace
+
+int main(int argc, char** argv) {
+  bpo::options_description options("Allowed options");
+  options.add_options()
+      ("xml-path,x", bpo::value<std::string>()->required(), "xml package path")
+      ("help,h", "display this help message");
+  bpo::variables_map opt_map;
+  try {
+    bpo::store(bpo::parse_command_line(argc, argv, options), opt_map);
+    if (opt_map.count("help")) {
+      std::cerr << options << std::endl;
+      return -1;
+    }
+    bpo::notify(opt_map);
+  } catch (const bpo::error& error) {
+    std::cerr << error.what() << std::endl;
+    return -1;
+  }
+
+  bf::path manifest_path(opt_map["xml-path"].as<std::string>());
+  tpk::parse::TPKConfigParser parser;
+  if (!parser.ParseManifest(manifest_path)) {
+    LOG(ERROR) << "Failed to parse tizen manifest file: "
+               << parser.GetErrorMessage();
+    return 1;
+  }
+  auto package_info = std::static_pointer_cast<const tpk::parse::PackageInfo>(
+      parser.GetManifestData(tpk::parse::PackageInfo::key()));
+  if (!package_info) {
+    LOG(ERROR) << "Failed to get package info";
+    return 1;
+  }
+  std::string type = package_info->type();
+  if (type.empty())
+    type = "tpk";
+
+  return InstallManifestOffline(package_info->package(), type);
+}