11#! /usr/bin/env sh
22
3+ set -e
4+
35LOG_PATH=${LOG_PATH}
46VERSION=${VERSION}
57DOWNLOAD_URL=${DOWNLOAD_URL}
@@ -13,7 +15,9 @@ printf "${BOLD}Installing AWS CLI...\\n${RESET}"
1315if command -v aws > /dev/null 2>&1 ; then
1416 INSTALLED_VERSION=$( aws --version 2>&1 | cut -d' ' -f1 | cut -d' /' -f2)
1517 if [ -n " $VERSION " ] && [ " $INSTALLED_VERSION " != " $VERSION " ]; then
16- printf " AWS CLI $INSTALLED_VERSION is installed, but version $VERSION was requested.\\ n"
18+ printf " ❌ AWS CLI $INSTALLED_VERSION is installed, but version $VERSION was requested.\\ n"
19+ printf " Note: AWS CLI installer does not support version-specific installation.\\ n"
20+ exit 1
1721 else
1822 printf " AWS CLI is already installed ($INSTALLED_VERSION ). Skipping installation.\\ n"
1923 exit 0
@@ -28,7 +32,7 @@ case "$ARCH" in
2832 x86_64) ARCH=" x86_64" ;;
2933 aarch64 | arm64) ARCH=" aarch64" ;;
3034 * )
31- printf " Unsupported architecture: $ARCH \\ n" > " ${LOG_PATH} " 2>&1
35+ printf " Unsupported architecture: $ARCH \\ n" >> " ${LOG_PATH} " 2>&1
3236 exit 1
3337 ;;
3438esac
@@ -41,74 +45,85 @@ if [ "$OS" = "linux" ]; then
4145 fi
4246
4347 printf " Downloading AWS CLI from $DOWNLOAD_URL ...\\ n"
44- curl -fsSL " $DOWNLOAD_URL " -o /tmp/awscliv2.zip >> " ${LOG_PATH} " 2>&1
48+ curl -fsSL " $DOWNLOAD_URL " -o /tmp/awscliv2.zip >> " ${LOG_PATH} " 2>&1 || exit 1
4549
46- unzip -q /tmp/awscliv2.zip -d /tmp >> " ${LOG_PATH} " 2>&1
47- sudo /tmp/aws/install >> " ${LOG_PATH} " 2>&1
50+ unzip -q /tmp/awscliv2.zip -d /tmp >> " ${LOG_PATH} " 2>&1 || exit 1
51+ sudo /tmp/aws/install >> " ${LOG_PATH} " 2>&1 || exit 1
4852
4953 rm -rf /tmp/awscliv2.zip /tmp/aws
5054
5155elif [ " $OS " = " darwin" ]; then
52- # Use custom download URL if provided, otherwise use default AWS URL
56+ # Use custom download URL if provided, otherwise use architecture-specific AWS URL
5357 if [ -z " $DOWNLOAD_URL " ]; then
54- DOWNLOAD_URL=" https://awscli.amazonaws.com/AWSCLIV2.pkg"
58+ case " $ARCH " in
59+ x86_64)
60+ DOWNLOAD_URL=" https://awscli.amazonaws.com/AWSCLIV2-x86_64.pkg"
61+ ;;
62+ aarch64)
63+ DOWNLOAD_URL=" https://awscli.amazonaws.com/AWSCLIV2-arm64.pkg"
64+ ;;
65+ * )
66+ DOWNLOAD_URL=" https://awscli.amazonaws.com/AWSCLIV2.pkg"
67+ ;;
68+ esac
5569 fi
5670
5771 printf " Downloading AWS CLI from $DOWNLOAD_URL ...\\ n"
58- curl -fsSL " $DOWNLOAD_URL " -o /tmp/AWSCLIV2.pkg >> " ${LOG_PATH} " 2>&1
72+ curl -fsSL " $DOWNLOAD_URL " -o /tmp/AWSCLIV2.pkg >> " ${LOG_PATH} " 2>&1 || exit 1
5973
60- sudo installer -pkg /tmp/AWSCLIV2.pkg -target / >> " ${LOG_PATH} " 2>&1
74+ sudo installer -pkg /tmp/AWSCLIV2.pkg -target / >> " ${LOG_PATH} " 2>&1 || exit 1
6175
6276 rm -f /tmp/AWSCLIV2.pkg
6377
6478else
65- printf " Unsupported OS: $OS \\ n" > " ${LOG_PATH} " 2>&1
79+ printf " Unsupported OS: $OS \\ n" >> " ${LOG_PATH} " 2>&1
6680 exit 1
6781fi
6882
83+ # Verify installation was successful
6984if command -v aws > /dev/null 2>&1 ; then
7085 printf " 🥳 AWS CLI installed successfully!\\ n"
7186 aws --version
72- else
73- printf " ❌ AWS CLI installation failed. Check logs at ${LOG_PATH} \\ n"
74- exit 1
75- fi
7687
77- # Configure autocomplete for common shells
78- if command -v aws_completer > /dev/null 2>&1 ; then
79- AWS_COMPLETER_PATH=$( which aws_completer)
88+ # Configure autocomplete for common shells
89+ if command -v aws_completer > /dev/null 2>&1 ; then
90+ AWS_COMPLETER_PATH=$( which aws_completer)
8091
81- # Bash autocomplete
82- if [ -f ~ /.bashrc ]; then
83- if ! grep -q " aws_completer.*aws" ~ /.bashrc; then
84- echo " complete -C '$AWS_COMPLETER_PATH ' aws" >> ~ /.bashrc
85- printf " ✓ Configured AWS CLI autocomplete for bash\\ n"
92+ # Bash autocomplete
93+ if [ -f ~ /.bashrc ]; then
94+ if ! grep -q " aws_completer.*aws" ~ /.bashrc; then
95+ echo " complete -C '$AWS_COMPLETER_PATH ' aws" >> ~ /.bashrc
96+ printf " ✓ Configured AWS CLI autocomplete for bash\\ n"
97+ fi
8698 fi
87- fi
8899
89- # Zsh autocomplete
90- if [ -f ~ /.zshrc ] || [ -d ~ /.oh-my-zsh ]; then
91- if ! grep -q " aws_completer.*aws" ~ /.zshrc 2> /dev/null; then
92- cat >> ~ /.zshrc << EOF
100+ # Zsh autocomplete
101+ if [ -f ~ /.zshrc ] || [ -d ~ /.oh-my-zsh ]; then
102+ if ! grep -q " aws_completer.*aws" ~ /.zshrc 2> /dev/null; then
103+ cat >> ~ /.zshrc << ZSHEOF
93104
94105# AWS CLI autocomplete
95106autoload bashcompinit && bashcompinit
96107autoload -Uz compinit && compinit
97108complete -C '$AWS_COMPLETER_PATH ' aws
98- EOF
99- printf " ✓ Configured AWS CLI autocomplete for zsh\\ n"
109+ ZSHEOF
110+ printf " ✓ Configured AWS CLI autocomplete for zsh\\ n"
111+ fi
100112 fi
101- fi
102113
103- # Fish autocomplete
104- if [ -d ~ /.config/fish ] || command -v fish > /dev/null 2>&1 ; then
105- mkdir -p ~ /.config/fish/completions
106- FISH_COMPLETION=~ /.config/fish/completions/aws.fish
107- if [ ! -f " $FISH_COMPLETION " ]; then
108- cat > " $FISH_COMPLETION " << 'EOF '
114+ # Fish autocomplete
115+ if [ -d ~ /.config/fish ] || command -v fish > /dev/null 2>&1 ; then
116+ mkdir -p ~ /.config/fish/completions
117+ FISH_COMPLETION=~ /.config/fish/completions/aws.fish
118+ if [ ! -f " $FISH_COMPLETION " ]; then
119+ cat > " $FISH_COMPLETION " << 'FISHEOF '
109120complete --command aws --no-files --arguments '(begin; set --local --export COMP_SHELL fish; set --local --export COMP_LINE (commandline); aws_completer | sed '"'"'s/ $//'"'"'; end)'
110- EOF
111- printf " ✓ Configured AWS CLI autocomplete for fish\\ n"
121+ FISHEOF
122+ printf " ✓ Configured AWS CLI autocomplete for fish\\ n"
123+ fi
112124 fi
113125 fi
126+ else
127+ printf " ❌ AWS CLI installation failed. Check logs at ${LOG_PATH} \\ n"
128+ exit 1
114129fi
0 commit comments