blob: 54ac3c494888dbe7ca85211e475f0a31e4351823 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
# SPDX-License-Identifier: GPL-3.0-or-later
cmake_minimum_required(VERSION 3.16.0...3.30)
list(APPEND RHEL_DISTROS centos centos-stream rocky almalinux cloudlinux)
list(APPEND SUSE_DISTROS opensuse-leap opensuse-tumbleweed)
list(APPEND RPM_DISTROS rhel opensuse ol amzn fedora)
list(APPEND DEB_DISTROS debian ubuntu)
set(DEB_GPG_KEY_SOURCE "https://repo.netdata.cloud/netdatabot.gpg.key")
set(PACKAGE_VERSION 4)
set(PACKAGE_RELEASE 1)
set(CPACK_THREADS 0)
set(CPACK_STRIP_FILES NO)
set(CPACK_PACKAGE_INSTALL_DIRECTORY "netdata")
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/packages")
set(CPACK_PACKAGING_INSTALL_PREFIX "/")
set(CPACK_PACKAGE_VENDOR "Netdata Inc.")
set(CPACK_COMPONENT_NETDATA-REPO_PACKAGE_DESCRIPTION "Configuration for the official Netdata Stable package repository.")
set(CPACK_COMPONENT_NETDATA-REPO-EDGE_PACKAGE_DESCRIPTION "Configuration for the official Netdata Edge package repository.")
project(netdata-repoconfig VERSION "${PACKAGE_VERSION}.${PACKAGE_RELEASE}"
DESCRIPTION "Repository configuration for Netdata’s official native packages."
HOMEPAGE_URL "https://www.netdata.cloud/"
LANGUAGES NONE)
function(extract_release_item _variable _item)
if(DEFINED "${_variable}")
return()
endif()
if(DEFINED OS_RELEASE_FILE)
else()
message(CHECK_START "Searching for os-release file")
find_file(OS_RELEASE_FILE os-release PATHS /etc /lib /usr/lib NO_DEFAULT_PATH)
if(${OS_RELEASE_FILE} STREQUAL "OS_RELEASE_FILE-NOTFOUND")
message(CHECK_FAIL "failed")
message(FATAL_ERROR "Could not find os-release file")
endif()
message(CHECK_PASS "${OS_RELEASE_FILE}")
endif()
message(CHECK_START "Extracting ${_item} from ${OS_RELEASE_FILE}")
execute_process(COMMAND sh -c ". ${OS_RELEASE_FILE} && printf %s $${_item}"
RESULT_VARIABLE _result
OUTPUT_VARIABLE _output)
if(NOT ${_result} EQUAL 0)
message(CHECK_FAIL "failed to parse ${OS_RELEASE_FILE}")
return()
elseif(${_output} STREQUAL "")
message(CHECK_FAIL "variable ${_item} not defined in ${OS_RELEASE_FILE}")
return()
endif()
message(CHECK_PASS ${_output})
set(${_variable} ${_output} PARENT_SCOPE)
endfunction()
function(require_command _variable _cmd)
if(DEFINED ${_variable})
return()
endif()
message(CHECK_START "Looking for ${_cmd}")
find_program(_result_${_cmd} ${_cmd})
if(${_result_${_cmd}} STREQUAL "_result_${_cmd}-NOTFOUND")
message(CHECK_FAIL "failed")
message(FATAL_ERROR "Unable to find required command: ${_cmd}")
endif()
message(CHECK_PASS "${_result_${_cmd}}")
set(${_variable} ${_result_${_cmd}} PARENT_SCOPE)
endfunction()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
extract_release_item("DISTRO" ID)
if(NOT DEFINED DISTRO)
message(FATAL_ERROR "Failed to auto-detect distro ID")
endif()
extract_release_item(DISTRO_VERSION VERSION_ID)
if(NOT DEFINED DISTRO_VERSION)
message(FATAL_ERROR "Failed to auto-detect distro version ID.")
endif()
else()
message(FATAL_ERROR "Repository configuration packages can only be built on Linux")
endif()
if(${DISTRO} IN_LIST RHEL_DISTROS)
set(DISTRO "rhel")
elseif(${DISTRO} STREQUAL "opensuse-leap")
set(DISTRO "opensuse")
elseif(${DISTRO} STREQUAL "opensuse-tumbleweed")
set(DISTRO "opensuse")
set(DISTRO_VERSION "tumbleweed")
endif()
if(${DISTRO} IN_LIST DEB_DISTROS)
extract_release_item(SUITE VERSION_CODENAME)
if(NOT DEFINED SUITE)
message(FATAL_ERROR "Failed to determine version codename")
endif()
require_command(DPKG dpkg)
require_command(CURL curl)
require_command(GPG gpg)
set(DIST_NAME ${DISTRO})
message(STATUS "Generating stable repository configuration for ${DISTRO} ${SUITE}")
set(VARIANT stable)
configure_file(netdata.sources.in netdata.sources @ONLY)
message(STATUS "Generating edge repository configuration for ${DISTRO} ${SUITE}")
set(VARIANT edge)
configure_file(netdata.sources.in netdata-edge.sources @ONLY)
message(STATUS "Preparing changelogs")
set(PKG_NAME netdata-repo)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/netdata-repo)
configure_file(deb.changelog netdata-repo/changelog @ONLY)
set(PKG_NAME netdata-repo-edge)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/netdata-repo-edge)
configure_file(deb.changelog netdata-repo-edge/changelog @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/netdata.sources
DESTINATION etc/apt/sources.list.d
COMPONENT netdata-repo)
install(FILES ${CMAKE_BINARY_DIR}/netdata-edge.sources
DESTINATION etc/apt/sources.list.d
COMPONENT netdata-repo-edge)
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/netdatabot.gpg.key
COMMENT "Fetch GPG key from ${DEB_GPG_KEY_SOURCE}"
COMMAND ${CURL} -f -L -o ${CMAKE_BINARY_DIR}/netdatabot.gpg.key ${DEB_GPG_KEY_SOURCE})
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/netdata.gpg
COMMENT "Dearmor ${CMAKE_BINARY_DIR}/netdatabot.gpg.key"
DEPENDS ${CMAKE_BINARY_DIR}/netdatabot.gpg.key
COMMAND ${GPG} --dearmor --output ${CMAKE_BINARY_DIR}/netdata.gpg ${CMAKE_BINARY_DIR}/netdatabot.gpg.key)
add_custom_target(dearmor_gpg_key
ALL
COMMENT "Dearmor ${CMAKE_BINARY_DIR}/netdatabot.gpg.key"
DEPENDS ${CMAKE_BINARY_DIR}/netdata.gpg)
install(FILES ${CMAKE_BINARY_DIR}/netdata.gpg
DESTINATION usr/share/keyrings
RENAME netdata-archive-keyring.gpg
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
COMPONENT netdata-repo)
install(FILES ${CMAKE_BINARY_DIR}/netdata.gpg
DESTINATION usr/share/keyrings
RENAME netdata-archive-keyring.gpg
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
COMPONENT netdata-repo-edge)
set(CPACK_DEB_COMPONENT_INSTALL YES)
set(CPACK_DEBIAN_DEBUGINFO_PACKAGE NO)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS NO)
set(CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS YES)
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Netdata Builder <bot@netdata.cloud>")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "all")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "debian-keyring, gnupg")
set(CPACK_DEBIAN_PACKAGE_SECTION "net")
set(CPACK_DEBIAN_PACKAGE_VERSION "${PACKAGE_VERSION}")
set(CPACK_DEBIAN_PACKAGE_RELEASE "${PACKAGE_RELEASE}")
set(CPACK_DEBIAN_NETDATA-REPO_PACKAGE_NAME "netdata-repo")
set(CPACK_DEBIAN_NETDATA-REPO-EDGE_PACKAGE_NAME "netdata-repo-edge")
set(CPACK_DEBIAN_NETDATA-REPO_PACKAGE_CONFLICTS "netdata-repo-edge")
set(CPACK_DEBIAN_NETDATA-REPO-EDGE_PACKAGE_CONFLICTS "netdata-repo")
set(CPACK_DEBIAN_NETDATA-REPO_PACKAGE_CONTROL_EXTRA "${CMAKE_BINARY_DIR}/netdata-repo/changelog")
set(CPACK_DEBIAN_NETDATA-REPO-EDGE_PACKAGE_CONTROL_EXTRA "${CMAKE_BINARY_DIR}/netdata-repo-edge/changelog")
elseif(${DISTRO} IN_LIST RPM_DISTROS)
require_command(RPM rpm)
if(${RPM} STREQUAL "RPM-NOTFOUND")
message(FATAL_ERROR "Unable to find rpm, which is required for RPM package builds.")
endif()
set(REPO_CFG_PATH "yum.repos.d")
set(REPO_ID "dnf")
set(DIST_NAME "${DISTRO}")
set(DIST_VERSION "$releasever")
if(${DISTRO} STREQUAL "amzn")
set(DIST_NAME "amazonlinux")
if(${DISTRO_VERSION} VERSION_EQUAL 2)
# Nothing to do in this case, defaults work here.
elseif(${DISTRO_VERSION} VERSION_EQUAL 2023)
set(DIST_VERSION "2023")
else()
message(FATAL_ERROR "Unsupported version of Amazon Linux: ${DISTRO_VERSION}")
endif()
elseif(${DISTRO} STREQUAL "opensuse")
set(REPO_CFG_PATH "zypp/repos.d")
set(REPO_ID "zypp")
set(DIST_NAME "opensuse")
elseif(${DISTRO} STREQUAL "rhel")
set(DIST_NAME "el")
if(${DISTRO_VERSION} VERSION_LESS_EQUAL 8)
set(CPACK_RPM_PACKAGE_REQUIRES "yum-plugin-priorities, epel-release")
else()
set(CPACK_RPM_PACKAGE_REQUIRES "epel-release")
endif()
endif()
message(STATUS "Generating stable repository configuration for ${DISTRO} ${DISTRO_VERSION}")
set(VARIANT stable)
configure_file(netdata.repo.${REPO_ID} netdata.repo @ONLY)
message(STATUS "Generating edge repository configuration for ${DISTRO} ${DISTRO_VERSION}")
set(VARIANT edge)
configure_file(netdata.repo.${REPO_ID} netdata-edge.repo @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/netdata.repo
COMPONENT netdata-repo
DESTINATION etc/${REPO_CFG_PATH})
install(FILES ${CMAKE_BINARY_DIR}/netdata-edge.repo
COMPONENT netdata-repo-edge
DESTINATION etc/${REPO_CFG_PATH})
set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_RPM_PACAKGE_AUTOREQPROV OFF)
set(CPACK_RPM_DEBUGINFO_PACKAGE OFF)
set(CPACK_RPM_PACKAGE_LICENSE "GPLv2")
set(CPACK_RPM_PACKAGE_GROUP "System Environment/Base")
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST "")
set(CPACK_RPM_PACKAGE_ARCHITECTURE "noarch")
set(CPACK_RPM_PACKAGE_VERSION "${PACKAGE_VERSION}")
set(CPACK_RPM_PACKAGE_RELEASE "${PACKAGE_RELEASE}")
set(CPACK_RPM_PACKAGE_CHANGELOG "${CMAKE_SOURCE_DIR}/rpm.changelog")
set(CPACK_RPM_NETDATA-REPO_FILE_NAME "netdata-repo-${PACKAGE_VERSION}-${PACKAGE_RELEASE}.noarch.rpm")
set(CPACK_RPM_NETDATA-REPO_PACKAGE_NAME "netdata-repo")
set(CPACK_RPM_NETDATA-REPO_PACAKGE_CONFLICTS "netdata-repo-edge")
set(CPACK_RPM_NETDATA-REPO-EDGE_FILE_NAME "netdata-repo-edge-${PACKAGE_VERSION}-${PACKAGE_RELEASE}.noarch.rpm")
set(CPACK_RPM_NETDATA-REPO-EDGE_PACKAGE_NAME "netdata-repo-edge")
set(CPACK_RPM_NETDATA-REPO-EDGE_PACKAGE_CONFLICTS "netdata-repo")
else()
message(FATAL_ERROR "Unsupported distribution ${DISTRO} ${DISTRO_VERSION}")
endif()
include(CPack)
|