Fix Rpi config file corruption

* Add uninstall to Makefile
This commit is contained in:
Marcelo Aquino
2016-08-22 21:26:44 -03:00
parent 412e41967f
commit f0c5a993d5
5 changed files with 30 additions and 7 deletions
+23 -1
View File
@@ -11,7 +11,8 @@ CONFIG_FILE=Makefile.inc
include $(CONFIG_FILE)
GATEWAY=examples_linux/mysGateway
GATEWAY_BIN=mysGateway
GATEWAY=examples_linux/$(GATEWAY_BIN)
GATEWAY_SOURCES=$(wildcard drivers/Linux/*.cpp) examples_linux/mysGateway.cpp
GATEWAY_OBJECTS=$(patsubst %.cpp,%.o,$(GATEWAY_SOURCES))
DEPS+=$(patsubst %.cpp,%.d,$(GATEWAY_SOURCES))
@@ -61,7 +62,28 @@ ifeq ($(INIT_SYSTEM), systemd)
install -m0644 initscripts/mysgateway.systemd /etc/systemd/system/mysgateway.service
@sed -i -e "s|%gateway_dir%|${GATEWAY_DIR}|g" /etc/systemd/system/mysgateway.service
systemctl daemon-reload
@echo "MySensors gateway has been installed, to add to the boot run:"
@echo " sudo systemctl enable mysgateway.service"
@echo "To start the gateway run:"
@echo " sudo systemctl start mysgateway.service"
else ifeq ($(INIT_SYSTEM), sysvinit)
install -m0755 initscripts/mysgateway.sysvinit /etc/init.d/mysgateway
@sed -i -e "s|%gateway_dir%|${GATEWAY_DIR}|g" /etc/init.d/mysgateway
@echo "MySensors gateway has been installed, to add to the boot run:"
@echo " sudo update-rc.d mysgateway defaults"
@echo "To start the gateway run:"
@echo " sudo service mysgateway start"
endif
uninstall:
ifeq ($(INIT_SYSTEM), systemd)
@echo "Stopping daemon mysgateway (ignore errors)"
-@systemctl stop mysgateway.service
@echo "removing files"
rm /etc/systemd/system/mysgateway.service $(GATEWAY_DIR)/$(GATEWAY_BIN)
else ifeq ($(INIT_SYSTEM), sysvinit)
@echo "Stopping daemon mysgateway (ignore errors)"
-@service mysgateway stop
@echo "removing files"
rm /etc/init.d/mysgateway $(GATEWAY_DIR)/$(GATEWAY_BIN)
endif
+1 -1
View File
@@ -732,7 +732,7 @@
* For now the configuration file is only used to store the emulated eeprom state
*/
#ifndef MY_LINUX_CONFIG_FILE
#define MY_LINUX_CONFIG_FILE "/etc/MySensorGateway.cfg"
#define MY_LINUX_CONFIG_FILE "/etc/mysensors.dat"
#endif
// Doxygen specific constructs, not included when built normally
Vendored
+2 -2
View File
@@ -35,7 +35,7 @@ MySensors options:
--my-debug=[enable|disable]
Enables or disables debugging.
Default to enable.
--my-config-file=<FILE> Config file path. [/etc/MySensorGateway.cfg]
--my-config-file=<FILE> Config file path. [/etc/mysensors.dat]
--my-gateway=[none|ethernet|serial|mqtt]
Gateway type, set to none to disable gateway feature.
Default to ethernet.
@@ -248,7 +248,7 @@ for opt do
gateway_type=${optarg}
;;
--my-config-file=*)
CXXFLAGS="-DMY_CONFIG_FILE=${optarg} $CXXFLAGS"
CXXFLAGS="-DMY_LINUX_CONFIG_FILE=\\\"${optarg}\\\" $CXXFLAGS"
;;
--my-radio=*)
radio_type=${optarg}
+3 -2
View File
@@ -90,12 +90,13 @@ void hwWriteConfigBlock(void* buf, void* addr, size_t length)
if (length && offs + length <= _length) {
memcpy(_config+offs, buf, length);
std::ofstream myFile(CONFIG_FILE, std::ios::out | std::ios::binary);
std::ofstream myFile(CONFIG_FILE, std::ios::out | std::ios::in | std::ios::binary);
if (!myFile) {
debug("Unable to write config to file %s.\n", CONFIG_FILE);
return;
}
myFile.write((const char*)buf+offs, _length);
myFile.seekp(offs);
myFile.write((const char*)buf, length);
myFile.close();
}
}
+1 -1
View File
@@ -24,7 +24,7 @@
// For more options run ./configure --help
// Config file
//#define MY_LINUX_CONFIG_FILE "/etc/MySensorGateway.cfg"
//#define MY_LINUX_CONFIG_FILE "/etc/mysensors.dat"
// How many clients should be able to connect to this gateway (default 1)
#define MY_GATEWAY_MAX_CLIENTS 10