1
-#!/usr/bin/env bash
2
-# SPDX-License-Identifier: GPL-3.0-or-later
3
-
4
-set -x
5
-
6
-# shellcheck source=packaging/makeself/functions.sh
7
-. "$(dirname "${0}")/../functions.sh" "${@}" || exit 1
8
-
9
-# shellcheck disable=SC2015
10
-[ "${GITHUB_ACTIONS}" = "true" ] && echo "::group::Building self-extracting archive" || true
11
-
12
-run cd "${NETDATA_SOURCE_PATH}" || exit 1
13
-
14
-# -----------------------------------------------------------------------------
15
-# find the netdata version
16
-
17
-VERSION="$("${NETDATA_INSTALL_PARENT}/netdata/bin/netdata" -v | cut -f 2 -d ' ')"
18
-[ -z "${VERSION}" ] && VERSION="$(cat "${NETDATA_SOURCE_PATH}/packaging/version")"
19
-
20
-if [ "${VERSION}" == "" ]; then
21
- echo >&2 "Cannot find version number. Create makeself executable from source code with git tree structure."
22
- exit 1
23
-fi
24
-
25
-# -----------------------------------------------------------------------------
26
-# copy the files needed by makeself installation
27
-
28
-run mkdir -p "${NETDATA_INSTALL_PATH}/system"
29
-
30
-run cp \
31
- packaging/makeself/post-installer.sh \
32
- packaging/makeself/install-or-update.sh \
33
- packaging/installer/functions.sh \
34
- "${NETDATA_INSTALL_PATH}/system/"
35
-
36
-# -----------------------------------------------------------------------------
37
-# create a wrapper to start our netdata with a modified path
38
-
39
-run mkdir -p "${NETDATA_INSTALL_PATH}/bin/srv"
40
-
41
-run mv "${NETDATA_INSTALL_PATH}/bin/netdata" \
42
- "${NETDATA_INSTALL_PATH}/bin/srv/netdata" || exit 1
43
-
44
-cat > "${NETDATA_INSTALL_PATH}/bin/netdata" << EOF
45
-#!${NETDATA_INSTALL_PATH}/bin/bash
46
-export NETDATA_BASH_LOADABLES="DISABLE"
47
-export PATH="${NETDATA_INSTALL_PATH}/bin:\${PATH}"
48
-exec "${NETDATA_INSTALL_PATH}/bin/srv/netdata" "\${@}"
49
-EOF
50
-run chmod 755 "${NETDATA_INSTALL_PATH}/bin/netdata"
51
-
52
-# -----------------------------------------------------------------------------
53
-# the claiming script must be in the same directory as the netdata binary for web-based claiming to work
54
-
55
-run ln -s "${NETDATA_INSTALL_PATH}/bin/netdata-claim.sh" \
56
- "${NETDATA_INSTALL_PATH}/bin/srv/netdata-claim.sh" || exit 1
57
-
58
-# -----------------------------------------------------------------------------
59
-# copy the SSL/TLS configuration and certificates from the build system
60
-
61
-run cp -a /etc/ssl "${NETDATA_INSTALL_PATH}/share/ssl"
62
-
63
-# -----------------------------------------------------------------------------
64
-# remove the links to allow untaring the archive
65
-
66
-run rm "${NETDATA_INSTALL_PATH}/sbin" \
67
- "${NETDATA_INSTALL_PATH}/usr/bin" \
68
- "${NETDATA_INSTALL_PATH}/usr/sbin" \
69
- "${NETDATA_INSTALL_PATH}/usr/local"
70
-
71
-# -----------------------------------------------------------------------------
72
-# ensure required directories actually exist
73
-
74
-for dir in var/lib/netdata var/cache/netdata var/log/netdata ; do
75
- run mkdir -p "${NETDATA_INSTALL_PATH}/${dir}"
76
- run touch "${NETDATA_INSTALL_PATH}/${dir}/.keep"
77
-done
78
-
79
-# -----------------------------------------------------------------------------
80
-# create the makeself archive
81
-
82
-run sed "s|NETDATA_VERSION|${VERSION}|g" < "${NETDATA_MAKESELF_PATH}/makeself.lsm" > "${NETDATA_MAKESELF_PATH}/makeself.lsm.tmp"
83
-
84
-run "${NETDATA_MAKESELF_PATH}/makeself.sh" \
85
- --gzip \
86
- --complevel 9 \
87
- --notemp \
88
- --needroot \
89
- --target "${NETDATA_INSTALL_PATH}" \
90
- --header "${NETDATA_MAKESELF_PATH}/makeself-header.sh" \
91
- --lsm "${NETDATA_MAKESELF_PATH}/makeself.lsm.tmp" \
92
- --license "${NETDATA_MAKESELF_PATH}/makeself-license.txt" \
93
- --help-header "${NETDATA_MAKESELF_PATH}/makeself-help-header.txt" \
94
- "${NETDATA_INSTALL_PATH}" \
95
- "${NETDATA_INSTALL_PATH}.gz.run" \
96
- "Netdata, X-Ray Vision for your infrastructure" \
97
- ./system/post-installer.sh
98
-
99
-run rm "${NETDATA_MAKESELF_PATH}/makeself.lsm.tmp"
100
-
101
-# -----------------------------------------------------------------------------
102
-# copy it to the netdata build dir
103
-
104
-FILE="netdata-${BUILDARCH}-${VERSION}.gz.run"
105
-
106
-run mkdir -p artifacts
107
-run mv "${NETDATA_INSTALL_PATH}.gz.run" "artifacts/${FILE}"
108
-
109
-[ -f "netdata-${BUILDARCH}-latest.gz.run" ] && rm "netdata-${BUILDARCH}-latest.gz.run"
110
-run cp "artifacts/${FILE}" "netdata-${BUILDARCH}-latest.gz.run"
111
-
112
-if [ "${BUILDARCH}" = "x86_64" ]; then
113
- [ -f "netdata-latest.gz.run" ] && rm "netdata-latest.gz.run"
114
- run cp "artifacts/${FILE}" "netdata-latest.gz.run"
115
- [ -f "artifacts/netdata-${VERSION}.gz.run" ] && rm "netdata-${VERSION}.gz.run"
116
- run cp "artifacts/${FILE}" "artifacts/netdata-${VERSION}.gz.run"
117
-fi
118
-
119
-# shellcheck disable=SC2015
120
-[ "${GITHUB_ACTIONS}" = "true" ] && echo "::endgroup::" || true
121
-
122
-echo >&2 "Self-extracting installer moved to 'artifacts/${FILE}'"