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