2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 /* @file wrt-installer.cpp
18 * @brief Implementation file for installer
21 #include "wrt-installer.h"
22 #include "plugin_utils.h"
29 #include <sys/resource.h>
31 #include <dpl/log/log.h>
32 #include <dpl/optional.h>
33 #include <dpl/optional_typedefs.h>
34 #include <dpl/exception.h>
35 #include <dpl/wrt-dao-ro/global_config.h>
36 #include <dpl/wrt-dao-ro/config_parser_data.h>
37 #include <dpl/string.h>
38 #include <dpl/abstract_waitable_input_adapter.h>
39 #include <dpl/abstract_waitable_output_adapter.h>
40 #include <dpl/zip_input.h>
41 #include <dpl/binary_queue.h>
43 #include <dpl/errno_string.h>
44 #include <dpl/utils/wrt_global_settings.h>
45 #include <dpl/utils/wrt_utility.h>
46 #include <parser_runner.h>
47 #include <widget_parser.h>
48 #include <root_parser.h>
50 #include <Elementary.h>
52 #include <pkg-manager/pkgmgr_signal_interface.h>
53 #include <pkg-manager/pkgmgr_signal_dummy.h>
54 #include <pkg-manager/pkgmgr_signal.h>
56 using namespace WrtDB;
58 namespace { // anonymous
59 const char * const PKGMGR_INSTALL_MSG = "Install widget";
60 const char * const PKGMGR_UNINSTALL_MSG = "Uninstall widget";
62 const char * const CONFIG_XML = "config.xml";
63 const char * const HYBRID_CONFIG_XML = "res/wgt/config.xml";
65 const unsigned int NOFILE_CNT_FOR_INSTALLER = 9999;
69 void operator()(void* x)
75 struct PluginInstallerData
78 std::string pluginPath;
80 } // namespace anonymous
82 WrtInstaller::WrtInstaller(int argc, char **argv) :
83 Application(argc, argv, "backend", false),
84 DPL::TaskDecl<WrtInstaller>(this),
87 m_numPluginsToInstall(0),
90 m_installByPkgmgr(false),
91 m_startupPluginInstallation(false)
94 LogDebug("App Created");
97 WrtInstaller::~WrtInstaller()
99 LogDebug("App Finished");
102 int WrtInstaller::getReturnStatus() const
104 if (!m_returnStatus) {
111 void WrtInstaller::OnStop()
113 LogInfo("Stopping Dummy Client");
116 void WrtInstaller::OnCreate()
118 LogInfo("Creating DummyClient");
120 "===========================================================\n");
121 fprintf(stderr, "# wrt-installer #\n");
122 fprintf(stderr, "# argc [%d]\n", m_argc);
123 fprintf(stderr, "# argv[0] = [%s]\n", m_argv[0]);
124 fprintf(stderr, "# argv[1] = [%s]\n", m_argv[1]);
125 fprintf(stderr, "# argv[2] = [%s]\n", m_argv[2]);
127 "===========================================================\n");
129 AddStep(&WrtInstaller::initStep);
131 std::string arg = m_argv[0];
133 pkgmgrSignalInterface =
134 std::static_pointer_cast<PackageManager::IPkgmgrSignal>(
135 std::shared_ptr<PackageManager::PkgmgrSignalDummy>(
136 new PackageManager::PkgmgrSignalDummy()
141 return showHelpAndQuit();
146 if (arg.find("wrt-installer") != std::string::npos) {
148 return showHelpAndQuit();
152 if (arg == "-h" || arg == "--help") {
154 return showHelpAndQuit();
158 return showHelpAndQuit();
159 } else if (arg == "-p" || arg == "--install-plugins") {
161 return showHelpAndQuit();
164 if (!m_startupPluginInstallation) {
165 AddStep(&WrtInstaller::installPluginsStep);
167 LogInfo("Plugin installation alredy started");
169 } else if (arg == "-i" || arg == "--install") {
171 return showHelpAndQuit();
175 if (-1 != stat(m_argv[2], &info) && S_ISDIR(info.st_mode)) {
176 LogInfo("Installing package directly from directory");
177 m_installMode.extension = InstallMode::ExtensionType::DIR;
179 LogInfo("Installing from regular location");
180 m_installMode.extension = InstallMode::ExtensionType::WGT;
182 m_packagePath = m_argv[2];
184 AddStep(&WrtInstaller::installStep);
185 } else if (arg == "-ip" || arg == "--install-preload") {
186 LogDebug("Install preload web app");
188 return showHelpAndQuit();
190 m_packagePath = m_argv[2];
191 m_installMode.installTime = InstallMode::InstallTime::PRELOAD;
192 m_installMode.rootPath = InstallMode::RootPath::RO;
193 AddStep(&WrtInstaller::installStep);
194 } else if (arg == "-ipw" || arg == "--install-preload-writable") {
195 LogDebug("Install preload web application to writable storage");
197 return showHelpAndQuit();
199 m_packagePath = m_argv[2];
200 m_installMode.installTime = InstallMode::InstallTime::PRELOAD;
201 m_installMode.rootPath = InstallMode::RootPath::RW;
202 AddStep(&WrtInstaller::installStep);
203 } else if (arg == "-c" || arg == "--csc-update") {
204 // "path=/opt/system/csc/Ozq2iEG15R-2.0.0-arm.wgt:op=install:removable=true"
205 LogDebug("Install & uninstall by csc configuration");
207 return showHelpAndQuit();
209 std::string configuration = m_argv[2];
210 m_CSCconfigurationMap = parseCSCConfiguration(configuration);
212 CSCConfiguration::dataMap::iterator it;
213 it = m_CSCconfigurationMap.find(CSCConfiguration::KEY_OP);
214 if (it == m_CSCconfigurationMap.end()) {
215 return showHelpAndQuit();
218 if (it->second == CSCConfiguration::VALUE_INSTALL) {
219 LogDebug("operation = " << it->second);
220 m_installMode.extension = InstallMode::ExtensionType::WGT;
221 it = m_CSCconfigurationMap.find(CSCConfiguration::KEY_PATH);
222 if (it == m_CSCconfigurationMap.end()) {
223 return showHelpAndQuit();
225 m_packagePath = it->second;
226 AddStep(&WrtInstaller::installStep);
227 LogDebug("path = " << m_packagePath);
228 } else if (it->second == CSCConfiguration::VALUE_UNINSTALL) {
229 LogDebug("operation = " << it->second);
230 // uninstall command isn't confirmed yet
231 it = m_CSCconfigurationMap.find(CSCConfiguration::KEY_PATH);
232 if (it == m_CSCconfigurationMap.end()) {
233 return showHelpAndQuit();
235 m_packagePath = it->second;
236 AddStep(&WrtInstaller::unistallWgtFileStep);
237 LogDebug("operation = uninstall");
238 LogDebug("path = " << m_packagePath);
240 LogError("Unknown operation : " << it->second);
241 LogDebug("operation = " << it->second);
242 return showHelpAndQuit();
244 } else if (arg == "-un" || arg == "--uninstall-name") {
246 return showHelpAndQuit();
249 AddStep(&WrtInstaller::uninstallPkgNameStep);
250 } else if (arg == "-up" || arg == "--uninstall-packagepath") {
252 return showHelpAndQuit();
254 m_packagePath = m_argv[2];
255 AddStep(&WrtInstaller::unistallWgtFileStep);
256 } else if (arg == "-r" || arg == "--reinstall") {
258 return showHelpAndQuit();
260 LogInfo("Installing package directly from directory");
261 m_installMode.command = InstallMode::Command::REINSTALL;
262 m_installMode.extension = InstallMode::ExtensionType::DIR;
263 m_packagePath = m_argv[2];
264 AddStep(&WrtInstaller::installStep);
266 return showHelpAndQuit();
268 } else if (arg.find("backend") != std::string::npos) {
269 using namespace PackageManager;
270 m_installByPkgmgr = true;
272 auto pkgmgrSignal = std::shared_ptr<PackageManager::PkgmgrSignal>(
273 new PackageManager::PkgmgrSignal()
276 pkgmgrSignal->initialize(m_argc, m_argv);
278 int reqType = pkgmgrSignal->getRequestedType();
280 pkgmgrSignalInterface =
281 std::static_pointer_cast<PackageManager::IPkgmgrSignal>(
284 case PKGMGR_REQ_INSTALL:
285 m_packagePath = m_argv[4];
287 if (-1 != stat(m_argv[4], &info) && S_ISDIR(info.st_mode)) {
288 LogInfo("Installing package directly from directory");
289 m_installMode.extension = InstallMode::ExtensionType::DIR;
291 LogInfo("Installing from regular location");
292 m_installMode.extension = InstallMode::ExtensionType::WGT;
294 AddStep(&WrtInstaller::installStep);
296 case PKGMGR_REQ_UNINSTALL:
298 AddStep(&WrtInstaller::uninstallPkgNameStep);
300 case PKGMGR_REQ_REINSTALL:
301 m_packagePath = m_argv[4];
302 m_installMode.command = InstallMode::Command::REINSTALL;
303 m_installMode.extension = InstallMode::ExtensionType::DIR;
304 AddStep(&WrtInstaller::installStep);
307 LogDebug("Not available type");
312 AddStep(&WrtInstaller::shutdownStep);
313 DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::
315 WRTInstallerNS::NextStepEvent());
318 void WrtInstaller::OnReset(bundle* /*b*/)
323 void WrtInstaller::OnTerminate()
325 LogDebug("Wrt Shutdown now");
326 PluginUtils::unlockPluginInstallation(
327 m_installMode.installTime == InstallMode::InstallTime::PRELOAD);
329 wrt_installer_shutdown();
333 void WrtInstaller::showHelpAndQuit()
335 printf("Usage: wrt-installer [OPTION]... [WIDGET: ID/NAME/PATH]...\n"
336 "Operate with WebRuntime daemon: install, uninstall"
337 " and launch widgets.\n"
338 "Query list of installed widgets and setup up debugging support.\n"
340 "Exactly one option must be selected.\n"
341 "Mandatory arguments to long options are mandatory for short "
343 " -h, --help show this help\n"
344 " -p, --install-plugins install plugins\n"
346 "install or update widget package for given path\n"
348 "install or uninstall by CSC configuration \n"
349 " -un, --uninstall-name "
350 "uninstall widget for given package name\n"
351 " -up, --uninstall-packagepath "
352 "uninstall widget for given package file path\n"
354 "reinstall web application\n"
360 void WrtInstaller::OnEventReceived(const WRTInstallerNS::QuitEvent& /*event*/)
365 LogDebug("Wrt Shutdown now");
366 SwitchToStep(&WrtInstaller::shutdownStep);
367 DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::
369 WRTInstallerNS::NextStepEvent());
371 LogDebug("Quiting application");
376 void WrtInstaller::OnEventReceived(
377 const WRTInstallerNS::NextStepEvent& /*event*/)
379 LogDebug("Executing next step");
383 void WrtInstaller::OnEventReceived(
384 const WRTInstallerNS::InstallPluginEvent& /*event*/)
386 PluginInstallerData* privateData = new PluginInstallerData;
387 privateData->wrtInstaller = this;
389 if (!(*m_pluginsPaths).empty()) {
390 privateData->pluginPath = (*m_pluginsPaths).front();
391 (*m_pluginsPaths).pop_front();
393 wrt_install_plugin(privateData->pluginPath.c_str(),
394 static_cast<void*>(privateData),
395 &staticWrtPluginInstallationCallback,
396 &staticWrtPluginInstallProgressCb);
402 void WrtInstaller::initStep()
404 wrt_installer_init(this, staticWrtInitCallback);
407 void WrtInstaller::installStep()
409 LogDebug("Installing widget ...");
410 std::unique_ptr<char, free_deleter> packagePath(canonicalize_file_name(
411 m_packagePath.c_str()));
413 wrt_install_widget(packagePath ? packagePath.get() : m_packagePath.c_str(),
414 this, &staticWrtStatusCallback,
416 ? &staticWrtInstallProgressCallback : NULL,
418 pkgmgrSignalInterface);
421 void WrtInstaller::installPluginsStep()
423 LogDebug("Installing plugins ...");
424 fprintf(stderr, "Installing plugins ...\n");
426 if (m_startupPluginInstallation) {
427 LogInfo("Plugin installation started because new plugin package found");
428 } else if (!PluginUtils::lockPluginInstallation(
429 m_installMode.installTime == InstallMode::InstallTime::PRELOAD))
431 LogError("Failed to open plugin installation lock file"
432 " Plugins are currently installed by other process");
433 staticWrtPluginInstallationCallback(WRT_INSTALLER_ERROR_PLUGIN_INSTALLATION_FAILED,
438 std::string PLUGIN_PATH = std::string(GlobalConfig::GetDevicePluginPath());
441 dir = opendir(PLUGIN_PATH.c_str());
447 LogInfo("Plugin DIRECTORY IS" << PLUGIN_PATH);
449 std::list<std::string> pluginsPaths;
450 struct dirent libdir;
451 struct dirent *result;
454 for (return_code = readdir_r(dir, &libdir, &result);
455 result != NULL && return_code == 0;
456 return_code = readdir_r(dir, &libdir, &result))
458 if (strcmp(libdir.d_name, ".") == 0 ||
459 strcmp(libdir.d_name, "..") == 0)
464 std::string path = PLUGIN_PATH;
466 path += libdir.d_name;
470 if (stat(path.c_str(), &tmp) == -1) {
471 LogError("Failed to open file" << path);
475 if (!S_ISDIR(tmp.st_mode)) {
476 LogError("Not a directory" << path);
480 pluginsPaths.push_back(path);
483 if (return_code != 0 || errno != 0) {
484 LogError("readdir_r() failed with " << DPL::GetErrnoString());
487 //set nb of plugins to install
488 //this value indicate how many callbacks are expected
489 m_numPluginsToInstall = pluginsPaths.size();
490 LogInfo("Plugins to install: " << m_numPluginsToInstall);
491 m_pluginsPaths = pluginsPaths;
493 m_totalPlugins = m_numPluginsToInstall;
494 DPL::Event::ControllerEventHandler<WRTInstallerNS::InstallPluginEvent>
495 ::PostEvent(WRTInstallerNS::InstallPluginEvent());
497 if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
498 LogError("Failed to close dir: " << PLUGIN_PATH << " with error: "
499 << DPL::GetErrnoString());
503 void WrtInstaller::uninstallPkgNameStep()
505 LogDebug("Uninstalling widget ...");
506 LogDebug("Package name : " << m_name);
507 wrt_uninstall_widget(m_name.c_str(), this, &staticWrtStatusCallback,
509 ? &staticWrtUninstallProgressCallback : NULL,
510 pkgmgrSignalInterface);
513 void WrtInstaller::unistallWgtFileStep()
515 LogDebug("Uninstalling widget ...");
520 ConfigParserData configInfo;
523 std::unique_ptr<DPL::ZipInput> zipFile(
524 new DPL::ZipInput(m_packagePath));
525 std::unique_ptr<DPL::ZipInput::File> configFile;
528 // Open config.xml file
529 configFile.reset(zipFile->OpenFile(CONFIG_XML));
531 Catch(DPL::ZipInput::Exception::OpenFileFailed)
533 // Open config.xml file for hybrid
534 configFile.reset(zipFile->OpenFile(HYBRID_CONFIG_XML));
538 DPL::BinaryQueue buffer;
539 DPL::AbstractWaitableInputAdapter inputAdapter(configFile.get());
540 DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
541 DPL::Copy(&inputAdapter, &outputAdapter);
542 parser.Parse(&buffer,
544 new RootParser<WidgetParser>(configInfo,
545 DPL::FromUTF32String(
548 DPL::OptionalString pkgId = configInfo.tizenPkgId;
549 if (!pkgId.IsNull()) {
550 LogDebug("Pkgid from packagePath : " << pkgId);
551 wrt_uninstall_widget(
552 DPL::ToUTF8String(*pkgId).c_str(), this, &staticWrtStatusCallback,
553 !m_installByPkgmgr ? &staticWrtUninstallProgressCallback
555 pkgmgrSignalInterface);
557 LogError("Fail to uninstalling widget... ");
559 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
561 WRTInstallerNS::QuitEvent());
564 Catch(DPL::ZipInput::Exception::OpenFailed)
566 LogError("Failed to open widget package");
567 printf("failed: widget package does not exist\n");
569 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
571 WRTInstallerNS::QuitEvent());
573 Catch(DPL::ZipInput::Exception::OpenFileFailed)
575 printf("failed: widget config file does not exist\n");
576 LogError("Failed to open config.xml file");
578 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
580 WRTInstallerNS::QuitEvent());
582 Catch(ElementParser::Exception::ParseError)
584 printf("failed: can not parse config file\n");
585 LogError("Failed to parse config.xml file");
587 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
589 WRTInstallerNS::QuitEvent());
593 void WrtInstaller::shutdownStep()
595 LogDebug("Closing Wrt connection ...");
597 wrt_installer_shutdown();
598 m_initialized = false;
599 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
601 WRTInstallerNS::QuitEvent());
605 void WrtInstaller::staticWrtInitCallback(WrtErrStatus status,
608 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
611 if (status == WRT_SUCCESS) {
612 LogDebug("Init succesfull");
613 This->m_initialized = true;
614 This->m_returnStatus = 0;
616 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
617 ::PostEvent(WRTInstallerNS::NextStepEvent());
619 LogError("Init unsuccesfull");
620 This->m_returnStatus = -1;
621 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
623 WRTInstallerNS::QuitEvent());
627 void WrtInstaller::staticWrtStatusCallback(std::string tizenId,
631 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
634 Step current = This->GetCurrentStep();
635 DPL::String resultMsg;
636 std::string printMsg;
638 if (current == &WrtInstaller::installStep) {
639 resultMsg = DPL::FromUTF8String(PKGMGR_INSTALL_MSG);
640 printMsg = "installation";
641 } else if (current == &WrtInstaller::uninstallPkgNameStep ||
642 current == &WrtInstaller::unistallWgtFileStep)
644 resultMsg = DPL::FromUTF8String(PKGMGR_UNINSTALL_MSG);
645 printMsg = "uninstallation";
648 if (WRT_SUCCESS != status) {
650 LogError("Step failed");
651 This->m_returnStatus = -1;
653 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
654 ::PostEvent(WRTInstallerNS::QuitEvent());
657 case WRT_INSTALLER_ERROR_PACKAGE_NOT_FOUND:
658 This->m_returnStatus = 1; //this status is specific
659 fprintf(stderr, "## wrt-installer : %s %s has failed - widget package does not exist\n",
660 tizenId.c_str(), printMsg.c_str());
663 case WRT_INSTALLER_ERROR_PACKAGE_INVALID:
664 This->m_returnStatus = 1; //this status is specific
665 fprintf(stderr, "## wrt-installer : %s %s has failed - invalid widget package\n",
666 tizenId.c_str(), printMsg.c_str());
669 case WRT_INSTALLER_ERROR_PACKAGE_LOWER_VERSION:
670 This->m_returnStatus = 1; //this status is specific
671 fprintf(stderr, "## wrt-installer : %s %s has failed - given"
672 " version is lower than existing version\n",
673 tizenId.c_str(), printMsg.c_str());
676 case WRT_INSTALLER_ERROR_MANIFEST_NOT_FOUND:
677 This->m_returnStatus = 1; //this status is specific
678 fprintf(stderr, "## wrt-installer : %s %s has failed - manifest"
679 " file doesn't find in package.\n",
680 tizenId.c_str(), printMsg.c_str());
683 case WRT_INSTALLER_ERROR_MANIFEST_INVALID:
684 This->m_returnStatus = 1; //this status is specific
685 fprintf(stderr, "## wrt-installer : %s %s has failed - "
686 "invalid manifestx.xml\n",
687 tizenId.c_str(), printMsg.c_str());
690 case WRT_INSTALLER_CONFIG_NOT_FOUND:
691 This->m_returnStatus = 1; //this status is specific
692 fprintf(stderr, "## wrt-installer : %s %s has failed - "
693 "config.xml does not exist\n",
694 tizenId.c_str(), printMsg.c_str());
697 case WRT_INSTALLER_ERROR_CONFIG_INVALID:
698 This->m_returnStatus = 1; //this status is specific
699 fprintf(stderr, "## wrt-installer : %s %s has failed - "
700 "invalid config.xml\n",
701 tizenId.c_str(), printMsg.c_str());
704 case WRT_INSTALLER_ERROR_SIGNATURE_NOT_FOUND:
705 This->m_returnStatus = 1; //this status is specific
706 fprintf(stderr, "## wrt-installer : %s %s has failed - "
707 "signature doesn't exist in package.\n",
708 tizenId.c_str(), printMsg.c_str());
711 case WRT_INSTALLER_ERROR_SIGNATURE_INVALID:
712 This->m_returnStatus = 1; //this status is specific
713 fprintf(stderr, "## wrt-installer : %s %s has failed - "
714 "invalid signature.\n",
715 tizenId.c_str(), printMsg.c_str());
718 case WRT_INSTALLER_ERROR_SIGNATURE_VERIFICATION_FAILED:
719 This->m_returnStatus = 1; //this status is specific
720 fprintf(stderr, "## wrt-installer : %s %s has failed - "
721 "signature verification failed.\n",
722 tizenId.c_str(), printMsg.c_str());
725 case WRT_INSTALLER_ERROR_ROOT_CERTIFICATE_NOT_FOUND:
726 This->m_returnStatus = 1; //this status is specific
727 fprintf(stderr, "## wrt-installer : %s %s has failed - "
728 "root certificate could not find.\n",
729 tizenId.c_str(), printMsg.c_str());
732 case WRT_INSTALLER_ERROR_CERTIFICATION_INVAID:
733 This->m_returnStatus = 1; //this status is specific
734 fprintf(stderr, "## wrt-installer : %s %s has failed - "
735 "invalid certification.\n",
736 tizenId.c_str(), printMsg.c_str());
739 case WRT_INSTALLER_ERROR_CERTIFICATE_CHAIN_VERIFICATION_FAILED:
740 This->m_returnStatus = 1; //this status is specific
741 fprintf(stderr, "## wrt-installer : %s %s has failed - "
742 "certificate chain verification failed.\n",
743 tizenId.c_str(), printMsg.c_str());
746 case WRT_INSTALLER_ERROR_CERTIFICATE_EXPIRED:
747 This->m_returnStatus = 1; //this status is specific
748 fprintf(stderr, "## wrt-installer : %s %s has failed - "
749 "certificate expired.\n",
750 tizenId.c_str(), printMsg.c_str());
753 case WRT_INSTALLER_ERROR_INVALID_PRIVILEGE:
754 This->m_returnStatus = 1; //this status is specific
755 fprintf(stderr, "## wrt-installer : %s %s has failed - "
756 "invalid privilege\n",
757 tizenId.c_str(), printMsg.c_str());
760 case WRT_INSTALLER_ERROR_PRIVILEGE_LEVEL_VIOLATION:
761 This->m_returnStatus = 1; //this status is specific
762 fprintf(stderr, "## wrt-installer : %s %s has failed - "
763 "privilege level violation\n",
764 tizenId.c_str(), printMsg.c_str());
767 case WRT_INSTALLER_ERROR_MENU_ICON_NOT_FOUND:
768 This->m_returnStatus = 1; //this status is specific
769 fprintf(stderr, "## wrt-installer : %s %s has failed - "
770 "menu icon could not find\n",
771 tizenId.c_str(), printMsg.c_str());
774 case WRT_INSTALLER_ERROR_FATAL_ERROR:
775 This->m_returnStatus = 1; //this status is specific
776 fprintf(stderr, "## wrt-installer : %s %s has failed - "
778 tizenId.c_str(), printMsg.c_str());
781 case WRT_INSTALLER_ERROR_OUT_OF_STORAGE:
782 This->m_returnStatus = 1; //this status is specific
783 fprintf(stderr, "## wrt-installer : %s %s has failed - "
785 tizenId.c_str(), printMsg.c_str());
788 case WRT_INSTALLER_ERROR_OUT_OF_MEMORY:
789 This->m_returnStatus = 1; //this status is specific
790 fprintf(stderr, "## wrt-installer : %s %s has failed - "
792 tizenId.c_str(), printMsg.c_str());
795 case WRT_INSTALLER_ERROR_ARGUMENT_INVALID:
796 This->m_returnStatus = 1; //this status is specific
797 fprintf(stderr, "## wrt-installer : %s %s has failed - "
798 "invalid argument\n",
799 tizenId.c_str(), printMsg.c_str());
802 case WRT_INSTALLER_ERROR_PACKAGE_ALREADY_INSTALLED:
803 This->m_returnStatus = 1; //this status is specific
804 fprintf(stderr, "## wrt-installer : %s %s has failed - "
805 "package already installed\n",
806 tizenId.c_str(), printMsg.c_str());
809 case WRT_INSTALLER_ERROR_ACE_CHECK_FAILED:
810 This->m_returnStatus = 1; //this status is specific
811 fprintf(stderr, "## wrt-installer : %s %s has failed - "
812 "ace check failure\n",
813 tizenId.c_str(), printMsg.c_str());
816 case WRT_INSTALLER_ERROR_MANIFEST_CREATE_FAILED:
817 This->m_returnStatus = 1; //this status is specific
818 fprintf(stderr, "## wrt-installer : %s %s has failed - "
819 "to create manifest failed\n",
820 tizenId.c_str(), printMsg.c_str());
823 case WRT_INSTALLER_ERROR_ENCRYPTION_FAILED:
824 This->m_returnStatus = 1; //this status is specific
825 fprintf(stderr, "## wrt-installer : %s %s has failed - "
826 "encryption of resource failed\n",
827 tizenId.c_str(), printMsg.c_str());
830 case WRT_INSTALLER_ERROR_INSTALL_OSP_SERVCIE:
831 This->m_returnStatus = 1; //this status is specific
832 fprintf(stderr, "## wrt-installer : %s %s has failed - "
833 "installation of osp service failed\n",
834 tizenId.c_str(), printMsg.c_str());
837 case WRT_INSTALLER_ERROR_UNINSTALLATION_FAILED:
838 This->m_returnStatus = 1; //this status is specific
839 fprintf(stderr, "## wrt-installer : %s %s has failed - "
840 "widget uninstallation failed\n",
841 tizenId.c_str(), printMsg.c_str());
845 case WRT_INSTALLER_ERROR_UNKNOWN:
846 fprintf(stderr,"## wrt-installer : %s %s has failed - unknown error\n",
847 tizenId.c_str(), printMsg.c_str());
855 "## wrt-installer : %s %s was successful.\n",
858 LogDebug("Status succesfull");
859 This->m_returnStatus = 0;
860 resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_SUCCESS);
862 if (This->m_installMode.installTime == InstallMode::InstallTime::PRELOAD &&
863 !This->m_packagePath.empty())
865 LogDebug("This widget is preloaded so it will be removed : "
866 << This->m_packagePath);
867 if (!WrtUtilRemove(This->m_packagePath)) {
868 LogError("Failed to remove " << This->m_packagePath);
872 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
874 ::PostEvent(WRTInstallerNS::NextStepEvent());
878 void WrtInstaller::staticWrtPluginInstallationCallback(WrtErrStatus status,
883 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
885 WrtInstaller *This = static_cast<WrtInstaller*>(data->wrtInstaller);
887 std::string path = std::string(data->pluginPath);
890 This->m_numPluginsToInstall--;
891 LogDebug("Plugins to install: " << This->m_numPluginsToInstall);
893 if (This->m_numPluginsToInstall < 1) {
894 LogDebug("All plugins installation completed");
895 fprintf(stderr, "All plugins installation completed.\n");
897 //remove installation request
898 if (!PluginUtils::removeInstallationRequiredFlag()) {
899 LogInfo("Failed to remove file initializing plugin installation");
903 if (!PluginUtils::unlockPluginInstallation(
904 This->m_installMode.installTime == InstallMode::InstallTime::PRELOAD))
906 LogInfo("Failed to remove installation lock");
909 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
910 ::PostEvent(WRTInstallerNS::NextStepEvent());
912 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
913 InstallPluginEvent>::
915 WRTInstallerNS::InstallPluginEvent());
918 if (WRT_SUCCESS == status) {
919 This->m_returnStatus = 0;
921 "## wrt-installer : plugin installation successfull [%s]\n",
923 LogDebug("One plugin Installation succesfull: " << path);
928 LogWarning("One of the plugins installation failed!: " << path);
931 case WRT_INSTALLER_ERROR_PLUGIN_INSTALLATION_FAILED:
932 LogError("failed: plugin installation failed\n");
935 case WRT_INSTALLER_ERROR_UNKNOWN:
936 LogError("failed: unknown error\n");
944 void WrtInstaller::staticWrtPluginInstallProgressCb(float percent,
945 const char* description,
948 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
950 std::string path = std::string(data->pluginPath);
952 LogInfo("Plugin Installation: " << path <<
953 " progress: " << percent <<
954 "description " << description);
957 void WrtInstaller::staticWrtInstallProgressCallback(float percent,
958 const char* description,
961 //WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
962 LogInfo(" progress: " << percent <<
963 " description: " << description);
965 void WrtInstaller::staticWrtUninstallProgressCallback(float percent,
966 const char* description,
969 //WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
970 LogInfo(" progress: " << percent <<
971 " description: " << description);
974 void WrtInstaller::showResultCallback(void *data, Evas_Object* /*obj*/,
975 void* /*event_info*/)
977 WrtInstaller *This = static_cast<WrtInstaller*>(data);
980 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
981 ::PostEvent(WRTInstallerNS::NextStepEvent());
984 void WrtInstaller::failResultCallback(void *data, Evas_Object* /*obj*/,
985 void* /*event_info*/)
987 WrtInstaller *This = static_cast<WrtInstaller*>(data);
990 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
991 ::PostEvent(WRTInstallerNS::QuitEvent());
994 void WrtInstaller::installNewPlugins()
996 LogDebug("Install new plugins");
998 if (!PluginUtils::lockPluginInstallation(
999 m_installMode.installTime == InstallMode::InstallTime::PRELOAD))
1001 LogInfo("Lock NOT created");
1005 if (!PluginUtils::checkPluginInstallationRequired()) {
1006 LogDebug("Plugin installation not required");
1007 PluginUtils::unlockPluginInstallation(
1008 m_installMode.installTime == InstallMode::InstallTime::PRELOAD);
1012 m_startupPluginInstallation = true;
1013 AddStep(&WrtInstaller::installPluginsStep);
1016 CSCConfiguration::dataMap WrtInstaller::parseCSCConfiguration(
1019 // path=/opt/system/csc/Ozq2iEG15R-2.0.0-arm.wgt:op=install:removable=true
1020 // parsing CSC configuration string
1021 LogDebug("parseConfiguration");
1022 CSCConfiguration::dataMap result;
1025 LogDebug("Input argument is empty");
1029 char* buf = strdup(str.c_str());
1030 const char* ptr = strtok(buf,":");
1031 while (ptr != NULL) {
1032 std::string string = ptr;
1033 ptr = strtok (NULL, ":");
1034 size_t pos = string.find('=');
1035 if (pos == std::string::npos) {
1039 CSCConfiguration::dataPair(string.substr(0, pos),
1040 string.substr(pos+1)));
1046 int main(int argc, char *argv[])
1048 UNHANDLED_EXCEPTION_HANDLER_BEGIN
1050 // Output on stdout will be flushed after every newline character,
1051 // even if it is redirected to a pipe. This is useful for running
1052 // from a script and parsing output.
1053 // (Standard behavior of stdlib is to use full buffering when
1054 // redirected to a pipe, which means even after an end of line
1055 // the output may not be flushed).
1058 // Check and re-set the file open limitation
1060 if (getrlimit(RLIMIT_NOFILE, &rlim) != -1) {
1061 LogDebug("RLIMIT_NOFILE sft(" << rlim.rlim_cur << ")");
1062 LogDebug("RLIMIT_NOFILE hrd(" << rlim.rlim_max << ")");
1064 if (rlim.rlim_cur < NOFILE_CNT_FOR_INSTALLER) {
1065 rlim.rlim_cur = NOFILE_CNT_FOR_INSTALLER;
1066 rlim.rlim_max = NOFILE_CNT_FOR_INSTALLER;
1067 if (setrlimit(RLIMIT_NOFILE, &rlim) == -1) {
1068 LogError("setrlimit is fail!!");
1072 LogError("getrlimit is fail!!");
1075 // set evas backend type for emulator
1076 // popup isn't showed in the emulator,
1077 // if backend isn't set to SW backend
1078 if (GlobalSettings::IsEmulator()) {
1079 if (setenv("ELM_ENGINE", "x11", 1)) {
1080 LogDebug("Enable backend");
1084 WrtInstaller app(argc, argv);
1085 int ret = app.Exec();
1086 LogDebug("App returned: " << ret);
1087 ret = app.getReturnStatus();
1088 LogDebug("WrtInstaller returned: " << ret);
1091 UNHANDLED_EXCEPTION_HANDLER_END