-
Notifications
You must be signed in to change notification settings - Fork 2
/
recorder.rb
243 lines (194 loc) · 7.32 KB
/
recorder.rb
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
class Recorder < Formula
desc "Store and access location data published via MQTT from OwnTracks apps"
homepage "http://owntracks.org"
url "https://github.com/owntracks/recorder/archive/0.9.9.tar.gz"
version "0.9.9"
sha256 "66e6adc71e011548f3902664c5f643edb45665b01fedeb0c5d8892416a3808a2"
option "with-lua", "Add support for Lua filtering"
def withlua
if build.with?("lua")
"yes"
else
"no"
end
end
# Recorder requires Mosquitto headers/libs for building
depends_on "mosquitto"
depends_on "lmdb"
depends_on "lua" => [:optional, "lua"]
depends_on "libconfig"
def pre_install
if (etc+"ot-recorder.sh").exist?
(etc+"ot-recorder.sh").copy("/tmp/ot-recorder.sh")
ohai "Existing ot-recorder.sh has been copied to /tmp"
end
end
def install
if (etc+"ot-recorder.sh").exist?
copy(etc+"ot-recorder.sh", "/tmp/ot-recorder.sh.backup")
ohai "Existing ot-recorder.sh has been copied to /tmp/ot-recorder.sh.backup"
end
ENV.deparallelize # if your formula fails when building in parallel
# Create our config.mk from scratch
(buildpath+"config.mk").write config_mk
system "make"
# system "make", "install", "DESTDIR=#{prefix}"
# Create the working directories
(var/"owntracks").mkpath
(var/"owntracks/recorder").mkpath
(var/"owntracks/recorder/htdocs").mkpath
(var/"owntracks/recorder/store").mkpath
(var/"owntracks/recorder/store/last").mkpath
(var/"owntracks/recorder/store/ghash").mkpath
(var/"owntracks/recorder/store/rec").mkpath
sbin.install "ot-recorder"
chmod 0755, sbin/"ot-recorder"
bin.install "ocat"
chmod 0755, bin/"ocat"
doc.install "README.md"
# (var/"owntracks/recorder/htdocs").install Dir["docroot/*"]
# install htdocs/docroot. This will create a symlink to
# /usr/local/share/recorder/docroot
pkgshare.install Dir["docroot"]
pkgshare.install "contrib"
end
def post_install
(etc/"default").mkpath
unless (etc+"default/ot-recorder").exist?
(etc+"default/ot-recorder").write settings_template
end
unless (etc+"ot-recorder.sh").exist?
# Create Recorder launch script with configuration in it
(etc+"ot-recorder.sh").write launch_script
chmod 0755, etc/"ot-recorder.sh"
end
# ohai "initializing topic2tid" + %x("#{bin}/ocat" --load=topic2tid < /dev/null)
ohai "checking whether lmdb needs initializing"
system "#{sbin}/ot-recorder", "--initialize"
end
test do
system "#{bin}/ocat", "--version"
end
def caveats; <<-EOD
OwnTracks Recorder has been installed with a default configuration.
You can make changes to the configuration by editing and then
launching:
#{etc}/ot-recorder.sh
EOD
end
def config_mk; <<-EOS
INSTALLDIR = /
CONFIGFILE = #{etc}/default/ot-recorder
WITH_MQTT ?= yes
WITH_HTTP ?= yes
WITH_TOURS ?= yes
WITH_LUA ?= #{withlua}
WITH_PING ?= yes
WITH_KILL ?= no
WITH_ENCRYPT ?= no
WITH_GREENWICH ?= no
WITH_TZ ?= yes
TZDATADB = #{share}/recorder/timezone16.bin
STORAGEDEFAULT = #{var}/owntracks/recorder/store
DOCROOT = #{share}/recorder/docroot
GHASHPREC = 7
JSON_INDENT ?= no
APIKEY ?=
MOSQUITTO_CFLAGS = `$(PKG_CONFIG) --cflags libmosquitto`
MOSQUITTO_LIBS = `$(PKG_CONFIG) --libs libmosquitto`
MORELIBS = # -lssl
LUA_CFLAGS = -I#{include}
LUA_LIBS = -L#{lib} -llua -lm
GEOCODE_TIMEOUT = 4000
EOS
end
def launch_script; <<-EOS
#!/bin/sh
# Launch script for OwnTracks Recorder
#: Configuration for Private mode (your own MQTT broker). This requires
#: at least HOST and PORT. If you need TLS, set CAFILE, and for
#: authentication set USER and PASS additionally.
#:-- Private mode
export OTR_HOST="127.0.0.1" # MQTT hostname
export OTR_PORT="1883" # MQTT port (set to 8883 for TLS and define OTR_CAFILE)
#export OTR_USER="" # broker user name
#export OTR_PASS="" # broker password
#export OTR_CAFILE="" # PEM CA certificate chain for broker
opts="${opts} --http-host 127.0.0.1 --http-port 8083"
exec "#{sbin}/ot-recorder" ${opts} "owntracks/#"
EOS
end
def settings_template; <<-EOS
#(@)ot-recorder.default
#
# Specify global configuration options for the OwnTracks Recorder
# and its associated utilities to override compiled-in defaults.
# Lines beginning with # are comments
# *** In libconfig versions < 1.4 a trailing semicolon is mandatory
# -----------------------------------------------------
# Storage directory
# OTR_STORAGEDIR="/var/spool/owntracks/recorder/store"
# -----------------------------------------------------
# Address or hostname of the MQTT broker
# OTR_HOST="localhost"
# -----------------------------------------------------
# Port number of the MQTT broker. Defaults to 1883.
# MQTT can be disabled by setting this to 0.
# OTR_PORT=1883
# -----------------------------------------------------
# Username for the MQTT connection
# OTR_USER=""
# -----------------------------------------------------
# Password for the MQTT connection
# OTR_PASS=""
# -----------------------------------------------------
# QoS for MQTT connection
# OTR_QOS=2
# -----------------------------------------------------
# MQTT clientid (default is constant+hostname+pid)
# OTR_CLIENTID=""
# -----------------------------------------------------
# Path to PEM-encoded CA certificate file for MQTT (no default)
# OTR_CAFILE=""
# -----------------------------------------------------
# Address for the HTTP module to bind to (default: localhost)
# OTR_HTTPHOST="localhost"
# -----------------------------------------------------
# Port number for the HTTP module to bind to (default: 8083)
# OTR_HTTPPORT=8083
# -----------------------------------------------------
# optional path to HTTP directory in which to store
# access log. Default is to not log access
# OTR_HTTPLOGDIR=""
# -----------------------------------------------------
# API key for reverse-geo lookups
# OTR_GEOKEY=""
# -----------------------------------------------------
# Reverse geo precision
# OTR_PRECISION=7
# -----------------------------------------------------
# Browser API key for Google maps
# OTR_BROWSERAPIKEY=""
# -----------------------------------------------------
# List of topics for MQTT to subscribe to, blank separated in a string
# OTR_TOPICS="owntracks/#"
EOS
end
test do
# `test do` will create, run in and delete a temporary directory.
#
# This test will fail and we won't accept that! It's enough to just replace
# "false" with the main program this formula installs, but it'd be nice if you
# were more thorough. Run the test with `brew test recorder`. Options passed
# to `brew install` such as `--HEAD` also need to be provided to `brew test`.
#
# The installed folder is not in the path, so use the entire path to any
# executables being tested: `system "#{bin}/program", "do", "something"`.
system "false"
end
service do
run etc+"ot-recorder.sh"
require_root false
environment_variables PATH: std_service_path_env
end
end