1#   BAREOS® - Backup Archiving REcovery Open Sourced
2#
3#   Copyright (C) 2017-2020 Bareos GmbH & Co. KG
4#
5#   This program is Free Software; you can redistribute it and/or
6#   modify it under the terms of version three of the GNU Affero General Public
7#   License as published by the Free Software Foundation and included
8#   in the file LICENSE.
9#
10#   This program is distributed in the hope that it will be useful, but
11#   WITHOUT ANY WARRANTY; without even the implied warranty of
12#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13#   Affero General Public License for more details.
14#
15#   You should have received a copy of the GNU Affero General Public License
16#   along with this program; if not, write to the Free Software
17#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18#   02110-1301, USA.
19
20macro(BareosInstallConfigFiles CONFDIR CONFIGBASEDIRECTORY PLUGINS BACKENDS
21      SRC_DIR
22)
23
24  message(
25    STATUS
26      "BareosInstallConfigFiles called with CONFDIR:${CONFDIR} CONFIGBASEDIRECTORY:${CONFIGBASEDIRECTORY} PLUGINS:${PLUGINS} BACKENDS:${BACKENDS} SRC_DIR:${SRC_DIR}"
27  )
28  message(
29    STATUS "CPACK_PACKAGING_INSTALL_PREFIX: ${CPACK_PACKAGING_INSTALL_PREFIX}"
30  )
31  message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
32  message(STATUS "DESTDIR: $ENV{DESTDIR}")
33
34  if(IS_ABSOLUTE ${CONFDIR})
35    set(DESTCONFDIR "$ENV{DESTDIR}${CONFDIR}/${CONFIGBASEDIRECTORY}/")
36  else()
37    set(DESTCONFDIR
38        "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${CONFDIR}/${CONFIGBASEDIRECTORY}/"
39    )
40  endif()
41
42  message(
43    STATUS
44      "installing configuration ${CONFIGBASEDIRECTORY}  resource files to ${DESTCONFDIR}"
45  )
46
47  message(
48    STATUS "globbing ${SRC_DIR}/src/defaultconfigs/${CONFIGBASEDIRECTORY}/*"
49  )
50  file(GLOB resourcedirs
51       "${SRC_DIR}/src/defaultconfigs/${CONFIGBASEDIRECTORY}/*"
52  )
53  foreach(resdir ${resourcedirs})
54    file(GLOB configfiles "${resdir}/*.conf")
55    get_filename_component(resname ${resdir} NAME)
56    foreach(configfile ${configfiles})
57      get_filename_component(fname ${configfile} NAME)
58      message(STATUS "${resname}/${fname} as ${resname}/${fname}.sample (new installation)")
59      file(RENAME "${configfile}" "${configfile}.sample")
60      file(
61       COPY "${configfile}.sample"
62       DESTINATION "${DESTCONFDIR}/${resname}"
63      )
64    endforeach()
65  endforeach()
66
67  # add bareos-dir-export for bareos-dir
68  if(${CONFIGBASEDIRECTORY} STREQUAL "bareos-dir.d")
69    file(MAKE_DIRECTORY "${DESTCONFDIR}/../bareos-dir-export/client/")
70    file(MAKE_DIRECTORY "${DESTCONFDIR}/counter")
71    file(MAKE_DIRECTORY "${DESTCONFDIR}/user")
72  endif()
73
74  # add ndmp resource directory for bareos-sd
75  if(${CONFIGBASEDIRECTORY} STREQUAL "bareos-sd.d")
76    file(MAKE_DIRECTORY "${DESTCONFDIR}/ndmp")
77  endif()
78
79  # install configs from sd backends
80  foreach(BACKEND ${BACKENDS})
81
82    message(
83      STATUS
84        "install ${CONFIGBASEDIRECTORY} config files for BACKEND ${BACKEND}"
85    )
86    set(BackendConfigSrcDir
87        "${SRC_DIR}/src/stored/backends/${BACKEND}/${CONFIGBASEDIRECTORY}"
88    )
89
90    file(
91      GLOB_RECURSE configfiles
92      RELATIVE "${BackendConfigSrcDir}"
93      "${BackendConfigSrcDir}/*.conf"
94    )
95    foreach(configfile ${configfiles})
96      get_filename_component(dir ${configfile} DIRECTORY)
97      get_filename_component(fname ${configfile} NAME)
98
99      message(STATUS "${configfile} as ${configfile}")
100      file(RENAME "${BackendConfigSrcDir}/${configfile}" "${BackendConfigSrcDir}/${configfile}.sample")
101      file(
102       COPY "${BackendConfigSrcDir}/${configfile}.sample"
103       DESTINATION "${DESTCONFDIR}/${dir}"
104      )
105    endforeach()
106
107    file(
108      GLOB_RECURSE configfiles
109      RELATIVE "${BackendConfigSrcDir}"
110      "${BackendConfigSrcDir}/*.example"
111    )
112    foreach(configfile ${configfiles})
113      get_filename_component(dir ${configfile} DIRECTORY)
114      get_filename_component(fname ${configfile} NAME)
115      get_filename_component(fsname ${configfile} NAME_WE)
116
117      if(EXISTS ${DESTCONFDIR}/${configfile})
118        message(STATUS "overwriting ${configfile}")
119      else()
120        message(STATUS "${configfile} as ${configfile}")
121      endif()
122
123      file(RENAME "${BackendConfigSrcDir}/${configfile}" "${BackendConfigSrcDir}/${fsname}.conf.sample")
124       file(
125       COPY "${BackendConfigSrcDir}/${fsname}.conf.sample"
126       DESTINATION "${DESTCONFDIR}/${dir}"
127       )
128    endforeach()
129
130  endforeach()
131
132  # install configs from  fd plugins
133  foreach(PLUGIN ${PLUGINS})
134    message(STATUS "install config files for PLUGIN ${PLUGIN}")
135
136    # if plugin has -, conf.d directory is: python-ovirt ->
137    # python/ovirt/python-ovirt-conf.d else it is : cephfs ->
138    # cephfs/cephfs-conf.d
139
140    string(REPLACE "-" "/" PLUGINPATH "${PLUGIN}")
141    string(APPEND PLUGINPATH "/" ${PLUGIN} "-conf.d")
142    message(STATUS "PLUGINPATH for PLUGIN ${PLUGIN} is ${PLUGINPATH}")
143
144    file(GLOB resourcedirs
145         "${SRC_DIR}/src/plugins/filed/${PLUGINPATH}/${CONFIGBASEDIRECTORY}/*"
146    )
147    foreach(resdir ${resourcedirs})
148      file(GLOB configfiles "${resdir}/*.conf*")
149      get_filename_component(resname ${resdir} NAME)
150      foreach(configfile ${configfiles})
151        string(REGEX MATCH "\\.in\$" IS_INFILE ${configfile})
152        if(NOT "${IS_INFILE}" STREQUAL ".in")
153          get_filename_component(fname ${configfile} NAME)
154          get_filename_component(fsname ${configfile} NAME_WE)
155          message(STATUS "${resname}/${fname} as ${resname}/${fname}")
156          file(RENAME "${configfile}" "${resdir}/${fsname}.conf.sample")
157          file(
158            COPY "${resdir}/${fsname}.conf.sample"
159            DESTINATION "${DESTCONFDIR}/${resname}"
160          )
161        else()
162          message(STATUS "skipping .in file ${configfile}:${IS_INFILE}")
163        endif()
164      endforeach()
165    endforeach()
166  endforeach()
167
168endmacro(BareosInstallConfigFiles)
169