don't overwrite config on update
Config.cpp namespace instead of static class print version on service startup
This commit is contained in:
@ -5,6 +5,7 @@
|
||||
#include <Config.h>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
|
||||
#include "libconfig.h++"
|
||||
|
||||
@ -22,7 +23,31 @@ bool Config::readCredentials() {
|
||||
}
|
||||
catch (const libconfig::FileIOException &fioex) {
|
||||
std::cout << "I/O error while reading config file." << std::endl << "creating new config file!" << std::endl;
|
||||
cfg.writeFile("/etc/iprefresher.cfg");
|
||||
|
||||
std::string defaultconf = R"(# Dynu IP refresher config
|
||||
# 2020
|
||||
# Lukas Heiligenbrunner
|
||||
|
||||
## DYNU API Config
|
||||
dynuapikey = ""
|
||||
domainid = ""
|
||||
domainname = ""
|
||||
|
||||
## Telegram API Config (optional)
|
||||
#telegramApiKey = ""
|
||||
#chatId = ""
|
||||
)";
|
||||
|
||||
std::ofstream myfile;
|
||||
myfile.open("/etc/iprefresher.cfg");
|
||||
if(myfile.is_open()){
|
||||
myfile << defaultconf;
|
||||
myfile.close();
|
||||
} else {
|
||||
std::cout << "error creating file" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
catch (const libconfig::ParseException &pex) {
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include <IPRefresher.h>
|
||||
#include <Config.h>
|
||||
#include <Version.h>
|
||||
|
||||
void IPRefresher::checkIPAdress(bool force) {
|
||||
FileLogger logger;
|
||||
@ -55,6 +56,7 @@ IPRefresher::IPRefresher() = default;
|
||||
IPRefresher::IPRefresher(bool loop) {
|
||||
if (loop) {
|
||||
Logger::message("startup of service");
|
||||
Logger::message("Version: " + Version::VERSION);
|
||||
if (Config::readCredentials()) {
|
||||
while (true) {
|
||||
Logger::message("starting check");
|
||||
|
@ -3,8 +3,8 @@
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <IPRefresher.h>
|
||||
#include <Version.h>
|
||||
#include <IPRefresher.h>
|
||||
#include <Logger.h>
|
||||
#include <Config.h>
|
||||
|
||||
|
Reference in New Issue
Block a user