forked from SignalK/signalk-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpi-setup.sh
154 lines (128 loc) · 3.23 KB
/
rpi-setup.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
148
149
150
151
152
153
154
#!/bin/bash
if [[ $EUID > 0 ]]
then echo "Please run as root if you want this server configuration to run at every startup, type:"
echo "\"sudo bash rpi-setup.sh\""
echo ""
fi
echo "YOU ARE LOGGED IN AS $SUDO_USER AND THE SERVER WILL BE STARTED AS THIS USER"
echo "ARE YOU SURE YOU WANT TO DELETE ANY CONFIGURATION"
echo "EXISTING AND SET UP A NEW STARTUP SERVICE?"
echo ""
echo "IF NOT, PRESS <CTRL+C> TO ABORT"
echo ""
systemd="/etc/systemd/system/signalk.service"
dir=$(pwd)
socket="/etc/systemd/system/signalk.socket"
echo -n "Enter your vessel name and press [enter]:"
read vesselName
vesselName=${vesselName// /_}
echo ""
echo "Signal K default port is 3000 as per documentation"
echo "port 80 does not require \":3000\" in browser and app interfaces"
read -p "Do you want Signal K to change to port 80? [Y/n]" ans;
case $ans in
n|N)
port=3000;;
y|Y|*)
port=80;;
esac
echo "port $port selected"
UUIDFile="$dir/UUID"
if [ -f $UUIDFile ]
then
UUID=$( cat $UUIDFile)
echo "UUID=$UUID"
else
UUID=$( cat /proc/sys/kernel/random/uuid)
echo $UUID > $UUIDFile
echo "UUID generated: $UUID"
fi
vesselBash="$dir/bin/$vesselName"
vesselJson="$dir/settings/$vesselName.json"
echo "A file will be created with your settings in"
echo "$vesselJson."
echo "This uses stored NMEA data to set up the server."
echo "See configuration examples in same folder."
cat > $vesselBash <<bashScript
#!/bin/sh
DIR=\`dirname \$0\`
\${DIR}/signalk-server -s /settings/$vesselName.json \$*
bashScript
sudo chmod 755 $vesselBash
cat > $vesselJson <<jsonfile
{
"vessel": {
"name": "$vesselName",
"uuid" : "urn:mrn:signalk:uuid:$UUID"
},
"interfaces": {},
"pipedProviders": [{
"id": "nmeaFromFile",
"pipeElements": [
{
"type": "providers/filestream",
"options": {
"filename": "samples/plaka.log"
},
"optionMappings": [
{
"fromAppProperty": "argv.nmeafilename",
"toOption": "filename"
}
]
},
{
"type": "providers/throttle",
"options": {
"rate": 500
}
},
{
"type": "providers/liner"
},
{
"type": "providers/nmea0183-signalk",
"optionMappings": [
{
"fromAppProperty": "selfId",
"toOption": "selfId"
},
{
"fromAppProperty": "selfType",
"toOption": "selfType"
}
]
}
]
}]
}
jsonfile
group_full=$(getent group $SUDO_GID)
group="$( cut -d ':' -f 1 <<< "$group_full" )"
sudo chmod 644 $vesselJson
sudo chown $SUDO_USER $vesselJson
sudo chgrp $group $vesselJson
cat > $systemd <<systemdfile
[Service]
ExecStart=$vesselBash
Restart=always
StandardOutput=syslog
StandardError=syslog
WorkingDirectory=$dir
User=$SUDO_USER
[Install]
WantedBy=multi-user.target
systemdfile
sudo chmod 755 $systemd
cat > $socket <<socket
[Socket]
ListenStream=$port
[Install]
WantedBy=sockets.target
socket
sudo chmod 755 $socket
sed -i -e "s/env.PORT || [0-9]\+;/env.PORT || $port;/g" $dir/lib/config/config.js
echo "A reboot is recommended"
sudo systemctl daemon-reload
sudo systemctl enable signalk.service
sudo systemctl enable signalk.socket