Skip to content

Commit dc570e6

Browse files
committed
list network devices while configuring static ip
1 parent 66ec937 commit dc570e6

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

install.sh

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -548,22 +548,32 @@ configure_static_ip() {
548548
fi
549549
fi
550550

551-
# Get a list of available network devices
551+
# Get a list of available network devices and their types
552552
network_devices=($(ip -o link show | awk -F': ' '{print $2}'))
553+
network_device_types=($(ip -o link show | awk -F': ' '{print $2" " $3}'))
554+
555+
# Filter devices to include only Ethernet and Wi-Fi
556+
selected_devices=()
557+
for ((i = 0; i < ${#network_devices[@]}; i++)); do
558+
device_type="${network_device_types[i]}"
559+
if [[ "$device_type" == "ether" || "$device_type" == "wlan" ]]; then
560+
selected_devices+=("${network_devices[i]}")
561+
fi
562+
done
553563

554564
# Check if there are multiple network devices and let the user choose
555-
if [ ${#network_devices[@]} -eq 1 ]; then
556-
selected_device=${network_devices[0]}
565+
if [ ${#selected_devices[@]} -eq 1 ]; then
566+
selected_device=${selected_devices[0]}
557567
else
558568
echo "Select the network device for the static IP configuration:"
559-
for ((i = 0; i < ${#network_devices[@]}; i++)); do
560-
echo "$i) ${network_devices[i]}"
569+
for ((i = 0; i < ${#selected_devices[@]}; i++)); do
570+
echo "$i) ${selected_devices[i]}"
561571
done
562572
read -rp "Enter the number corresponding to your choice: " device_choice
563573

564574
# Validate the user's choice
565-
if [[ "$device_choice" =~ ^[0-9]+$ ]] && [ "$device_choice" -ge 0 ] && [ "$device_choice" -lt ${#network_devices[@]} ]; then
566-
selected_device=${network_devices[device_choice]}
575+
if [[ "$device_choice" =~ ^[0-9]+$ ]] && [ "$device_choice" -ge 0 ] && [ "$device_choice" -lt ${#selected_devices[@]} ]; then
576+
selected_device=${selected_devices[device_choice]}
567577
else
568578
echo "Invalid choice. Aborting static IP configuration."
569579
return

0 commit comments

Comments
 (0)