don't overwrite config on update
Config.cpp namespace instead of static class print version on service startup
This commit is contained in:
parent
78d07ac95b
commit
cf49bf7bc5
@ -1,3 +1,6 @@
|
||||
# author Lukas Heiligenbrunner
|
||||
# main CMake file
|
||||
#
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
project(iprefresher DESCRIPTION "Dynu ip refresher")
|
||||
|
||||
@ -47,7 +50,7 @@ message("")
|
||||
|
||||
#add version header
|
||||
FILE(WRITE ${CMAKE_SOURCE_DIR}/inc/Version.h
|
||||
"\#pragma once\nclass Version {\npublic:\n static const std::string VERSION;\n};\n\nstd::string const Version::VERSION = \"${PROJECT_VERSION}\";"
|
||||
"\#pragma once\n#include <string>\nnamespace Version {\n const std::string VERSION = \"${PROJECT_VERSION}\";\n}"
|
||||
)
|
||||
|
||||
add_library(api ${LIB_METHOD}
|
||||
@ -78,9 +81,17 @@ target_link_libraries(iprefresher api logger ${CURL_LIBRARIES} config++)
|
||||
|
||||
# INSTALL to SYSTEM #
|
||||
set(CMAKE_INSTALL_PREFIX "/")
|
||||
# install binaries
|
||||
install(TARGETS iprefresher DESTINATION usr/bin)
|
||||
# install config file if it doesn't exist
|
||||
install(CODE "MESSAGE(STATUS \"Copy iprefresher.cfg to ${CMAKE_INSTALL_PREFIX}etc/iprefresher.cfg\")
|
||||
IF (NOT EXISTS ${CMAKE_INSTALL_PREFIX}etc/iprefresher.cfg)
|
||||
EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/config/iprefresher.cfg
|
||||
${CMAKE_INSTALL_PREFIX}etc/iprefresher.cfg)
|
||||
ENDIF (NOT EXISTS ${CMAKE_INSTALL_PREFIX}etc/iprefresher.cfg)")
|
||||
# install systemd service and enable it
|
||||
install(FILES service/iprefresher.service DESTINATION lib/systemd/system)
|
||||
install(FILES config/iprefresher.cfg DESTINATION etc)
|
||||
|
||||
|
||||
IF (UNIX)
|
||||
|
@ -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>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user