master
sh 59 lines 1.74 KB
Raw
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: GPL-3.0-or-later
3
4 # shellcheck source=./packaging/makeself/functions.sh
5 . "${NETDATA_MAKESELF_PATH}"/functions.sh "${@}" || exit 1
6
7 # shellcheck disable=SC2015
8 [ "${GITHUB_ACTIONS}" = "true" ] && echo "::group::Checking Go plugin CPU architecture" || true
9
10 check_files="${NETDATA_INSTALL_PATH}/bin/netdata ${NETDATA_INSTALL_PATH}/usr/libexec/netdata/plugins.d/go.d.plugin"
11
12 case "${BUILDARCH}" in
13 aarch64)
14 ELF_MACHINE="AArch64"
15 ELF_CLASS="ELF64"
16 ;;
17 armv6l | armv7l)
18 ELF_MACHINE="ARM"
19 ELF_CLASS="ELF32"
20 ;;
21 x86_64)
22 ELF_MACHINE="X86-64"
23 ELF_CLASS="ELF64"
24 ;;
25 *)
26 echo "Buildarch is not recognized for architecture check."
27 exit 1
28 ;;
29 esac
30
31 for f in ${check_files}; do
32 if [ ! -f "${f}" ]; then
33 echo "File ${f} not found, skipping check"
34 continue
35 fi
36
37 # Get both the machine type and the class (32-bit vs 64-bit)
38 elf_info=$(readelf -h "${f}")
39 file_machine=$(echo "${elf_info}" | grep 'Machine:' | awk -F: '{print $2}' | xargs)
40 file_class=$(echo "${elf_info}" | grep 'Class:' | awk -F: '{print $2}' | xargs)
41
42 echo "Checking ${f}:"
43 echo " Expected: Class=${ELF_CLASS}, Machine contains '${ELF_MACHINE}'"
44 echo " Found: Class=${file_class}, Machine='${file_machine}'"
45
46 if [ "${file_class}" != "${ELF_CLASS}" ]; then
47 echo "ERROR: ${f} has wrong ELF class (${file_class} instead of ${ELF_CLASS})"
48 echo "This indicates a 32-bit/64-bit mismatch!"
49 exit 1
50 fi
51
52 if ! echo "${file_machine}" | grep -q "${ELF_MACHINE}"; then
53 echo "ERROR: ${f} was built for the wrong architecture (${file_machine} does not contain ${ELF_MACHINE})"
54 exit 1
55 fi
56 done
57
58 # shellcheck disable=SC2015
59 [ "${GITHUB_ACTIONS}" = "true" ] && echo "::endgroup::" || true