This repository has been archived by the owner on May 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinstall.sh
executable file
·147 lines (127 loc) · 3.58 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
# Exit immediately if a pipeline returns a non-zero status
set -e
if [ $UID != 0 ]; then
echo "Error: you cannot perform this operation unless you are root."
exit 1
fi
# Pick frequency plan
# See [Frequency plan and regulations by country](https://www.thethingsnetwork.org/docs/lorawan/frequencies-by-country.html)
# and [The Things Network Master Gateway Configurations](https://github.com/TheThingsNetwork/gateway-conf)
PS3="Please enter your frequency plan (number): "
FREQUENCY_PLANS=("EU" "US" "AU" "AS1" "AS2" "KR" "IN" "CN" "RU")
select FREQUENCY_PLAN in "${FREQUENCY_PLANS[@]}";
do
if [ ! -z "$FREQUENCY_PLAN" ]; then
echo "You picked $FREQUENCY_PLAN."
break;
else
echo "Error: invalid frequency plan."
exit 1
fi
done
# Create ttn group if it isn't already there
if ! getent group ttn >/dev/null; then
# Add system group: ttn
addgroup --system ttn >/dev/null
fi
# Create ttn user if it isn't already there
if ! getent passwd ttn >/dev/null; then
# Add system user: ttn
adduser \
--system \
--disabled-login \
--ingroup ttn \
--no-create-home \
--home /nonexistent \
--gecos "The Things Network Gateway" \
--shell /bin/false \
ttn >/dev/null
# Add ttn user to supplementary groups so it can
# reset and communicate with concentrator board
usermod --groups gpio,spi ttn
fi
# Create install target directory
DESTDIR="/opt/ttn-gateway"
if [ ! -d "$DESTDIR" ]; then
mkdir $DESTDIR
fi
# Dive into target directory
pushd $DESTDIR
# Build Semtech LoRa gateway driver
if [ ! -d lora_gateway ]; then
git clone -b master https://github.com/Lora-net/lora_gateway.git
pushd lora_gateway
else
pushd lora_gateway
git pull
fi
make
popd
# Build Semtech LoRa packet forwarder
if [ ! -d packet_forwarder ]; then
git clone -b master https://github.com/Lora-net/packet_forwarder.git
pushd packet_forwarder
else
pushd packet_forwarder
git pull
fi
make
popd
# Download The Things Network frequency plans
if [ ! -d gateway-conf ]; then
git clone -b master https://github.com/TheThingsNetwork/gateway-conf.git
pushd gateway-conf
else
pushd gateway-conf
git pull
fi
popd
# Create binary directory
if [ ! -d bin ]; then
mkdir bin
fi
# Symlink concentrator board reset script
if [ -f ./bin/reset_lgw.sh ]; then
rm ./bin/reset_lgw.sh
fi
ln -s \
$DESTDIR/lora_gateway/reset_lgw.sh \
./bin/reset_lgw.sh
# Symlink gateway ID updater
if [ -f ./bin/update_gwid.sh ]; then
rm ./bin/update_gwid.sh
fi
ln -s \
$DESTDIR/packet_forwarder/lora_pkt_fwd/update_gwid.sh \
./bin/update_gwid.sh
# Symlink LoRa packet forwarder
if [ -f ./bin/lora_pkt_fwd ]; then
rm ./bin/lora_pkt_fwd
fi
ln -s \
$DESTDIR/packet_forwarder/lora_pkt_fwd/lora_pkt_fwd \
./bin/lora_pkt_fwd
# Create configuration directory
if [ ! -d conf ]; then
mkdir conf
fi
# Back to installer directory
popd
# Generate LBT (Listen Before Talk) disabled global_conf.json
# as we cannot do LBT without FPGA
./disable_lbt.py \
$DESTDIR/gateway-conf/$FREQUENCY_PLAN-global_conf.json \
$DESTDIR/conf/global_conf.json
# Generate local_conf.json
cp \
$DESTDIR/packet_forwarder/lora_pkt_fwd/local_conf.json \
$DESTDIR/conf/local_conf.json
$DESTDIR/bin/update_gwid.sh $DESTDIR/conf/local_conf.json
# Make configurations self updatable
chown --recursive ttn:ttn $DESTDIR/conf
# Start packet forwarder as a service
cp ./start.sh $DESTDIR/bin/
cp ./ttn-gateway.service /lib/systemd/system/
systemctl enable ttn-gateway.service
systemctl restart ttn-gateway.service