Skip to content

Commit

Permalink
Fixing default route search and code comment typo
Browse files Browse the repository at this point in the history
  • Loading branch information
igorpecovnik committed Oct 8, 2024
1 parent 388ce4e commit dd538c1
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 21 deletions.
4 changes: 2 additions & 2 deletions lib/armbian-configng/config.ng.functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ module_options+=(
function set_colors() {
local color_code=$1

if [ "$DIALOG" = "whiptail" ]; then
if [ "$DIALOG" = "clear; whiptail" ]; then
set_newt_colors "$color_code"
#echo "color code: $color_code" | show_infobox ;
elif [ "$DIALOG" = "dialog" ]; then
Expand Down Expand Up @@ -775,7 +775,7 @@ menu_options+=(
function process_input() {
local input="$1"
if [ "$input" = "No" ]; then
exit 1
return 1
fi
}

Expand Down
8 changes: 4 additions & 4 deletions lib/armbian-configng/config.ng.jobs.json
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@
"sub": [
{
"id": "N02",
"description": "Add interface",
"description": "Add / change interface",
"command": [
"network_config armbian"
],
Expand All @@ -425,11 +425,11 @@
],
"status": "Preview",
"author": "Igor Pecovnik",
"condition": "[[ -f /etc/netplan/armbian.yaml ]] && ! cat /etc/netplan/armbian.yaml | diff -q 1>/dev/null <(netplan get all) - || [[ ! -f /etc/netplan/10-dhcp-all-interfaces.yaml ]] && ! cat /etc/netplan/10-dhcp-all-interfaces.yaml 2>/dev/null | diff -q 1>/dev/null <(netplan get all) -"
"condition": ""
},
{
"id": "N04",
"description": "Show draft configuration",
"description": "Show configuration",
"command": [
"show_message <<< \"$(netplan get all)\""
],
Expand All @@ -442,7 +442,7 @@
{
"id": "N05",
"description": "Apply changes",
"prompt": "This will apply new network configuration\n\nwould you like to continue?",
"prompt": "This action might disconnect you from network.\n\nAre you sure network was configured correctly?",
"command": [
"netplan apply"
],
Expand Down
74 changes: 63 additions & 11 deletions lib/armbian-configng/config.ng.network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,27 @@ function default_network_config() {
local renderer=networkd
local yamlfile=10-dhcp-all-interfaces

# remove all configs
rm -f /etc/netplan/*.yaml
netplan set --origin-hint ${yamlfile} renderer=${renderer}
netplan set --origin-hint ${yamlfile} ethernets.all-eth-interfaces.dhcp4=true
netplan set --origin-hint ${yamlfile} ethernets.all-eth-interfaces.dhcp6=true
netplan set --origin-hint ${yamlfile} ethernets.all-eth-interfaces.match.name=e*
show_message <<< "$(sudo netplan get ${type})"
# store current configs to temporal folder
store_netplan_config

get_user_continue "This action might disconnect you from network.\n\nAre you sure network was configured correctly?" process_input
if [[ $? == 0 ]]; then
# remove all configs
rm -f /etc/netplan/*.yaml
netplan set --origin-hint ${yamlfile} renderer=${renderer}
netplan set --origin-hint ${yamlfile} ethernets.all-eth-interfaces.dhcp4=true
netplan set --origin-hint ${yamlfile} ethernets.all-eth-interfaces.dhcp6=true
netplan set --origin-hint ${yamlfile} ethernets.all-eth-interfaces.match.name=e*
show_message <<< "$(sudo netplan get ${type})"

# drop and delete bridge interface in case its there
if [[ -n $(ip link show type bridge) ]]; then
ip link set br0 down
brctl delbr br0
fi
else
restore_netplan_config
fi
}

module_options+=(
Expand All @@ -148,7 +161,10 @@ function network_config() {
# defaul yaml file
local yamlfile=${1:-armbian}

# delete default automatic DHCP on all wired networks setup
# store current configs to temporal folder
store_netplan_config

# remove default configuration
rm -f /etc/netplan/10-dhcp-all-interfaces.yaml

LIST=()
Expand Down Expand Up @@ -238,7 +254,7 @@ function network_config() {
else

#
# Wireless networking
# Wired networking
#
LIST=("dhcp" "Auto IP assigning")
LIST+=("static" "Set IP manually")
Expand All @@ -251,16 +267,35 @@ function network_config() {
netplan set --origin-hint ${yamlfile} bridges.br0.dhcp4=yes
netplan set --origin-hint ${yamlfile} bridges.br0.dhcp6=yes
show_message <<< "$(netplan get all)"
$DIALOG --title " Changing network settings " --yes-button "Yes" --no-button "Cancel" --yesno "This action might disconnect you from network.\n\nAre you sure network was configured correctly?" 9 50
if [[ $? = 0 ]]; then
netplan apply
else
restore_netplan_config
fi
elif [[ "${wiredmode}" == "static" ]]; then
address=$(ip -br addr show dev $adapter | awk '{print $3}')
local ips=()
for f in /sys/class/net/*; do
local intf=$(basename $f)
# skip unwanted
if [[ $intf =~ ^dummy0|^lo|^docker|^virbr ]]; then
continue
else
local tmp=$(ip -4 addr show dev $intf | grep -v "$intf:avahi" | awk '/inet/ {print $2}' | uniq)
[[ -n $tmp ]] && ips+=("$tmp")
fi
done
address=${ips[@]}
[[ -z "${address}" ]] && address="1.2.3.4/5"
address=$($DIALOG --title "Enter IP for $adapter" --inputbox "\nValid format: $address" 9 40 "$address" 3>&1 1>&2 2>&3)
if [[ -n $address && $? == 0 ]]; then
defaultroute=$(ip route show default | grep "$adapter" | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]" | head 1 | xargs)
defaultroute=$(ip route show default | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]" | head -1 | xargs)
defaultroute=$($DIALOG --title "Enter IP for default route" --inputbox "\nValid format: $defaultroute" 9 40 "$defaultroute" 3>&1 1>&2 2>&3)
if [[ -n $defaultroute && $? == 0 ]]; then
nameservers="9.9.9.9,1.1.1.1"
nameservers=$($DIALOG --title "Enter DNS server" --inputbox "\nValid format: $nameservers" 9 40 "$nameservers" 3>&1 1>&2 2>&3)
else
restore_netplan_config
fi
if [[ -n $nameservers && $? == 0 ]]; then
netplan set --origin-hint ${yamlfile} renderer=${renderer}
Expand All @@ -270,9 +305,26 @@ function network_config() {
netplan set --origin-hint ${yamlfile} bridges.br0.addresses='['$address']'
netplan set --origin-hint ${yamlfile} bridges.br0.routes='[{"to":"0.0.0.0/0", "via": "'$defaultroute'","metric":200}]'
netplan set --origin-hint ${yamlfile} bridges.br0.nameservers.addresses='['$nameservers']'
else
restore_netplan_config
fi
if [[ $? == 0 ]]; then
show_message <<< "$(netplan get all)"
$DIALOG --title " Changing network settings " --yes-button "Yes" --no-button "Cancel" --yesno "This action might disconnect you from network.\n\nAre you sure network was configured correctly?" 9 50
if [[ $? = 0 ]]; then
netplan apply
else
restore_netplan_config
fi
fi
else
restore_netplan_config
fi
else
restore_netplan_config
fi
fi
else
restore_netplan_config
fi
}
42 changes: 42 additions & 0 deletions lib/armbian-configng/config.ng.system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,45 @@ function manage_dtoverlays () {
esac
done
}

module_options+=(
["store_netplan_config,author"]="Igor Pecovnik"
["store_netplan_config,ref_link"]=""
["store_netplan_config,feature"]="Storing netplan config to tmp"
["store_netplan_config,desc"]=""
["store_netplan_config,example"]=""
["store_netplan_config,status"]="Active"
)
#
# @description Storing Netplan configuration to temp folder
#
function store_netplan_config () {

# store current configs to temporal folder
restore_netplan_config_folder=$(mktemp -d /tmp/XXXXXXXXXX)
rsync --quiet /etc/netplan/* ${restore_netplan_config_folder}/ 2>/dev/null
trap restore_netplan_config 1 2 3 6

}

module_options+=(
["store_netplan_config,author"]="Igor Pecovnik"
["store_netplan_config,ref_link"]=""
["store_netplan_config,feature"]="Storing netplan config to tmp"
["store_netplan_config,desc"]=""
["store_netplan_config,example"]=""
["store_netplan_config,status"]="Active"
)
#
# @description Restoring Netplan configuration from temp folder
#
restore_netplan_config() {

echo "Restoring NetPlan configs" | show_infobox
# just in case
if [[ -n ${restore_netplan_config_folder} ]]; then
rm -f /etc/netplan/*
rsync -ar ${restore_netplan_config_folder}/. /etc/netplan
fi

}
8 changes: 4 additions & 4 deletions tools/json/config.network.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"sub": [
{
"id": "N02",
"description": "Add interface",
"description": "Add / change interface",
"command": [
"network_config armbian"
],
Expand All @@ -26,11 +26,11 @@
],
"status": "Preview",
"author": "Igor Pecovnik",
"condition": "[[ -f /etc/netplan/armbian.yaml ]] && ! cat /etc/netplan/armbian.yaml | diff -q 1>/dev/null <(netplan get all) - || [[ ! -f /etc/netplan/10-dhcp-all-interfaces.yaml ]] && ! cat /etc/netplan/10-dhcp-all-interfaces.yaml 2>/dev/null | diff -q 1>/dev/null <(netplan get all) -"
"condition": ""
},
{
"id": "N04",
"description": "Show draft configuration",
"description": "Show configuration",
"command": [
"show_message <<< \"$(netplan get all)\""
],
Expand All @@ -43,7 +43,7 @@
{
"id": "N05",
"description": "Apply changes",
"prompt": "This will apply new network configuration\n\nwould you like to continue?",
"prompt": "This action might disconnect you from network.\n\nAre you sure network was configured correctly?",
"command": [
"netplan apply"
],
Expand Down

0 comments on commit dd538c1

Please sign in to comment.