From b2e7c439a0982af4a357245fd54c9bd970f4ecb6 Mon Sep 17 00:00:00 2001 From: Igor Pecovnik Date: Sun, 8 Sep 2024 09:00:50 +0200 Subject: [PATCH] Iprove wrapper function --- lib/armbian-configng/config.ng.jobs.json | 61 ++++++++++++++--------- lib/armbian-configng/config.ng.network.sh | 48 +++++++++++++----- 2 files changed, 73 insertions(+), 36 deletions(-) diff --git a/lib/armbian-configng/config.ng.jobs.json b/lib/armbian-configng/config.ng.jobs.json index 956e962a7..ca4af5c22 100644 --- a/lib/armbian-configng/config.ng.jobs.json +++ b/lib/armbian-configng/config.ng.jobs.json @@ -287,11 +287,11 @@ "description": "Configure network interfaces", "sub": [ { - "id": "N03", + "id": "N02", "description": "Wired", "sub": [ { - "id": "N04", + "id": "N06", "description": "Show configuration", "command": [ "show_message <<< \"$(sudo netplan get ethernets)\"" ], "condition": "[ -f /etc/netplan/30-*static-interfaces.yaml ] || [ -f /etc/netplan/10-dhcp-all-interfaces.yaml ]", @@ -299,35 +299,38 @@ "author": "Igor Pecovnik" }, { - "id": "N05", + "id": "N07", "description": "Enable DHCP on all interfaces", - "command": [ - "rm -f /etc/netplan/30-*-static-interfaces.yaml", - "netplan set --origin-hint 10-dhcp-all-interfaces renderer=networkd", - "netplan set --origin-hint 10-dhcp-all-interfaces ethernets.all-eth-interfaces.dhcp4=true", - "netplan set --origin-hint 10-dhcp-all-interfaces ethernets.all-eth-interfaces.dhcp6=true", - "netplan set --origin-hint 10-dhcp-all-interfaces ethernets.all-eth-interfaces.match.name=e*", - "show_message <<< \"$(sudo netplan get ethernets)\"" - ], + "command": ["netplan_wrapper \"dhcp_all_wired_interfaces\" \"10-dhcp-all-interfaces\" \"\" \"networkd\""], "status": "Active", "author": "Igor Pecovnik", "condition": "[ ! -f /etc/netplan/10-dhcp-all-interfaces.yaml ]" }, { - "id": "N06", + "id": "N08", "description": "Set fixed IP address", + "command": ["netplan_wrapper \"set_ip\" \"10-dhcp-all-interfaces\" \"ethernets\" \"networkd\""], + "status": "Active", + "doc_link": "", + "src_reference": "", + "author": "Igor Pecovnik", + "condition": "[ -f /etc/netplan/10-dhcp-all-interfaces.yaml ] || true" + }, + { + "id": "N09", + "description": "Disable IPV6 in wireless configuration", "command": [ - "choose_adapter \"e\"", - "[[ -n \"$IP_ADDRESS\" ]] && netplan_wrapper \"10-dhcp-all-interfaces\" \"ethernets\" \"networkd\" \"${SELECTED_ADAPTER}\" \"$IP_ADDRESS\"" + "choose_adapter \"e\" \"false\"", + "[[ -n \"$SELECTED_ADAPTER\" ]] && netplan_wrapper \"disable_ipv6\" \"10-dhcp-all-interfaces\" \"ethernets\" \"networkd\" \"${SELECTED_ADAPTER}\" \"$IP_ADDRESS\"" ], "status": "Active", "doc_link": "", "src_reference": "", "author": "Igor Pecovnik", - "condition": "[ -f /etc/netplan/10-dhcp-all-interfaces.yaml ] || true" + "condition": "[ -f /etc/netplan/10-dhcp-all-interfaces.yaml ]" }, { - "id": "N07", + "id": "N11", "description": "Disable wired networking", "command": [ "rm -f /etc/netplan/10-dhcp-all-interfaces.yaml /etc/netplan/30-*static-interfaces.yaml" ], "condition": "[ -f /etc/netplan/30-*static-interfaces.yaml ] || [ -f /etc/netplan/10-dhcp-all-interfaces.yaml ]", @@ -337,11 +340,11 @@ ] }, { - "id": "N08", + "id": "N03", "description": "Wireless", "sub": [ { - "id": "N09", + "id": "N25", "description": "Show configuration", "command": [ "show_message <<< \"$(sudo netplan get wifis)\"" ], "condition": "[ -f /etc/netplan/20-dhcp-wlan-interface.yaml ]", @@ -349,7 +352,7 @@ "author": "Igor Pecovnik" }, { - "id": "N10", + "id": "N26", "description": "Disable wireless networking", "command": [ "rm -f /etc/netplan/20-dhcp-wlan-interface.yaml" ], "condition": "[ -f /etc/netplan/20-dhcp-wlan-interface.yaml ]", @@ -357,7 +360,7 @@ "author": "Igor Pecovnik" }, { - "id": "N11", + "id": "N27", "description": "Disable IPV6 in wireless configuration", "command": [ "wifi_index=$(netplan get wifis | head -1 | cut -d\":\" -f1)", @@ -369,7 +372,7 @@ "author": "Igor Pecovnik" }, { - "id": "N12", + "id": "N28", "description": "Enable DHCP on wireless network interface", "command": [ "wifi_connect" @@ -381,11 +384,21 @@ ] }, { - "id": "N02", + "id": "N04", + "description": "Show configs", + "command": [ "show_message <<< \"$(sudo netplan get all)\"" ], + "status": "Active", + "doc_link": "", + "src_reference": "", + "author": "https://github.com/igorpecovnik", + "condition": "" + }, + { + "id": "N05", "description": "Apply configs", "command": [ - "get_user_continue \"This will apply new network configuration\n\nwould you like to continue?\" process_input", - "netplan apply" + "get_user_continue \"This will apply new network configuration\n\nwould you like to continue?\" process_input", + "netplan apply" ], "status": "Active", "doc_link": "", diff --git a/lib/armbian-configng/config.ng.network.sh b/lib/armbian-configng/config.ng.network.sh index 0d6062ffc..aaa49540e 100644 --- a/lib/armbian-configng/config.ng.network.sh +++ b/lib/armbian-configng/config.ng.network.sh @@ -235,6 +235,8 @@ function choose_adapter() { local getip=$2 LIST=() + # this functionality is exposed only on wired network + [[ $type == e ]] && LIST=("all-eth-interfaces" "") HIDE_IP_PATTERN="^dummy0|^lo|^docker" for f in /sys/class/net/*; do interface=$(basename $f) @@ -246,9 +248,9 @@ function choose_adapter() { fi done LIST_LENGTH=$((${#LIST[@]}/2)); - SELECTED_ADAPTER=$(whiptail --title "Select interface" --menu "" $((${LIST_LENGTH} + 8)) 40 $((${LIST_LENGTH})) "${LIST[@]}" 3>&1 1>&2 2>&3) - if [[ -n $SELECTED_ADAPTER && "${getip}" != false ]]; then - IP_ADDRESS=$(whiptail --title "Enter new IP for $SELECTED_ADAPTER" --inputbox "\nValid format: 1.2.3.4/5" 9 40 3>&1 1>&2 2>&3) + adapter=$(whiptail --title "Select interface" --menu "" $((${LIST_LENGTH} + 8)) 40 $((${LIST_LENGTH})) "${LIST[@]}" 3>&1 1>&2 2>&3) + if [[ -n $adapter && adapter != "all-eth-interfaces" && "${getip}" != false ]]; then + address=$(whiptail --title "Enter new IP for $SELECTED_ADAPTER" --inputbox "\nValid format: 1.2.3.4/5" 9 40 3>&1 1>&2 2>&3) fi } @@ -287,15 +289,37 @@ module_options+=( # function netplan_wrapper() { - local config=$1 - local type=$2 - local renderer=$3 - local adapter=$4 - local address=$5 + local what=$1 + local config=$2 + local type=$3 + local renderer=$4 + local adapter=$5 + local address=$6 + + case "$1" in + dhcp_all_wired_interfaces) + rm -f /etc/netplan/30-*-static-interfaces.yaml + netplan set --origin-hint ${config} renderer=${renderer} + netplan set --origin-hint ${config} ethernets.all-eth-interfaces.dhcp4=true + netplan set --origin-hint ${config} ethernets.all-eth-interfaces.dhcp6=true + netplan set --origin-hint ${config} ethernets.all-eth-interfaces.match.name=e* + show_message <<< "$(sudo netplan get ${type})" + ;; + set_ip) + choose_adapter "e" + netplan set --origin-hint ${config} renderer=${renderer} + netplan set --origin-hint ${config} ethernets.${adapter}.addresses=[$address] + show_message <<< "$(sudo netplan get ${type})" + ;; + disable_ipv6) + netplan set --origin-hint ${config} renderer=${renderer} + netplan set --origin-hint ${config} ethernets.${adapter}.dhcp6=false + show_message <<< "$(sudo netplan get ${type})" + ;; + *) + esac + + - #rm -f /etc/netplan/${config}.yaml - netplan set --origin-hint ${config} renderer=${renderer} - netplan set --origin-hint ${config} ethernets.${adapter}.addresses=[$address] - show_message <<< "$(sudo netplan get ${type})" } \ No newline at end of file