From bcae80898d18bd8640efae10c3f3dff93c1be3d0 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Mon, 10 Oct 2011 15:50:35 +0200 Subject: [PATCH] proto-shell: move all proto init code to a separate function --- dummy/netifd-proto.sh | 68 ++++++++++++++++++++++--------------------- dummy/proto/ppp.sh | 1 + 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/dummy/netifd-proto.sh b/dummy/netifd-proto.sh index 2fbfd4e..7ce88ee 100755 --- a/dummy/netifd-proto.sh +++ b/dummy/netifd-proto.sh @@ -36,41 +36,43 @@ _proto_do_setup() { eval "$1_setup \"$interface\" \"$ifname\"" } -proto="$1"; shift -cmd="$1"; shift +init_proto() { + proto="$1"; shift + cmd="$1"; shift -case "$cmd" in - dump) - add_protocol() { - no_device=0 - available=0 + case "$cmd" in + dump) + add_protocol() { + no_device=0 + available=0 - add_default_handler "$1_init_config" + add_default_handler "$1_init_config" - json_init - json_add_string "name" "$1" - eval "$1_init" - json_add_boolean no-device "$no_device" - json_add_boolean available "$available" - json_add_array "config" - eval "$1_init_config" - json_close_array - json_dump - } - ;; - setup|teardown) - interface="$1"; shift - data="$1"; shift - ifname="$1"; shift + json_init + json_add_string "name" "$1" + eval "$1_init" + json_add_boolean no-device "$no_device" + json_add_boolean available "$available" + json_add_array "config" + eval "$1_init_config" + json_close_array + json_dump + } + ;; + setup|teardown) + interface="$1"; shift + data="$1"; shift + ifname="$1"; shift - add_protocol() { - [[ "$proto" == "$1" ]] || return 0 + add_protocol() { + [[ "$proto" == "$1" ]] || return 0 - case "$cmd" in - setup) _proto_do_setup "$1";; - teardown) _proto_do_teardown "$1" ;; - *) return 1 ;; - esac - } - ;; -esac + case "$cmd" in + setup) _proto_do_setup "$1";; + teardown) _proto_do_teardown "$1" ;; + *) return 1 ;; + esac + } + ;; + esac +} diff --git a/dummy/proto/ppp.sh b/dummy/proto/ppp.sh index 9a35fc9..5078833 100755 --- a/dummy/proto/ppp.sh +++ b/dummy/proto/ppp.sh @@ -1,6 +1,7 @@ #!/bin/sh . ../netifd-proto.sh +init_proto "$@" ppp_init_config() { proto_config_add_string "username" -- 2.25.1