This commit is contained in:
Ray Ozzie 2016-03-22 10:45:40 -07:00
parent 58d93f7435
commit 30d77be52f
3 changed files with 97 additions and 55 deletions

View File

@ -79,7 +79,9 @@ popd
if [ ! -d bin ]; then mkdir bin; fi if [ ! -d bin ]; then mkdir bin; fi
if [ -f ./bin/poly_pkt_fwd ]; then rm ./bin/poly_pkt_fwd; fi if [ -f ./bin/poly_pkt_fwd ]; then rm ./bin/poly_pkt_fwd; fi
ln -s $INSTALL_DIR/packet_forwarder/poly_pkt_fwd/poly_pkt_fwd ./bin/poly_pkt_fwd ln -s $INSTALL_DIR/packet_forwarder/poly_pkt_fwd/poly_pkt_fwd ./bin/poly_pkt_fwd
cp -f ./packet_forwarder/poly_pkt_fwd/global_conf.json ./bin/global_conf.json
# copy initial global configuration file
# cp -f ./packet_forwarder/poly_pkt_fwd/global_conf.json ./bin/global_conf.json
# Restore location back to where we started the install # Restore location back to where we started the install

View File

@ -1,74 +1,92 @@
#! /bin/bash #! /bin/bash
# Display the environment, which is useful when debugging # Stop on the first sign of trouble
set -e
echo "******************" if [ $UID != 0 ]; then
echo "*** Environment:" echo "ERROR: Operation not permitted. Forgot sudo?"
env exit 1
echo "******************" fi
VERSION="master"
if [[ $1 != "" ]]; then VERSION=$1; fi
echo "The Things Network Gateway installer"
echo "" echo ""
# Configure the global and local configuration files via the environment # Check dependencies
echo "Installing dependencies..."
apt-get update
apt-get install swig libftdi-dev python-dev
echo "******************" # Install LoRaWAN packet forwarder repositories
echo "*** Configuration:" INSTALL_DIR="/opt/ttn-gateway"
echo "******************" if [ ! -d "$INSTALL_DIR" ]; then mkdir $INSTALL_DIR; fi
pushd $INSTALL_DIR
if [[ $GATEWAY_NAME == "" ]]; then # Build libraries
echo "ERROR: NO GATEWAY_NAME FOUND IN ENVIRONMENT" if [ ! -d libmpsse ]; then
exit 1 git clone https://github.com/devttys0/libmpsse.git
pushd libmpsse/src
else
pushd libmpsse/src
git reset --hard
git pull
fi fi
echo GATEWAY_NAME: $GATEWAY_NAME
if [[ $GATEWAY_EMAIL == "" ]]; then ./configure --disable-python
echo "ERROR: NO GATEWAY_EMAIL FOUND IN ENVIRONMENT" make
exit 1 make install
ldconfig
popd
# Build LoRa gateway app
if [ ! -d lora_gateway ]; then
git clone https://github.com/TheThingsNetwork/lora_gateway.git
pushd lora_gateway
else
pushd lora_gateway
git reset --hard
git pull
fi fi
echo GATEWAY_EMAIL: $GATEWAY_EMAIL
if [[ $GATEWAY_LAT == "" ]]; then cp ./libloragw/99-libftdi.rules /etc/udev/rules.d/99-libftdi.rules
echo "ERROR: NO GATEWAY_LAT (latitude) FOUND IN ENVIRONMENT"
exit 1 sed -i -e 's/CFG_SPI= native/CFG_SPI= ftdi/g' ./libloragw/library.cfg
sed -i -e 's/PLATFORM= kerlink/PLATFORM= lorank/g' ./libloragw/library.cfg
sed -i -e 's/ATTRS{idProduct}=="6010"/ATTRS{idProduct}=="6014"/g' /etc/udev/rules.d/99-libftdi.rules
make
popd
# Build packet forwarder
if [ ! -d packet_forwarder ]; then
git clone https://github.com/TheThingsNetwork/packet_forwarder.git
pushd packet_forwarder
else
pushd packet_forwarder
git pull
git reset --hard
fi fi
echo GATEWAY_LAT: $GATEWAY_LAT
if [[ $GATEWAY_LON == "" ]]; then make
echo "ERROR: NO GATEWAY_LON (longitude) FOUND IN ENVIRONMENT"
exit 1
fi
echo GATEWAY_LON: $GATEWAY_LON
if [[ $GATEWAY_ALT == "" ]]; then popd
echo "ERROR: NO GATEWAY_ALT (altitude) FOUND IN ENVIRONMENT"
exit 1
fi
echo GATEWAY_ALT: $GATEWAY_ALT
echo "******************" # Symlink poly packet forwarder
echo "" if [ ! -d bin ]; then mkdir bin; fi
if [ -f ./bin/poly_pkt_fwd ]; then rm ./bin/poly_pkt_fwd; fi
ln -s $INSTALL_DIR/packet_forwarder/poly_pkt_fwd/poly_pkt_fwd ./bin/poly_pkt_fwd
cp -f ./packet_forwarder/poly_pkt_fwd/global_conf.json ./bin/global_conf.json
echo -e "{\n\t\"gateway_conf\": {\n\t\t\"gateway_ID\": \"0000000000000000\",\n\t\t\"servers\": [ { \"server_address\": \"croft.thethings.girovito.nl\", \"serv_port_up\": 1700, \"serv_port_down\": 1701, \"serv_enabled\": true } ],\n\t\t\"ref_latitude\": $GATEWAY_LAT,\n\t\t\"ref_longitude\": $GATEWAY_LON,\n\t\t\"ref_altitude\": $GATEWAY_ALT,\n\t\t\"contact_email\": \"$GATEWAY_EMAIL\",\n\t\t\"description\": \"$GATEWAY_NAME\" \n\t}\n}" >./local_conf.json # Restore location back to where we started the install
# Reset gateway ID based on MAC popd
echo "******************" # Copy startup shell script to the install directory
../packet_forwarder/reset_pkt_fwd.sh start ./local_conf.json
echo "******************"
echo ""
# Test the connection, wait if needed. cp ./resin-run.sh $INSTALL_DIR/bin/resin-run.sh
while [[ $(ping -c1 google.com 2>&1 | grep " 0% packet loss") == "" ]]; do
echo "[TTN Gateway]: Waiting for internet connection..."
sleep 30
done
# Fire up the forwarder. echo "Installation completed."
while true
do
echo "[TTN Gateway]: Starting packet forwarder..."
./poly_pkt_fwd
echo "******************"
echo "*** [TTN Gateway]: EXIT (retrying in 15s)"
echo "******************"
sleep 15
done

View File

@ -14,6 +14,12 @@ echo "******************"
echo "*** Configuration:" echo "*** Configuration:"
echo "******************" echo "******************"
if [[ $GATEWAY_REGION == "" ]]; then
echo "ERROR: NO GATEWAY_REGION FOUND IN ENVIRONMENT"
exit 1
fi
echo GATEWAY_REGION: $GATEWAY_REGION
if [[ $GATEWAY_NAME == "" ]]; then if [[ $GATEWAY_NAME == "" ]]; then
echo "ERROR: NO GATEWAY_NAME FOUND IN ENVIRONMENT" echo "ERROR: NO GATEWAY_NAME FOUND IN ENVIRONMENT"
exit 1 exit 1
@ -47,6 +53,22 @@ echo GATEWAY_ALT: $GATEWAY_ALT
echo "******************" echo "******************"
echo "" echo ""
# load the region-appropriate global conf
echo eval curl "https://raw.githubusercontent.com/rayozzie/ttn-gateway-conf/master/$GATEWAY_REGION-global-conf.json --output ./global-conf.json
eval curl "https://raw.githubusercontent.com/rayozzie/ttn-gateway-conf/master/$GATEWAY_REGION-global-conf.json --output ./global-conf.json
err=$?
if [ $err -ne 0 ]
then
echo "******************"
echo "ERROR: GATEWAY_REGION not found: $err"
echo "******************"
exit 1
fi
# create local.conf
echo -e "{\n\t\"gateway_conf\": {\n\t\t\"gateway_ID\": \"0000000000000000\",\n\t\t\"servers\": [ { \"server_address\": \"croft.thethings.girovito.nl\", \"serv_port_up\": 1700, \"serv_port_down\": 1701, \"serv_enabled\": true } ],\n\t\t\"ref_latitude\": $GATEWAY_LAT,\n\t\t\"ref_longitude\": $GATEWAY_LON,\n\t\t\"ref_altitude\": $GATEWAY_ALT,\n\t\t\"contact_email\": \"$GATEWAY_EMAIL\",\n\t\t\"description\": \"$GATEWAY_NAME\" \n\t}\n}" >./local_conf.json echo -e "{\n\t\"gateway_conf\": {\n\t\t\"gateway_ID\": \"0000000000000000\",\n\t\t\"servers\": [ { \"server_address\": \"croft.thethings.girovito.nl\", \"serv_port_up\": 1700, \"serv_port_down\": 1701, \"serv_enabled\": true } ],\n\t\t\"ref_latitude\": $GATEWAY_LAT,\n\t\t\"ref_longitude\": $GATEWAY_LON,\n\t\t\"ref_altitude\": $GATEWAY_ALT,\n\t\t\"contact_email\": \"$GATEWAY_EMAIL\",\n\t\t\"description\": \"$GATEWAY_NAME\" \n\t}\n}" >./local_conf.json
# Reset gateway ID based on MAC # Reset gateway ID based on MAC