[Release] wrt-installer_0.1.53
[framework/web/wrt-installer.git] / src / wrt-installer / wrt-installer.cpp
index 1f5bc8c..77457f5 100644 (file)
@@ -21,6 +21,7 @@
 #include "wrt-installer.h"
 #include "plugin_utils.h"
 
+#include <map>
 #include <string>
 #include <cstring>
 #include <cstdlib>
@@ -81,14 +82,12 @@ struct PluginInstallerData
 WrtInstaller::WrtInstaller(int argc, char **argv) :
     Application(argc, argv, "backend", false),
     DPL::TaskDecl<WrtInstaller>(this),
-    m_installMode(WRT_INSTALL_MODE_UNKNOWN),
     m_packagePath(),
     m_initialized(false),
     m_numPluginsToInstall(0),
     m_totalPlugins(0),
     m_returnStatus(-1),
     m_installByPkgmgr(false),
-    m_quiet(true),
     m_startupPluginInstallation(false)
 {
     Touch();
@@ -175,10 +174,10 @@ void WrtInstaller::OnCreate()
             struct stat info;
             if (-1 != stat(m_argv[2], &info) && S_ISDIR(info.st_mode)) {
                 LogInfo("Installing package directly from directory");
-                m_installMode = WRT_INSTALL_MODE_INSTALL_DIRECTORY;
+                m_installMode.extension = InstallMode::ExtensionType::DIR;
             } else {
                 LogInfo("Installing from regular location");
-                m_installMode = WRT_INSTALL_MODE_INSTALL_WGT;
+                m_installMode.extension = InstallMode::ExtensionType::WGT;
             }
             m_packagePath = m_argv[2];
 
@@ -189,8 +188,59 @@ void WrtInstaller::OnCreate()
                 return showHelpAndQuit();
             }
             m_packagePath = m_argv[2];
-            m_installMode = WRT_INSTALL_MODE_INSTALL_PRELOAD;
+            m_installMode.installTime = InstallMode::InstallTime::PRELOAD;
+            m_installMode.rootPath = InstallMode::RootPath::RO;
             AddStep(&WrtInstaller::installStep);
+        } else if (arg == "-ipw" || arg == "--install-preload-writable") {
+            LogDebug("Install preload web application to writable storage");
+            if (m_argc != 3) {
+                return showHelpAndQuit();
+            }
+            m_packagePath = m_argv[2];
+            m_installMode.installTime = InstallMode::InstallTime::PRELOAD;
+            m_installMode.rootPath = InstallMode::RootPath::RW;
+            AddStep(&WrtInstaller::installStep);
+        } else if (arg == "-c" || arg == "--csc-update") {
+            // "path=/opt/system/csc/Ozq2iEG15R-2.0.0-arm.wgt:op=install:removable=true"
+            LogDebug("Install & uninstall by csc configuration");
+            if (m_argc != 3) {
+                return showHelpAndQuit();
+            }
+            std::string configuration = m_argv[2];
+            m_CSCconfigurationMap = parseCSCConfiguration(configuration);
+
+            CSCConfiguration::dataMap::iterator it;
+            it = m_CSCconfigurationMap.find(CSCConfiguration::KEY_OP);
+            if (it == m_CSCconfigurationMap.end()) {
+                return showHelpAndQuit();
+            }
+
+            if (it->second == CSCConfiguration::VALUE_INSTALL) {
+                LogDebug("operation = " << it->second);
+                m_installMode.extension = InstallMode::ExtensionType::WGT;
+                it = m_CSCconfigurationMap.find(CSCConfiguration::KEY_PATH);
+                if (it == m_CSCconfigurationMap.end()) {
+                    return showHelpAndQuit();
+                }
+                m_packagePath = it->second;
+                AddStep(&WrtInstaller::installStep);
+                LogDebug("path      = " << m_packagePath);
+            } else if (it->second == CSCConfiguration::VALUE_UNINSTALL) {
+                LogDebug("operation = " << it->second);
+                // uninstall command isn't confirmed yet
+                it = m_CSCconfigurationMap.find(CSCConfiguration::KEY_PATH);
+                if (it == m_CSCconfigurationMap.end()) {
+                    return showHelpAndQuit();
+                }
+                m_packagePath = it->second;
+                AddStep(&WrtInstaller::unistallWgtFileStep);
+                LogDebug("operation = uninstall");
+                LogDebug("path      = " << m_packagePath);
+            } else {
+                LogError("Unknown operation : " << it->second);
+                LogDebug("operation = " << it->second);
+                return showHelpAndQuit();
+            }
         } else if (arg == "-un" || arg == "--uninstall-name") {
             if (m_argc != 3) {
                 return showHelpAndQuit();
@@ -208,7 +258,8 @@ void WrtInstaller::OnCreate()
                 return showHelpAndQuit();
             }
             LogInfo("Installing package directly from directory");
-            m_installMode = WRT_INSTALL_MODE_REINSTALL;
+            m_installMode.command = InstallMode::Command::REINSTALL;
+            m_installMode.extension = InstallMode::ExtensionType::DIR;
             m_packagePath = m_argv[2];
             AddStep(&WrtInstaller::installStep);
         } else {
@@ -223,8 +274,6 @@ void WrtInstaller::OnCreate()
                 );
 
         pkgmgrSignal->initialize(m_argc, m_argv);
-        m_quiet = pkgmgrSignal->isNoPopupRequired();
-        LogDebug("backend m_quiet" << m_quiet);
 
         int reqType = pkgmgrSignal->getRequestedType();
 
@@ -237,10 +286,10 @@ void WrtInstaller::OnCreate()
             struct stat info;
             if (-1 != stat(m_argv[4], &info) && S_ISDIR(info.st_mode)) {
                 LogInfo("Installing package directly from directory");
-                m_installMode = WRT_INSTALL_MODE_INSTALL_DIRECTORY;
+                m_installMode.extension = InstallMode::ExtensionType::DIR;
             } else {
                 LogInfo("Installing from regular location");
-                m_installMode = WRT_INSTALL_MODE_INSTALL_WGT;
+                m_installMode.extension = InstallMode::ExtensionType::WGT;
             }
             AddStep(&WrtInstaller::installStep);
             break;
@@ -250,7 +299,8 @@ void WrtInstaller::OnCreate()
             break;
         case PKGMGR_REQ_REINSTALL:
             m_packagePath = m_argv[4];
-            m_installMode = WRT_INSTALL_MODE_REINSTALL;
+            m_installMode.command = InstallMode::Command::REINSTALL;
+            m_installMode.extension = InstallMode::ExtensionType::DIR;
             AddStep(&WrtInstaller::installStep);
             break;
         default:
@@ -273,8 +323,8 @@ void WrtInstaller::OnReset(bundle* /*b*/)
 void WrtInstaller::OnTerminate()
 {
     LogDebug("Wrt Shutdown now");
-    PluginUtils::unlockPluginInstallation(m_installMode ==
-            WRT_INSTALL_MODE_INSTALL_PRELOAD);
+    PluginUtils::unlockPluginInstallation(
+        m_installMode.installTime == InstallMode::InstallTime::PRELOAD);
     if (m_initialized) {
         wrt_installer_shutdown();
     }
@@ -294,6 +344,8 @@ void WrtInstaller::showHelpAndQuit()
            "  -p,    --install-plugins                      install plugins\n"
            "  -i,    --install                              "
            "install or update widget package for given path\n"
+           "  -c,    --csc-update                           "
+           "install or uninstall by CSC configuration \n"
            "  -un,   --uninstall-name                       "
            "uninstall widget for given package name\n"
            "  -up,   --uninstall-packagepath                "
@@ -360,10 +412,9 @@ void WrtInstaller::installStep()
 
     wrt_install_widget(packagePath ? packagePath.get() : m_packagePath.c_str(),
                        this, &staticWrtStatusCallback,
-                       (!m_quiet || m_installByPkgmgr)
+                       (m_installByPkgmgr)
                        ? &staticWrtInstallProgressCallback : NULL,
                        m_installMode,
-                       m_quiet,
                        pkgmgrSignalInterface);
 }
 
@@ -374,8 +425,9 @@ void WrtInstaller::installPluginsStep()
 
     if (m_startupPluginInstallation) {
         LogInfo("Plugin installation started because new plugin package found");
-    } else if (!PluginUtils::lockPluginInstallation(m_installMode ==
-                WRT_INSTALL_MODE_INSTALL_PRELOAD)) {
+    } else if (!PluginUtils::lockPluginInstallation(
+        m_installMode.installTime == InstallMode::InstallTime::PRELOAD))
+    {
         LogError("Failed to open plugin installation lock file"
                  " Plugins are currently installed by other process");
         staticWrtPluginInstallationCallback(WRT_INSTALLER_ERROR_PLUGIN_INSTALLATION_FAILED,
@@ -453,7 +505,7 @@ void WrtInstaller::uninstallPkgNameStep()
     LogDebug("Uninstalling widget ...");
     LogDebug("Package name : " << m_name);
     wrt_uninstall_widget(m_name.c_str(), this, &staticWrtStatusCallback,
-                         (!m_quiet || m_installByPkgmgr)
+                         (m_installByPkgmgr)
                          ? &staticWrtUninstallProgressCallback : NULL,
                          pkgmgrSignalInterface);
 }
@@ -498,7 +550,7 @@ void WrtInstaller::unistallWgtFileStep()
             LogDebug("Pkgid from packagePath : " << pkgId);
             wrt_uninstall_widget(
                 DPL::ToUTF8String(*pkgId).c_str(), this, &staticWrtStatusCallback,
-                !m_quiet ? &staticWrtUninstallProgressCallback
+                !m_installByPkgmgr ? &staticWrtUninstallProgressCallback
                 : NULL,
                 pkgmgrSignalInterface);
         } else {
@@ -705,6 +757,13 @@ void WrtInstaller::staticWrtStatusCallback(std::string tizenId,
                         tizenId.c_str(), printMsg.c_str());
                 break;
 
+            case WRT_INSTALLER_ERROR_PRIVILEGE_LEVEL_VIOLATION:
+                This->m_returnStatus = 1; //this status is specific
+                fprintf(stderr, "## wrt-installer : %s %s has failed - "
+                        "privilege level violation\n",
+                        tizenId.c_str(), printMsg.c_str());
+                break;
+
             case WRT_INSTALLER_ERROR_MENU_ICON_NOT_FOUND:
                 This->m_returnStatus = 1; //this status is specific
                 fprintf(stderr, "## wrt-installer : %s %s has failed - "
@@ -733,6 +792,13 @@ void WrtInstaller::staticWrtStatusCallback(std::string tizenId,
                         tizenId.c_str(), printMsg.c_str());
                 break;
 
+            case WRT_INSTALLER_ERROR_ARGUMENT_INVALID:
+                This->m_returnStatus = 1; //this status is specific
+                fprintf(stderr, "## wrt-installer : %s %s has failed - "
+                        "invalid argument\n",
+                        tizenId.c_str(), printMsg.c_str());
+                break;
+
             case WRT_INSTALLER_ERROR_PACKAGE_ALREADY_INSTALLED:
                 This->m_returnStatus = 1; //this status is specific
                 fprintf(stderr, "## wrt-installer : %s %s has failed - "
@@ -793,8 +859,9 @@ void WrtInstaller::staticWrtStatusCallback(std::string tizenId,
         This->m_returnStatus = 0;
         resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_SUCCESS);
 
-        if (This->m_installMode == WRT_INSTALL_MODE_INSTALL_PRELOAD &&
-                !This->m_packagePath.empty()) {
+        if (This->m_installMode.installTime == InstallMode::InstallTime::PRELOAD &&
+                !This->m_packagePath.empty())
+        {
             LogDebug("This widget is preloaded so it will be removed : "
                     << This->m_packagePath);
             if (!WrtUtilRemove(This->m_packagePath)) {
@@ -833,8 +900,9 @@ void WrtInstaller::staticWrtPluginInstallationCallback(WrtErrStatus status,
         }
 
         //remove lock file
-        if (!PluginUtils::unlockPluginInstallation(This->m_installMode ==
-                WRT_INSTALL_MODE_INSTALL_PRELOAD)) {
+        if (!PluginUtils::unlockPluginInstallation(
+            This->m_installMode.installTime == InstallMode::InstallTime::PRELOAD))
+        {
             LogInfo("Failed to remove installation lock");
         }
 
@@ -927,16 +995,17 @@ void WrtInstaller::installNewPlugins()
 {
     LogDebug("Install new plugins");
 
-    if (!PluginUtils::lockPluginInstallation(m_installMode ==
-                WRT_INSTALL_MODE_INSTALL_PRELOAD)) {
+    if (!PluginUtils::lockPluginInstallation(
+        m_installMode.installTime == InstallMode::InstallTime::PRELOAD))
+    {
         LogInfo("Lock NOT created");
         return;
     }
 
     if (!PluginUtils::checkPluginInstallationRequired()) {
         LogDebug("Plugin installation not required");
-        PluginUtils::unlockPluginInstallation(m_installMode ==
-            WRT_INSTALL_MODE_INSTALL_PRELOAD);
+        PluginUtils::unlockPluginInstallation(
+            m_installMode.installTime == InstallMode::InstallTime::PRELOAD);
         return;
     }
 
@@ -944,6 +1013,36 @@ void WrtInstaller::installNewPlugins()
     AddStep(&WrtInstaller::installPluginsStep);
 }
 
+CSCConfiguration::dataMap WrtInstaller::parseCSCConfiguration(
+    std::string str)
+{
+    // path=/opt/system/csc/Ozq2iEG15R-2.0.0-arm.wgt:op=install:removable=true
+    // parsing CSC configuration string
+    LogDebug("parseConfiguration");
+    CSCConfiguration::dataMap result;
+
+    if (str.empty()) {
+        LogDebug("Input argument is empty");
+        return result;
+    }
+
+    char* buf = strdup(str.c_str());
+    const char* ptr = strtok(buf,":");
+    while (ptr != NULL) {
+        std::string string = ptr;
+        ptr = strtok (NULL, ":");
+        size_t pos = string.find('=');
+        if (pos == std::string::npos) {
+            continue;
+        }
+        result.insert(
+            CSCConfiguration::dataPair(string.substr(0, pos),
+                                       string.substr(pos+1)));
+    }
+    free(buf);
+    return result;
+}
+
 int main(int argc, char *argv[])
 {
     UNHANDLED_EXCEPTION_HANDLER_BEGIN