902_add-scripts-path.patch (8458B)
1 --- a/hardware/OpenZWave.cpp 2 +++ b/hardware/OpenZWave.cpp 3 @@ -993,7 +993,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 @@ -44,7 +44,7 @@ extern "C" { 15 using namespace boost::python; 16 #endif 17 18 -extern std::string szUserDataFolder; 19 +extern std::string szScriptsFolder; 20 21 CEventSystem::CEventSystem(void) 22 { 23 @@ -1086,9 +1086,9 @@ void CEventSystem::EvaluateEvent(const s 24 std::stringstream lua_DirT; 25 26 #ifdef WIN32 27 - lua_DirT << szUserDataFolder << "scripts\\lua\\"; 28 + lua_DirT << szScriptsFolder << "lua\\"; 29 #else 30 - lua_DirT << szUserDataFolder << "scripts/lua/"; 31 + lua_DirT << szScriptsFolder << "lua/"; 32 #endif 33 34 std::string lua_Dir = lua_DirT.str(); 35 @@ -1139,9 +1139,9 @@ void CEventSystem::EvaluateEvent(const s 36 { 37 std::stringstream python_DirT; 38 #ifdef WIN32 39 - python_DirT << szUserDataFolder << "scripts\\python\\"; 40 + python_DirT << szScriptsFolder << "python\\"; 41 #else 42 - python_DirT << szUserDataFolder << "scripts/python/"; 43 + python_DirT << szScriptsFolder << "python/"; 44 #endif 45 46 std::string python_Dir = python_DirT.str(); 47 @@ -2021,7 +2021,7 @@ bool CEventSystem::parseBlocklyActions(c 48 } 49 #if !defined WIN32 50 if (sPath.find("/") != 0) 51 - sPath = szUserDataFolder + "scripts/" + sPath; 52 + sPath = szScriptsFolder + sPath; 53 #endif 54 55 m_sql.AddTaskItem(_tTaskItem::ExecuteScript(1, sPath, sParam)); 56 @@ -2133,9 +2133,9 @@ void CEventSystem::EvaluatePython(const 57 std::stringstream python_DirT; 58 59 #ifdef WIN32 60 - python_DirT << szUserDataFolder << "scripts\\python\\"; 61 + python_DirT << szScriptsFolder << "python\\"; 62 #else 63 - python_DirT << szUserDataFolder << "scripts/python/"; 64 + python_DirT << szScriptsFolder << "python/"; 65 #endif 66 std::string python_Dir = python_DirT.str(); 67 if(!Py_IsInitialized()) { 68 @@ -3909,9 +3909,9 @@ namespace http { 69 70 std::stringstream template_file; 71 #ifdef WIN32 72 - template_file << szUserDataFolder << "scripts\\templates\\" << eventType << "." << interpreter; 73 + template_file << szScriptsFolder << "templates\\" << eventType << "." << interpreter; 74 #else 75 - template_file << szUserDataFolder << "scripts/templates/" << eventType << "." << interpreter; 76 + template_file << szScriptsFolder << "templates/" << eventType << "." << interpreter; 77 #endif 78 std::ifstream file; 79 std::stringstream template_content; 80 --- a/main/LuaHandler.cpp 81 +++ b/main/LuaHandler.cpp 82 @@ -22,7 +22,7 @@ extern "C" { 83 #include "mainworker.h" 84 #include "../hardware/hardwaretypes.h" 85 86 -extern std::string szUserDataFolder; 87 +extern std::string szScriptsFolder; 88 89 int CLuaHandler::l_domoticz_applyXPath(lua_State* lua_state) 90 { 91 @@ -319,9 +319,9 @@ bool CLuaHandler::executeLuaScript(const 92 { 93 std::stringstream lua_DirT; 94 #ifdef WIN32 95 - lua_DirT << szUserDataFolder << "scripts\\lua_parsers\\"; 96 + lua_DirT << szScriptsFolder << "lua_parsers\\"; 97 #else 98 - lua_DirT << szUserDataFolder << "scripts/lua_parsers/"; 99 + lua_DirT << szScriptsFolder << "lua_parsers/"; 100 #endif 101 std::string lua_Dir = lua_DirT.str(); 102 103 --- a/main/SQLHelper.cpp 104 +++ b/main/SQLHelper.cpp 105 @@ -612,6 +612,7 @@ const char *sqlCreateMobileDevices = 106 "[LastUpdate] DATETIME DEFAULT(datetime('now', 'localtime'))" 107 ");"; 108 109 +extern std::string szScriptsFolder; 110 extern std::string szUserDataFolder; 111 112 CSQLHelper::CSQLHelper(void) 113 @@ -3408,9 +3409,9 @@ unsigned long long CSQLHelper::UpdateVal 114 //Execute possible script 115 std::string scriptname; 116 #ifdef WIN32 117 - scriptname = szUserDataFolder + "scripts\\domoticz_main.bat"; 118 + scriptname = szScriptsFolder + "domoticz_main.bat"; 119 #else 120 - scriptname = szUserDataFolder + "scripts/domoticz_main"; 121 + scriptname = szScriptsFolder + "domoticz_main"; 122 #endif 123 if (file_exist(scriptname.c_str())) 124 { 125 @@ -6460,7 +6461,7 @@ bool CSQLHelper::HandleOnOffAction(const 126 std::string scriptname = OnAction.substr(9); 127 #if !defined WIN32 128 if (scriptname.find("/") != 0) 129 - scriptname = szUserDataFolder + "scripts/" + scriptname; 130 + scriptname = szScriptsFolder + scriptname; 131 #endif 132 std::string scriptparams=""; 133 //Add parameters 134 @@ -6492,7 +6493,7 @@ bool CSQLHelper::HandleOnOffAction(const 135 std::string scriptname = OffAction.substr(9); 136 #if !defined WIN32 137 if (scriptname.find("/") != 0) 138 - scriptname = szUserDataFolder + "scripts/" + scriptname; 139 + scriptname = szScriptsFolder + scriptname; 140 #endif 141 std::string scriptparams=""; 142 int pindex=scriptname.find(' '); 143 --- a/main/WebServer.cpp 144 +++ b/main/WebServer.cpp 145 @@ -55,6 +55,7 @@ 146 147 #define round(a) ( int ) ( a + .5 ) 148 149 +extern std::string szScriptsFolder; 150 extern std::string szUserDataFolder; 151 extern std::string szWWWFolder; 152 153 @@ -2614,9 +2615,9 @@ namespace http { 154 if (scriptname.find("..") != std::string::npos) 155 return; 156 #ifdef WIN32 157 - scriptname = szUserDataFolder + "scripts\\" + scriptname; 158 + scriptname = szScriptsFolder + scriptname; 159 #else 160 - scriptname = szUserDataFolder + "scripts/" + scriptname; 161 + scriptname = szScriptsFolder + scriptname; 162 #endif 163 if (!file_exist(scriptname.c_str())) 164 return; 165 --- a/main/domoticz.cpp 166 +++ b/main/domoticz.cpp 167 @@ -135,6 +135,7 @@ static const _facilities facilities[] = 168 }; 169 std::string logfacname = "user"; 170 #endif 171 +std::string szScriptsFolder; 172 std::string szStartupFolder; 173 std::string szUserDataFolder; 174 std::string szWWWFolder; 175 @@ -603,6 +604,19 @@ int main(int argc, char**argv) 176 szUserDataFolder = szroot; 177 } 178 179 + szScriptsFolder=szStartupFolder; 180 + if (cmdLine.HasSwitch("-scripts")) 181 + { 182 + if (cmdLine.GetArgumentCount("-scripts") != 1) 183 + { 184 + _log.Log(LOG_ERROR, "Please specify a path for scripts directory"); 185 + return 1; 186 + } 187 + std::string szroot = cmdLine.GetSafeArgument("-scripts", 0, ""); 188 + if (szroot.size() != 0) 189 + szScriptsFolder = szroot; 190 + } 191 + 192 if (cmdLine.HasSwitch("-startupdelay")) 193 { 194 if (cmdLine.GetArgumentCount("-startupdelay") != 1) 195 --- a/main/mainworker.cpp 196 +++ b/main/mainworker.cpp 197 @@ -139,6 +139,7 @@ 198 199 #define round(a) ( int ) ( a + .5 ) 200 201 +extern std::string szScriptsFolder; 202 extern std::string szStartupFolder; 203 extern std::string szUserDataFolder; 204 extern std::string szWWWFolder; 205 @@ -1394,8 +1395,8 @@ void MainWorker::Do_Work() 206 m_sql.GetPreferencesVar("ReleaseChannel", nValue); 207 bool bIsBetaChannel = (nValue != 0); 208 209 - std::string scriptname = szUserDataFolder + "scripts/download_update.sh"; 210 - std::string strparm = szUserDataFolder; 211 + std::string scriptname = szScriptsFolder + "download_update.sh"; 212 + std::string strparm = szScriptsFolder; 213 if (bIsBetaChannel) 214 strparm += " /beta"; 215 216 --- a/notifications/NotificationHTTP.cpp 217 +++ b/notifications/NotificationHTTP.cpp 218 @@ -6,7 +6,7 @@ 219 #include "../main/SQLHelper.h" 220 #include "../main/Logger.h" 221 222 -extern std::string szUserDataFolder; 223 +extern std::string szScriptsFolder; 224 225 CNotificationHTTP::CNotificationHTTP() : CNotificationBase(std::string("http"), OPTIONS_NONE) 226 { 227 @@ -97,7 +97,7 @@ bool CNotificationHTTP::SendMessageImple 228 std::string scriptparams = ""; 229 #if !defined WIN32 230 if (scriptname.find("/") != 0) 231 - scriptname = szUserDataFolder + "scripts/" + scriptname; 232 + scriptname = szScriptsFolder + scriptname; 233 #endif 234 //Add parameters 235 uPos = scriptname.find(" "); 236 --- a/push/GooglePubSubPush.cpp 237 +++ b/push/GooglePubSubPush.cpp 238 @@ -20,7 +20,7 @@ extern "C" { 239 using namespace boost::python; 240 #endif 241 242 -extern std::string szUserDataFolder; 243 +extern std::string szScriptsFolder; 244 245 // this should be filled in by the preprocessor 246 extern const char * Python_exe; 247 @@ -222,11 +222,11 @@ void CGooglePubSubPush::DoGooglePubSubPu 248 249 #ifdef ENABLE_PYTHON 250 #ifdef WIN32 251 - python_DirT << szUserDataFolder << "scripts\\python\\"; 252 - std::string filename = szUserDataFolder + "scripts\\python\\" + "googlepubsub.py"; 253 + python_DirT << szScriptsFolder << "python\\"; 254 + std::string filename = szScriptsFolder + "python\\" + "googlepubsub.py"; 255 #else 256 - python_DirT << szUserDataFolder << "scripts/python/"; 257 - std::string filename = szUserDataFolder + "scripts/python/" + "googlepubsub.py"; 258 + python_DirT << szScriptsFolder << "python/"; 259 + std::string filename = szScriptsFolder + "python/" + "googlepubsub.py"; 260 #endif 261 262 char * argv[1];