Skip to content

Commit

Permalink
introduce system-wide defaults file
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan-Piet Mens committed Feb 9, 2016
1 parent c501130 commit ea0d1d4
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Makefile
Expand Up @@ -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 \
Expand Down Expand Up @@ -64,8 +64,7 @@ else
endif

CFLAGS += -DSTORAGEDEFAULT=\"$(STORAGEDEFAULT)\" -DDOCROOT=\"$(DOCROOT)\"


CFLAGS += -DCONFIGFILE=\"$(CONFIGFILE)\"

TARGETS += ot-recorder ocat

Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions config.mk.in
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions etc/centos/config.mk.in
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion etc/centos/fpm-make.sh
Expand Up @@ -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 change: 1 addition & 0 deletions etc/debian/config.mk.in
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion etc/debian/fpm-make.sh
Expand Up @@ -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}"
6 changes: 6 additions & 0 deletions etc/ot-recorder.default
@@ -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"
31 changes: 31 additions & 0 deletions misc.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions misc.h
Expand Up @@ -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
3 changes: 3 additions & 0 deletions ocat.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 5 additions & 3 deletions recorder.c
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)) {
Expand All @@ -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
Expand Down

0 comments on commit ea0d1d4

Please sign in to comment.