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
9 -extern std::string szUserDataFolder;
10 +extern std::string szScriptsFolder;
13 CEvohomeScript::CEvohomeScript(const int ID)
14 @@ -143,7 +143,7 @@ void CEvohomeScript::RunScript(const char *pdata, const unsigned char length)
15 std::string scriptname = OnAction.substr(9);
17 if (scriptname.find("/") != 0)
18 - scriptname = szUserDataFolder + "scripts/" + scriptname;
19 + scriptname = szScriptsFolder + "scripts/" + scriptname;
21 std::string scriptparams="";
23 diff --git a/hardware/OpenZWave.cpp b/hardware/OpenZWave.cpp
24 index 1f5c341c..24db61c9 100644
25 --- a/hardware/OpenZWave.cpp
26 +++ b/hardware/OpenZWave.cpp
27 @@ -948,7 +948,7 @@ bool COpenZWave::OpenSerialConnector()
31 - std::string ConfigPath = szStartupFolder + "Config/";
32 + std::string ConfigPath = "/usr/share/domoticz/openzwave/";
33 std::string UserPath = ConfigPath;
34 if (szStartupFolder != szUserDataFolder)
36 diff --git a/main/EventSystem.cpp b/main/EventSystem.cpp
37 index 4eff02fd..f2b17b97 100644
38 --- a/main/EventSystem.cpp
39 +++ b/main/EventSystem.cpp
40 @@ -33,9 +33,11 @@ extern "C" {
44 +extern std::string szScriptsFolder;
45 extern std::string szUserDataFolder;
46 extern http::server::CWebServerHelper m_webservers;
48 +static std::string dzv_Dir;
49 static std::string m_printprefix;
52 @@ -115,7 +117,6 @@ static const _tJsonMap JsonMap[] =
53 { NULL, NULL, tString }
57 CEventSystem::CEventSystem(void)
59 m_stoprequested = false;
60 @@ -149,7 +150,7 @@ void CEventSystem::StartEventSystem()
61 GetCurrentScenesGroups();
62 GetCurrentUserVariables();
64 - Plugins::PythonEventsInitialize(szUserDataFolder);
65 + Plugins::PythonEventsInitialize(szScriptsFolder);
68 m_thread = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&CEventSystem::Do_Work, this)));
69 @@ -179,11 +180,11 @@ void CEventSystem::SetEnabled(const bool bEnabled)
71 void CEventSystem::LoadEvents()
73 - std::string dzv_Dir,s;
76 - dzv_Dir = szUserDataFolder + "scripts\\dzVents\\generated_scripts\\";
77 + dzv_Dir = szUserDataFolder + "generated_scripts\\";
79 - dzv_Dir = szUserDataFolder + "scripts/dzVents/generated_scripts/";
80 + dzv_Dir = szUserDataFolder + "generated_scripts/";
82 boost::unique_lock<boost::shared_mutex> eventsMutexLock(m_eventsMutex);
83 _log.Log(LOG_STATUS, "EventSystem: reset all events...");
84 @@ -274,18 +275,18 @@ void CEventSystem::LoadEvents()
85 void CEventSystem::Do_Work()
88 - m_lua_Dir = szUserDataFolder + "scripts\\lua\\";
89 - m_dzv_Dir = szUserDataFolder + "scripts\\dzVents\\runtime\\";
90 + m_lua_Dir = szScriptsFolder + "lua\\";
91 + m_dzv_Dir = szScriptsFolder + "dzVents\\runtime\\";
93 - m_lua_Dir = szUserDataFolder + "scripts/lua/";
94 - m_dzv_Dir = szUserDataFolder + "scripts/dzVents/runtime/";
95 + m_lua_Dir = szScriptsFolder + "lua/";
96 + m_dzv_Dir = szScriptsFolder + "dzVents/runtime/";
101 - m_python_Dir = szUserDataFolder + "scripts\\python\\";
102 + m_python_Dir = szScriptsFolder + "python\\";
104 - m_python_Dir = szUserDataFolder + "scripts/python/";
105 + m_python_Dir = szScriptsFolder + "python/";
108 m_stoprequested = false;
109 @@ -1426,9 +1427,9 @@ void CEventSystem::EvaluateEvent(const std::string &reason, const uint64_t Devic
111 std::string dzv_scripts;
113 - dzv_scripts = szUserDataFolder + "scripts\\dzVents\\scripts\\";
114 + dzv_scripts = szScriptsFolder + "dzVents\\scripts\\";
116 - dzv_scripts = szUserDataFolder + "scripts/dzVents/scripts/";
117 + dzv_scripts = szScriptsFolder + "dzVents/scripts/";
119 DirectoryListing(FileEntries, dzv_scripts, false, true);
120 for (itt = FileEntries.begin(); itt != FileEntries.end(); ++itt)
121 @@ -2404,7 +2405,7 @@ bool CEventSystem::parseBlocklyActions(const std::string &Actions, const std::st
124 if (sPath.find("/") != 0)
125 - sPath = szUserDataFolder + "scripts/" + sPath;
126 + sPath = szScriptsFolder + sPath;
129 m_sql.AddTaskItem(_tTaskItem::ExecuteScript(0.2f, sPath, sParam));
130 @@ -3508,13 +3509,16 @@ void CEventSystem::EvaluateLua(const std::string &reason, const std::string &fil
132 std::stringstream lua_DirT;
134 - lua_DirT << szUserDataFolder <<
135 + lua_DirT << szScriptsFolder <<
137 - "scripts\\dzVents\\";
140 - "scripts/dzVents/";
144 + lua_pushstring(lua_state, "generated_script_path");
145 + lua_pushstring(lua_state, dzv_Dir.c_str());
146 + lua_rawset(lua_state, -3);
147 lua_pushstring(lua_state, "script_path");
148 lua_pushstring(lua_state, lua_DirT.str().c_str());
149 lua_rawset(lua_state, -3);
150 @@ -4695,9 +4699,9 @@ namespace http {
152 std::stringstream template_file;
154 - template_file << szUserDataFolder << "scripts\\templates\\" << eventType << "." << interpreter;
155 + template_file << szScriptsFolder << "templates\\" << eventType << "." << interpreter;
157 - template_file << szUserDataFolder << "scripts/templates/" << eventType << "." << interpreter;
158 + template_file << szScriptsFolder << "templates/" << eventType << "." << interpreter;
161 std::stringstream template_content;
162 diff --git a/main/EventsPythonModule.cpp b/main/EventsPythonModule.cpp
163 index f69e7219..2d97562e 100644
164 --- a/main/EventsPythonModule.cpp
165 +++ b/main/EventsPythonModule.cpp
168 int PythonEventsInitalized = 0;
170 - bool PythonEventsInitialize(std::string szUserDataFolder) {
171 + bool PythonEventsInitialize(std::string szScriptsFolder) {
173 if (!Plugins::Py_LoadLibrary())
179 - ssPath = szUserDataFolder + "scripts\\python\\;";
180 + ssPath = szScriptsFolder + "python\\;";
182 - ssPath = szUserDataFolder + "scripts/python/:";
183 + ssPath = szScriptsFolder + "python/:";
186 std::wstring sPath = std::wstring(ssPath.begin(), ssPath.end());
187 diff --git a/main/LuaHandler.cpp b/main/LuaHandler.cpp
188 index 8fdcb278..c2ad98ff 100644
189 --- a/main/LuaHandler.cpp
190 +++ b/main/LuaHandler.cpp
191 @@ -22,7 +22,7 @@ extern "C" {
192 #include "mainworker.h"
193 #include "../hardware/hardwaretypes.h"
195 -extern std::string szUserDataFolder;
196 +extern std::string szScriptsFolder;
198 int CLuaHandler::l_domoticz_updateDevice(lua_State* lua_state)
200 @@ -155,9 +155,9 @@ bool CLuaHandler::executeLuaScript(const std::string &script, const std::string
202 std::stringstream lua_DirT;
204 - lua_DirT << szUserDataFolder << "scripts\\lua_parsers\\";
205 + lua_DirT << szScriptsFolder << "lua_parsers\\";
207 - lua_DirT << szUserDataFolder << "scripts/lua_parsers/";
208 + lua_DirT << szScriptsFolder << "lua_parsers/";
210 std::string lua_Dir = lua_DirT.str();
212 diff --git a/main/SQLHelper.cpp b/main/SQLHelper.cpp
213 index 491aa5a2..d529243a 100644
214 --- a/main/SQLHelper.cpp
215 +++ b/main/SQLHelper.cpp
216 @@ -633,6 +633,7 @@ const char *sqlCreateMobileDevices =
217 "[LastUpdate] DATETIME DEFAULT(datetime('now', 'localtime'))"
220 +extern std::string szScriptsFolder;
221 extern std::string szUserDataFolder;
223 CSQLHelper::CSQLHelper(void)
224 @@ -3683,9 +3684,9 @@ uint64_t CSQLHelper::UpdateValueInt(const int HardwareID, const char* ID, const
225 //Execute possible script
226 std::string scriptname;
228 - scriptname = szUserDataFolder + "scripts\\domoticz_main.bat";
229 + scriptname = szScriptsFolder + "domoticz_main.bat";
231 - scriptname = szUserDataFolder + "scripts/domoticz_main";
232 + scriptname = szScriptsFolder + "domoticz_main";
234 if (file_exist(scriptname.c_str()))
236 @@ -6641,7 +6642,7 @@ bool CSQLHelper::HandleOnOffAction(const bool bIsOn, const std::string &OnAction
237 std::string scriptname = OnAction.substr(9);
239 if (scriptname.find("/") != 0)
240 - scriptname = szUserDataFolder + "scripts/" + scriptname;
241 + scriptname = szScriptsFolder + scriptname;
243 std::string scriptparams="";
245 @@ -6675,7 +6676,7 @@ bool CSQLHelper::HandleOnOffAction(const bool bIsOn, const std::string &OnAction
246 std::string scriptname = OffAction.substr(9);
248 if (scriptname.find("/") != 0)
249 - scriptname = szUserDataFolder + "scripts/" + scriptname;
250 + scriptname = szScriptsFolder + scriptname;
252 std::string scriptparams = "";
253 int pindex = scriptname.find(' ');
254 diff --git a/main/WebServer.cpp b/main/WebServer.cpp
255 index f8471791..d2cf10b2 100644
256 --- a/main/WebServer.cpp
257 +++ b/main/WebServer.cpp
260 #define round(a) ( int ) ( a + .5 )
262 +extern std::string szScriptsFolder;
263 extern std::string szUserDataFolder;
264 extern std::string szWWWFolder;
266 @@ -2987,9 +2988,9 @@ namespace http {
267 if (scriptname.find("..") != std::string::npos)
270 - scriptname = szUserDataFolder + "scripts\\" + scriptname;
271 + scriptname = szScriptsFolder + scriptname;
273 - scriptname = szUserDataFolder + "scripts/" + scriptname;
274 + scriptname = szScriptsFolder + scriptname;
276 if (!file_exist(scriptname.c_str()))
278 diff --git a/main/domoticz.cpp b/main/domoticz.cpp
279 index 5ef96f68..52599b14 100644
280 --- a/main/domoticz.cpp
281 +++ b/main/domoticz.cpp
282 @@ -136,6 +136,7 @@ static const _facilities facilities[] =
284 std::string logfacname = "user";
286 +std::string szScriptsFolder;
287 std::string szStartupFolder;
288 std::string szUserDataFolder;
289 std::string szWWWFolder;
290 @@ -696,6 +697,19 @@ int main(int argc, char**argv)
291 szUserDataFolder = szroot;
294 + szScriptsFolder=szStartupFolder;
295 + if (cmdLine.HasSwitch("-scripts"))
297 + if (cmdLine.GetArgumentCount("-scripts") != 1)
299 + _log.Log(LOG_ERROR, "Please specify a path for scripts directory");
302 + std::string szroot = cmdLine.GetSafeArgument("-scripts", 0, "");
303 + if (szroot.size() != 0)
304 + szScriptsFolder = szroot;
307 if (cmdLine.HasSwitch("-startupdelay"))
309 if (cmdLine.GetArgumentCount("-startupdelay") != 1)
310 diff --git a/main/mainworker.cpp b/main/mainworker.cpp
311 index 803690e1..e89a783b 100644
312 --- a/main/mainworker.cpp
313 +++ b/main/mainworker.cpp
316 #define round(a) ( int ) ( a + .5 )
318 +extern std::string szScriptsFolder;
319 extern std::string szStartupFolder;
320 extern std::string szUserDataFolder;
321 extern std::string szWWWFolder;
322 @@ -1473,8 +1474,8 @@ void MainWorker::Do_Work()
323 m_sql.GetPreferencesVar("ReleaseChannel", nValue);
324 bool bIsBetaChannel = (nValue != 0);
326 - std::string scriptname = szUserDataFolder + "scripts/download_update.sh";
327 - std::string strparm = szUserDataFolder;
328 + std::string scriptname = szScriptsFolder + "download_update.sh";
329 + std::string strparm = szScriptsFolder;
333 diff --git a/notifications/NotificationHTTP.cpp b/notifications/NotificationHTTP.cpp
334 index decff3b4..632e4e66 100644
335 --- a/notifications/NotificationHTTP.cpp
336 +++ b/notifications/NotificationHTTP.cpp
338 #include "../main/SQLHelper.h"
339 #include "../main/Logger.h"
341 -extern std::string szUserDataFolder;
342 +extern std::string szScriptsFolder;
344 CNotificationHTTP::CNotificationHTTP() : CNotificationBase(std::string("http"), OPTIONS_NONE)
346 @@ -105,7 +105,7 @@ bool CNotificationHTTP::SendMessageImplementation(
347 std::string scriptparams = "";
349 if (scriptname.find("/") != 0)
350 - scriptname = szUserDataFolder + "scripts/" + scriptname;
351 + scriptname = szScriptsFolder + scriptname;
354 uPos = scriptname.find(" ");
355 diff --git a/push/GooglePubSubPush.cpp b/push/GooglePubSubPush.cpp
356 index 359a7d7c..46e489f6 100644
357 --- a/push/GooglePubSubPush.cpp
358 +++ b/push/GooglePubSubPush.cpp
359 @@ -22,7 +22,7 @@ extern "C" {
360 using namespace boost::python;
363 -extern std::string szUserDataFolder;
364 +extern std::string szScriptsFolder;
366 // this should be filled in by the preprocessor
367 extern const char * Python_exe;
368 @@ -231,11 +231,11 @@ void CGooglePubSubPush::DoGooglePubSubPush()
370 #ifdef ENABLE_PYTHON_DECAP
372 - python_DirT << szUserDataFolder << "scripts\\python\\";
373 - std::string filename = szUserDataFolder + "scripts\\python\\" + "googlepubsub.py";
374 + python_DirT << szScriptsFolder << "python\\";
375 + std::string filename = szScriptsFolder + "python\\" + "googlepubsub.py";
377 - python_DirT << szUserDataFolder << "scripts/python/";
378 - std::string filename = szUserDataFolder + "scripts/python/" + "googlepubsub.py";
379 + python_DirT << szScriptsFolder << "python/";
380 + std::string filename = szScriptsFolder + "python/" + "googlepubsub.py";
384 diff --git a/scripts/dzVents/runtime/dzVents.lua b/scripts/dzVents/runtime/dzVents.lua
385 index d0dfa869..8370d6a9 100644
386 --- a/scripts/dzVents/runtime/dzVents.lua
387 +++ b/scripts/dzVents/runtime/dzVents.lua
389 local currentPath = globalvariables['script_path']
390 +local generatedScriptPath = globalvariables['generated_script_path']
391 local triggerReason = globalvariables['script_reason']
393 _G.scriptsFolderPath = currentPath .. 'scripts' -- global
394 -_G.generatedScriptsFolderPath = currentPath .. 'generated_scripts' -- global
395 +_G.generatedScriptsFolderPath = generatedScriptPath -- global
396 _G.dataFolderPath = currentPath .. 'data' -- global
398 package.path = package.path .. ';' .. currentPath .. '?.lua'
399 @@ -10,7 +11,7 @@ package.path = package.path .. ';' .. currentPath .. 'runtime/?.lua'
400 package.path = package.path .. ';' .. currentPath .. 'runtime/device-adapters/?.lua'
401 package.path = package.path .. ';' .. currentPath .. 'dzVents/?.lua'
402 package.path = package.path .. ';' .. currentPath .. 'scripts/?.lua'
403 -package.path = package.path .. ';' .. currentPath .. 'generated_scripts/?.lua'
404 +package.path = package.path .. ';' .. generatedScriptPath .. '?.lua'
405 package.path = package.path .. ';' .. currentPath .. 'data/?.lua'
407 local EventHelpers = require('EventHelpers')