aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan McCrohan <jmccrohan@gmail.com>2012-12-04 01:12:15 +0000
committerJonathan McCrohan <jmccrohan@gmail.com>2012-12-04 01:29:32 +0000
commit45b134f897572318f182aa5faa348c5bd39fa7ae (patch)
tree1dec0092e27d994750b39b809e88182515e4e705
parent9083b82a25bdb9c25e7da0cfb4ebe515186c71e1 (diff)
downloadverteco-45b134f897572318f182aa5faa348c5bd39fa7ae.tar.gz
ftpupload: decouple ftpupload from modbuslog
Allow ftpupload to be used as an independent program. This enables it to be used by both modbuslog and phidgetcontrol. The ftp stanza in /etc/modbuslog has been split out into a separate ftpupload configuration file located at /etc/ftpupload. ftpupload now reads the $UPLOADTYPE variable to determine which type of upload to execute. If $UPLOADTYPE has not been set, ftpupload will default to modbuslog.
-rw-r--r--Makefile24
-rw-r--r--cron/modbuslog2
-rw-r--r--cron/phidgetcontrol2
-rw-r--r--src/ftphelper.c2
-rwxr-xr-xsrc/ftpupload3
-rw-r--r--src/modbuslog.cfg7
-rw-r--r--src/modbuslog_all.cfg7
-rw-r--r--src/modbuslog_pulse.cfg7
-rw-r--r--src/modbuslog_ws.cfg7
-rw-r--r--src/modbuslog_wsgps.cfg7
10 files changed, 18 insertions, 50 deletions
diff --git a/Makefile b/Makefile
index aa4f279..ccdbb65 100644
--- a/Makefile
+++ b/Makefile
@@ -8,9 +8,10 @@ MODBUSLOGBINDIR=/usr/sbin
MODBUSLOGCFGDIR=/etc
MODBUSLOGLOGDIR=/var/modbuslog
MODBUSLOGCRONDIR=/etc/cron.d
-FTPHELPERCFLAGS=
-FTPHELPERLIBS=-lconfig
-FTPHELPERDIR=/usr/bin
+FTPUPLOADCFLAGS=
+FTPUPLOADLIBS=-lconfig
+FTPUPLOADCFGDIR=/etc
+FTPUPLOADBINDIR=/usr/bin
LIGHTINGCONTROLCFLAGS=
LIGHTINGCONTROLLIBS=-lconfig
LIGHTINGCONTROLBINDIR=/usr/sbin
@@ -28,11 +29,11 @@ WWWDIR=/var/www
GITTAGFLAG := -D'VERSION_STRING="$(shell LC_ALL=C git describe --tags)"'
MODBUSLOGCFLAGS += $(GITTAGFLAG)
-FTPHELPERCFLAGS += $(GITTAGFLAG)
+FTPUPLOADCFLAGS += $(GITTAGFLAG)
LIGHTINGCONTROLCFLAGS += $(GITTAGFLAG)
PHIDGETCONTROLCFLAGS += $(GITTAGFLAG)
-all: modbuslog ftphelper lightingcontrol phidgetcontrol weatherstation_test
+all: modbuslog ftpupload lightingcontrol phidgetcontrol weatherstation_test
clean:
rm -f $(SDIR)/modbuslog
@@ -44,8 +45,8 @@ clean:
modbuslog: $(SDIR)/modbuslog.c
$(CC) -o $(SDIR)/$@ $^ $(MODBUSLOGCFLAGS) $(MODBUSLOGLIBS)
-ftphelper: $(SDIR)/ftphelper.c
- $(CC) -o $(SDIR)/$@ $^ $(FTPHELPERCFLAGS) $(FTPHELPERLIBS)
+ftpupload: $(SDIR)/ftphelper.c
+ $(CC) -o $(SDIR)/ftphelper $^ $(FTPUPLOADCFLAGS) $(FTPUPLOADLIBS)
lightingcontrol: $(SDIR)/lightingcontrol.c
$(CC) -o $(SDIR)/$@ $^ $(LIGHTINGCONTROLCFLAGS) $(LIGHTINGCONTROLLIBS)
@@ -69,9 +70,10 @@ install_modbuslog:
test -f $(MODBUSLOGCRONDIR)/modbuslog || $(INSTALL) -m 644 $(CRONDIR)/modbuslog $(MODBUSLOGCRONDIR)/modbuslog
$(INSTALL) $(PHPSDIR)/readfile.php $(WWWDIR)/readfile.php
-install_ftphelper:
- $(INSTALL) $(SDIR)/ftpupload $(FTPHELPERDIR)/ftpupload
- $(INSTALL) $(SDIR)/ftphelper $(FTPHELPERDIR)/ftphelper
+install_ftpupload:
+ test -f $(CFGDIR)/ftpupload.cfg || $(INSTALL) -m 644 $(SDIR)/ftpupload.cfg $(FTPUPLOADCFGDIR)/ftpupload.cfg
+ $(INSTALL) $(SDIR)/ftpupload $(FTPUPLOADBINDIR)/ftpupload
+ $(INSTALL) $(SDIR)/ftphelper $(FTPUPLOADBINDIR)/ftphelper
install_lightingcontrol:
$(INSTALL) $(SDIR)/lightingcontrol $(LIGHTINGCONTROLDIR)/lightingcontrol
@@ -89,6 +91,6 @@ install_phidgetcontrol:
fi
test -f $(PHIDGETCONTROLCRONDIR)/phidgetcontrol || $(INSTALL) -m 644 $(CRONDIR)/phidgetcontrol $(PHIDGETCONTROLCRONDIR)/phidgetcontrol
-installall: install_modbuslog install_ftphelper install_lightingcontrol install_phidgetcontrol
+installall: install_modbuslog install_ftpupload install_lightingcontrol install_phidgetcontrol
install: all installall
diff --git a/cron/modbuslog b/cron/modbuslog
index 58abb29..453ffff 100644
--- a/cron/modbuslog
+++ b/cron/modbuslog
@@ -3,4 +3,4 @@ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
@reboot root /usr/sbin/modbuslog
-10 0 * * * root /usr/bin/ftpupload
+10 0 * * * root UPLOADTYPE=modbuslog /usr/bin/ftpupload
diff --git a/cron/phidgetcontrol b/cron/phidgetcontrol
index 7a6438b..32de0a8 100644
--- a/cron/phidgetcontrol
+++ b/cron/phidgetcontrol
@@ -3,4 +3,4 @@ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
@reboot root /usr/sbin/phidgetcontrol
-10 0 * * * root /usr/bin/ftpupload
+10 0 * * * root UPLOADTYPE=phidgetcontrol /usr/bin/ftpupload
diff --git a/src/ftphelper.c b/src/ftphelper.c
index 69527db..889b9c5 100644
--- a/src/ftphelper.c
+++ b/src/ftphelper.c
@@ -64,7 +64,7 @@ int main(int argc, char *argv[]) {
return 0;
}
- const char *configfile = "/etc/modbuslog.cfg";
+ const char *configfile = "/etc/ftpupload.cfg";
config_t cfg;
const char *ftp_server;
const char *ftp_username;
diff --git a/src/ftpupload b/src/ftpupload
index 7c612d5..f02e269 100755
--- a/src/ftpupload
+++ b/src/ftpupload
@@ -7,7 +7,8 @@
USERNAME=`/usr/bin/ftphelper --username`
PASSWORD=`/usr/bin/ftphelper --password`
SERVER=`/usr/bin/ftphelper --server`
-LOCALDIRECTORY="/var/modbuslog"
+# default to modbuslog if unset
+LOCALDIRECTORY="/var/${UPLOADTYPE-modbuslog}"
REMOTEDIRECTORY=`/usr/bin/ftphelper --directory`
# current file to be uploaded
diff --git a/src/modbuslog.cfg b/src/modbuslog.cfg
index 9c23660..75f29eb 100644
--- a/src/modbuslog.cfg
+++ b/src/modbuslog.cfg
@@ -11,13 +11,6 @@ modbus = {
retry = 2;
};
-ftp = {
- server = "ftp.verteco.ie";
- username = "loggerdevice";
- password = "securepassword";
- directory = ".";
-};
-
reading= (
{
# digirail series number
diff --git a/src/modbuslog_all.cfg b/src/modbuslog_all.cfg
index 9c23660..75f29eb 100644
--- a/src/modbuslog_all.cfg
+++ b/src/modbuslog_all.cfg
@@ -11,13 +11,6 @@ modbus = {
retry = 2;
};
-ftp = {
- server = "ftp.verteco.ie";
- username = "loggerdevice";
- password = "securepassword";
- directory = ".";
-};
-
reading= (
{
# digirail series number
diff --git a/src/modbuslog_pulse.cfg b/src/modbuslog_pulse.cfg
index 05377a9..e628bc2 100644
--- a/src/modbuslog_pulse.cfg
+++ b/src/modbuslog_pulse.cfg
@@ -11,13 +11,6 @@ modbus = {
retry = 2;
};
-ftp = {
- server = "ftp.verteco.ie";
- username = "loggerdevice";
- password = "securepassword";
- directory = ".";
-};
-
reading= (
{
# digirail series number
diff --git a/src/modbuslog_ws.cfg b/src/modbuslog_ws.cfg
index 9d0d8e6..97b033e 100644
--- a/src/modbuslog_ws.cfg
+++ b/src/modbuslog_ws.cfg
@@ -11,13 +11,6 @@ modbus = {
retry = 2;
};
-ftp = {
- server = "ftp.verteco.ie";
- username = "loggerdevice";
- password = "securepassword";
- directory = ".";
-};
-
reading= (
{
# digirail series number
diff --git a/src/modbuslog_wsgps.cfg b/src/modbuslog_wsgps.cfg
index 0dbf5a4..2022da4 100644
--- a/src/modbuslog_wsgps.cfg
+++ b/src/modbuslog_wsgps.cfg
@@ -11,13 +11,6 @@ modbus = {
retry = 2;
};
-ftp = {
- server = "ftp.verteco.ie";
- username = "loggerdevice";
- password = "securepassword";
- directory = ".";
-};
-
reading= (
{