From patchwork Tue May 23 17:23:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 6910 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4QQh4f6ghdz3wls for ; Tue, 23 May 2023 17:24:02 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4QQh4d1kyTz9Vp; Tue, 23 May 2023 17:24:01 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4QQh4c67r3z30Km; Tue, 23 May 2023 17:24:00 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4QQh4b6ksKz2xR4 for ; Tue, 23 May 2023 17:23:59 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4QQh4b0Hnlz9WJ; Tue, 23 May 2023 17:23:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1684862639; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5aAiS96RsV7mO7Nxbn4i+L36Y2w/Fl0nYmMqAeSywuc=; b=Z8RBiiuJEP5PsufOg2XRoO7gAOgpE0amB3qycasFpJ830a7iA90HSV/WK2LxeEHBSw3Nkc kcZMzgSBjOUU/04iN3hyHL8OTBYXjJEftxZuaJWIg61HPe3MP7uGtdx8bC9LtTnNxoMDvR EjYtREFxaJ4ZyG6ntAr+d31U4Kf9iKZzRJyFxYuG3++BHQTfWQcrxOkwA5A5Cy0ZCCNRiC b3nKE6u81HamIEU+1Zz8iWYFEKqcSaMpWpmYW47KFgF26N7DFpxGdP3sYWOtQXxjg91AtI 752O5aooviAae85vfcwSZyE4ztwddl81NWHhJWQ0e0+QkLeN064h1t6EU/cIxQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1684862639; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5aAiS96RsV7mO7Nxbn4i+L36Y2w/Fl0nYmMqAeSywuc=; b=6tzlwMtWTkU9XXKxsfuSm8figZltLj2oC9+0hdQifhJWhffKJZOkltx4x5FtYNYGa3vTYb zTJRH+hxH6bjEmCw== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [Patch RFC 11/15] network startup: Clean up duplicated Code Date: Tue, 23 May 2023 19:23:11 +0200 Message-Id: <20230523172314.7826-12-jonatan.schlag@ipfire.org> In-Reply-To: <20230523172314.7826-1-jonatan.schlag@ipfire.org> References: <20230523172314.7826-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" This gives us more flexibilty for future changes. Signed-off-by: Jonatan Schlag --- src/initscripts/system/network | 43 +++++++++++++--------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/src/initscripts/system/network b/src/initscripts/system/network index 008fbbe2b..0db64eaad 100644 --- a/src/initscripts/system/network +++ b/src/initscripts/system/network @@ -31,6 +31,13 @@ if ! [[ "${DO}" == "start" || "${DO}" == "restart" || "${DO}" == "stop" ]]; the exit 1 fi +declare -a VALID_ZONES + +VALID_ZONES+=("blue") +VALID_ZONES+=("green") +VALID_ZONES+=("orange") +VALID_ZONES+=("red") + declare -A ZONE_ACTION ZONE_ACTION[blue]=false @@ -47,7 +54,7 @@ fi while [ $# -ne 0 ]; do ZONE_VALID=false - for i in green red blue orange; do + for i in "${VALID_ZONES[@]}"; do if [ "${i}" == "${1}" ]; then ZONE_ACTION[${i}]=true ZONE_VALID=true @@ -65,17 +72,9 @@ done case "${DO}" in start) # Starting interfaces... - # GREEN - ${ZONE_ACTION[green]} && /etc/rc.d/init.d/networking/green start - - # BLUE - ${ZONE_ACTION[blue]} && /etc/rc.d/init.d/networking/blue start - - # ORANGE - ${ZONE_ACTION[orange]} && /etc/rc.d/init.d/networking/orange start - - # RED - ${ZONE_ACTION[red]} && /etc/rc.d/init.d/networking/red start + for i in "${VALID_ZONES[@]}"; do + ${ZONE_ACTION[${i}]} && /etc/rc.d/init.d/networking/${i} start + done boot_mesg "Mounting network file systems..." mount -a -O _netdev @@ -88,26 +87,16 @@ case "${DO}" in evaluate_retval # Stopping interfaces... - # GREEN - ${ZONE_ACTION[green]} && /etc/rc.d/init.d/networking/green stop - - # BLUE - ${ZONE_ACTION[blue]} && /etc/rc.d/init.d/networking/blue stop - - # ORANGE - ${ZONE_ACTION[orange]} && /etc/rc.d/init.d/networking/orange stop - - # RED - if ${ZONE_ACTION[red]}; then - /etc/rc.d/init.d/networking/red stop - fi + for i in "${VALID_ZONES[@]}"; do + ${ZONE_ACTION[${i}]} && /etc/rc.d/init.d/networking/${i} stop + done exit 0 ;; restart) - for i in green red blue orange; do - if {ZONE_ACTION[${i}]}; then + for i in "${VALID_ZONES[@]}"; do + if ${ZONE_ACTION[${i}]}; then ARGS+=" ${i}" fi done