From mboxrd@z Thu Jan 1 00:00:00 1970 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> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0534639691623067630==" List-Id: --===============0534639691623067630== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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}" =3D=3D "start" || "${DO}" =3D=3D "restart= " || "${DO}" =3D=3D "stop" ]]; the exit 1 fi =20 +declare -a VALID_ZONES + +VALID_ZONES+=3D("blue") +VALID_ZONES+=3D("green") +VALID_ZONES+=3D("orange") +VALID_ZONES+=3D("red") + declare -A ZONE_ACTION =20 ZONE_ACTION[blue]=3Dfalse @@ -47,7 +54,7 @@ fi =20 while [ $# -ne 0 ]; do ZONE_VALID=3Dfalse - for i in green red blue orange; do + for i in "${VALID_ZONES[@]}"; do if [ "${i}" =3D=3D "${1}" ]; then ZONE_ACTION[${i}]=3Dtrue ZONE_VALID=3Dtrue @@ -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 =20 boot_mesg "Mounting network file systems..." mount -a -O _netdev @@ -88,26 +87,16 @@ case "${DO}" in evaluate_retval =20 # 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 =20 exit 0 ;; =20 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+=3D" ${i}" fi done --=20 2.30.2 --===============0534639691623067630==--