From: Enrico Zini Date: Sat, 27 Mar 2010 15:50:06 +0000 (+0000) Subject: Look into system hook dir if scripts not found in homedir X-Git-Url: https://git.toastfreeware.priv.at/gregoa/zavai.git/commitdiff_plain/7f11b62646b923c12542bef8ed8021598d555990?ds=sidebyside Look into system hook dir if scripts not found in homedir --- diff --git a/src/config.vala b/src/config.vala index 444bbc2..5a982be 100644 --- a/src/config.vala +++ b/src/config.vala @@ -228,6 +228,24 @@ public class Config refresh_from_lua(); } + /** + * Find a zavai script. + * + * ~/.zavai/NAME is searched first, then /usr/share/zavai/hooks/ + * + * If the script is not found, NULL is returned + */ + public string find_script(string name) + { + string candidate = homedir + "/" + name; + if (FileUtils.test(candidate, FileTest.EXISTS)) + return candidate; + candidate = "/usr/share/zavai/hooks/" + name; + if (FileUtils.test(candidate, FileTest.EXISTS)) + return candidate; + return null; + } + public void run_script(string command) { zavai.log.info("Run program: " + command); diff --git a/src/core.vala b/src/core.vala index 3c31ccd..c971a29 100644 --- a/src/core.vala +++ b/src/core.vala @@ -153,26 +153,40 @@ public abstract class Service : Object, Resource { public abstract class ScriptService : Service { + protected string script; + protected bool script_start() { + string script = zavai.config.find_script(name); + if (script == null) + { + zavai.log.error("Hook " + name + " does not exist"); + return false; + } try { // Then run our own script - zavai.config.run_script(zavai.config.homedir + "/" + name + " start"); + zavai.config.run_script(script + " start"); return true; } catch (Error e) { - zavai.log.error("Running " + zavai.config.homedir + "/" + name + " start: " + e.message); + zavai.log.error("Running " + script + " start: " + e.message); return false; } } protected bool script_stop() { + string script = zavai.config.find_script(name); + if (script == null) + { + zavai.log.error("Hook " + name + " does not exist"); + return false; + } try { // Then run our own script - zavai.config.run_script(zavai.config.homedir + "/" + name + " stop"); + zavai.config.run_script(script + " stop"); return true; } catch (Error e) { - zavai.log.error("Running " + zavai.config.homedir + "/" + name + " stop: " + e.message); + zavai.log.error("Running " + script + " stop: " + e.message); return false; } } @@ -181,7 +195,13 @@ public abstract class ScriptService : Service { string std_out; string std_err; - string command = zavai.config.homedir + "/" + name + " status"; + string script = zavai.config.find_script(name); + if (script == null) + { + zavai.log.error("Hook " + name + " does not exist"); + return false; + } + string command = script + " status"; int res = zavai.config.run_script_sync(command, out std_out, out std_err); if (res != 0) {