]> git.ipfire.org Git - network.git/blobdiff - src/header-config
Makefile: Fix typo in localstatedir
[network.git] / src / header-config
index ec85a70ec3c51487a056cc36363f0c2ecf07ea94..ed647cdfc2af6d3dab19b45b6fdb43cd9cc3d6b1 100644 (file)
 #                                                                             #
 ###############################################################################
 
+# Allow only one instance of this hook
+HOOK_UNIQUE="true"
+
 hook_new() {
-       cmd_not_implemented
+       local zone="${1}"
+       shift
+
+       # Check if we are allowed to have multiple configurations of $HOOK
+       if enabled HOOK_UNIQUE && zone_config_hook_is_configured "${zone}" "${HOOK}"; then
+               error "You can only have one configuration of type ${HOOK}"
+               return ${EXIT_CONF_ERROR}
+       fi
+
+       local id=$(zone_config_get_new_id ${zone})
+       log DEBUG "ID for the config is: ${id}"
+
+       # Import all default variables
+       hook_set_defaults
+
+       # Parse command line arguments
+       if ! hook_parse_cmdline "${id}" "$@"; then
+               # Return an error if the parsing of the cmd line fails
+               return ${EXIT_ERROR}
+       fi
+
+       # Write configuration to disk
+       if ! zone_config_settings_write "${zone}" "${HOOK}" "${id}"; then
+               return ${EXIT_ERROR}
+       fi
+
+       return ${EXIT_OK}
 }
 
 hook_edit() {
@@ -47,7 +76,7 @@ hook_edit() {
                fi
        fi
 
-       local ${HOOK_CONFIG_SETTINGS}
+       local ${HOOK_SETTINGS}
 
        # If reading the config fails we cannot go on
        if ! zone_config_settings_read "${zone}" "${config}"; then
@@ -55,7 +84,7 @@ hook_edit() {
                return ${EXIT_ERROR}
        fi
 
-       if ! hook_parse_cmdline "$@"; then
+       if ! hook_parse_cmdline "${id}" "$@"; then
                # Return an error if the parsing of the cmd line fails
                return ${EXIT_ERROR}
        fi