Skip to content

Commit

Permalink
Pick lan interface with an ip in unum init (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-sommer authored Jan 21, 2019
1 parent 5bcb3b5 commit 5972da1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
1 change: 1 addition & 0 deletions unum/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ define Package/unum/install
$(INSTALL_BIN) $(PKG_BUILD_DIR_UNUM)/unum $(1)/usr/bin/
# Agent configuration folder
$(INSTALL_DIR) $(1)$(AGENT_ETC_DIR)
$(INSTALL_DATA) $(PKG_BUILD_DIR_FILES)/linux_generic/etc/opt/unum/config.json $(1)$(AGENT_ETC_DIR)/config.json
# Trusted certificates (install our own CA list)
$(INSTALL_DIR) $(1)/etc/ssl/certs
cat $(PKG_BUILD_DIR_FILES)/ca/*.pem > $(1)$(AGENT_TRUSTED_CA_LIST)
Expand Down
40 changes: 27 additions & 13 deletions unum/files/unum.common
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

UNUM_PID_FILE_PREFIX=/var/run
UNUM_PID_FILE_PREFIX=/var/run/unum

# Kills unum process instance using its PID file
kill_unum() {
Expand Down Expand Up @@ -59,20 +59,34 @@ prep_startup() {
if [ -e /www ] && [ ! -e /www/provision.json ]; then
ln -sf /tmp/provision_info.json /www/provision.json
fi
LANIF=$(uci get network.lan.ifname)
LANMAC=$(ifconfig $LANIF | awk '/HWaddr/ { print $5 }')
LANIFS=$(ifconfig | awk '/'$LANIF'/ { next }; /'$LANMAC'/ { print $1 }')
uci del unum.@agent[0].lan_if
for IFNAME in $LANIFS; do
uci add_list unum.@agent[0].lan_if=$IFNAME
done
uci add_list unum.@agent[0].lan_if=$LANIF
WANIF=$(uci get network.wan.ifname)
LANIF=$(uci get network.lan.ifname)
LANIP=$(ifconfig "$LANIF" | awk '/inet addr/ { print substr($2, 6) }')
if [ -z "$LANIP" ]; then
LANMAC=$(ifconfig $LANIF | awk '/HWaddr/ { print $5 }')
LANIFS=$(ifconfig | awk '/'$LANIF'/ { next }; /'$WANIF'/ { next }; /'$LANMAC'/ { print $1 }')
LANIF=
for IFNAME in $LANIFS; do
LANIP=$(ifconfig "$IFNAME" | awk '/inet addr/ { print substr($2, 6) }')
if [ ! -z "$LANIP" ]; then
LANIF="$IFNAME"
break
fi
done
fi
if [ -z "$LANIF" ]; then
echo "warning: unable to determine LAN network interface name"
fi
uci set unum.@agent[0].wan_if=$WANIF
uci set unum.@agent[0].lan_if=$LANIF
uci commit unum
cp -f /etc/unum/config.json /tmp/config.json.orig
# Generate agent JSON configuration
echo '{' > /etc/unum/config.json
echo ' "lan-if": "'$(uci get unum.@agent[0].lan_if)'",' >> /etc/unum/config.json
echo ' "wan-if": "'$(uci get unum.@agent[0].wan_if)'"' >> /etc/unum/config.json
echo '}' >> /etc/unum/config.json
if [ -e /etc/unum/config.json ]; then
sed -i -E -e 's/"lan-if":[ ]?".*"/"lan-if": "'$LANIF'"/' \
-e 's/"wan-if":[ ]?".*"/"wan-if": "'$WANIF'"/' \
/etc/unum/config.json
else
echo '{"lan-if":"'$LANIF'","wan-if":"'$WANIF'"}' > /etc/unum/config.json
fi
}

0 comments on commit 5972da1

Please sign in to comment.