From c96ec28171ad36a891f5738355e491d57caa79bf 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 | 32 +++++++++++++---- lib/armbian-configng/config.ng.network.sh | 43 +++++++++++++++++------ 2 files changed, 58 insertions(+), 17 deletions(-) diff --git a/lib/armbian-configng/config.ng.jobs.json b/lib/armbian-configng/config.ng.jobs.json index 956e962a7..f2155f8c2 100644 --- a/lib/armbian-configng/config.ng.jobs.json +++ b/lib/armbian-configng/config.ng.jobs.json @@ -302,12 +302,7 @@ "id": "N05", "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)\"" + "netplan_wrapper \"dhcp_all_wired_interfaces\" \"10-dhcp-all-interfaces\" \"\" \"networkd\"" ], "status": "Active", "author": "Igor Pecovnik", @@ -318,7 +313,7 @@ "description": "Set fixed IP address", "command": [ "choose_adapter \"e\"", - "[[ -n \"$IP_ADDRESS\" ]] && netplan_wrapper \"10-dhcp-all-interfaces\" \"ethernets\" \"networkd\" \"${SELECTED_ADAPTER}\" \"$IP_ADDRESS\"" + "[[ -n \"$IP_ADDRESS\" ]] && netplan_wrapper \"set_ip\" \"10-dhcp-all-interfaces\" \"ethernets\" \"networkd\" \"${SELECTED_ADAPTER}\" \"$IP_ADDRESS\"" ], "status": "Active", "doc_link": "", @@ -326,6 +321,19 @@ "author": "Igor Pecovnik", "condition": "[ -f /etc/netplan/10-dhcp-all-interfaces.yaml ] || true" }, + { + "id": "N061", + "description": "Disable IPV6 in wireless configuration", + "command": [ + "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 ]" + }, { "id": "N07", "description": "Disable wired networking", @@ -380,6 +388,16 @@ } ] }, + { + "id": "N202", + "description": "Show configs", + "command": [ "command": [ "show_message <<< \"$(sudo netplan get all)\"" ], + "status": "Active", + "doc_link": "", + "src_reference": "", + "author": "https://github.com/igorpecovnik", + "condition": "" + }, { "id": "N02", "description": "Apply configs", diff --git a/lib/armbian-configng/config.ng.network.sh b/lib/armbian-configng/config.ng.network.sh index 0d6062ffc..4b8215079 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) @@ -247,7 +249,7 @@ function choose_adapter() { 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 + if [[ -n $SELECTED_ADAPTER && SELECTED_ADAPTER != "all-eth-interfaces" && "${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) fi @@ -287,15 +289,36 @@ 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) + 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