ttn-resin-gateway-rpi/install.sh~

124 lines
3.1 KiB
Bash
Raw Normal View History

2016-03-21 19:36:55 +00:00
#!/bin/bash
# Stop on the first sign of trouble
set -e
if [ $UID != 0 ]; then
echo "ERROR: Operation not permitted. Forgot sudo?"
exit 1
fi
VERSION="master"
if [[ $1 != "" ]]; then VERSION=$1; fi
echo "The Things Network Gateway installer"
2016-03-21 21:11:00 +00:00
echo ""
2016-03-21 19:36:55 +00:00
# Retrieve gateway configuration for later
2016-03-21 21:06:34 +00:00
echo "Configuring gateway:"
2016-03-21 21:11:00 +00:00
if [[ $GATEWAY_NAME == "" ]]; then
2016-03-21 21:06:34 +00:00
echo "ERROR: NO GATEWAY_NAME FOUND IN ENVIRONMENT"
2016-03-21 21:04:16 +00:00
exit 1
fi
2016-03-21 21:06:34 +00:00
echo GATEWAY_NAME: $GATEWAY_NAME
2016-03-21 19:36:55 +00:00
2016-03-21 21:13:03 +00:00
if [[ $GATEWAY_EMAIL == "" ]]; then
echo "ERROR: NO GATEWAY_EMAIL FOUND IN ENVIRONMENT"
exit 1
fi
echo GATEWAY_EMAIL: $GATEWAY_EMAIL
if [[ $GATEWAY_LAT == "" ]]; then
echo "ERROR: NO GATEWAY_LAT (latitude) FOUND IN ENVIRONMENT"
exit 1
fi
echo GATEWAY_LAT: $GATEWAY_LAT
2016-03-21 19:36:55 +00:00
2016-03-21 21:13:03 +00:00
if [[ $GATEWAY_LON == "" ]]; then
echo "ERROR: NO GATEWAY_LON (longitude) FOUND IN ENVIRONMENT"
exit 1
fi
echo GATEWAY_LON: $GATEWAY_LON
2016-03-21 19:36:55 +00:00
2016-03-21 21:13:03 +00:00
if [[ $GATEWAY_ALT == "" ]]; then
echo "ERROR: NO GATEWAY_ALT (altitude) FOUND IN ENVIRONMENT"
exit 1
fi
echo GATEWAY_ALT: $GATEWAY_ALT
2016-03-21 19:36:55 +00:00
2016-03-21 21:13:03 +00:00
echo ""
2016-03-21 19:36:55 +00:00
# Check dependencies
echo "Installing dependencies..."
2016-03-21 20:55:18 +00:00
apt-get update
2016-03-21 19:36:55 +00:00
apt-get install swig libftdi-dev python-dev
# Install LoRaWAN packet forwarder repositories
INSTALL_DIR="/opt/ttn-gateway"
if [ ! -d "$INSTALL_DIR" ]; then mkdir $INSTALL_DIR; fi
pushd $INSTALL_DIR
# Build libraries
if [ ! -d libmpsse ]; then
git clone https://github.com/devttys0/libmpsse.git
pushd libmpsse/src
else
pushd libmpsse/src
git reset --hard
git pull
fi
./configure --disable-python
make
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
cp ./libloragw/99-libftdi.rules /etc/udev/rules.d/99-libftdi.rules
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
make
popd
# Symlink poly packet forwarder
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}" >./bin/local_conf.json
popd
echo "Installation completed."