Skip to content

Commit a18b6df

Browse files
author
Ville Walveranta
committed
Added Linux compatibility to aws-iam-rotate-keys.sh
1 parent 22d43be commit a18b6df

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

awscli-mfa.sh

+46-4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,29 @@ if [[ "$ONEPROFILE" = "false" ]]; then
7171

7272
else
7373

74+
# Check OS for some supported platforms
75+
OS="`uname`"
76+
case $OS in
77+
'Linux')
78+
OS='Linux'
79+
;;
80+
'Darwin')
81+
OS='macOS'
82+
;;
83+
*)
84+
OS='unknown'
85+
echo
86+
echo "** NOTE: THIS SCRIPT HAS NOT BEEN TESTED ON YOUR CURRENT PLATFORM."
87+
echo
88+
;;
89+
esac
90+
91+
# make sure ~/.aws/credentials has a linefeed in the end
92+
c=$(tail -c 1 "$CREDFILE")
93+
if [ "$c" != "" ]; then
94+
echo "" >> "$CREDFILE"
95+
fi
96+
7497
## PREREQS PASSED; PROCEED..
7598

7699
declare -a cred_profiles
@@ -385,10 +408,29 @@ else
385408
echo "Region is set to: $get_region"
386409
echo "Output format is set to: $get_output"
387410
echo
388-
echo "Execute the following in Terminal to activate this profile:"
389-
echo "export AWS_PROFILE=${final_selection}"
390-
echo -n "export AWS_PROFILE=${final_selection}" | pbcopy
391-
echo "(the activation command is now on your clipboard -- just paste in Terminal, and press [ENTER])"
411+
if [ "$OS" = "macOS" ]; then
412+
echo "Execute the following in Terminal to activate this profile:"
413+
echo
414+
echo "export AWS_PROFILE=${final_selection}"
415+
echo
416+
echo -n "export AWS_PROFILE=${final_selection}" | pbcopy
417+
echo "(the activation command is now on your clipboard -- just paste in Terminal, and press [ENTER])"
418+
elif [ "$OS" = "Linux" ]; then
419+
echo "Execute the following on the command line to activate this profile:"
420+
echo
421+
echo "export AWS_PROFILE=${final_selection}"
422+
echo
423+
if exists xclip ; then
424+
echo -n "export AWS_PROFILE=${final_selection}" | xclip -i
425+
echo "(xclip found; the activation command is now on your X PRIMARY clipboard -- just paste on the command line, and press [ENTER])"
426+
else
427+
echo "If you're using an X GUI on Linux, install 'xclip' to have the activation command copied to the clipboard automatically."
428+
fi
429+
else
430+
echo "Execute the following on the command line to activate this profile:"
431+
echo
432+
echo "export AWS_PROFILE=${final_selection}"
433+
fi
392434
echo
393435
394436
fi

0 commit comments

Comments
 (0)