Skip to content

Commit

Permalink
test new script
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelgavache committed Dec 10, 2024
1 parent bf79e39 commit d87cebe
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
48 changes: 27 additions & 21 deletions pkg/fleet/installer/setup/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
10 changes: 7 additions & 3 deletions tasks/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d87cebe

Please sign in to comment.