Commit 77b8e9f4 authored by Igor Pecovnik's avatar Igor Pecovnik
Browse files

Add support for systemd-network type of changing IP

parent ecc2280a
......@@ -194,18 +194,35 @@ function jobs ()
# Select dynamic or edit static IP address
#
"IP" )
# select default interfaces if there is more than one
select_default_interface
# check if we have systemd networking in action
SYSTEMDNET=$(service systemd-networkd status | grep -w active | grep -w running)
dialog --title " IP address assignment " --colors --backtitle "$BACKTITLE" --help-button --help-label "Cancel" \
--yes-label "DHCP" --no-label "Static" --yesno \
"\n\Z1DHCP:\Z0 automatic IP asignment by your router or DHCP server\n\n\Z1Static:\Z0 manually fixed IP address" 9 70
exitstatus=$?;
# dynamic
if [[ $exitstatus = 0 ]]; then
create_if_config "$DEFAULT_ADAPTER" "$DEFAULT_ADAPTER" "dynamic" > /etc/network/interfaces
if [[ -n $SYSTEMDNET ]]; then
filename="/etc/systemd/network/10-${DEFAULT_ADAPTER}.network"
if [[ -f $filename ]]; then
sed -i '/Network/,$d' $filename
echo -e "[Network]" >>$filename
echo -e "DHCP=ipv4" >>$filename
fi
else
create_if_config "$DEFAULT_ADAPTER" "$DEFAULT_ADAPTER" "dynamic" > /etc/network/interfaces
fi
fi
# static
if [[ $exitstatus = 1 ]]; then
create_if_config "$DEFAULT_ADAPTER" "$DEFAULT_ADAPTER" "fixed" > /dev/null
ip_editor "$DEFAULT_ADAPTER" "$DEFAULT_ADAPTER" "/etc/network/interfaces"
if [[ -n $SYSTEMDNET ]]; then
systemd_ip_editor "${DEFAULT_ADAPTER}"
else
ip_editor "$DEFAULT_ADAPTER" "$DEFAULT_ADAPTER" "/etc/network/interfaces"
fi
fi
;;
......
......@@ -245,6 +245,30 @@ function description
}
function systemd_ip_editor ()
{
local filename="/etc/systemd/network/10-$1.network"
if [[ -f $filename ]]; then
sed -i '/Network/,$d' $filename
exec 3>&1
dialog --title " Static IP configuration" --backtitle "$BACKTITLE" --form "\nAdapter: $1
\n " 12 38 0 \
"Address:" 1 1 "$address" 1 15 15 0 \
"Netmask:" 2 1 "$netmask" 2 15 15 0 \
"Gateway:" 3 1 "$gateway" 3 15 15 0 \
2>&1 1>&3 | {
read -r address;read -r netmask;read -r gateway
if [[ $? = 0 ]]; then
echo -e "[Network]" >>$filename
echo -e "Address=$address" >> $filename
echo -e "Gateway=$gateway" >> $filename
echo -e "DNS=8.8.8.8" >> $filename
fi
}
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
# edit ip address
#
......@@ -719,10 +743,15 @@ while true; do
local ipadd=$(ip -4 addr show dev $DEFAULT_ADAPTER | awk '/inet/ {print $2}' | cut -d'/' -f1)
if [[ -n $(LC_ALL=C nmcli device status | grep wlan0 | grep connected) ]]; then
if [[ -n $(LC_ALL=C nmcli device status | grep $DEFAULT_ADAPTER | grep connected) ]]; then
local ifup="\nIP ($DEFAULT_ADAPTER) via Network Manager: \Z1${ipadd}\n\Z0 "
else
local ifup="\nIP ($DEFAULT_ADAPTER) via IFUPDOWN: \Z1${ipadd}\n\Z0 "
if [[ -n $(service systemd-networkd status | grep -w active | grep -w running) ]]; then
local ifup="\nIP ($DEFAULT_ADAPTER) via systemd-networkd: \Z1${ipadd}\n\Z0 "
else
local ifup="\nIP ($DEFAULT_ADAPTER) via IFUPDOWN: \Z1${ipadd}\n\Z0 "
fi
fi
disclaimer="$ifup"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment