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
167e0dc2
Unverified
Commit
167e0dc2
authored
Jul 11, 2019
by
Igor Pečovnik
Committed by
GitHub
Jul 11, 2019
Browse files
Merge pull request #57 from armbian/development
Development
parents
2119a82d
5b3f2aa6
Changes
3
Hide whitespace changes
Inline
Side-by-side
debian-config-functions-network
View file @
167e0dc2
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
# check_ht_capab
# check_ht_capab
# check_vht_capab
# check_vht_capab
# check_channels
# check_channels
# netmask_to_cidr
# nm_ip_editor
# nm_ip_editor
# systemd_ip_editor
# systemd_ip_editor
# ip_editor
# ip_editor
...
@@ -330,6 +331,19 @@ function check_channels ()
...
@@ -330,6 +331,19 @@ function check_channels ()
}
}
#
# convert netmask to CIDR
#
function
netmask_to_cidr
()
{
IFS
=
' '
local
bits
=
0
for
octet
in
$(
echo
$1
|
sed
's/\./ /g'
)
;
do
binbits
=
$(
echo
"obase=2; ibase=10;
${
octet
}
"
| bc |
sed
's/0//g'
)
let
bits+
=
${#
binbits
}
done
echo
"
${
bits
}
"
}
#
#
...
@@ -347,13 +361,27 @@ exec 3>&1
...
@@ -347,13 +361,27 @@ exec 3>&1
2>&1 1>&3 |
{
2>&1 1>&3 |
{
read
-r
address
;
read
-r
netmask
;
read
-r
gateway
read
-r
address
;
read
-r
netmask
;
read
-r
gateway
if
[[
$?
=
0
]]
;
then
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}'
)
nmcli con mod
$localuuid
ipv4.method manual ipv4.addresses
"
$address
/
$netmask
"
>
/dev/null 2>&1
# convert netmask value to CIDR if required
if
[[
$netmask
=
~ ^[0-9]
{
1,3
}
\.
[
0-9]
{
1,3
}
\.
[
0-9]
{
1,3
}
\.
[
0-9]
{
1,3
}
$
]]
;
then
CIDR
=
$(
netmask_to_cidr
${
netmask
}
)
else
CIDR
=
${
netmask
}
fi
if
[[
-n
"
$localuuid
"
]]
;
then
# adjust existing
nmcli con mod
$localuuid
ipv4.method manual ipv4.addresses
"
$address
/
$CIDR
"
>
/dev/null 2>&1
nmcli con mod
$localuuid
ipv4.method manual ipv4.gateway
"
$gateway
"
>
/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 mod
$localuuid
ipv4.dns
"8.8.8.8,
$gateway
"
>
/dev/null 2>&1
nmcli con down
$localuuid
>
/dev/null 2>&1
nmcli con down
$localuuid
>
/dev/null 2>&1
sleep
2
sleep
2
nmcli con up
$localuuid
>
/dev/null 2>&1
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
/
$CIDR
"
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
fi
}
}
}
}
...
@@ -453,7 +481,7 @@ function wlan_edit ()
...
@@ -453,7 +481,7 @@ function wlan_edit ()
{
{
# select default interfaces if there is more than one
# 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"
\
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
--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
if
[[
$?
=
0
]]
;
then
...
@@ -543,19 +571,56 @@ function get_wlan_interface ()
...
@@ -543,19 +571,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
# select interface if there is more than one and adjust metric
#
#
# $1 = default | all
#
function
select_default_interface
()
function
select_default_interface
()
{
{
ALREADY_DEFINED
=
$(
cat
/etc/iptables.ipv4.nat 2> /dev/null |
grep
"POSTROUTING -o"
|
tail
-1
|
awk
'{ print $4 }'
)
ALREADY_DEFINED
=
$(
cat
/etc/iptables.ipv4.nat 2> /dev/null |
grep
"POSTROUTING -o"
|
tail
-1
|
awk
'{ print $4 }'
)
if
[[
-n
"
${
ALREADY_DEFINED
}
"
]]
;
then
if
[[
-n
"
${
ALREADY_DEFINED
}
"
]]
;
then
DEFAULT_ADAPTER
=
${
ALREADY_DEFINED
}
DEFAULT_ADAPTER
=
${
ALREADY_DEFINED
}
else
else
IFS
=
$'
\r\n
'
IFS
=
$'
\r\n
'
GLOBIGNORE
=
'*'
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
=()
local
LIST
=()
for
i
in
"
${
ADAPTER
[@]
}
"
for
i
in
"
${
ADAPTER
[@]
}
"
do
do
...
@@ -563,7 +628,11 @@ function select_default_interface ()
...
@@ -563,7 +628,11 @@ function select_default_interface ()
ADD_SPEED
=
""
ADD_SPEED
=
""
[[
$i
==
eth
*
||
$i
==
en
*
]]
&&
ADD_SPEED
=
$(
ethtool
$i
|
grep
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
)
[[
$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
done
LIST_LENGTH
=
$((${#
LIST
[@]
}
/
2
))
;
LIST_LENGTH
=
$((${#
LIST
[@]
}
/
2
))
;
if
[
"
$LIST_LENGTH
"
-eq
0
]
;
then
if
[
"
$LIST_LENGTH
"
-eq
0
]
;
then
...
@@ -573,7 +642,7 @@ function select_default_interface ()
...
@@ -573,7 +642,7 @@ function select_default_interface ()
else
else
exec
3>&1
exec
3>&1
DEFAULT_ADAPTER
=
$(
dialog
--nocancel
--backtitle
"
$BACKTITLE
"
--no-collapse
\
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>&-
exec
3>&-
fi
fi
fi
fi
...
...
debian-config-jobs
View file @
167e0dc2
...
@@ -263,6 +263,7 @@ function jobs ()
...
@@ -263,6 +263,7 @@ function jobs ()
# Select dynamic or edit static IP address
# Select dynamic or edit static IP address
#
#
"IP"
)
"IP"
)
select_interface
# check if we have systemd networking in action
# check if we have systemd networking in action
SYSTEMDNET
=
$(
service systemd-networkd status |
grep
-w
active |
grep
-w
running
)
SYSTEMDNET
=
$(
service systemd-networkd status |
grep
-w
active |
grep
-w
running
)
dialog
--title
" IP address assignment "
--colors
--backtitle
"
$BACKTITLE
"
--help-button
--help-label
"Cancel"
\
dialog
--title
" IP address assignment "
--colors
--backtitle
"
$BACKTITLE
"
--help-button
--help-label
"Cancel"
\
...
@@ -273,33 +274,33 @@ function jobs ()
...
@@ -273,33 +274,33 @@ function jobs ()
# dynamic
# dynamic
if
[[
$exitstatus
=
0
]]
;
then
if
[[
$exitstatus
=
0
]]
;
then
if
[[
-n
$SYSTEMDNET
]]
;
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
if
[[
-f
$filename
]]
;
then
sed
-i
'/Network/,$d'
$filename
sed
-i
'/Network/,$d'
$filename
echo
-e
"[Network]"
>>
$filename
echo
-e
"[Network]"
>>
$filename
echo
-e
"DHCP=ipv4"
>>
$filename
echo
-e
"DHCP=ipv4"
>>
$filename
fi
fi
else
else
if
[[
-n
$(
LC_ALL
=
C nmcli device status |
grep
$
DEFAULT
_ADAPTER
|
grep
connected
)
]]
;
then
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
$
DEFAULT
_ADAPTER
|
awk
'{print $1}'
)
>
/dev/null 2>&1
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
$
DEFAULT
_ADAPTER
>
/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
nmcli con up
"Armbian ethernet"
>
/dev/null 2>&1
else
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
fi
fi
fi
# static
# static
if
[[
$exitstatus
=
1
]]
;
then
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
if
[[
-n
$SYSTEMDNET
]]
;
then
systemd_ip_editor
"
${
DEFAULT
_ADAPTER
}
"
systemd_ip_editor
"
${
SELECTED
_ADAPTER
}
"
else
else
if
[[
-n
$(
LC_ALL
=
C nmcli device status |
grep
$
DEFAULT
_ADAPTER
|
grep
connected
)
]]
;
then
if
[[
-n
$(
LC_ALL
=
C nmcli device status |
grep
$
SELECTED
_ADAPTER
)
]]
;
then
nm_ip_editor
"
$
DEFAULT
_ADAPTER
"
nm_ip_editor
"
$
SELECTED
_ADAPTER
"
else
else
ip_editor
"
$
DEFAULT
_ADAPTER
"
"
$
DEFAULT
_ADAPTER
"
"/etc/network/interfaces"
ip_editor
"
$
SELECTED
_ADAPTER
"
"
$
SELECTED
_ADAPTER
"
"/etc/network/interfaces"
fi
fi
fi
fi
fi
fi
...
@@ -524,7 +525,7 @@ function jobs ()
...
@@ -524,7 +525,7 @@ function jobs ()
[[
!
-f
/etc/network/interfaces
]]
&&
echo
"source /etc/network/interfaces.d/*"
>
/etc/network/interfaces
[[
!
-f
/etc/network/interfaces
]]
&&
echo
"source /etc/network/interfaces.d/*"
>
/etc/network/interfaces
# select default interfaces if there is more than one
# select default interfaces if there is more than one
#
select_default_interface
select_default_interface
NETWORK_CONF
=
"/etc/network/interfaces"
NETWORK_CONF
=
"/etc/network/interfaces"
...
...
debian-config-submenu
View file @
167e0dc2
...
@@ -168,8 +168,8 @@ done
...
@@ -168,8 +168,8 @@ done
function
submenu_networking
()
function
submenu_networking
()
{
{
# if there is more than one connected
device
#
select default interface
if there is more than one connected
select_
default_
interface
#
select_interface
"default"
while
true
;
do
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