mirror of
https://github.com/owntracks/recorder.git
synced 2026-08-23 11:26:16 +00:00
introduce system-wide defaults file
This commit is contained in:
@@ -2,7 +2,7 @@ include config.mk
|
||||
|
||||
CFLAGS =-Wall -Werror $(MOSQUITTO_INC)
|
||||
LIBS = $(MORELIBS) $(MOSQUITTO_LIB) -lmosquitto -lm
|
||||
LIBS += -lcurl
|
||||
LIBS += -lcurl -lconfig
|
||||
|
||||
TARGETS=
|
||||
OTR_OBJS = json.o \
|
||||
@@ -64,8 +64,7 @@ else
|
||||
endif
|
||||
|
||||
CFLAGS += -DSTORAGEDEFAULT=\"$(STORAGEDEFAULT)\" -DDOCROOT=\"$(DOCROOT)\"
|
||||
|
||||
|
||||
CFLAGS += -DCONFIGFILE=\"$(CONFIGFILE)\"
|
||||
|
||||
TARGETS += ot-recorder ocat
|
||||
|
||||
@@ -111,6 +110,7 @@ install: ot-recorder ocat
|
||||
cp -R docroot/* $(DESTDIR)$(DOCROOT)/
|
||||
install -m 0755 ot-recorder $(DESTDIR)$(INSTALLDIR)/sbin
|
||||
install -m 0755 ocat $(DESTDIR)$(INSTALLDIR)/bin
|
||||
test -r $(DESTDIR)/$(CONFIGFILE) || install -D etc/ot-recorder.default $(DESTDIR)/$(CONFIGFILE)
|
||||
ifndef DESTDIR
|
||||
$(INSTALLDIR)/sbin/ot-recorder --initialize
|
||||
endif
|
||||
|
||||
@@ -56,6 +56,9 @@ GHASHPREC = 7
|
||||
# yes or no
|
||||
JSON_INDENT ?= no
|
||||
|
||||
# Location of optional default configuration file
|
||||
CONFIGFILE = /etc/defaults/ot-recorder
|
||||
|
||||
# Optionally specify the path to the Mosquitto libs, include here
|
||||
MOSQUITTO_INC = -I/usr/include
|
||||
MOSQUITTO_LIB = -L/usr/lib
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#(@)config.mk for Centos 7 (x86_64)
|
||||
|
||||
INSTALLDIR = /usr/local
|
||||
CONFIGFILE = /etc/default/ot-recorder
|
||||
|
||||
WITH_HTTP ?= yes
|
||||
WITH_LMDB ?= yes
|
||||
|
||||
@@ -28,8 +28,9 @@ fpm -s dir \
|
||||
-d "libcurl" \
|
||||
-d "libmosquitto1" \
|
||||
-d "lua" \
|
||||
-d "libconfig" \
|
||||
--post-install etc/centos/postinst \
|
||||
usr var
|
||||
usr var etc
|
||||
|
||||
echo "${rpmfile}" > package.name
|
||||
rm -rf "${tempdir}"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#(@)config.mk for Debian 8 (x86_64)
|
||||
|
||||
INSTALLDIR = /usr/local
|
||||
CONFIGFILE = /etc/default/ot-recorder
|
||||
|
||||
WITH_HTTP ?= yes
|
||||
WITH_LMDB ?= yes
|
||||
|
||||
@@ -33,8 +33,9 @@ fpm -s dir \
|
||||
-d "libcurl3" \
|
||||
-d "libmosquitto1" \
|
||||
-d "liblua5.2-0" \
|
||||
-d "libconfig9" \
|
||||
--post-install etc/debian/postinst \
|
||||
usr var
|
||||
usr var etc
|
||||
|
||||
echo "${debfile}" > package.name
|
||||
rm -rf "${tempdir}"
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#(@)ot-recorder.default
|
||||
#
|
||||
# Specify global configuration options for the OwnTracks Recorder
|
||||
# and its associated utilities to override compiled-in defaults.
|
||||
|
||||
# OTR_STORAGEDIR = "/var/spool/owntracks/recorder/store"
|
||||
@@ -22,6 +22,8 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <libconfig.h>
|
||||
#include "utstring.h"
|
||||
#include "ctype.h"
|
||||
#include "udata.h"
|
||||
@@ -93,3 +95,32 @@ char *monitor_get()
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* Fill in some defaults
|
||||
*/
|
||||
|
||||
void get_defaults(char *filename, struct udata *ud)
|
||||
{
|
||||
config_t cfg, *cf;
|
||||
const char *value;
|
||||
|
||||
if (access(filename, R_OK) == -1)
|
||||
return;
|
||||
|
||||
config_init(cf = &cfg);
|
||||
|
||||
if (!config_read_file(cf, filename)) {
|
||||
olog(LOG_ERR, "%s:%d - %s",
|
||||
config_error_file(cf),
|
||||
config_error_line(cf),
|
||||
config_error_text(cf));
|
||||
config_destroy(cf);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
if (config_lookup_string(cf, "OTR_STORAGEDIR", &value) != CONFIG_FALSE)
|
||||
strcpy(STORAGEDIR, value);
|
||||
|
||||
config_destroy(cf);
|
||||
}
|
||||
|
||||
@@ -17,5 +17,6 @@ char *bindump(char *buf, long buflen);
|
||||
// void monitor_update(struct udata *ud, time_t now, char *topic);
|
||||
void monitorhook(struct udata *userdata, time_t now, char *topic);
|
||||
char *monitor_get();
|
||||
void get_defaults(char *filename, struct udata *userdata);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -114,6 +114,7 @@ void print_versioninfo()
|
||||
printf("\tWITH_RONLY = yes\n");
|
||||
#endif
|
||||
printf("\tSTORAGEDEFAULT = \"%s\"\n", STORAGEDEFAULT);
|
||||
printf("\tSTORAGEDIR = \"%s\"\n", STORAGEDIR);
|
||||
printf("\tDOCROOT = \"%s\"\n", DOCROOT);
|
||||
printf("\tGHASHPREC = %d\n", GHASHPREC);
|
||||
printf("\tDEFAULT_HISTORY_HOURS = %d\n", DEFAULT_HISTORY_HOURS);
|
||||
@@ -152,6 +153,8 @@ int main(int argc, char **argv)
|
||||
JsonNode *fields = NULL;
|
||||
FILE *xmlp = stdout;
|
||||
|
||||
get_defaults(CONFIGFILE, NULL);
|
||||
|
||||
if ((p = getenv("OCAT_USERNAME")) != NULL) {
|
||||
username = strdup(p);
|
||||
}
|
||||
|
||||
+5
-3
@@ -1321,6 +1321,10 @@ int main(int argc, char **argv)
|
||||
udata.geokey = NULL; /* default: no API key */
|
||||
udata.debug = FALSE;
|
||||
|
||||
openlog("ot-recorder", LOG_PID | LOG_PERROR, syslog_facility_code(logfacility));
|
||||
|
||||
get_defaults(CONFIGFILE, &udata);
|
||||
|
||||
if ((p = getenv("OTR_HOST")) != NULL) {
|
||||
hostname = strdup(p);
|
||||
}
|
||||
@@ -1568,8 +1572,6 @@ int main(int argc, char **argv)
|
||||
password = getenv("OTR_PASS");
|
||||
}
|
||||
|
||||
openlog("ot-recorder", LOG_PID | LOG_PERROR, syslog_facility_code(logfacility));
|
||||
|
||||
#ifdef WITH_HTTP
|
||||
if (http_port) {
|
||||
if (!is_directory(doc_root)) {
|
||||
@@ -1580,7 +1582,7 @@ int main(int argc, char **argv)
|
||||
udata.mgserver = mg_create_server(ud, ev_handler);
|
||||
}
|
||||
#endif
|
||||
olog(LOG_DEBUG, "starting");
|
||||
olog(LOG_DEBUG, "starting with STORAGEDIR=%s", STORAGEDIR);
|
||||
|
||||
if (ud->revgeo == TRUE) {
|
||||
#ifdef WITH_LMDB
|
||||
|
||||
Reference in New Issue
Block a user