}
function cli_device() {
- local action=${1}
- shift
-
- local device
- local devices=$@
-
- if [ -z "${devices}" ]; then
- devices=$(devices_get_all)
- fi
+ if device_config_exists ${1}; then
+ local device=${1}
+ local action=${2}
+ shift 2
- case "${action}" in
- discover)
- echo "# XXX need to implement --raw here"
- for device in ${devices}; do
- cli_device_discover ${device} $@
- done
- ;;
+ case "${action}" in
+ down|up)
+ device_${action} ${device} $@
+ ;;
+ esac
+ else
+ local action=${1}
+ shift
- show|"")
- for device in ${devices}; do
- cli_device_print ${device}
- done
- ;;
- *)
- cli_usage device
- ;;
- esac
-}
+ case "${action}" in
+ create)
+ device_${action} $@
+ ;;
-function cli_device_print() {
- local device=${1}
+ discover)
+ echo "# XXX need to implement --raw here"
+ local device
+ for device in ${devices}; do
+ cli_device_discover ${device} $@
+ done
+ ;;
- if ! device_exists ${device}; then
- error "Device '${device}' does not exist."
- return ${EXIT_ERROR}
+ show|"")
+ local device
+ for device in $(device_get $@); do
+ device_print ${device}
+ done
+ ;;
+ *)
+ cli_usage device
+ ;;
+ esac
fi
-
- echo "${device}"
- echo " Type: $(device_get_type ${device})"
- echo " Addr: $(device_get_address ${device})"
- echo
}
function cli_device_discover() {
local hook
local out
local ret
- for hook in $(hooks_get_all); do
- out=$(hook_exec ${hook} discover ${device})
+ for hook in $(hook_zone_get_all); do
+ out=$(hook_zone_exec ${hook} discover ${device})
ret=$?
[ ${ret} -eq ${DISCOVER_NOT_SUPPORTED} ] && continue
[ "${up}" = "1" ] || device_set_down ${device}
}
+function cli_port() {
+ if cli_help_requested $@; then
+ cli_usage root-port
+ exit ${EXIT_OK}
+ fi
+
+ local action
+ local port
+
+ if port_exists ${1}; then
+ port=${1}
+ action=${2}
+ shift 2
+
+ # Action aliases
+ case "${action}" in
+ start)
+ action="up"
+ ;;
+ stop)
+ action="down"
+ ;;
+ show)
+ action="status"
+ ;;
+ esac
+
+ case "${action}" in
+ edit|up|down|status)
+ port_${action} ${port} $@
+ ;;
+ *)
+ error "Unrecognized argument: ${action}"
+ exit ${EXIT_ERROR}
+ ;;
+ esac
+ else
+ action=${1}
+ shift
+
+ case "${action}" in
+ create|destroy)
+ port_${action} $@
+ ;;
+ *)
+ error "Unrecognized argument: ${action}"
+ exit ${EXIT_ERROR}
+ ;;
+ esac
+ fi
+}
+
function cli_zone() {
if cli_help_requested $@; then
cli_usage root-zone
action=${2}
shift 2
+ # Action aliases
case "${action}" in
- config|down|edit|port|show|status|up)
+ start)
+ action="up"
+ ;;
+ stop)
+ action="down"
+ ;;
+ show)
+ action="status"
+ ;;
+ esac
+
+ case "${action}" in
+ config|down|edit|port|status|up)
zone_${action} ${zone} $@
;;
*)
cli_start $@
}
+function cli_status() {
+ if cli_help_requested $@; then
+ cli_usage root-status
+ exit ${EXIT_OK}
+ fi
+
+ local zones=$(zones_get $@)
+
+ local zone
+ for zone in ${zones}; do
+ zone_status ${zone}
+ done
+}
+
function cli_help_requested() {
local argument
- for argument in $@; do
+ for argument in ${1}; do
if [ "${argument}" = "help" -o "${argument}" = "-h" -o "${argument}" = "--help" ]; then
return ${EXIT_OK}
fi
echo " start - ..."
echo " stop - ..."
echo " restart - ..."
+ echo " status - ..."
echo
echo " config - ..."
echo
echo " device - ..."
- echo " show - ???"
echo " zone - ..."
echo
;;
echo " One can pass several parameters to only process a subset of all"
echo " available zones:"
echo
- echo -e " ${BOLD}--local-only${NORMAL}"
+ echo -e " ${COLOUR_BOLD}--local-only${COLOUR_NORMAL}"
+ echo " Process all local zones which includes every zone without red."
+ echo
+ echo -e " ${COLOUR_BOLD}--remote-only${COLOUR_NORMAL}"
+ echo " Process all remote zones which means only the red ones."
+ echo
+ echo -e " ${COLOUR_BOLD}--all${COLOUR_NORMAL}"
+ echo " Process all zones. This is the default parameter."
+ echo
+ echo " Additionally, you can pass one or more zone names which will"
+ echo " be processed."
+ echo
+ ;;
+ root-status)
+ echo "${0}: ${what#root-} [--local-only|--remote-only|--all|<zone>...]"
+ echo
+ echo " This commands shows status information of all zones by default."
+ echo " One can pass several parameters to only process a subset of all"
+ echo " available zones:"
+ echo
+ echo -e " ${COLOUR_BOLD}--local-only${COLOUR_NORMAL}"
echo " Process all local zones which includes every zone without red."
echo
- echo -e " ${BOLD}--remote-only${NORMAL}"
+ echo -e " ${COLOUR_BOLD}--remote-only${COLOUR_NORMAL}"
echo " Process all remote zones which means only the red ones."
echo
- echo -e " ${BOLD}--all${NORMAL}"
+ echo -e " ${COLOUR_BOLD}--all${COLOUR_NORMAL}"
echo " Process all zones. This is the default parameter."
echo
echo " Additionally, you can pass one or more zone names which will"
echo
echo " Create or remove a zone."
echo
- echo -e " ${BOLD}create <zone> <type> <options>${NORMAL}"
+ echo -e " ${COLOUR_BOLD}create <zone> <type> <options>${COLOUR_NORMAL}"
echo " Create a new zone of type <type> where <zone> is an allowed"
echo " zone name."
echo
- echo -e " ${BOLD}remove <zone>${NORMAL}"
+ echo -e " ${COLOUR_BOLD}remove <zone>${COLOUR_NORMAL}"
echo " Remove the zone <zone>."
echo
echo " You may also edit the configuration of the zones."
echo
- echo -e " ${BOLD}<zone> ...${NORMAL}"
+ echo -e " ${COLOUR_BOLD}<zone> ...${COLOUR_NORMAL}"
echo " Edit the zone <zone>."
echo
;;
echo "Network configuration tool. Report all bugs to <http://bugs.ipfire.org>."
}
+
+function cli_status_headline() {
+ local zone=${1}
+
+ local state="${COLOUR_DOWN}DOWN${COLOUR_NORMAL}"
+ zone_is_up ${zone} && state="${COLOUR_UP}UP${COLOUR_NORMAL}"
+
+ echo -e "${zone} - ${state} - $(zone_get_hook ${zone})"
+}
+
+function cli_headline() {
+ echo
+ echo -e "${COLOUR_BOLD}$@${COLOUR_NORMAL}"
+}