]> git.ipfire.org Git - people/jschlag/network.git/commitdiff
config: add new functions
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Mon, 17 Jul 2017 15:24:25 +0000 (17:24 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 17 Jul 2017 20:17:56 +0000 (16:17 -0400)
This patch add two new functions:
config_get_id_from_config()
config_get_hook_from_config

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.config

index 854f4907fcdb24f1bdcc1c09454f62183db0414f..e11a1c2b1736f4eabea78c3809f31f6a83dfffa0 100644 (file)
@@ -51,3 +51,23 @@ config_domainname() {
        # the domain part.
        print "${hostname#*.}"
 }
+
+config_get_id_from_config() {
+       # This function returns the id for a given config name
+       # Example 'dhcp.0' => 0
+       assert [ $# -eq 1 ]
+       local config=${1}
+
+       local hook=$(config_get_hook_from_config ${config})
+       echo "${config//"${hook}."/}"
+
+}
+
+config_get_hook_from_config() {
+       # This function returns the hook for a given config name
+       # Example 'dhcp.0' => dhcp
+       assert [ $# -eq 1 ]
+       local config=${1}
+
+       echo "${config//.*[[:digit:]]/}"
+}