Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions cmd/agent/install_mac_os.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Datadog Agent install script for macOS.
set -e
install_script_version=1.4.0
install_script_version=1.5.0
dmg_file=/tmp/datadog-agent.dmg
dmg_base_url="https://s3.amazonaws.com/dd-agent"
etc_dir=/opt/datadog-agent/etc
Expand Down Expand Up @@ -63,19 +63,13 @@ if [ -n "$DD_AGENT_MINOR_VERSION" ]; then
fi

arch=$(/usr/bin/arch)
if [ "$arch" == "arm64" ]; then
if ! /usr/bin/pgrep oahd >/dev/null 2>&1; then
printf "\033[31mRosetta is needed to run datadog-agent on $arch.\nYou can install it by running the following command :\n/usr/sbin/softwareupdate --install-rosetta --agree-to-license\033[0m\n"
exit 1
fi
fi

# Cleanup tmp files used for installation
rm -f /tmp/install-ddagent/system-wide

function find_latest_patch_version_for() {
major_minor="$1"
patch_versions=$(curl "https://s3.amazonaws.com/dd-agent?prefix=datadog-agent-${major_minor}." 2>/dev/null | grep -o "datadog-agent-${major_minor}.[0-9]*-1.dmg")
patch_versions=$(curl "$dmg_base_url?prefix=datadog-agent-${major_minor}." 2>/dev/null | grep -Eo "datadog-agent-${major_minor}.[0-9]*-1(.$arch)?.dmg")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notes to reviewers:

  1. DRY: leveraging existing dmg_base_url defined somewhere above (and set to https://s3.amazonaws.com/dd-agent)
  2. grep -E: so as to avoid escaping parenthesis in the regexp (-E is portable, contrarily to -P)
  3. (.$arch)?: retained DMGs will be either "universal" (well, let's call it that way) or match the current $arch (important is to discard other archs)

if [ -z "$patch_versions" ]; then
echo "-1"
fi
Expand Down Expand Up @@ -218,12 +212,6 @@ if [ -z "$dmg_version" ]; then
fi
fi

if [ -z "$agent_dist_channel" ]; then
dmg_url="$dmg_base_url/datadog-agent-${dmg_version}.dmg"
else
dmg_url="$dmg_base_url/$agent_dist_channel/datadog-agent-${dmg_version}.dmg"
fi

if [ "$upgrade" ]; then
if [ ! -f $etc_dir/datadog.conf ]; then
printf "\033[31mDD_UPGRADE set but no config was found at $etc_dir/datadog.conf.\033[0m\n"
Expand Down Expand Up @@ -365,6 +353,22 @@ function plist_modify_user_group() {
$sudo_cmd sh -c "sed $i_cmd -e \"${closing_dict_line},${closing_dict_line}s|</dict>|<key>$user_parameter</key><string>$user_value</string>\n</dict>|\" -e \"${closing_dict_line},${closing_dict_line}s|</dict>|<key>$group_parameter</key><string>$group_value</string>\n</dict>|\" \"$plist_file\""
}

# Determine agent flavor to install
if [ -z "$agent_dist_channel" ]; then
dmg_url_prefix="$dmg_base_url/datadog-agent-${dmg_version}"
else
dmg_url_prefix="$dmg_base_url/$agent_dist_channel/datadog-agent-${dmg_version}"
fi
Comment on lines +357 to +361
Copy link
Copy Markdown
Contributor Author

@rdesgroppes rdesgroppes Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to reviewers: moved from somewhere above because determining dmg_url (now dmg_url_prefix) was too distant from its usage.


dmg_url="$dmg_url_prefix.$arch.dmg" # favor architecture-specific DMG, if available
if [ "$(curl --head --location --output /dev/null --silent --write-out '%{http_code}' "$dmg_url")" != 200 ]; then
dmg_url="$dmg_url_prefix.dmg" # fallback to "universal" DMG
if [ "$arch" = arm64 ] && ! /usr/bin/pgrep oahd >/dev/null 2>&1; then
printf "\033[31mRosetta is needed to run datadog-agent on $arch.\nYou can install it by running the following command :\n/usr/sbin/softwareupdate --install-rosetta --agree-to-license\033[0m\n"
exit 1
fi
Comment on lines +366 to +369
Copy link
Copy Markdown
Contributor Author

@rdesgroppes rdesgroppes Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to reviewers: snippet moved from somewhere above so that it's executed only when applicable.
In particular, if $arch is arm64 and the retained DMG is also arm64, there's no point to prompt for Rosetta 2 installation.

fi

# # Install the agent
printf "\033[34m\n* Downloading datadog-agent\n\033[0m"
prepare_dmg_file $dmg_file
Expand Down