Address PR review comments
- Add set -e for strict error handling - Exit on version mismatch with clear error message - Use >> for log appending (was overwriting with >) - Add error checking after curl, unzip, and install commands - Add macOS architecture-specific download URLs - Move autocomplete config after successful installation verification
This commit is contained in:
parent
7a70127f35
commit
be4dc937b5
@ -1,5 +1,7 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
LOG_PATH=${LOG_PATH}
|
LOG_PATH=${LOG_PATH}
|
||||||
VERSION=${VERSION}
|
VERSION=${VERSION}
|
||||||
DOWNLOAD_URL=${DOWNLOAD_URL}
|
DOWNLOAD_URL=${DOWNLOAD_URL}
|
||||||
@ -13,7 +15,9 @@ printf "${BOLD}Installing AWS CLI...\\n${RESET}"
|
|||||||
if command -v aws > /dev/null 2>&1; then
|
if command -v aws > /dev/null 2>&1; then
|
||||||
INSTALLED_VERSION=$(aws --version 2>&1 | cut -d' ' -f1 | cut -d'/' -f2)
|
INSTALLED_VERSION=$(aws --version 2>&1 | cut -d' ' -f1 | cut -d'/' -f2)
|
||||||
if [ -n "$VERSION" ] && [ "$INSTALLED_VERSION" != "$VERSION" ]; then
|
if [ -n "$VERSION" ] && [ "$INSTALLED_VERSION" != "$VERSION" ]; then
|
||||||
printf "AWS CLI $INSTALLED_VERSION is installed, but version $VERSION was requested.\\n"
|
printf "❌ AWS CLI $INSTALLED_VERSION is installed, but version $VERSION was requested.\\n"
|
||||||
|
printf "Note: AWS CLI installer does not support version-specific installation.\\n"
|
||||||
|
exit 1
|
||||||
else
|
else
|
||||||
printf "AWS CLI is already installed ($INSTALLED_VERSION). Skipping installation.\\n"
|
printf "AWS CLI is already installed ($INSTALLED_VERSION). Skipping installation.\\n"
|
||||||
exit 0
|
exit 0
|
||||||
@ -28,7 +32,7 @@ case "$ARCH" in
|
|||||||
x86_64) ARCH="x86_64" ;;
|
x86_64) ARCH="x86_64" ;;
|
||||||
aarch64 | arm64) ARCH="aarch64" ;;
|
aarch64 | arm64) ARCH="aarch64" ;;
|
||||||
*)
|
*)
|
||||||
printf "Unsupported architecture: $ARCH\\n" > "${LOG_PATH}" 2>&1
|
printf "Unsupported architecture: $ARCH\\n" >> "${LOG_PATH}" 2>&1
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -41,74 +45,85 @@ if [ "$OS" = "linux" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
printf "Downloading AWS CLI from $DOWNLOAD_URL...\\n"
|
printf "Downloading AWS CLI from $DOWNLOAD_URL...\\n"
|
||||||
curl -fsSL "$DOWNLOAD_URL" -o /tmp/awscliv2.zip >> "${LOG_PATH}" 2>&1
|
curl -fsSL "$DOWNLOAD_URL" -o /tmp/awscliv2.zip >> "${LOG_PATH}" 2>&1 || exit 1
|
||||||
|
|
||||||
unzip -q /tmp/awscliv2.zip -d /tmp >> "${LOG_PATH}" 2>&1
|
unzip -q /tmp/awscliv2.zip -d /tmp >> "${LOG_PATH}" 2>&1 || exit 1
|
||||||
sudo /tmp/aws/install >> "${LOG_PATH}" 2>&1
|
sudo /tmp/aws/install >> "${LOG_PATH}" 2>&1 || exit 1
|
||||||
|
|
||||||
rm -rf /tmp/awscliv2.zip /tmp/aws
|
rm -rf /tmp/awscliv2.zip /tmp/aws
|
||||||
|
|
||||||
elif [ "$OS" = "darwin" ]; then
|
elif [ "$OS" = "darwin" ]; then
|
||||||
# Use custom download URL if provided, otherwise use default AWS URL
|
# Use custom download URL if provided, otherwise use architecture-specific AWS URL
|
||||||
if [ -z "$DOWNLOAD_URL" ]; then
|
if [ -z "$DOWNLOAD_URL" ]; then
|
||||||
DOWNLOAD_URL="https://awscli.amazonaws.com/AWSCLIV2.pkg"
|
case "$ARCH" in
|
||||||
|
x86_64)
|
||||||
|
DOWNLOAD_URL="https://awscli.amazonaws.com/AWSCLIV2-x86_64.pkg"
|
||||||
|
;;
|
||||||
|
aarch64)
|
||||||
|
DOWNLOAD_URL="https://awscli.amazonaws.com/AWSCLIV2-arm64.pkg"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
DOWNLOAD_URL="https://awscli.amazonaws.com/AWSCLIV2.pkg"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf "Downloading AWS CLI from $DOWNLOAD_URL...\\n"
|
printf "Downloading AWS CLI from $DOWNLOAD_URL...\\n"
|
||||||
curl -fsSL "$DOWNLOAD_URL" -o /tmp/AWSCLIV2.pkg >> "${LOG_PATH}" 2>&1
|
curl -fsSL "$DOWNLOAD_URL" -o /tmp/AWSCLIV2.pkg >> "${LOG_PATH}" 2>&1 || exit 1
|
||||||
|
|
||||||
sudo installer -pkg /tmp/AWSCLIV2.pkg -target / >> "${LOG_PATH}" 2>&1
|
sudo installer -pkg /tmp/AWSCLIV2.pkg -target / >> "${LOG_PATH}" 2>&1 || exit 1
|
||||||
|
|
||||||
rm -f /tmp/AWSCLIV2.pkg
|
rm -f /tmp/AWSCLIV2.pkg
|
||||||
|
|
||||||
else
|
else
|
||||||
printf "Unsupported OS: $OS\\n" > "${LOG_PATH}" 2>&1
|
printf "Unsupported OS: $OS\\n" >> "${LOG_PATH}" 2>&1
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Verify installation was successful
|
||||||
if command -v aws > /dev/null 2>&1; then
|
if command -v aws > /dev/null 2>&1; then
|
||||||
printf "🥳 AWS CLI installed successfully!\\n"
|
printf "🥳 AWS CLI installed successfully!\\n"
|
||||||
aws --version
|
aws --version
|
||||||
else
|
|
||||||
printf "❌ AWS CLI installation failed. Check logs at ${LOG_PATH}\\n"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Configure autocomplete for common shells
|
# Configure autocomplete for common shells
|
||||||
if command -v aws_completer > /dev/null 2>&1; then
|
if command -v aws_completer > /dev/null 2>&1; then
|
||||||
AWS_COMPLETER_PATH=$(which aws_completer)
|
AWS_COMPLETER_PATH=$(which aws_completer)
|
||||||
|
|
||||||
# Bash autocomplete
|
# Bash autocomplete
|
||||||
if [ -f ~/.bashrc ]; then
|
if [ -f ~/.bashrc ]; then
|
||||||
if ! grep -q "aws_completer.*aws" ~/.bashrc; then
|
if ! grep -q "aws_completer.*aws" ~/.bashrc; then
|
||||||
echo "complete -C '$AWS_COMPLETER_PATH' aws" >> ~/.bashrc
|
echo "complete -C '$AWS_COMPLETER_PATH' aws" >> ~/.bashrc
|
||||||
printf "✓ Configured AWS CLI autocomplete for bash\\n"
|
printf "✓ Configured AWS CLI autocomplete for bash\\n"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
# Zsh autocomplete
|
# Zsh autocomplete
|
||||||
if [ -f ~/.zshrc ] || [ -d ~/.oh-my-zsh ]; then
|
if [ -f ~/.zshrc ] || [ -d ~/.oh-my-zsh ]; then
|
||||||
if ! grep -q "aws_completer.*aws" ~/.zshrc 2> /dev/null; then
|
if ! grep -q "aws_completer.*aws" ~/.zshrc 2> /dev/null; then
|
||||||
cat >> ~/.zshrc << EOF
|
cat >> ~/.zshrc << ZSHEOF
|
||||||
|
|
||||||
# AWS CLI autocomplete
|
# AWS CLI autocomplete
|
||||||
autoload bashcompinit && bashcompinit
|
autoload bashcompinit && bashcompinit
|
||||||
autoload -Uz compinit && compinit
|
autoload -Uz compinit && compinit
|
||||||
complete -C '$AWS_COMPLETER_PATH' aws
|
complete -C '$AWS_COMPLETER_PATH' aws
|
||||||
EOF
|
ZSHEOF
|
||||||
printf "✓ Configured AWS CLI autocomplete for zsh\\n"
|
printf "✓ Configured AWS CLI autocomplete for zsh\\n"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
# Fish autocomplete
|
# Fish autocomplete
|
||||||
if [ -d ~/.config/fish ] || command -v fish > /dev/null 2>&1; then
|
if [ -d ~/.config/fish ] || command -v fish > /dev/null 2>&1; then
|
||||||
mkdir -p ~/.config/fish/completions
|
mkdir -p ~/.config/fish/completions
|
||||||
FISH_COMPLETION=~/.config/fish/completions/aws.fish
|
FISH_COMPLETION=~/.config/fish/completions/aws.fish
|
||||||
if [ ! -f "$FISH_COMPLETION" ]; then
|
if [ ! -f "$FISH_COMPLETION" ]; then
|
||||||
cat > "$FISH_COMPLETION" << 'EOF'
|
cat > "$FISH_COMPLETION" << 'FISHEOF'
|
||||||
complete --command aws --no-files --arguments '(begin; set --local --export COMP_SHELL fish; set --local --export COMP_LINE (commandline); aws_completer | sed '"'"'s/ $//'"'"'; end)'
|
complete --command aws --no-files --arguments '(begin; set --local --export COMP_SHELL fish; set --local --export COMP_LINE (commandline); aws_completer | sed '"'"'s/ $//'"'"'; end)'
|
||||||
EOF
|
FISHEOF
|
||||||
printf "✓ Configured AWS CLI autocomplete for fish\\n"
|
printf "✓ Configured AWS CLI autocomplete for fish\\n"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
printf "❌ AWS CLI installation failed. Check logs at ${LOG_PATH}\\n"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user