diff --git a/lib/armbian-configng/config.ng.jobs.json b/lib/armbian-configng/config.ng.jobs.json index a1a52e5dc..09c0a131e 100644 --- a/lib/armbian-configng/config.ng.jobs.json +++ b/lib/armbian-configng/config.ng.jobs.json @@ -290,14 +290,16 @@ { "id": "N02", "description": "Apply configuration", - "command": [ - "netplan apply" + "command": [ + "get_user_continue \"This will apply new network configuration\n\nwould you like to continue?\" process_input", + "echo ok; read; rm -f /tmp/*.yaml", + "#netplan apply" ], "status": "Active", "doc_link": "", "src_reference": "", "author": "https://github.com/igorpecovnik", - "condition": "" + "condition": "diff_netplan_configs" }, { "id": "N03", @@ -330,12 +332,8 @@ "id": "N06", "description": "Set fixed IP address", "command": [ - "rm -f /etc/netplan/10-dhcp-all-interfaces.yaml", - "eth_index=\"eth0\"", - "eth_ip=\"10.0.10.199/24\"", - "netplan set --origin-hint 30-eth0-static-interfaces renderer=networkd", - "netplan set --origin-hint 30-eth0-static-interfaces ethernets.${eth_index}.addresses=[$eth_ip]", - "show_message <<< \"$(sudo netplan get ethernets)\"" + "choose_adapter", + "[[ -n \"$IP_ADDRESS\" ]] && netplan_wrapper \"10-dhcp-all-interfaces\" \"ethernets\" \"networkd\" \"${SELECTED_ADAPTER}\" \"$IP_ADDRESS\"" ], "status": "Active", "doc_link": "", diff --git a/lib/armbian-configng/config.ng.network.sh b/lib/armbian-configng/config.ng.network.sh index 9d20e7ddc..2fe959257 100644 --- a/lib/armbian-configng/config.ng.network.sh +++ b/lib/armbian-configng/config.ng.network.sh @@ -214,4 +214,91 @@ systemctl enable dnsmasq whiptail --msgbox "Hotspot setup complete. Rebooting now." 8 40 reboot +} + + +module_options+=( +["choose_adapter,author"]="Igor Pecovnik" +["choose_adapter,ref_link"]="" +["choose_adapter,feature"]="choose_adapter" +["choose_adapter,desc"]="Displays available adapters" +["choose_adapter,example"]="choose_adapter" +["choose_adapter,doc_link"]="" +["choose_adapter,status"]="review" +) +# +# Function to check the internet connection +# +function choose_adapter() { + + local type=$1 + + LIST=() + HIDE_IP_PATTERN="^dummy0|^lo|^docker" + for f in /sys/class/net/*; do + interface=$(basename $f) + if [[ $intf =~ $HIDE_IP_PATTERN ]]; then + continue + else + QUERY=$(ip -br addr show dev $interface | grep UP | awk '{print $1" " $3}') + [[ -n $QUERY ]] && LIST+=($QUERY) + 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 ]]; 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 + +} + +module_options+=( +["netplan_wrapper,author"]="Igor Pecovnik" +["netplan_wrapper,ref_link"]="" +["netplan_wrapper,feature"]="netplan_wrapper" +["netplan_wrapper,desc"]="Displays available adapters" +["netplan_wrapper,example"]="netplan_wrapper" +["netplan_wrapper,doc_link"]="" +["netplan_wrapper,status"]="review" +) +# +# Function to check the internet connection +# +function netplan_wrapper() { + + local config=$1 + local type=$2 + local renderer=$3 + local adapter=$4 + local address=$5 + + #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})" + +} + +function diff_netplan_configs(){ + + + [[ ! -f /tmp/10-dhcp-all-interfaces.yaml ]] && cp /etc/netplan/10-dhcp-all-interfaces.yaml /tmp/ + [[ ! -f /tmp/20-dhcp-wlan-interface.yaml ]] && cp /etc/netplan/20-dhcp-wlan-interface.yaml /tmp/ + + HASH_ETHERNETS="$(cat /etc/netplan/10-dhcp-all-interfaces.yaml | awk '/ethernets/{y=1;next}y' | xargs | md5sum)" + HASH_WIFI="$(cat /etc/netplan/20-dhcp-wlan-interface.yaml | awk '/wifis/{y=1;next}y' | xargs | md5sum)" + + HASH_TMP_ETHERNETS="$(cat /tmp/10-dhcp-all-interfaces.yaml | awk '/ethernets/{y=1;next}y' | xargs | md5sum)" + HASH_TMP_WIFI="$(cat /tmp/20-dhcp-wlan-interface.yaml | awk '/wifis/{y=1;next}y' | xargs | md5sum)" + + #echo "$HASH_ETHERNETS $HASH_WIFI $HASH_TMP_ETHERNETS $HASH_TMP_WIFI" + + + + + if [[ "$HASH_ETHERNETS" == "$HASH_TMP_ETHERNETS" ]] && [[ "$HASH_WIFI" == "$HASH_TMP_WIFI" ]]; then + return 0 + else + return 1 + fi } \ No newline at end of file