#!/bin/bash

set -euo pipefail

if command -v aws >/dev/null 2>&1; then
  echo "awscli already installed. Skipping installation."
  exit 0
fi

echo "Installing unzip dependency..."
apt-get update -qq >/dev/null
apt-get install -y -qq unzip >/dev/null

echo "Downloading AWS CLI v2 (arm64)..."
curl -sS "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip"

echo "Installing AWS CLI..."
unzip -q awscliv2.zip
./aws/install >/dev/null
rm -rf aws awscliv2.zip

echo "Installing groff dependency..."
# apt-get update -qq >/dev/null
apt-get install -y -qq groff >/dev/null

echo "AWS CLI installation completed successfully."
