Skip to content

Commit

Permalink
Add apaptor selection and IP input box
Browse files Browse the repository at this point in the history
  • Loading branch information
igorpecovnik committed Sep 5, 2024
1 parent 5ed24bc commit c9d9bbe
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/armbian-configng/config.ng.jobs.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,14 @@
"id": "N02",
"description": "Apply configuration",
"command": [
"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": "",
"src_reference": "",
"author": "https://github.com/igorpecovnik",
"condition": ""
"condition": "diff_netplan_configs"
},
{
"id": "N03",
Expand Down Expand Up @@ -330,12 +331,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": "",
Expand Down
74 changes: 74 additions & 0 deletions lib/armbian-configng/config.ng.network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,78 @@ 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})"

}

diff_netplan_configs(){

if [[ "$(cat /etc/netplan/10-dhcp-all-interfaces.yaml | awk '/ethernets/{y=1;next}y' | xargs | md5sum)" != "$(netplan get ethernets | xargs | md5sum)" ]]; then
return 1
elif [[ "$(cat /etc/netplan/20-dhcp-wlan-interface.yaml | awk '/wifis/{y=1;next}y' | xargs | md5sum)" != "$(netplan get wifis | xargs | md5sum)" ]]; then
return 1
else
return 0
fi
}

0 comments on commit c9d9bbe

Please sign in to comment.