Merge pull request #4825 from nxhack/node-hid_fix_depends
[feed/packages.git] / utils / domoticz / patches / 903_fhs.patch
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
7 #include <string>
8
9 -extern std::string szUserDataFolder;
10 +extern std::string szScriptsFolder;
11
12
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);
16 #if !defined WIN32
17 if (scriptname.find("/") != 0)
18 - scriptname = szUserDataFolder + "scripts/" + scriptname;
19 + scriptname = szScriptsFolder + "scripts/" + scriptname;
20 #endif
21 std::string scriptparams="";
22 //Add parameters
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()
28
29 m_nodes.clear();
30 m_bNeedSave = false;
31 - std::string ConfigPath = szStartupFolder + "Config/";
32 + std::string ConfigPath = "/usr/share/domoticz/openzwave/";
33 std::string UserPath = ConfigPath;
34 if (szStartupFolder != szUserDataFolder)
35 {
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" {
41 #endif
42 }
43
44 +extern std::string szScriptsFolder;
45 extern std::string szUserDataFolder;
46 extern http::server::CWebServerHelper m_webservers;
47
48 +static std::string dzv_Dir;
49 static std::string m_printprefix;
50
51 #ifdef ENABLE_PYTHON
52 @@ -115,7 +117,6 @@ static const _tJsonMap JsonMap[] =
53 { NULL, NULL, tString }
54 };
55
56 -
57 CEventSystem::CEventSystem(void)
58 {
59 m_stoprequested = false;
60 @@ -149,7 +150,7 @@ void CEventSystem::StartEventSystem()
61 GetCurrentScenesGroups();
62 GetCurrentUserVariables();
63 #ifdef ENABLE_PYTHON
64 - Plugins::PythonEventsInitialize(szUserDataFolder);
65 + Plugins::PythonEventsInitialize(szScriptsFolder);
66 #endif
67
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)
70
71 void CEventSystem::LoadEvents()
72 {
73 - std::string dzv_Dir,s;
74 + std::string s;
75 #ifdef WIN32
76 - dzv_Dir = szUserDataFolder + "scripts\\dzVents\\generated_scripts\\";
77 + dzv_Dir = szUserDataFolder + "generated_scripts\\";
78 #else
79 - dzv_Dir = szUserDataFolder + "scripts/dzVents/generated_scripts/";
80 + dzv_Dir = szUserDataFolder + "generated_scripts/";
81 #endif
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()
86 {
87 #ifdef WIN32
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\\";
92 #else
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/";
97 #endif
98
99 #ifdef ENABLE_PYTHON
100 #ifdef WIN32
101 - m_python_Dir = szUserDataFolder + "scripts\\python\\";
102 + m_python_Dir = szScriptsFolder + "python\\";
103 #else
104 - m_python_Dir = szUserDataFolder + "scripts/python/";
105 + m_python_Dir = szScriptsFolder + "python/";
106 #endif
107 #endif
108 m_stoprequested = false;
109 @@ -1426,9 +1427,9 @@ void CEventSystem::EvaluateEvent(const std::string &reason, const uint64_t Devic
110 {
111 std::string dzv_scripts;
112 #ifdef WIN32
113 - dzv_scripts = szUserDataFolder + "scripts\\dzVents\\scripts\\";
114 + dzv_scripts = szScriptsFolder + "dzVents\\scripts\\";
115 #else
116 - dzv_scripts = szUserDataFolder + "scripts/dzVents/scripts/";
117 + dzv_scripts = szScriptsFolder + "dzVents/scripts/";
118 #endif
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
122 }
123 #if !defined WIN32
124 if (sPath.find("/") != 0)
125 - sPath = szUserDataFolder + "scripts/" + sPath;
126 + sPath = szScriptsFolder + sPath;
127 #endif
128
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
131 {
132 std::stringstream lua_DirT;
133
134 - lua_DirT << szUserDataFolder <<
135 + lua_DirT << szScriptsFolder <<
136 #ifdef WIN32
137 - "scripts\\dzVents\\";
138 + "dzVents\\";
139 #else
140 - "scripts/dzVents/";
141 + "dzVents/";
142 #endif
143
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 {
151
152 std::stringstream template_file;
153 #ifdef WIN32
154 - template_file << szUserDataFolder << "scripts\\templates\\" << eventType << "." << interpreter;
155 + template_file << szScriptsFolder << "templates\\" << eventType << "." << interpreter;
156 #else
157 - template_file << szUserDataFolder << "scripts/templates/" << eventType << "." << interpreter;
158 + template_file << szScriptsFolder << "templates/" << eventType << "." << interpreter;
159 #endif
160 std::ifstream file;
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
166 @@ -108,7 +108,7 @@
167
168 int PythonEventsInitalized = 0;
169
170 - bool PythonEventsInitialize(std::string szUserDataFolder) {
171 + bool PythonEventsInitialize(std::string szScriptsFolder) {
172
173 if (!Plugins::Py_LoadLibrary())
174 {
175 @@ -131,9 +131,9 @@
176
177 std::string ssPath;
178 #ifdef WIN32
179 - ssPath = szUserDataFolder + "scripts\\python\\;";
180 + ssPath = szScriptsFolder + "python\\;";
181 #else
182 - ssPath = szUserDataFolder + "scripts/python/:";
183 + ssPath = szScriptsFolder + "python/:";
184 #endif
185
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"
194
195 -extern std::string szUserDataFolder;
196 +extern std::string szScriptsFolder;
197
198 int CLuaHandler::l_domoticz_updateDevice(lua_State* lua_state)
199 {
200 @@ -155,9 +155,9 @@ bool CLuaHandler::executeLuaScript(const std::string &script, const std::string
201 {
202 std::stringstream lua_DirT;
203 #ifdef WIN32
204 - lua_DirT << szUserDataFolder << "scripts\\lua_parsers\\";
205 + lua_DirT << szScriptsFolder << "lua_parsers\\";
206 #else
207 - lua_DirT << szUserDataFolder << "scripts/lua_parsers/";
208 + lua_DirT << szScriptsFolder << "lua_parsers/";
209 #endif
210 std::string lua_Dir = lua_DirT.str();
211
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'))"
218 ");";
219
220 +extern std::string szScriptsFolder;
221 extern std::string szUserDataFolder;
222
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;
227 #ifdef WIN32
228 - scriptname = szUserDataFolder + "scripts\\domoticz_main.bat";
229 + scriptname = szScriptsFolder + "domoticz_main.bat";
230 #else
231 - scriptname = szUserDataFolder + "scripts/domoticz_main";
232 + scriptname = szScriptsFolder + "domoticz_main";
233 #endif
234 if (file_exist(scriptname.c_str()))
235 {
236 @@ -6641,7 +6642,7 @@ bool CSQLHelper::HandleOnOffAction(const bool bIsOn, const std::string &OnAction
237 std::string scriptname = OnAction.substr(9);
238 #if !defined WIN32
239 if (scriptname.find("/") != 0)
240 - scriptname = szUserDataFolder + "scripts/" + scriptname;
241 + scriptname = szScriptsFolder + scriptname;
242 #endif
243 std::string scriptparams="";
244 //Add parameters
245 @@ -6675,7 +6676,7 @@ bool CSQLHelper::HandleOnOffAction(const bool bIsOn, const std::string &OnAction
246 std::string scriptname = OffAction.substr(9);
247 #if !defined WIN32
248 if (scriptname.find("/") != 0)
249 - scriptname = szUserDataFolder + "scripts/" + scriptname;
250 + scriptname = szScriptsFolder + scriptname;
251 #endif
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
258 @@ -59,6 +59,7 @@
259
260 #define round(a) ( int ) ( a + .5 )
261
262 +extern std::string szScriptsFolder;
263 extern std::string szUserDataFolder;
264 extern std::string szWWWFolder;
265
266 @@ -2987,9 +2988,9 @@ namespace http {
267 if (scriptname.find("..") != std::string::npos)
268 return;
269 #ifdef WIN32
270 - scriptname = szUserDataFolder + "scripts\\" + scriptname;
271 + scriptname = szScriptsFolder + scriptname;
272 #else
273 - scriptname = szUserDataFolder + "scripts/" + scriptname;
274 + scriptname = szScriptsFolder + scriptname;
275 #endif
276 if (!file_exist(scriptname.c_str()))
277 return;
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[] =
283 };
284 std::string logfacname = "user";
285 #endif
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;
292 }
293
294 + szScriptsFolder=szStartupFolder;
295 + if (cmdLine.HasSwitch("-scripts"))
296 + {
297 + if (cmdLine.GetArgumentCount("-scripts") != 1)
298 + {
299 + _log.Log(LOG_ERROR, "Please specify a path for scripts directory");
300 + return 1;
301 + }
302 + std::string szroot = cmdLine.GetSafeArgument("-scripts", 0, "");
303 + if (szroot.size() != 0)
304 + szScriptsFolder = szroot;
305 + }
306 +
307 if (cmdLine.HasSwitch("-startupdelay"))
308 {
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
314 @@ -159,6 +159,7 @@
315
316 #define round(a) ( int ) ( a + .5 )
317
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);
325
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;
330 if (bIsBetaChannel)
331 strparm += " /beta";
332
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
337 @@ -6,7 +6,7 @@
338 #include "../main/SQLHelper.h"
339 #include "../main/Logger.h"
340
341 -extern std::string szUserDataFolder;
342 +extern std::string szScriptsFolder;
343
344 CNotificationHTTP::CNotificationHTTP() : CNotificationBase(std::string("http"), OPTIONS_NONE)
345 {
346 @@ -105,7 +105,7 @@ bool CNotificationHTTP::SendMessageImplementation(
347 std::string scriptparams = "";
348 #if !defined WIN32
349 if (scriptname.find("/") != 0)
350 - scriptname = szUserDataFolder + "scripts/" + scriptname;
351 + scriptname = szScriptsFolder + scriptname;
352 #endif
353 //Add parameters
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;
361 #endif
362
363 -extern std::string szUserDataFolder;
364 +extern std::string szScriptsFolder;
365
366 // this should be filled in by the preprocessor
367 extern const char * Python_exe;
368 @@ -231,11 +231,11 @@ void CGooglePubSubPush::DoGooglePubSubPush()
369
370 #ifdef ENABLE_PYTHON_DECAP
371 #ifdef WIN32
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";
376 #else
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";
381 #endif
382
383 wchar_t * argv[1];
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
388 @@ -1,8 +1,9 @@
389 local currentPath = globalvariables['script_path']
390 +local generatedScriptPath = globalvariables['generated_script_path']
391 local triggerReason = globalvariables['script_reason']
392
393 _G.scriptsFolderPath = currentPath .. 'scripts' -- global
394 -_G.generatedScriptsFolderPath = currentPath .. 'generated_scripts' -- global
395 +_G.generatedScriptsFolderPath = generatedScriptPath -- global
396 _G.dataFolderPath = currentPath .. 'data' -- global
397
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'
406
407 local EventHelpers = require('EventHelpers')