Skip to content

Commit

Permalink
cmake: unify installing Bareos config files
Browse files Browse the repository at this point in the history
The handling of bconsole.conf have been wrong in some cases.
Now installing config files uses the same cmake code.
  • Loading branch information
joergsteffens authored and arogge committed Dec 12, 2023
1 parent e347937 commit 4e9f6fa
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 29 deletions.
55 changes: 38 additions & 17 deletions core/cmake/BareosInstallConfigFiles.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2017-2022 Bareos GmbH & Co. KG
# Copyright (C) 2017-2023 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand All @@ -17,6 +17,39 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.

function(bareos_install_single_config_file configfile baseconfigdir
additionalconfigdir
)
if(IS_ABSOLUTE ${baseconfigdir})
set(DESTCONFDIR "$ENV{DESTDIR}${baseconfigdir}/")
else()
set(DESTCONFDIR "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${baseconfigdir}/")
endif()

get_filename_component(fname ${configfile} NAME)
if(EXISTS ${DESTCONFDIR}${additionalconfigdir}/${fname})
message(
STATUS "${DESTCONFDIR}${additionalconfigdir}/${fname} already exists"
)
message(
STATUS
"Installing config: ${DESTCONFDIR}${additionalconfigdir}/${fname}.new"
)
file(RENAME "${configfile}" "${configfile}.new")
file(COPY "${configfile}.new"
DESTINATION "${DESTCONFDIR}${additionalconfigdir}"
)
file(RENAME "${configfile}.new" "${configfile}")
else()
message(
STATUS "Installing config: ${DESTCONFDIR}${additionalconfigdir}/${fname}"
)
file(COPY "${configfile}"
DESTINATION "${DESTCONFDIR}${additionalconfigdir}"
)
endif()
endfunction()

macro(BareosInstallConfigFiles CONFDIR CONFIGBASEDIRECTORY PLUGINS BACKENDS
SRC_DIR
)
Expand All @@ -41,7 +74,7 @@ macro(BareosInstallConfigFiles CONFDIR CONFIGBASEDIRECTORY PLUGINS BACKENDS

message(
STATUS
"installing configuration ${CONFIGBASEDIRECTORY} resource files to ${DESTCONFDIR}"
"installing configuration ${CONFIGBASEDIRECTORY} resource files to ${DESTCONFDIR}"
)

message(
Expand All @@ -54,21 +87,9 @@ macro(BareosInstallConfigFiles CONFDIR CONFIGBASEDIRECTORY PLUGINS BACKENDS
file(GLOB configfiles "${resdir}/*.conf")
get_filename_component(resname ${resdir} NAME)
foreach(configfile ${configfiles})
get_filename_component(fname ${configfile} NAME)
if(EXISTS ${DESTCONFDIR}/${resname}/${fname})
message(STATUS "${DESTCONFDIR}/${resname}/${fname} exists")
message(STATUS "rename ${configfile} to ${configfile}.new")
file(RENAME "${configfile}" "${configfile}.new")

message(STATUS "copy ${configfile}.new to ${DESTCONFDIR}/${resname}")
file(COPY "${configfile}.new" DESTINATION "${DESTCONFDIR}/${resname}")
file(RENAME "${configfile}.new" "${configfile}")
else()
message(
STATUS "${resname}/${fname} as ${resname}/${fname} (new installation)"
)
file(COPY "${configfile}" DESTINATION "${DESTCONFDIR}/${resname}")
endif()
bareos_install_single_config_file(
"${configfile}" "${CONFDIR}" "${CONFIGBASEDIRECTORY}/${resname}"
)
endforeach()
endforeach()

Expand Down
15 changes: 3 additions & 12 deletions core/src/console/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2017-2022 Bareos GmbH & Co. KG
# Copyright (C) 2017-2023 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -53,16 +53,7 @@ install(

install(
CODE "
message(STATUS \"DESTDIR is \$ENV{DESTDIR}\")
set(DESTDIR \$ENV{DESTDIR})
if(NOT EXISTS \$ENV{DESTDIR}${configtemplatedir}/bconsole.conf)
message(STATUS \"Installing: \$ENV{DESTDIR}${configtemplatedir}/bconsole.conf\")
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/bconsole.conf DESTINATION \$ENV{DESTDIR}${configtemplatedir})
else()
message(STATUS \"Installing: \$ENV{DESTDIR}${configtemplatedir}/bconsole.conf.new\")
file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/bconsole.conf ${CMAKE_CURRENT_SOURCE_DIR}/bconsole.conf.new)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/bconsole.conf.new DESTINATION \$ENV{DESTDIR}${configtemplatedir})
file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/bconsole.conf.new ${CMAKE_CURRENT_SOURCE_DIR}/bconsole.conf)
endif()
include(\"${PROJECT_SOURCE_DIR}/cmake/BareosInstallConfigFiles.cmake\")
bareos_install_single_config_file(\"${CMAKE_CURRENT_SOURCE_DIR}/bconsole.conf\" \"${configtemplatedir}\" \".\")
"
)

0 comments on commit 4e9f6fa

Please sign in to comment.