# #
###############################################################################
+function hook_dir() {
+ local type=${1}
+
+ if [ -n "${type}" ]; then
+ type="/${type}s"
+ fi
+
+ echo "${HOOKS_DIR}${type}"
+}
+
function hook_exists() {
- local hook=${1}
+ local type=${1}
+ local hook=${2}
+
+ assert isset type
+ assert isset hook
+
+ local hook_dir=$(hook_dir ${type})
+
+ [ -d "${hook_dir}/${hook}" ] && return ${EXIT_ERROR}
+
+ [ -x "${hook_dir}/${hook}" ]
+}
+
+function hook_exec() {
+ local type=${1}
+ local hook=${2}
+ shift 2
+
+ assert isset type
+ assert isset hook
+
+ if ! hook_exists ${type} ${hook}; then
+ error "Hook '${hook}' does not exist."
+ return ${EXIT_ERROR}
+ fi
+
+ exec_cmd $(hook_dir ${type})/${hook} $@
+}
+
+function config_get_hook() {
+ local config=${1}
+
+ assert isset config
+ assert [ -e "${config}" ]
+
+ (
+ . ${config}
+ echo "${HOOK}"
+ )
+}
- [ -d "${HOOKS_DIR}/${hook}" ] && return ${EXIT_ERROR}
+## Wrappers around the hook functions for zones
- [ -x "${HOOKS_DIR}/${hook}" ]
+function hook_zone_exists() {
+ hook_exists zone $@
}
-function hook_port_exists() {
+function hook_zone_port_exists() {
local hook_zone=${1}
local hook_port=${2}
- hook_exists ${hook_zone} || return ${EXIT_ERROR}
+ hook_zone_exists ${hook_zone} || return ${EXIT_ERROR}
- [ -x "${HOOKS_DIR}/${hook_zone}.ports/${hook_port}" ]
+ [ -x "$(hook_dir zone)/${hook_zone}.ports/${hook_port}" ]
}
-function hook_config_exists() {
+function hook_zone_config_exists() {
local hook_zone=${1}
local hook_config=${2}
- hook_exists ${hook_zone} || return ${EXIT_ERROR}
+ hook_zone_exists ${hook_zone} || return ${EXIT_ERROR}
- [ -x "${HOOKS_DIR}/${hook_zone}.configs/${hook_config}" ]
+ [ -x "$(hook_dir zone)/${hook_zone}.configs/${hook_config}" ]
}
-function hook_has_ports() {
+function hook_zone_has_ports() {
local hook=${1}
- [ -d "${HOOKS_DIR}/${hook}.ports" ]
+ [ -d "$(hook_dir zone)/${hook}.ports" ]
}
-function hook_has_configs() {
- local hook=${1}
-
- [ -d "${HOOKS_DIR}/${hook}.configs" ]
+function hook_zone_port_exists() {
+ : # XXX WANTED
}
-function hook_exec() {
+function hook_zone_has_configs() {
local hook=${1}
- shift
- if ! hook_exists ${hook}; then
- error "Hook '${hook}' does not exist."
- return ${EXIT_ERROR}
- fi
+ [ -d "$(hook_dir zone)/${hook}.configs" ]
+}
- ${SHELL} ${HOOKS_DIR}/${hook} $@
+function hook_zone_exec() {
+ hook_exec zone $@
}
-function hook_port_exec() {
+function hook_zone_port_exec() {
local hook_zone=${1}
local hook_port=${2}
shift 2
- if ! hook_exists ${hook_zone}; then
+ if ! hook_exists zone ${hook_zone}; then
error "Hook '${hook_zone}' does not exist."
return ${EXIT_ERROR}
fi
- if ! hook_port_exists ${hook_zone} ${hook_port}; then
+ if ! hook_zone_port_exists ${hook_zone} ${hook_port}; then
error "Port hook '${hook_port}' does not exist."
return ${EXIT_ERROR}
fi
- ${SHELL} ${HOOKS_DIR}/${hook_zone}.ports/${hook_port} $@
+ exec_cmd $(hook_dir zone)/${hook_zone}.ports/${hook_port} $@
}
-function hook_config_exec() {
+function hook_zone_config_exec() {
local hook_zone=${1}
local hook_config=${2}
shift 2
- if ! hook_exists ${hook_zone}; then
+ assert isset hook_zone
+ assert isset hook_config
+
+ if ! hook_zone_exists ${hook_zone}; then
error "Hook '${hook_zone}' does not exist."
return ${EXIT_ERROR}
fi
- if ! hook_config_exists ${hook_zone} ${hook_config}; then
+ if ! hook_zone_config_exists ${hook_zone} ${hook_config}; then
error "Config hook '${hook_config}' does not exist."
return ${EXIT_ERROR}
fi
- ${SHELL} ${HOOKS_DIR}/${hook_zone}.configs/${hook_config} $@
+ exec_cmd $(hook_dir zone)/${hook_zone}.configs/${hook_config} $@
}
-function hooks_get_all() {
+function hook_zone_get_all() {
local type=${1}
local hook
- for hook in ${HOOKS_DIR}/*; do
+ for hook in $(hook_dir zone)/*; do
hook=$(basename ${hook})
- hook_exists ${hook} && echo "${hook}"
- done | sort
+ hook_zone_exists ${hook} && echo "${hook}"
+ done
}
-function hook_ports_get_all() {
+function hook_zone_ports_get_all() {
local hook=${1}
- if ! hook_exists ${hook}; then
+ if ! hook_exists zone ${hook}; then
error "Hook '${hook}' does not exist."
return ${EXIT_ERROR}
fi
- local hook
- for hook in ${HOOKS_DIR}/${zone}.ports/*; do
- hook=$(basename ${hook})
- ## XXX executeable?
- echo "${hook}"
- done | sort
+ # If the zone hook has got no ports we exit silently
+ if ! hook_zone_has_ports ${hook}; then
+ return ${EXIT_OK}
+ fi
+
+ local h
+ for h in $(hook_dir zone)/${hook}.ports/*; do
+ h=$(basename ${h})
+ if hook_zone_port_exists ${hook} ${h}; then
+ echo "${h}"
+ fi
+ done
}
-function config_get_hook() {
- local config=${1}
+function hook_zone_configs_get_all() {
+ local hook=${1}
- (
- . ${config}
- echo "${HOOK}"
- )
+ if ! hook_exists zone ${hook}; then
+ error "Hook '${hook}' does not exist."
+ return ${EXIT_ERROR}
+ fi
+
+ # If the zone hook has got no configurations we exit silently
+ if ! hook_zone_has_configs ${hook}; then
+ return ${EXIT_OK}
+ fi
+
+ local h
+ for h in $(hook_dir zone)/${hook}.configs/*; do
+ h=$(basename ${h})
+ if hook_zone_config_exists ${hook} ${h}; then
+ echo "${h}"
+ fi
+ done
+
+ return ${EXIT_OK}
}