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 fb90254
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 21 deletions.
38 changes: 17 additions & 21 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 @@ -389,9 +373,8 @@
"id": "N12",
"description": "Enable DHCP on wireless network interface",
"command": [
"wifi_index=\"wlx44334c47dec3\"",
"SSID=GOSTJE24",
"PASSWORD=password",
"choose_adapter \"w\"",
"wifi_connect \"${SELECTED_ADAPTER}\"",
"rm -f /etc/netplan/20-dhcp-wlan-interface",
"netplan set --origin-hint 20-dhcp-wlan-interface renderer=networkd",
"netplan set --origin-hint 20-dhcp-wlan-interface wifis.$wifi_index.access-points.\"${SSID}\".${PASSWORD}=password",
Expand All @@ -404,6 +387,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
77 changes: 77 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,81 @@ 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

}

function wifi_connect() {

local WIFI_DEVICE=$1

LIST=()
LIST=($(sudo iw dev ${WIFI_DEVICE} scan 2> /dev/null | grep 'SSID\|^BSS' | cut -d" " -f2 | sed "s/(.*//g" | xargs -n2 -d'\n' | awk '{print $2,$1}'))
LIST_LENGTH=$((${#LIST[@]}/2));
SELECTED_SSID=$(whiptail --title "Select SSID" --menu "rf" $((${LIST_LENGTH} + 6)) 50 $((${LIST_LENGTH})) "${LIST[@]}" 3>&1 1>&2 2>&3)
if [[ -n $SELECTED_SSID ]]; then
SELECTED_PASSWORD=$(whiptail --title "Enter new password for $SELECTED_SSID" --passwordbox "" 7 50 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 fb90254

Please sign in to comment.