Skip to content

Instantly share code, notes, and snippets.

@blurayne
Last active July 5, 2022 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blurayne/109f484d79f1a114f07dce42b5ff3ca1 to your computer and use it in GitHub Desktop.
Save blurayne/109f484d79f1a114f07dce42b5ff3ca1 to your computer and use it in GitHub Desktop.
AWS Helpers
#!/bin/bash
set -eEuo pipefail
ARCH="$(arch)"
PACKAGE_ARCH="${ARCH/x86_64/amd64}"
PACKAGE_ARCH="${PACKAGE_ARCH/aarch64/arm64}"
PACKAGE_URL=""
PACKAGE_FILE=""
source /etc/os-release
cd "$HOME"
if [[ "$ID_LIKE" == *debian* ]]; then
PACKAGE_URL="https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_${PACKAGE_ARCH}/amazon-ssm-agent.deb"
PACKAGE_FILE="${PACKAGE_URL##*/}"
elif [[ "$ID_LIKE" == *rhel* ]] || [[ "$ID" == "suse" ]] ; then
PACKAGE_URL="https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_${PACKAGE_ARCH}/amazon-ssm-agent.rpm"
PACKAGE_FILE="${PACKAGE_URL##*/}"
else
>2 echo "could not determine package URL (ID=${ID:-} ID_LIKE=${ID_LIKE:-} VERSION_ID=${VERSION_ID:-})"
exit 1
fi
# yum and dnf do support install from URL
if hash yum 2>/dev/null; then
sudo yum install -y "$PACKAGE_URL"
elif hash dnf 2>/dev/null; then
sudo dnf install -y python3 "$PACKAGE_URL"
else
# Get the package
if hash wget 2>/dev/null; then
wget "$PACKAGE_URL" -O "$PACKAGE_FILE"
elif hash curl 2>/dev/null; then
curl -sSfL "$PACKAGE_URL" -o "$PACKAGE_FILE"
else
>2 echo "no program to download SSM Agent"
exit 1
fi
# Intall the package
if hash apt 2>/dev/null; then
sudo apt install "$(realpath $PACKAGE_FILE)"
elif hash apt-get 2>/dev/null; then
sudo apt-get install "$(realpath $PACKAGE_FILE)"
elif hash dpkg 2>/dev/null; then
sudo dpkg -i "$PACKAGE_FILE"
elif hash rpm 2>/dev/null; then
sudo rpm --install "$PACKAGE_FILE"
else
>2 echo "no package manager to install SSM Agent"
exit 1
fi
# Remove the file again
rm "$PACKAGE_FILE"
fi
# Enable system unit
if hash systemctl 2>/dev/null; then
sudo systemctl enable amazon-ssm-agent
sudo systemctl start amazon-ssm-agent
elif hash start 2>/dev/null; then
# debian / ubutut
sudo start amazon-ssm-agent
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment