Skip to content

Commit

Permalink
dd 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 52ce265
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 18 deletions.
33 changes: 15 additions & 18 deletions lib/armbian-configng/config.ng.jobs.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,18 +287,6 @@
"id": "N01",
"description": "Configure network interfaces",
"sub": [
{
"id": "N02",
"description": "Apply configuration",
"command": [
"netplan apply"
],
"status": "Active",
"doc_link": "",
"src_reference": "",
"author": "https://github.com/igorpecovnik",
"condition": ""
},
{
"id": "N03",
"description": "Wired",
Expand Down Expand Up @@ -330,12 +318,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 \"e\"",
"[[ -n \"$IP_ADDRESS\" ]] && netplan_wrapper \"10-dhcp-all-interfaces\" \"ethernets\" \"networkd\" \"${SELECTED_ADAPTER}\" \"$IP_ADDRESS\""
],
"status": "Active",
"doc_link": "",
Expand Down Expand Up @@ -404,6 +388,19 @@
"condition": "[ ! -f /etc/netplan/20-dhcp-wlan-interface.yaml ]"
}
]
},
{
"id": "N02",
"description": "Apply configs",
"command": [
"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": ""
}
]
},
Expand Down
63 changes: 63 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,67 @@ 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 "^$type" | 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})"

}

0 comments on commit 52ce265

Please sign in to comment.