Skip to content

Commit

Permalink
Use current hostname in registration unless is "OpenWrt"
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Feb 29, 2016
1 parent bd64be8 commit e8ae900
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ the router to be unregistered and it will attempt to perform an automatic regist

The automatic registration is performed only if ``shared_secret`` is correctly set.

The device will choose as name one of its mac addresses, unless its hostname is not "OpenWrt",
in the latter case it will simply register itself with the current hostname.

When the registration is completed, the agent will automatically set ``uuid`` and ``key``
in ``/etc/config/openwisp``.

In the controller you will find a new (empty) configuration named as the mac address of the router.

Configuration test
------------------

Expand Down
11 changes: 7 additions & 4 deletions openwisp-config/files/openwisp.agent
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ register() {
logger -s "Registering new device" \
-t openwisp \
-p daemon.info
# gets the mac address of the first interface that shows in ifconfig
local name=$(ifconfig | grep -v lo | grep HWaddr | awk '/HWaddr/ { print $5 }' | head -n 1)
local hostname=$(uci get system.@system[0].hostname)
if [ $hostname = "OpenWrt" ]; then
# gets the mac address of the first interface that shows in ifconfig
hostname=$(ifconfig | grep -v lo | grep HWaddr | awk '/HWaddr/ { print $5 }' | head -n 1)
fi
local backend="netjsonconfig.OpenWrt"
local params="secret=$SHARED_SECRET&name=$name&backend=$backend"
local params="secret=$SHARED_SECRET&name=$hostname&backend=$backend"
$($FETCH_COMMAND -i --data $params $REGISTRATION_URL > $REGISTRATION_PARAMETERS)
local exit_code=$?

Expand Down Expand Up @@ -115,7 +118,7 @@ register() {
uci set openwisp.http.shared_secret=""
uci commit openwisp
rm $REGISTRATION_PARAMETERS
logger -s "Device registered successfully as $name, id: $UUID" \
logger -s "Device registered successfully as $hostname, id: $UUID" \
-t openwisp \
-p daemon.info
}
Expand Down

0 comments on commit e8ae900

Please sign in to comment.