You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

407 lines
14 KiB

  1. diff --git a/hardware/EvohomeScript.cpp b/hardware/EvohomeScript.cpp
  2. index 5258fc55..0a44e97c 100644
  3. --- a/hardware/EvohomeScript.cpp
  4. +++ b/hardware/EvohomeScript.cpp
  5. @@ -30,7 +30,7 @@
  6. #include <string>
  7. -extern std::string szUserDataFolder;
  8. +extern std::string szScriptsFolder;
  9. CEvohomeScript::CEvohomeScript(const int ID)
  10. @@ -143,7 +143,7 @@ void CEvohomeScript::RunScript(const char *pdata, const unsigned char length)
  11. std::string scriptname = OnAction.substr(9);
  12. #if !defined WIN32
  13. if (scriptname.find("/") != 0)
  14. - scriptname = szUserDataFolder + "scripts/" + scriptname;
  15. + scriptname = szScriptsFolder + "scripts/" + scriptname;
  16. #endif
  17. std::string scriptparams="";
  18. //Add parameters
  19. diff --git a/hardware/OpenZWave.cpp b/hardware/OpenZWave.cpp
  20. index 1f5c341c..24db61c9 100644
  21. --- a/hardware/OpenZWave.cpp
  22. +++ b/hardware/OpenZWave.cpp
  23. @@ -948,7 +948,7 @@ bool COpenZWave::OpenSerialConnector()
  24. m_nodes.clear();
  25. m_bNeedSave = false;
  26. - std::string ConfigPath = szStartupFolder + "Config/";
  27. + std::string ConfigPath = "/usr/share/domoticz/openzwave/";
  28. std::string UserPath = ConfigPath;
  29. if (szStartupFolder != szUserDataFolder)
  30. {
  31. diff --git a/main/EventSystem.cpp b/main/EventSystem.cpp
  32. index 4eff02fd..f2b17b97 100644
  33. --- a/main/EventSystem.cpp
  34. +++ b/main/EventSystem.cpp
  35. @@ -33,9 +33,11 @@ extern "C" {
  36. #endif
  37. }
  38. +extern std::string szScriptsFolder;
  39. extern std::string szUserDataFolder;
  40. extern http::server::CWebServerHelper m_webservers;
  41. +static std::string dzv_Dir;
  42. static std::string m_printprefix;
  43. #ifdef ENABLE_PYTHON
  44. @@ -115,7 +117,6 @@ static const _tJsonMap JsonMap[] =
  45. { NULL, NULL, tString }
  46. };
  47. -
  48. CEventSystem::CEventSystem(void)
  49. {
  50. m_stoprequested = false;
  51. @@ -149,7 +150,7 @@ void CEventSystem::StartEventSystem()
  52. GetCurrentScenesGroups();
  53. GetCurrentUserVariables();
  54. #ifdef ENABLE_PYTHON
  55. - Plugins::PythonEventsInitialize(szUserDataFolder);
  56. + Plugins::PythonEventsInitialize(szScriptsFolder);
  57. #endif
  58. m_thread = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&CEventSystem::Do_Work, this)));
  59. @@ -179,11 +180,11 @@ void CEventSystem::SetEnabled(const bool bEnabled)
  60. void CEventSystem::LoadEvents()
  61. {
  62. - std::string dzv_Dir,s;
  63. + std::string s;
  64. #ifdef WIN32
  65. - dzv_Dir = szUserDataFolder + "scripts\\dzVents\\generated_scripts\\";
  66. + dzv_Dir = szUserDataFolder + "generated_scripts\\";
  67. #else
  68. - dzv_Dir = szUserDataFolder + "scripts/dzVents/generated_scripts/";
  69. + dzv_Dir = szUserDataFolder + "generated_scripts/";
  70. #endif
  71. boost::unique_lock<boost::shared_mutex> eventsMutexLock(m_eventsMutex);
  72. _log.Log(LOG_STATUS, "EventSystem: reset all events...");
  73. @@ -274,18 +275,18 @@ void CEventSystem::LoadEvents()
  74. void CEventSystem::Do_Work()
  75. {
  76. #ifdef WIN32
  77. - m_lua_Dir = szUserDataFolder + "scripts\\lua\\";
  78. - m_dzv_Dir = szUserDataFolder + "scripts\\dzVents\\runtime\\";
  79. + m_lua_Dir = szScriptsFolder + "lua\\";
  80. + m_dzv_Dir = szScriptsFolder + "dzVents\\runtime\\";
  81. #else
  82. - m_lua_Dir = szUserDataFolder + "scripts/lua/";
  83. - m_dzv_Dir = szUserDataFolder + "scripts/dzVents/runtime/";
  84. + m_lua_Dir = szScriptsFolder + "lua/";
  85. + m_dzv_Dir = szScriptsFolder + "dzVents/runtime/";
  86. #endif
  87. #ifdef ENABLE_PYTHON
  88. #ifdef WIN32
  89. - m_python_Dir = szUserDataFolder + "scripts\\python\\";
  90. + m_python_Dir = szScriptsFolder + "python\\";
  91. #else
  92. - m_python_Dir = szUserDataFolder + "scripts/python/";
  93. + m_python_Dir = szScriptsFolder + "python/";
  94. #endif
  95. #endif
  96. m_stoprequested = false;
  97. @@ -1426,9 +1427,9 @@ void CEventSystem::EvaluateEvent(const std::string &reason, const uint64_t Devic
  98. {
  99. std::string dzv_scripts;
  100. #ifdef WIN32
  101. - dzv_scripts = szUserDataFolder + "scripts\\dzVents\\scripts\\";
  102. + dzv_scripts = szScriptsFolder + "dzVents\\scripts\\";
  103. #else
  104. - dzv_scripts = szUserDataFolder + "scripts/dzVents/scripts/";
  105. + dzv_scripts = szScriptsFolder + "dzVents/scripts/";
  106. #endif
  107. DirectoryListing(FileEntries, dzv_scripts, false, true);
  108. for (itt = FileEntries.begin(); itt != FileEntries.end(); ++itt)
  109. @@ -2404,7 +2405,7 @@ bool CEventSystem::parseBlocklyActions(const std::string &Actions, const std::st
  110. }
  111. #if !defined WIN32
  112. if (sPath.find("/") != 0)
  113. - sPath = szUserDataFolder + "scripts/" + sPath;
  114. + sPath = szScriptsFolder + sPath;
  115. #endif
  116. m_sql.AddTaskItem(_tTaskItem::ExecuteScript(0.2f, sPath, sParam));
  117. @@ -3508,13 +3509,16 @@ void CEventSystem::EvaluateLua(const std::string &reason, const std::string &fil
  118. {
  119. std::stringstream lua_DirT;
  120. - lua_DirT << szUserDataFolder <<
  121. + lua_DirT << szScriptsFolder <<
  122. #ifdef WIN32
  123. - "scripts\\dzVents\\";
  124. + "dzVents\\";
  125. #else
  126. - "scripts/dzVents/";
  127. + "dzVents/";
  128. #endif
  129. + lua_pushstring(lua_state, "generated_script_path");
  130. + lua_pushstring(lua_state, dzv_Dir.c_str());
  131. + lua_rawset(lua_state, -3);
  132. lua_pushstring(lua_state, "script_path");
  133. lua_pushstring(lua_state, lua_DirT.str().c_str());
  134. lua_rawset(lua_state, -3);
  135. @@ -4695,9 +4699,9 @@ namespace http {
  136. std::stringstream template_file;
  137. #ifdef WIN32
  138. - template_file << szUserDataFolder << "scripts\\templates\\" << eventType << "." << interpreter;
  139. + template_file << szScriptsFolder << "templates\\" << eventType << "." << interpreter;
  140. #else
  141. - template_file << szUserDataFolder << "scripts/templates/" << eventType << "." << interpreter;
  142. + template_file << szScriptsFolder << "templates/" << eventType << "." << interpreter;
  143. #endif
  144. std::ifstream file;
  145. std::stringstream template_content;
  146. diff --git a/main/EventsPythonModule.cpp b/main/EventsPythonModule.cpp
  147. index f69e7219..2d97562e 100644
  148. --- a/main/EventsPythonModule.cpp
  149. +++ b/main/EventsPythonModule.cpp
  150. @@ -108,7 +108,7 @@
  151. int PythonEventsInitalized = 0;
  152. - bool PythonEventsInitialize(std::string szUserDataFolder) {
  153. + bool PythonEventsInitialize(std::string szScriptsFolder) {
  154. if (!Plugins::Py_LoadLibrary())
  155. {
  156. @@ -131,9 +131,9 @@
  157. std::string ssPath;
  158. #ifdef WIN32
  159. - ssPath = szUserDataFolder + "scripts\\python\\;";
  160. + ssPath = szScriptsFolder + "python\\;";
  161. #else
  162. - ssPath = szUserDataFolder + "scripts/python/:";
  163. + ssPath = szScriptsFolder + "python/:";
  164. #endif
  165. std::wstring sPath = std::wstring(ssPath.begin(), ssPath.end());
  166. diff --git a/main/LuaHandler.cpp b/main/LuaHandler.cpp
  167. index 8fdcb278..c2ad98ff 100644
  168. --- a/main/LuaHandler.cpp
  169. +++ b/main/LuaHandler.cpp
  170. @@ -22,7 +22,7 @@ extern "C" {
  171. #include "mainworker.h"
  172. #include "../hardware/hardwaretypes.h"
  173. -extern std::string szUserDataFolder;
  174. +extern std::string szScriptsFolder;
  175. int CLuaHandler::l_domoticz_updateDevice(lua_State* lua_state)
  176. {
  177. @@ -155,9 +155,9 @@ bool CLuaHandler::executeLuaScript(const std::string &script, const std::string
  178. {
  179. std::stringstream lua_DirT;
  180. #ifdef WIN32
  181. - lua_DirT << szUserDataFolder << "scripts\\lua_parsers\\";
  182. + lua_DirT << szScriptsFolder << "lua_parsers\\";
  183. #else
  184. - lua_DirT << szUserDataFolder << "scripts/lua_parsers/";
  185. + lua_DirT << szScriptsFolder << "lua_parsers/";
  186. #endif
  187. std::string lua_Dir = lua_DirT.str();
  188. diff --git a/main/SQLHelper.cpp b/main/SQLHelper.cpp
  189. index 491aa5a2..d529243a 100644
  190. --- a/main/SQLHelper.cpp
  191. +++ b/main/SQLHelper.cpp
  192. @@ -633,6 +633,7 @@ const char *sqlCreateMobileDevices =
  193. "[LastUpdate] DATETIME DEFAULT(datetime('now', 'localtime'))"
  194. ");";
  195. +extern std::string szScriptsFolder;
  196. extern std::string szUserDataFolder;
  197. CSQLHelper::CSQLHelper(void)
  198. @@ -3683,9 +3684,9 @@ uint64_t CSQLHelper::UpdateValueInt(const int HardwareID, const char* ID, const
  199. //Execute possible script
  200. std::string scriptname;
  201. #ifdef WIN32
  202. - scriptname = szUserDataFolder + "scripts\\domoticz_main.bat";
  203. + scriptname = szScriptsFolder + "domoticz_main.bat";
  204. #else
  205. - scriptname = szUserDataFolder + "scripts/domoticz_main";
  206. + scriptname = szScriptsFolder + "domoticz_main";
  207. #endif
  208. if (file_exist(scriptname.c_str()))
  209. {
  210. @@ -6641,7 +6642,7 @@ bool CSQLHelper::HandleOnOffAction(const bool bIsOn, const std::string &OnAction
  211. std::string scriptname = OnAction.substr(9);
  212. #if !defined WIN32
  213. if (scriptname.find("/") != 0)
  214. - scriptname = szUserDataFolder + "scripts/" + scriptname;
  215. + scriptname = szScriptsFolder + scriptname;
  216. #endif
  217. std::string scriptparams="";
  218. //Add parameters
  219. @@ -6675,7 +6676,7 @@ bool CSQLHelper::HandleOnOffAction(const bool bIsOn, const std::string &OnAction
  220. std::string scriptname = OffAction.substr(9);
  221. #if !defined WIN32
  222. if (scriptname.find("/") != 0)
  223. - scriptname = szUserDataFolder + "scripts/" + scriptname;
  224. + scriptname = szScriptsFolder + scriptname;
  225. #endif
  226. std::string scriptparams = "";
  227. int pindex = scriptname.find(' ');
  228. diff --git a/main/WebServer.cpp b/main/WebServer.cpp
  229. index f8471791..d2cf10b2 100644
  230. --- a/main/WebServer.cpp
  231. +++ b/main/WebServer.cpp
  232. @@ -59,6 +59,7 @@
  233. #define round(a) ( int ) ( a + .5 )
  234. +extern std::string szScriptsFolder;
  235. extern std::string szUserDataFolder;
  236. extern std::string szWWWFolder;
  237. @@ -2987,9 +2988,9 @@ namespace http {
  238. if (scriptname.find("..") != std::string::npos)
  239. return;
  240. #ifdef WIN32
  241. - scriptname = szUserDataFolder + "scripts\\" + scriptname;
  242. + scriptname = szScriptsFolder + scriptname;
  243. #else
  244. - scriptname = szUserDataFolder + "scripts/" + scriptname;
  245. + scriptname = szScriptsFolder + scriptname;
  246. #endif
  247. if (!file_exist(scriptname.c_str()))
  248. return;
  249. diff --git a/main/domoticz.cpp b/main/domoticz.cpp
  250. index 5ef96f68..52599b14 100644
  251. --- a/main/domoticz.cpp
  252. +++ b/main/domoticz.cpp
  253. @@ -136,6 +136,7 @@ static const _facilities facilities[] =
  254. };
  255. std::string logfacname = "user";
  256. #endif
  257. +std::string szScriptsFolder;
  258. std::string szStartupFolder;
  259. std::string szUserDataFolder;
  260. std::string szWWWFolder;
  261. @@ -696,6 +697,19 @@ int main(int argc, char**argv)
  262. szUserDataFolder = szroot;
  263. }
  264. + szScriptsFolder=szStartupFolder;
  265. + if (cmdLine.HasSwitch("-scripts"))
  266. + {
  267. + if (cmdLine.GetArgumentCount("-scripts") != 1)
  268. + {
  269. + _log.Log(LOG_ERROR, "Please specify a path for scripts directory");
  270. + return 1;
  271. + }
  272. + std::string szroot = cmdLine.GetSafeArgument("-scripts", 0, "");
  273. + if (szroot.size() != 0)
  274. + szScriptsFolder = szroot;
  275. + }
  276. +
  277. if (cmdLine.HasSwitch("-startupdelay"))
  278. {
  279. if (cmdLine.GetArgumentCount("-startupdelay") != 1)
  280. diff --git a/main/mainworker.cpp b/main/mainworker.cpp
  281. index 803690e1..e89a783b 100644
  282. --- a/main/mainworker.cpp
  283. +++ b/main/mainworker.cpp
  284. @@ -159,6 +159,7 @@
  285. #define round(a) ( int ) ( a + .5 )
  286. +extern std::string szScriptsFolder;
  287. extern std::string szStartupFolder;
  288. extern std::string szUserDataFolder;
  289. extern std::string szWWWFolder;
  290. @@ -1473,8 +1474,8 @@ void MainWorker::Do_Work()
  291. m_sql.GetPreferencesVar("ReleaseChannel", nValue);
  292. bool bIsBetaChannel = (nValue != 0);
  293. - std::string scriptname = szUserDataFolder + "scripts/download_update.sh";
  294. - std::string strparm = szUserDataFolder;
  295. + std::string scriptname = szScriptsFolder + "download_update.sh";
  296. + std::string strparm = szScriptsFolder;
  297. if (bIsBetaChannel)
  298. strparm += " /beta";
  299. diff --git a/notifications/NotificationHTTP.cpp b/notifications/NotificationHTTP.cpp
  300. index decff3b4..632e4e66 100644
  301. --- a/notifications/NotificationHTTP.cpp
  302. +++ b/notifications/NotificationHTTP.cpp
  303. @@ -6,7 +6,7 @@
  304. #include "../main/SQLHelper.h"
  305. #include "../main/Logger.h"
  306. -extern std::string szUserDataFolder;
  307. +extern std::string szScriptsFolder;
  308. CNotificationHTTP::CNotificationHTTP() : CNotificationBase(std::string("http"), OPTIONS_NONE)
  309. {
  310. @@ -105,7 +105,7 @@ bool CNotificationHTTP::SendMessageImplementation(
  311. std::string scriptparams = "";
  312. #if !defined WIN32
  313. if (scriptname.find("/") != 0)
  314. - scriptname = szUserDataFolder + "scripts/" + scriptname;
  315. + scriptname = szScriptsFolder + scriptname;
  316. #endif
  317. //Add parameters
  318. uPos = scriptname.find(" ");
  319. diff --git a/push/GooglePubSubPush.cpp b/push/GooglePubSubPush.cpp
  320. index 359a7d7c..46e489f6 100644
  321. --- a/push/GooglePubSubPush.cpp
  322. +++ b/push/GooglePubSubPush.cpp
  323. @@ -22,7 +22,7 @@ extern "C" {
  324. using namespace boost::python;
  325. #endif
  326. -extern std::string szUserDataFolder;
  327. +extern std::string szScriptsFolder;
  328. // this should be filled in by the preprocessor
  329. extern const char * Python_exe;
  330. @@ -231,11 +231,11 @@ void CGooglePubSubPush::DoGooglePubSubPush()
  331. #ifdef ENABLE_PYTHON_DECAP
  332. #ifdef WIN32
  333. - python_DirT << szUserDataFolder << "scripts\\python\\";
  334. - std::string filename = szUserDataFolder + "scripts\\python\\" + "googlepubsub.py";
  335. + python_DirT << szScriptsFolder << "python\\";
  336. + std::string filename = szScriptsFolder + "python\\" + "googlepubsub.py";
  337. #else
  338. - python_DirT << szUserDataFolder << "scripts/python/";
  339. - std::string filename = szUserDataFolder + "scripts/python/" + "googlepubsub.py";
  340. + python_DirT << szScriptsFolder << "python/";
  341. + std::string filename = szScriptsFolder + "python/" + "googlepubsub.py";
  342. #endif
  343. wchar_t * argv[1];
  344. diff --git a/scripts/dzVents/runtime/dzVents.lua b/scripts/dzVents/runtime/dzVents.lua
  345. index d0dfa869..8370d6a9 100644
  346. --- a/scripts/dzVents/runtime/dzVents.lua
  347. +++ b/scripts/dzVents/runtime/dzVents.lua
  348. @@ -1,8 +1,9 @@
  349. local currentPath = globalvariables['script_path']
  350. +local generatedScriptPath = globalvariables['generated_script_path']
  351. local triggerReason = globalvariables['script_reason']
  352. _G.scriptsFolderPath = currentPath .. 'scripts' -- global
  353. -_G.generatedScriptsFolderPath = currentPath .. 'generated_scripts' -- global
  354. +_G.generatedScriptsFolderPath = generatedScriptPath -- global
  355. _G.dataFolderPath = currentPath .. 'data' -- global
  356. package.path = package.path .. ';' .. currentPath .. '?.lua'
  357. @@ -10,7 +11,7 @@ package.path = package.path .. ';' .. currentPath .. 'runtime/?.lua'
  358. package.path = package.path .. ';' .. currentPath .. 'runtime/device-adapters/?.lua'
  359. package.path = package.path .. ';' .. currentPath .. 'dzVents/?.lua'
  360. package.path = package.path .. ';' .. currentPath .. 'scripts/?.lua'
  361. -package.path = package.path .. ';' .. currentPath .. 'generated_scripts/?.lua'
  362. +package.path = package.path .. ';' .. generatedScriptPath .. '?.lua'
  363. package.path = package.path .. ';' .. currentPath .. 'data/?.lua'
  364. local EventHelpers = require('EventHelpers')