Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Config
Commits
c353b94b
Commit
c353b94b
authored
Jun 12, 2019
by
Igor Pecovnik
Browse files
Setting IP for inactive interfaces
parent
ad0b55d4
Changes
3
Hide whitespace changes
Inline
Side-by-side
debian-config-functions-network
View file @
c353b94b
...
...
@@ -347,13 +347,21 @@ exec 3>&1
2>&1 1>&3 |
{
read
-r
address
;
read
-r
netmask
;
read
-r
gateway
if
[[
$?
=
0
]]
;
then
localuuid
=
$(
LC_ALL
=
C nmcli
-f
UUID,DEVICE connection show |
grep
$1
|
awk
'{print $1}'
)
localuuid
=
$(
LC_ALL
=
C nmcli
-f
UUID,DEVICE connection show |
grep
$1
|
awk
'{print $1}'
)
if
[[
-n
"
$localuuid
"
]]
;
then
# adjust existing
nmcli con mod
$localuuid
ipv4.method manual ipv4.addresses
"
$address
/
$netmask
"
>
/dev/null 2>&1
nmcli con mod
$localuuid
ipv4.method manual ipv4.gateway
"
$gateway
"
>
/dev/null 2>&1
nmcli con mod
$localuuid
ipv4.dns
"8.8.8.8,
$gateway
"
>
/dev/null 2>&1
nmcli con down
$localuuid
>
/dev/null 2>&1
sleep
2
nmcli con up
$localuuid
>
/dev/null 2>&1
else
# create new
nmcli con add con-name
"armbian"
ifname
"
$1
"
type
802-3-ethernet ip4
"
$address
/
$netmask
"
gw4
"
$gateway
"
>
/dev/null 2>&1
nmcli con mod
"armbian"
ipv4.dns
"8.8.8.8,
$gateway
"
>
/dev/null 2>&1
nmcli con up
"armbian"
>
/dev/null 2>&1
fi
fi
}
}
...
...
@@ -453,7 +461,7 @@ function wlan_edit ()
{
# select default interfaces if there is more than one
select_
default_
interface
select_interface
"default"
dialog
--title
" Configuration edit "
--colors
--backtitle
"
$BACKTITLE
"
--help-button
--help-label
"Cancel"
--yes-label
"Basic"
\
--no-label
"Advanced"
--yesno
"
\n\Z
1Basic:
\Z
0 Change SSID, password and channel
\n\n\Z
1Advanced:
\Z
0 Edit /etc/hostapd.conf file"
9 70
if
[[
$?
=
0
]]
;
then
...
...
@@ -543,19 +551,56 @@ function get_wlan_interface ()
function
select_interface
()
{
IFS
=
$'
\r\n
'
GLOBIGNORE
=
'*'
local
ADAPTER
=(
$(
nmcli device status |
grep
ethernet |
awk
'{ print $1 }'
|
grep
-v
lo
)
)
local
LIST
=()
for
i
in
"
${
ADAPTER
[@]
}
"
do
local
IPADDR
=
$(
LC_ALL
=
C ip
-4
addr show dev
${
i
[0]
}
|
awk
'/inet/ {print $2}'
|
cut
-d
'/'
-f1
)
ADD_SPEED
=
""
[[
$i
==
eth
*
||
$i
==
en
*
]]
&&
ADD_SPEED
=
$(
ethtool
$i
|
grep
Speed
)
[[
$i
==
wl
*
]]
&&
ADD_SPEED
=
$(
LC_ALL
=
C nmcli
-f
RATE,DEVICE,ACTIVE dev wifi list |
grep
$i
|
grep yes
|
awk
'NF==4{print $1""$2}NF==1'
|
sed
-e
's/^/ Speed: /'
|
tail
-1
)
LIST+
=(
"
${
i
[0]//[[
:blank:]]/
}
"
"
${
IPADDR
}
${
ADD_SPEED
}
"
)
done
LIST_LENGTH
=
$((${#
LIST
[@]
}
/
2
))
;
if
[
"
$LIST_LENGTH
"
-eq
0
]
;
then
SELECTED_ADAPTER
=
"lo"
elif
[
"
$LIST_LENGTH
"
-eq
1
]
;
then
SELECTED_ADAPTER
=
${
ADAPTER
[0]
}
else
exec
3>&1
SELECTED_ADAPTER
=
$(
dialog
--nocancel
--backtitle
"
$BACKTITLE
"
--no-collapse
--title
"Select
$1
interface"
--clear
\
--menu
""
$((
6
+
${
LIST_LENGTH
}))
74 14
"
${
LIST
[@]
}
"
2>&1 1>&3
)
exec
3>&-
fi
}
#
# select interface if there is more than one and adjust metric
#
# $1 = default | all
#
function
select_default_interface
()
{
ALREADY_DEFINED
=
$(
cat
/etc/iptables.ipv4.nat 2> /dev/null |
grep
"POSTROUTING -o"
|
tail
-1
|
awk
'{ print $4 }'
)
if
[[
-n
"
${
ALREADY_DEFINED
}
"
]]
;
then
DEFAULT_ADAPTER
=
${
ALREADY_DEFINED
}
else
IFS
=
$'
\r\n
'
GLOBIGNORE
=
'*'
local
ADAPTER
=(
$(
nmcli
-t
-f
DEVICE connection show
--active
)
)
if
[[
$1
==
"default"
]]
;
then
local
ADAPTER
=(
$(
nmcli
-t
-f
DEVICE connection show
--active
)
)
else
local
ADAPTER
=(
$(
nmcli device status |
tail
-n
+2 |
awk
'{ print $1 }'
|
grep
-v
lo
)
)
fi
local
LIST
=()
for
i
in
"
${
ADAPTER
[@]
}
"
do
...
...
@@ -563,7 +608,11 @@ function select_default_interface ()
ADD_SPEED
=
""
[[
$i
==
eth
*
||
$i
==
en
*
]]
&&
ADD_SPEED
=
$(
ethtool
$i
|
grep
Speed
)
[[
$i
==
wl
*
]]
&&
ADD_SPEED
=
$(
LC_ALL
=
C nmcli
-f
RATE,DEVICE,ACTIVE dev wifi list |
grep
$i
|
grep yes
|
awk
'NF==4{print $1""$2}NF==1'
|
sed
-e
's/^/ Speed: /'
|
tail
-1
)
[[
$IPADDR
!=
"172.24.1.1"
&&
-n
$IPADDR
]]
&&
LIST+
=(
"
${
i
[0]//[[
:blank:]]/
}
"
"
${
IPADDR
}
${
ADD_SPEED
}
"
)
if
[[
$1
==
"default"
]]
;
then
[[
$IPADDR
!=
"172.24.1.1"
&&
-n
$IPADDR
]]
&&
LIST+
=(
"
${
i
[0]//[[
:blank:]]/
}
"
"
${
IPADDR
}
${
ADD_SPEED
}
"
)
else
[[
$IPADDR
!=
"172.24.1.1"
]]
&&
LIST+
=(
"
${
i
[0]//[[
:blank:]]/
}
"
"
${
IPADDR
}
${
ADD_SPEED
}
"
)
fi
done
LIST_LENGTH
=
$((${#
LIST
[@]
}
/
2
))
;
if
[
"
$LIST_LENGTH
"
-eq
0
]
;
then
...
...
@@ -573,7 +622,7 @@ function select_default_interface ()
else
exec
3>&1
DEFAULT_ADAPTER
=
$(
dialog
--nocancel
--backtitle
"
$BACKTITLE
"
--no-collapse
\
--title
"Select
default
interface"
--clear
--menu
""
$((
6
+
${
LIST_LENGTH
}))
74 14
"
${
LIST
[@]
}
"
2>&1 1>&3
)
--title
"Select
$1
interface"
--clear
--menu
""
$((
6
+
${
LIST_LENGTH
}))
74 14
"
${
LIST
[@]
}
"
2>&1 1>&3
)
exec
3>&-
fi
fi
...
...
debian-config-jobs
View file @
c353b94b
...
...
@@ -263,6 +263,7 @@ function jobs ()
# Select dynamic or edit static IP address
#
"IP"
)
select_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"
\
...
...
@@ -273,33 +274,33 @@ function jobs ()
# dynamic
if
[[
$exitstatus
=
0
]]
;
then
if
[[
-n
$SYSTEMDNET
]]
;
then
filename
=
"/etc/systemd/network/10-
${
DEFAULT
_ADAPTER
}
.network"
filename
=
"/etc/systemd/network/10-
${
SELECTED
_ADAPTER
}
.network"
if
[[
-f
$filename
]]
;
then
sed
-i
'/Network/,$d'
$filename
echo
-e
"[Network]"
>>
$filename
echo
-e
"DHCP=ipv4"
>>
$filename
fi
else
if
[[
-n
$(
LC_ALL
=
C nmcli device status |
grep
$
DEFAULT
_ADAPTER
|
grep
connected
)
]]
;
then
nmcli connection delete uuid
$(
LC_ALL
=
C nmcli
-f
UUID,DEVICE connection show |
grep
$
DEFAULT
_ADAPTER
|
awk
'{print $1}'
)
>
/dev/null 2>&1
nmcli con add con-name
"Armbian ethernet"
type
ethernet ifname
$
DEFAULT
_ADAPTER
>
/dev/null 2>&1
if
[[
-n
$(
LC_ALL
=
C nmcli device status |
grep
$
SELECTED
_ADAPTER
)
]]
;
then
nmcli connection delete uuid
$(
LC_ALL
=
C nmcli
-f
UUID,DEVICE connection show |
grep
$
SELECTED
_ADAPTER
|
awk
'{print $1}'
)
>
/dev/null 2>&1
nmcli con add con-name
"Armbian ethernet"
type
ethernet ifname
$
SELECTED
_ADAPTER
>
/dev/null 2>&1
nmcli con up
"Armbian ethernet"
>
/dev/null 2>&1
else
create_if_config
"
$
DEFAULT
_ADAPTER
"
"
$
DEFAULT
_ADAPTER
"
"dynamic"
>
/etc/network/interfaces
create_if_config
"
$
SELECTED
_ADAPTER
"
"
$
SELECTED
_ADAPTER
"
"dynamic"
>
/etc/network/interfaces
fi
fi
fi
# static
if
[[
$exitstatus
=
1
]]
;
then
create_if_config
"
$
DEFAULT
_ADAPTER
"
"
$
DEFAULT
_ADAPTER
"
"fixed"
>
/dev/null
create_if_config
"
$
SELECTED
_ADAPTER
"
"
$
SELECTED
_ADAPTER
"
"fixed"
>
/dev/null
if
[[
-n
$SYSTEMDNET
]]
;
then
systemd_ip_editor
"
${
DEFAULT
_ADAPTER
}
"
systemd_ip_editor
"
${
SELECTED
_ADAPTER
}
"
else
if
[[
-n
$(
LC_ALL
=
C nmcli device status |
grep
$
DEFAULT
_ADAPTER
|
grep
connected
)
]]
;
then
nm_ip_editor
"
$
DEFAULT
_ADAPTER
"
if
[[
-n
$(
LC_ALL
=
C nmcli device status |
grep
$
SELECTED
_ADAPTER
)
]]
;
then
nm_ip_editor
"
$
SELECTED
_ADAPTER
"
else
ip_editor
"
$
DEFAULT
_ADAPTER
"
"
$
DEFAULT
_ADAPTER
"
"/etc/network/interfaces"
ip_editor
"
$
SELECTED
_ADAPTER
"
"
$
SELECTED
_ADAPTER
"
"/etc/network/interfaces"
fi
fi
fi
...
...
@@ -524,7 +525,7 @@ function jobs ()
[[
!
-f
/etc/network/interfaces
]]
&&
echo
"source /etc/network/interfaces.d/*"
>
/etc/network/interfaces
# select default interfaces if there is more than one
#
select_default_interface
select_default_interface
NETWORK_CONF
=
"/etc/network/interfaces"
...
...
@@ -954,18 +955,8 @@ function jobs ()
--yes-label
"Stop"
--no-label
"Cancel"
--yesno
"
\n
Do you want to stop and disable this service?"
7 50
exitstatus
=
$?
;
if
[[
$exitstatus
=
0
]]
;
then
function
stop_display
()
{
bash
-c
"service lightdm stop >/dev/null 2>&1
systemctl disable lightdm.service >/dev/null 2>&1
service nodm stop >/dev/null 2>&1
systemctl disable nodm.service >/dev/null 2>&1"
}
if
xhost
>
& /dev/null
;
then
stop_display &
else
stop_display
fi
service lightdm stop
>
/dev/null 2>&1
&&
systemctl disable lightdm.service
>
/dev/null 2>&1
service nodm stop
>
/dev/null 2>&1
&&
systemctl disable nodm.service
>
/dev/null 2>&1
fi
else
if
!
is_package_manager_running
;
then
...
...
@@ -991,8 +982,6 @@ function jobs ()
ln
-s
/lib/systemd/system/lightdm.service /etc/systemd/system/display-manager.service
>
/dev/null 2>&1
service lightdm start
>
/dev/null 2>&1
fi
# kill this bash script after desktop is up and if executed on console
[[
$(
tty
|
sed
-e
"s:/dev/::"
)
==
tty
*
]]
&&
kill
-9
$$
fi
fi
fi
...
...
debian-config-submenu
View file @
c353b94b
...
...
@@ -161,8 +161,8 @@ done
function
submenu_networking
()
{
# if there is more than one connected
device
select_
default_
interface
#
select default interface
if there is more than one connected
#
select_interface
"default"
while
true
;
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment