From: Michael Tremer Date: Fri, 16 Jul 2010 16:15:24 +0000 (+0200) Subject: network: Add reset option. X-Git-Tag: 001~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f90e550bce4895568c7760df597c82638a3d2f72;p=network.git network: Add reset option. --- diff --git a/functions.cli b/functions.cli index 56db94c0..14b764d9 100644 --- a/functions.cli +++ b/functions.cli @@ -310,6 +310,49 @@ function cli_status() { done } +function cli_reset() { + if cli_help_requested $@; then + cli_usage root-reset + exit ${EXIT_OK} + fi + + warning_log "Will reset the whole network configuration!!!" + + # Force mode is disabled by default + local force=0 + + while [ $# -gt 0 ]; do + case "${1}" in + --force|-f) + force=1 + ;; + esac + shift + done + + # If we are not running in force mode, we ask the user if he does know + # what he is doing. + if ! enabled force; then + if ! cli_yesno "Do you really want to reset the whole network configuration?"; then + exit ${EXIT_ERROR} + fi + fi + + local zone + for zone in $(zones_get --all); do + zone_remove ${zone} + done + + local port + for port in $(ports_get --all); do + port_remove ${port} + done + + # XXX recreate ethernet ports + + exit ${EXIT_OK} +} + function cli_help_requested() { local argument for argument in ${1}; do @@ -351,6 +394,16 @@ function cli_usage() { echo " ${0} ${what#root-} DEBUG=1 ..." echo ;; + root-reset) + echo "${0}: ${what#root-} [--force | -f]" + echo + echo " This command resets the network configuration." + echo + echo " Will delete all zones and ports." + echo + echo -e " ${COLOUR_RED}USE WITH CAUTION!${COLOUR_NORMAL}" + echo + ;; root-start|root-stop|root-restart) echo "${0}: ${what#root-} [--local-only|--remote-only|--all|...]" echo @@ -436,3 +489,18 @@ function cli_headline() { echo echo -e "${COLOUR_BOLD}$@${COLOUR_NORMAL}" } + +function cli_yesno() { + local message="$@ [y/N] " + local yesno + + echo + echo -ne "${message}" + read yesno + + if listmatch ${yesno} y Y j J yes YES Yes; then + return ${EXIT_OK} + fi + + return ${EXIT_ERROR} +} diff --git a/functions.ports b/functions.ports index 25ce046c..d0d7dee6 100644 --- a/functions.ports +++ b/functions.ports @@ -93,6 +93,10 @@ function port_destroy() { rm -f $(port_file ${port}) } +function port_remove() { + port_destroy $@ +} + function port_edit() { port_cmd edit $@ } @@ -128,3 +132,13 @@ function port_cmd() { hook_exec port ${hook} ${cmd} ${port} $@ } + +function ports_get() { + local port + for port in $(port_dir)/*; do + port=$(basename ${port}) + if port_exists ${port}; then + echo "${port}" + fi + done +} diff --git a/network b/network index e315b19a..d4a75b83 100755 --- a/network +++ b/network @@ -38,7 +38,7 @@ done # Process the given action case "${action}" in - config|port|device|zone|start|stop|restart|status) + config|port|device|zone|start|stop|restart|status|reset) cli_${action} $@ ;;