From a186676d636aa5e5eed9ae554f0608082d560d38 Mon Sep 17 00:00:00 2001 From: Mykola Malkov Date: Wed, 10 Oct 2018 15:53:51 +0300 Subject: [PATCH] Fix non-interactive interface choosing In interactive mode user choose an interface and its number is used in the code. In function 'configiface' the actual interface is taken from NETDEVICES by this number. In non-interactive mode we have an interface name and it was used as index in NETDEVICES which failed and the 1st interface was always taken. It does not matter what interface was passed in NET_DEV variable script tried to configure eth0. Fix it with getting interface number by its name. --- sbin/netcardconfig | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sbin/netcardconfig b/sbin/netcardconfig index f57552b..41f08c9 100755 --- a/sbin/netcardconfig +++ b/sbin/netcardconfig @@ -683,7 +683,20 @@ while (true); do $DIALOG --menu "$MESSAGE1" 18 60 12 "${DEVICELIST[@]}" "${EXITMENU[@]}" 2>"$TMP" || bailout read -r DV <"$TMP" ; rm -f "$TMP" else - DV="${NET_DEV}" + # we have interface name so we need to find its number in NETDEVICES + DV=0 + found=false + for DV in "${!NETDEVICES[@]}"; do + if [[ "${NETDEVICES[$DV]}" =~ ^"${NET_DEV} " ]]; then + found=true + break + fi + done + if ! "${found}"; then + echo "There is no interface ${NET_DEV} in the system" >&2 + bailout 1 + fi + [[ -z "${IFACEDONE}" ]] || bailout fi [ "$DV" = "$EXITKEY" ] && bailout -- 2.1.4