diff --git a/pkg/fleet/installer/setup/install.sh b/pkg/fleet/installer/setup/install.sh index d76e790de910f..fae636cef5467 100644 --- a/pkg/fleet/installer/setup/install.sh +++ b/pkg/fleet/installer/setup/install.sh @@ -10,43 +10,49 @@ if [ "$(uname -s)" != "Linux" ] || { [ "$(uname -m)" != "x86_64" ] && [ "$(uname fi tmp_dir="/opt/datadog-packages/tmp" +extracted_base64="${tmp_dir}/download-installer_base64" downloader_path="${tmp_dir}/download-installer" +script_file="$0" -install() { - if [ "$UID" == "0" ]; then - sudo_cmd='' - else - sudo_cmd='sudo' - fi +# 0s are placeholders for the actual start offsets, avoiding to change script lengths +start_amd=$((10#000000000000)) +start_arm=$((10#000000000000)) + +if [ "$UID" == "0" ]; then + sudo_cmd='' +else + sudo_cmd='sudo' +fi +install() { $sudo_cmd mkdir -p "${tmp_dir}" case "$(uname -m)" in x86_64) - write_installer_amd64 "$sudo_cmd" "$downloader_path" + write_installer $((start_amd)) $((start_arm-start_amd)) ;; aarch64) - write_installer_arm64 "$sudo_cmd" "$downloader_path" + write_installer $((start_arm)) "0" ;; esac $sudo_cmd chmod +x "${downloader_path}" echo "Starting the Datadog installer..." $sudo_cmd "${downloader_path}" "$@" - $sudo_cmd rm -f "${downloader_path}" } -# Embedded binaries used to install Datadog. -# Source: https://github.com/DataDog/datadog-agent/tree/INSTALLER_COMMIT/pkg/fleet/installer -# DO NOT EDIT THIS SECTION MANUALLY. -write_installer_amd64() { - local sudo_cmd=$1 - local path=$2 - base64 -d <<<"DOWNLOADER_BIN_LINUX_AMD64" | $sudo_cmd tee "${path}" >/dev/null -} -write_installer_arm64() { - local sudo_cmd=$1 - local path=$2 - base64 -d <<<"DOWNLOADER_BIN_LINUX_ARM64" | $sudo_cmd tee "${path}" >/dev/null +write_installer() { + local skip=$1 + local count=$2 + if [ "$count" -eq "0" ]; then + dd if="${script_file}" bs=1 skip=$((skip)) status=none of="${extracted_base64}" + else + dd if="${script_file}" bs=1 skip=$((skip)) count=$((count)) status=none of="${extracted_base64}" + fi + base64 -d "${extracted_base64}" > "${downloader_path}" } install "$@" exit 0 + +# Embedded binaries used to install Datadog. +# Source: https://github.com/DataDog/datadog-agent/tree/INSTALLER_COMMIT/pkg/fleet/installer +# DO NOT EDIT THIS SECTION MANUALLY. diff --git a/tasks/installer.py b/tasks/installer.py index 381c2dc104db8..271818a93a725 100644 --- a/tasks/installer.py +++ b/tasks/installer.py @@ -111,12 +111,16 @@ def build_linux_script( if version == "nightly-a7": version = get_commit_sha(ctx) - archs = ['amd64', 'arm64'] + archs = ['amd', 'arm'] for arch in archs: - build_downloader(ctx, flavor=flavor, version=version, os='linux', arch=arch) + build_downloader(ctx, flavor=flavor, version=version, os='linux', arch=f'{arch}64') with open(DOWNLOADER_BIN, 'rb') as f: encoded_bin = base64.encodebytes(f.read()).decode('utf-8') - install_script = install_script.replace(f'DOWNLOADER_BIN_LINUX_{arch.upper()}', encoded_bin) + bin_start_placeholder = f'start_{arch}=$((10#000000000000))' + bin_start_str = str(len(install_script) - 1) + new_bin_start = bin_start_placeholder[: -(2 + len(bin_start_str))] + bin_start_str + bin_start_placeholder[-2:] + install_script = install_script.replace(bin_start_placeholder, new_bin_start) + install_script += encoded_bin commit_sha = ctx.run('git rev-parse HEAD', hide=True).stdout.strip() install_script = install_script.replace('INSTALLER_COMMIT', commit_sha)