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>
49 #include <pkgmgr-info.h>
51 #include <Elementary.h>
53 #include <pkg-manager/pkgmgr_signal_interface.h>
54 #include <pkg-manager/pkgmgr_signal_dummy.h>
55 #include <pkg-manager/pkgmgr_signal.h>
57 using namespace WrtDB;
59 namespace { // anonymous
60 const char * const PKGMGR_INSTALL_MSG = "Install widget";
61 const char * const PKGMGR_UNINSTALL_MSG = "Uninstall widget";
63 const char * const CONFIG_XML = "config.xml";
64 const char * const HYBRID_CONFIG_XML = "res/wgt/config.xml";
66 const unsigned int NOFILE_CNT_FOR_INSTALLER = 9999;
70 void operator()(void* x)
76 struct PluginInstallerData
79 std::string pluginPath;
81 } // namespace anonymous
83 WrtInstaller::WrtInstaller(int argc, char **argv) :
84 Application(argc, argv, "backend", false),
85 DPL::TaskDecl<WrtInstaller>(this),
88 m_numPluginsToInstall(0),
91 m_installByPkgmgr(false),
92 m_startupPluginInstallation(false)
95 LogDebug("App Created");
98 WrtInstaller::~WrtInstaller()
100 LogDebug("App Finished");
103 int WrtInstaller::getReturnStatus() const
105 if (!m_returnStatus) {
112 void WrtInstaller::OnStop()
114 LogDebug("Stopping Dummy Client");
117 void WrtInstaller::OnCreate()
119 LogDebug("Creating DummyClient");
122 AddStep(&WrtInstaller::initStep);
124 std::string arg = m_argv[0];
126 pkgmgrSignalInterface =
127 std::static_pointer_cast<PackageManager::IPkgmgrSignal>(
128 std::shared_ptr<PackageManager::PkgmgrSignalDummy>(
129 new PackageManager::PkgmgrSignalDummy()
134 return showHelpAndQuit();
139 if (arg.find("wrt-installer") != std::string::npos) {
141 return showHelpAndQuit();
145 if (arg == "-h" || arg == "--help") {
147 return showHelpAndQuit();
151 return showHelpAndQuit();
152 } else if (arg == "-p" || arg == "--install-plugins") {
154 return showHelpAndQuit();
157 if (!m_startupPluginInstallation) {
158 AddStep(&WrtInstaller::installPluginsStep);
160 LogDebug("Plugin installation alredy started");
162 } else if (arg == "-i" || arg == "--install") {
164 return showHelpAndQuit();
168 if (-1 != stat(m_argv[2], &info) && S_ISDIR(info.st_mode)) {
169 LogDebug("Installing package directly from directory");
170 m_installMode.extension = InstallMode::ExtensionType::DIR;
172 LogDebug("Installing from regular location");
173 m_installMode.extension = InstallMode::ExtensionType::WGT;
175 m_packagePath = m_argv[2];
177 AddStep(&WrtInstaller::installStep);
178 } else if (arg == "-ip" || arg == "--install-preload") {
179 LogDebug("Install preload web app");
181 return showHelpAndQuit();
183 m_packagePath = m_argv[2];
184 m_installMode.installTime = InstallMode::InstallTime::PRELOAD;
185 m_installMode.rootPath = InstallMode::RootPath::RO;
186 AddStep(&WrtInstaller::installStep);
187 } else if (arg == "-ipw" || arg == "--install-preload-writable") {
188 LogDebug("Install preload web application to writable storage");
190 return showHelpAndQuit();
192 m_packagePath = m_argv[2];
193 m_installMode.installTime = InstallMode::InstallTime::PRELOAD;
194 m_installMode.rootPath = InstallMode::RootPath::RW;
195 AddStep(&WrtInstaller::installStep);
196 } else if (arg == "-c" || arg == "--csc-update") {
197 // "path=/opt/system/csc/Ozq2iEG15R-2.0.0-arm.wgt:op=install:removable=true"
198 LogDebug("Install & uninstall by csc configuration");
200 return showHelpAndQuit();
202 std::string configuration = m_argv[2];
203 m_CSCconfigurationMap = parseCSCConfiguration(configuration);
205 CSCConfiguration::dataMap::iterator it;
206 it = m_CSCconfigurationMap.find(CSCConfiguration::KEY_OP);
207 if (it == m_CSCconfigurationMap.end()) {
208 return showHelpAndQuit();
211 if (it->second == CSCConfiguration::VALUE_INSTALL) {
212 LogDebug("operation = " << it->second);
213 m_installMode.extension = InstallMode::ExtensionType::WGT;
214 it = m_CSCconfigurationMap.find(CSCConfiguration::KEY_PATH);
215 if (it == m_CSCconfigurationMap.end()) {
216 return showHelpAndQuit();
218 m_packagePath = it->second;
220 it = m_CSCconfigurationMap.find(
221 CSCConfiguration::KEY_REMOVABLE);
222 if (it == m_CSCconfigurationMap.end()) {
223 return showHelpAndQuit();
226 m_installMode.removable =
227 (it->second.compare(CSCConfiguration::VALUE_FALSE) == 0)
230 AddStep(&WrtInstaller::installStep);
231 LogDebug("path = " << m_packagePath);
232 } else if (it->second == CSCConfiguration::VALUE_UNINSTALL) {
233 LogDebug("operation = " << it->second);
234 // uninstall command isn't confirmed yet
235 it = m_CSCconfigurationMap.find(CSCConfiguration::KEY_PATH);
236 if (it == m_CSCconfigurationMap.end()) {
237 return showHelpAndQuit();
239 m_packagePath = it->second;
240 AddStep(&WrtInstaller::unistallWgtFileStep);
241 LogDebug("operation = uninstall");
242 LogDebug("path = " << m_packagePath);
244 LogError("Unknown operation : " << it->second);
245 LogDebug("operation = " << it->second);
246 return showHelpAndQuit();
248 } else if (arg == "-un" || arg == "--uninstall-name") {
250 return showHelpAndQuit();
253 AddStep(&WrtInstaller::uninstallPkgNameStep);
254 } else if (arg == "-up" || arg == "--uninstall-packagepath") {
256 return showHelpAndQuit();
258 m_packagePath = m_argv[2];
259 AddStep(&WrtInstaller::unistallWgtFileStep);
260 } else if (arg == "-r" || arg == "--reinstall") {
262 return showHelpAndQuit();
264 LogDebug("Installing package directly from directory");
265 m_installMode.command = InstallMode::Command::REINSTALL;
266 m_installMode.extension = InstallMode::ExtensionType::DIR;
267 m_packagePath = m_argv[2];
268 AddStep(&WrtInstaller::installStep);
270 return showHelpAndQuit();
272 } else if (arg.find("backend") != std::string::npos) {
273 using namespace PackageManager;
274 m_installByPkgmgr = true;
276 auto pkgmgrSignal = std::shared_ptr<PackageManager::PkgmgrSignal>(
277 new PackageManager::PkgmgrSignal()
280 pkgmgrSignal->initialize(m_argc, m_argv);
282 int reqType = pkgmgrSignal->getRequestedType();
284 pkgmgrSignalInterface =
285 std::static_pointer_cast<PackageManager::IPkgmgrSignal>(
288 case PKGMGR_REQ_INSTALL:
289 m_packagePath = m_argv[4];
291 if (-1 != stat(m_argv[4], &info) && S_ISDIR(info.st_mode)) {
292 LogDebug("Installing package directly from directory");
293 m_installMode.extension = InstallMode::ExtensionType::DIR;
295 LogDebug("Installing from regular location");
296 m_installMode.extension = InstallMode::ExtensionType::WGT;
298 AddStep(&WrtInstaller::installStep);
300 case PKGMGR_REQ_UNINSTALL:
303 pkgmgrinfo_pkginfo_h handle = NULL;
304 bool system_app = false; // system app is preloaded and unremovable.
307 if (0 == pkgmgrinfo_pkginfo_get_pkginfo(m_name.c_str(), &handle)) {
308 if (0 > pkgmgrinfo_pkginfo_is_system(handle, &system_app)) {
309 LogError("Can't get package information : " << m_name);
311 if (0 > pkgmgrinfo_pkginfo_is_update(handle, &update)) {
312 LogError("Can't get package information about update : "
317 LogDebug("system app : " << system_app);
318 LogDebug("update : " << update);
320 if (system_app && update) {
321 AddStep(&WrtInstaller::removeUpdateStep);
323 AddStep(&WrtInstaller::uninstallPkgNameStep);
327 case PKGMGR_REQ_REINSTALL:
328 m_packagePath = m_argv[4];
329 m_installMode.command = InstallMode::Command::REINSTALL;
330 m_installMode.extension = InstallMode::ExtensionType::DIR;
331 AddStep(&WrtInstaller::installStep);
334 LogDebug("Not available type");
339 AddStep(&WrtInstaller::shutdownStep);
340 DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::
342 WRTInstallerNS::NextStepEvent());
345 void WrtInstaller::OnReset(bundle* /*b*/)
350 void WrtInstaller::OnTerminate()
352 LogDebug("Wrt Shutdown now");
353 PluginUtils::unlockPluginInstallation(
354 m_installMode.installTime == InstallMode::InstallTime::PRELOAD);
356 wrt_installer_shutdown();
360 void WrtInstaller::showHelpAndQuit()
362 printf("Usage: wrt-installer [OPTION]... [WIDGET: ID/NAME/PATH]...\n"
363 "Operate with WebRuntime daemon: install, uninstall"
364 " and launch widgets.\n"
365 "Query list of installed widgets and setup up debugging support.\n"
367 "Exactly one option must be selected.\n"
368 "Mandatory arguments to long options are mandatory for short "
370 " -h, --help show this help\n"
371 " -p, --install-plugins install plugins\n"
373 "install or update widget package for given path\n"
375 "install or uninstall by CSC configuration \n"
376 " -un, --uninstall-name "
377 "uninstall widget for given package name\n"
378 " -up, --uninstall-packagepath "
379 "uninstall widget for given package file path\n"
381 "reinstall web application\n"
387 void WrtInstaller::showArguments()
390 "===========================================================\n");
391 fprintf(stderr, "# wrt-installer #\n");
392 fprintf(stderr, "# argc [%d]\n", m_argc);
393 for (int i = 0; i < m_argc; i++) {
394 fprintf(stderr, "# argv[%d] = [%s]\n", i, m_argv[i]);
397 "===========================================================\n");
399 LogDebug("===========================================================");
400 LogDebug("# wrt-installer #");
401 LogDebug("# argc " << m_argc);
402 for (int i = 0; i < m_argc; i++) {
403 LogDebug("# argv[" << i << "] = " << m_argv[i]);
405 LogDebug("===========================================================");
409 void WrtInstaller::OnEventReceived(const WRTInstallerNS::QuitEvent& /*event*/)
414 LogDebug("Wrt Shutdown now");
415 SwitchToStep(&WrtInstaller::shutdownStep);
416 DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::
418 WRTInstallerNS::NextStepEvent());
420 LogDebug("Quiting application");
425 void WrtInstaller::OnEventReceived(
426 const WRTInstallerNS::NextStepEvent& /*event*/)
428 LogDebug("Executing next step");
432 void WrtInstaller::OnEventReceived(
433 const WRTInstallerNS::InstallPluginEvent& /*event*/)
435 PluginInstallerData* privateData = new PluginInstallerData;
436 privateData->wrtInstaller = this;
438 if (!(*m_pluginsPaths).empty()) {
439 privateData->pluginPath = (*m_pluginsPaths).front();
440 (*m_pluginsPaths).pop_front();
442 wrt_install_plugin(privateData->pluginPath.c_str(),
443 static_cast<void*>(privateData),
444 &staticWrtPluginInstallationCallback,
445 &staticWrtPluginInstallProgressCb);
451 void WrtInstaller::initStep()
453 wrt_installer_init(this, staticWrtInitCallback);
456 void WrtInstaller::installStep()
458 LogDebug("Installing widget ...");
459 std::unique_ptr<char, free_deleter> packagePath(canonicalize_file_name(
460 m_packagePath.c_str()));
462 wrt_install_widget(packagePath ? packagePath.get() : m_packagePath.c_str(),
463 this, &staticWrtStatusCallback,
465 ? &staticWrtInstallProgressCallback : NULL,
467 pkgmgrSignalInterface);
470 void WrtInstaller::installPluginsStep()
472 LogDebug("Installing plugins ...");
473 fprintf(stderr, "Installing plugins ...\n");
475 if (m_startupPluginInstallation) {
476 LogDebug("Plugin installation started because new plugin package found");
477 } else if (!PluginUtils::lockPluginInstallation(
478 m_installMode.installTime == InstallMode::InstallTime::PRELOAD))
480 LogError("Failed to open plugin installation lock file"
481 " Plugins are currently installed by other process");
482 staticWrtPluginInstallationCallback(WRT_INSTALLER_ERROR_PLUGIN_INSTALLATION_FAILED,
487 std::string PLUGIN_PATH = std::string(GlobalConfig::GetDevicePluginPath());
490 dir = opendir(PLUGIN_PATH.c_str());
496 LogDebug("Plugin DIRECTORY IS" << PLUGIN_PATH);
498 std::list<std::string> pluginsPaths;
499 struct dirent libdir;
500 struct dirent *result;
503 for (return_code = readdir_r(dir, &libdir, &result);
504 result != NULL && return_code == 0;
505 return_code = readdir_r(dir, &libdir, &result))
507 if (strcmp(libdir.d_name, ".") == 0 ||
508 strcmp(libdir.d_name, "..") == 0)
513 std::string path = PLUGIN_PATH;
515 path += libdir.d_name;
519 if (stat(path.c_str(), &tmp) == -1) {
520 LogError("Failed to open file" << path);
524 if (!S_ISDIR(tmp.st_mode)) {
525 LogError("Not a directory" << path);
529 pluginsPaths.push_back(path);
532 if (return_code != 0 || errno != 0) {
533 LogError("readdir_r() failed with " << DPL::GetErrnoString());
536 //set nb of plugins to install
537 //this value indicate how many callbacks are expected
538 m_numPluginsToInstall = pluginsPaths.size();
539 LogDebug("Plugins to install: " << m_numPluginsToInstall);
540 m_pluginsPaths = pluginsPaths;
542 m_totalPlugins = m_numPluginsToInstall;
543 DPL::Event::ControllerEventHandler<WRTInstallerNS::InstallPluginEvent>
544 ::PostEvent(WRTInstallerNS::InstallPluginEvent());
546 if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
547 LogError("Failed to close dir: " << PLUGIN_PATH << " with error: "
548 << DPL::GetErrnoString());
552 void WrtInstaller::uninstallPkgNameStep()
554 LogDebug("Uninstalling widget ...");
555 LogDebug("Package name : " << m_name);
557 wrt_uninstall_widget(m_name.c_str(), this,
558 &staticWrtStatusCallback,
560 ? &staticWrtUninstallProgressCallback : NULL,
561 pkgmgrSignalInterface);
564 void WrtInstaller::removeUpdateStep()
566 LogDebug("This web app need to initialize preload app");
567 LogDebug("Package name : " << m_name);
569 wrt_uninstall_widget(m_name.c_str(), this,
570 &staticWrtInitializeToPreloadCallback,
572 ? &staticWrtUninstallProgressCallback : NULL,
573 pkgmgrSignalInterface);
577 void WrtInstaller::unistallWgtFileStep()
579 LogDebug("Uninstalling widget ...");
584 ConfigParserData configInfo;
587 std::unique_ptr<DPL::ZipInput> zipFile(
588 new DPL::ZipInput(m_packagePath));
589 std::unique_ptr<DPL::ZipInput::File> configFile;
592 // Open config.xml file
593 configFile.reset(zipFile->OpenFile(CONFIG_XML));
595 Catch(DPL::ZipInput::Exception::OpenFileFailed)
597 // Open config.xml file for hybrid
598 configFile.reset(zipFile->OpenFile(HYBRID_CONFIG_XML));
602 DPL::BinaryQueue buffer;
603 DPL::AbstractWaitableInputAdapter inputAdapter(configFile.get());
604 DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
605 DPL::Copy(&inputAdapter, &outputAdapter);
606 parser.Parse(&buffer,
608 new RootParser<WidgetParser>(configInfo,
609 DPL::FromUTF32String(
612 DPL::OptionalString pkgId = configInfo.tizenPkgId;
613 if (!pkgId.IsNull()) {
614 LogDebug("Pkgid from packagePath : " << pkgId);
615 wrt_uninstall_widget(
616 DPL::ToUTF8String(*pkgId).c_str(), this, &staticWrtStatusCallback,
617 !m_installByPkgmgr ? &staticWrtUninstallProgressCallback
619 pkgmgrSignalInterface);
621 LogError("Fail to uninstalling widget... ");
623 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
625 WRTInstallerNS::QuitEvent());
628 Catch(DPL::ZipInput::Exception::OpenFailed)
630 LogError("Failed to open widget package");
631 printf("failed: widget package does not exist\n");
633 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
635 WRTInstallerNS::QuitEvent());
637 Catch(DPL::ZipInput::Exception::OpenFileFailed)
639 printf("failed: widget config file does not exist\n");
640 LogError("Failed to open config.xml file");
642 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
644 WRTInstallerNS::QuitEvent());
646 Catch(ElementParser::Exception::ParseError)
648 printf("failed: can not parse config file\n");
649 LogError("Failed to parse config.xml file");
651 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
653 WRTInstallerNS::QuitEvent());
657 void WrtInstaller::shutdownStep()
659 LogDebug("Closing Wrt connection ...");
661 wrt_installer_shutdown();
662 m_initialized = false;
663 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
665 WRTInstallerNS::QuitEvent());
669 void WrtInstaller::staticWrtInitCallback(WrtErrStatus status,
672 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
675 if (status == WRT_SUCCESS) {
676 LogDebug("Init succesfull");
677 This->m_initialized = true;
678 This->m_returnStatus = 0;
680 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
681 ::PostEvent(WRTInstallerNS::NextStepEvent());
683 LogError("Init unsuccesfull");
684 This->m_returnStatus = -1;
685 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
687 WRTInstallerNS::QuitEvent());
691 void WrtInstaller::staticWrtInitializeToPreloadCallback(std::string tizenId, WrtErrStatus
692 status, void* userdata)
694 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
697 std::string printMsg = "uninstallation";
699 if (WRT_SUCCESS != status) {
701 LogError("Step failed");
702 This->m_returnStatus = 1;
704 This->showErrorMsg(status, tizenId, printMsg);
706 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
707 ::PostEvent(WRTInstallerNS::QuitEvent());
710 mode.extension = InstallMode::ExtensionType::DIR;
711 mode.installTime = InstallMode::InstallTime::PRELOAD;
712 mode.rootPath = InstallMode::RootPath::RO;
713 std::string packagePath =
714 std::string(WrtDB::GlobalConfig::GetUserPreloadedWidgetPath()) + "/" +
717 wrt_install_widget(packagePath.c_str(),
718 This, &staticWrtInitPreloadStatusCallback,
721 This->pkgmgrSignalInterface);
725 void WrtInstaller::staticWrtInitPreloadStatusCallback(std::string tizenId,
729 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
732 DPL::String resultMsg;
733 std::string printMsg = "initialization";
735 if (WRT_SUCCESS != status) {
737 LogError("Step failed");
738 This->m_returnStatus = 1;
740 This->showErrorMsg(status, tizenId, printMsg);
742 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
743 ::PostEvent(WRTInstallerNS::QuitEvent());
746 "## wrt-installer : %s %s was successful.\n",
749 LogDebug("Status succesfull");
750 This->m_returnStatus = 0;
751 resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_SUCCESS);
753 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
755 ::PostEvent(WRTInstallerNS::NextStepEvent());
759 void WrtInstaller::staticWrtStatusCallback(std::string tizenId,
763 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
766 Step current = This->GetCurrentStep();
767 DPL::String resultMsg;
768 std::string printMsg;
770 if (current == &WrtInstaller::installStep) {
771 resultMsg = DPL::FromUTF8String(PKGMGR_INSTALL_MSG);
772 printMsg = "installation";
773 } else if (current == &WrtInstaller::uninstallPkgNameStep ||
774 current == &WrtInstaller::unistallWgtFileStep)
776 resultMsg = DPL::FromUTF8String(PKGMGR_UNINSTALL_MSG);
777 printMsg = "uninstallation";
780 if (WRT_SUCCESS != status) {
782 LogError("Step failed");
783 This->m_returnStatus = -1;
785 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
786 ::PostEvent(WRTInstallerNS::QuitEvent());
788 This->showErrorMsg(status, tizenId, printMsg);
791 "## wrt-installer : %s %s was successful.\n",
794 LogDebug("Status succesfull");
795 This->m_returnStatus = 0;
796 resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_SUCCESS);
798 if (This->m_installMode.installTime == InstallMode::InstallTime::PRELOAD &&
799 !This->m_packagePath.empty())
801 LogDebug("This widget is preloaded so it will be removed : "
802 << This->m_packagePath);
803 if (!WrtUtilRemove(This->m_packagePath)) {
804 LogError("Failed to remove " << This->m_packagePath);
808 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
810 ::PostEvent(WRTInstallerNS::NextStepEvent());
814 void WrtInstaller::showErrorMsg(WrtErrStatus status, std::string tizenId,
815 std::string printMsg)
818 case WRT_INSTALLER_ERROR_PACKAGE_NOT_FOUND:
819 fprintf(stderr, "## wrt-installer : %s %s has failed - widget package does not exist\n",
820 tizenId.c_str(), printMsg.c_str());
823 case WRT_INSTALLER_ERROR_PACKAGE_INVALID:
824 fprintf(stderr, "## wrt-installer : %s %s has failed - invalid widget package\n",
825 tizenId.c_str(), printMsg.c_str());
828 case WRT_INSTALLER_ERROR_PACKAGE_LOWER_VERSION:
829 fprintf(stderr, "## wrt-installer : %s %s has failed - given"
830 " version is lower than existing version\n",
831 tizenId.c_str(), printMsg.c_str());
834 case WRT_INSTALLER_ERROR_MANIFEST_NOT_FOUND:
835 fprintf(stderr, "## wrt-installer : %s %s has failed - manifest"
836 " file doesn't find in package.\n",
837 tizenId.c_str(), printMsg.c_str());
840 case WRT_INSTALLER_ERROR_MANIFEST_INVALID:
841 fprintf(stderr, "## wrt-installer : %s %s has failed - "
842 "invalid manifestx.xml\n",
843 tizenId.c_str(), printMsg.c_str());
846 case WRT_INSTALLER_CONFIG_NOT_FOUND:
847 fprintf(stderr, "## wrt-installer : %s %s has failed - "
848 "config.xml does not exist\n",
849 tizenId.c_str(), printMsg.c_str());
852 case WRT_INSTALLER_ERROR_CONFIG_INVALID:
853 fprintf(stderr, "## wrt-installer : %s %s has failed - "
854 "invalid config.xml\n",
855 tizenId.c_str(), printMsg.c_str());
858 case WRT_INSTALLER_ERROR_SIGNATURE_NOT_FOUND:
859 fprintf(stderr, "## wrt-installer : %s %s has failed - "
860 "signature doesn't exist in package.\n",
861 tizenId.c_str(), printMsg.c_str());
864 case WRT_INSTALLER_ERROR_SIGNATURE_INVALID:
865 fprintf(stderr, "## wrt-installer : %s %s has failed - "
866 "invalid signature.\n",
867 tizenId.c_str(), printMsg.c_str());
870 case WRT_INSTALLER_ERROR_SIGNATURE_VERIFICATION_FAILED:
871 fprintf(stderr, "## wrt-installer : %s %s has failed - "
872 "signature verification failed.\n",
873 tizenId.c_str(), printMsg.c_str());
876 case WRT_INSTALLER_ERROR_ROOT_CERTIFICATE_NOT_FOUND:
877 fprintf(stderr, "## wrt-installer : %s %s has failed - "
878 "root certificate could not find.\n",
879 tizenId.c_str(), printMsg.c_str());
882 case WRT_INSTALLER_ERROR_CERTIFICATION_INVAID:
883 fprintf(stderr, "## wrt-installer : %s %s has failed - "
884 "invalid certification.\n",
885 tizenId.c_str(), printMsg.c_str());
888 case WRT_INSTALLER_ERROR_CERTIFICATE_CHAIN_VERIFICATION_FAILED:
889 fprintf(stderr, "## wrt-installer : %s %s has failed - "
890 "certificate chain verification failed.\n",
891 tizenId.c_str(), printMsg.c_str());
894 case WRT_INSTALLER_ERROR_CERTIFICATE_EXPIRED:
895 fprintf(stderr, "## wrt-installer : %s %s has failed - "
896 "certificate expired.\n",
897 tizenId.c_str(), printMsg.c_str());
900 case WRT_INSTALLER_ERROR_INVALID_PRIVILEGE:
901 fprintf(stderr, "## wrt-installer : %s %s has failed - "
902 "invalid privilege\n",
903 tizenId.c_str(), printMsg.c_str());
906 case WRT_INSTALLER_ERROR_PRIVILEGE_LEVEL_VIOLATION:
907 fprintf(stderr, "## wrt-installer : %s %s has failed - "
908 "privilege level violation\n",
909 tizenId.c_str(), printMsg.c_str());
912 case WRT_INSTALLER_ERROR_MENU_ICON_NOT_FOUND:
913 fprintf(stderr, "## wrt-installer : %s %s has failed - "
914 "menu icon could not find\n",
915 tizenId.c_str(), printMsg.c_str());
918 case WRT_INSTALLER_ERROR_FATAL_ERROR:
919 fprintf(stderr, "## wrt-installer : %s %s has failed - "
921 tizenId.c_str(), printMsg.c_str());
924 case WRT_INSTALLER_ERROR_OUT_OF_STORAGE:
925 fprintf(stderr, "## wrt-installer : %s %s has failed - "
927 tizenId.c_str(), printMsg.c_str());
930 case WRT_INSTALLER_ERROR_OUT_OF_MEMORY:
931 fprintf(stderr, "## wrt-installer : %s %s has failed - "
933 tizenId.c_str(), printMsg.c_str());
936 case WRT_INSTALLER_ERROR_ARGUMENT_INVALID:
937 fprintf(stderr, "## wrt-installer : %s %s has failed - "
938 "invalid argument\n",
939 tizenId.c_str(), printMsg.c_str());
942 case WRT_INSTALLER_ERROR_PACKAGE_ALREADY_INSTALLED:
943 fprintf(stderr, "## wrt-installer : %s %s has failed - "
944 "package already installed\n",
945 tizenId.c_str(), printMsg.c_str());
948 case WRT_INSTALLER_ERROR_ACE_CHECK_FAILED:
949 fprintf(stderr, "## wrt-installer : %s %s has failed - "
950 "ace check failure\n",
951 tizenId.c_str(), printMsg.c_str());
954 case WRT_INSTALLER_ERROR_MANIFEST_CREATE_FAILED:
955 fprintf(stderr, "## wrt-installer : %s %s has failed - "
956 "to create manifest failed\n",
957 tizenId.c_str(), printMsg.c_str());
960 case WRT_INSTALLER_ERROR_ENCRYPTION_FAILED:
961 fprintf(stderr, "## wrt-installer : %s %s has failed - "
962 "encryption of resource failed\n",
963 tizenId.c_str(), printMsg.c_str());
966 case WRT_INSTALLER_ERROR_INSTALL_OSP_SERVCIE:
967 fprintf(stderr, "## wrt-installer : %s %s has failed - "
968 "installation of osp service failed\n",
969 tizenId.c_str(), printMsg.c_str());
972 case WRT_INSTALLER_ERROR_UNINSTALLATION_FAILED:
973 fprintf(stderr, "## wrt-installer : %s %s has failed - "
974 "widget uninstallation failed\n",
975 tizenId.c_str(), printMsg.c_str());
979 case WRT_INSTALLER_ERROR_UNKNOWN:
980 fprintf(stderr,"## wrt-installer : %s %s has failed - unknown error\n",
981 tizenId.c_str(), printMsg.c_str());
990 void WrtInstaller::staticWrtPluginInstallationCallback(WrtErrStatus status,
995 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
997 WrtInstaller *This = static_cast<WrtInstaller*>(data->wrtInstaller);
999 std::string path = std::string(data->pluginPath);
1002 This->m_numPluginsToInstall--;
1003 LogDebug("Plugins to install: " << This->m_numPluginsToInstall);
1005 if (This->m_numPluginsToInstall < 1) {
1006 LogDebug("All plugins installation completed");
1007 fprintf(stderr, "All plugins installation completed.\n");
1009 //remove installation request
1010 if (!PluginUtils::removeInstallationRequiredFlag()) {
1011 LogDebug("Failed to remove file initializing plugin installation");
1015 if (!PluginUtils::unlockPluginInstallation(
1016 This->m_installMode.installTime == InstallMode::InstallTime::PRELOAD))
1018 LogDebug("Failed to remove installation lock");
1021 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
1022 ::PostEvent(WRTInstallerNS::NextStepEvent());
1024 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
1025 InstallPluginEvent>::
1027 WRTInstallerNS::InstallPluginEvent());
1030 if (WRT_SUCCESS == status) {
1031 This->m_returnStatus = 0;
1033 "## wrt-installer : plugin installation successfull [%s]\n",
1035 LogDebug("One plugin Installation succesfull: " << path);
1040 LogWarning("One of the plugins installation failed!: " << path);
1043 case WRT_INSTALLER_ERROR_PLUGIN_INSTALLATION_FAILED:
1044 LogError("failed: plugin installation failed\n");
1047 case WRT_INSTALLER_ERROR_UNKNOWN:
1048 LogError("failed: unknown error\n");
1056 void WrtInstaller::staticWrtPluginInstallProgressCb(float percent,
1057 const char* description,
1060 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
1062 std::string path = std::string(data->pluginPath);
1064 LogDebug("Plugin Installation: " << path <<
1065 " progress: " << percent <<
1066 "description " << description);
1069 void WrtInstaller::staticWrtInstallProgressCallback(float percent,
1070 const char* description,
1073 //WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
1074 LogDebug(" progress: " << percent <<
1075 " description: " << description);
1077 void WrtInstaller::staticWrtUninstallProgressCallback(float percent,
1078 const char* description,
1081 //WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
1082 LogDebug(" progress: " << percent <<
1083 " description: " << description);
1086 void WrtInstaller::showResultCallback(void *data, Evas_Object* /*obj*/,
1087 void* /*event_info*/)
1089 WrtInstaller *This = static_cast<WrtInstaller*>(data);
1092 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
1093 ::PostEvent(WRTInstallerNS::NextStepEvent());
1096 void WrtInstaller::failResultCallback(void *data, Evas_Object* /*obj*/,
1097 void* /*event_info*/)
1099 WrtInstaller *This = static_cast<WrtInstaller*>(data);
1102 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
1103 ::PostEvent(WRTInstallerNS::QuitEvent());
1106 void WrtInstaller::installNewPlugins()
1108 LogDebug("Install new plugins");
1110 if (!PluginUtils::lockPluginInstallation(
1111 m_installMode.installTime == InstallMode::InstallTime::PRELOAD))
1113 LogDebug("Lock NOT created");
1117 if (!PluginUtils::checkPluginInstallationRequired()) {
1118 LogDebug("Plugin installation not required");
1119 PluginUtils::unlockPluginInstallation(
1120 m_installMode.installTime == InstallMode::InstallTime::PRELOAD);
1124 m_startupPluginInstallation = true;
1125 AddStep(&WrtInstaller::installPluginsStep);
1128 CSCConfiguration::dataMap WrtInstaller::parseCSCConfiguration(
1131 // path=/opt/system/csc/Ozq2iEG15R-2.0.0-arm.wgt:op=install:removable=true
1132 // parsing CSC configuration string
1133 LogDebug("parseConfiguration");
1134 CSCConfiguration::dataMap result;
1137 LogDebug("Input argument is empty");
1141 char* buf = strdup(str.c_str());
1142 const char* ptr = strtok(buf,":");
1143 while (ptr != NULL) {
1144 std::string string = ptr;
1145 ptr = strtok (NULL, ":");
1146 size_t pos = string.find('=');
1147 if (pos == std::string::npos) {
1151 CSCConfiguration::dataPair(string.substr(0, pos),
1152 string.substr(pos+1)));
1158 int main(int argc, char *argv[])
1160 UNHANDLED_EXCEPTION_HANDLER_BEGIN
1162 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT_INSTALLER");
1164 // Output on stdout will be flushed after every newline character,
1165 // even if it is redirected to a pipe. This is useful for running
1166 // from a script and parsing output.
1167 // (Standard behavior of stdlib is to use full buffering when
1168 // redirected to a pipe, which means even after an end of line
1169 // the output may not be flushed).
1172 // Check and re-set the file open limitation
1174 if (getrlimit(RLIMIT_NOFILE, &rlim) != -1) {
1175 LogDebug("RLIMIT_NOFILE sft(" << rlim.rlim_cur << ")");
1176 LogDebug("RLIMIT_NOFILE hrd(" << rlim.rlim_max << ")");
1178 if (rlim.rlim_cur < NOFILE_CNT_FOR_INSTALLER) {
1179 rlim.rlim_cur = NOFILE_CNT_FOR_INSTALLER;
1180 rlim.rlim_max = NOFILE_CNT_FOR_INSTALLER;
1181 if (setrlimit(RLIMIT_NOFILE, &rlim) == -1) {
1182 LogError("setrlimit is fail!!");
1186 LogError("getrlimit is fail!!");
1189 WrtInstaller app(argc, argv);
1190 int ret = app.Exec();
1191 LogDebug("App returned: " << ret);
1192 ret = app.getReturnStatus();
1193 LogDebug("WrtInstaller returned: " << ret);
1196 UNHANDLED_EXCEPTION_HANDLER_END