Skip to content

Instantly share code, notes, and snippets.

@drankard
Created August 6, 2019 14:25
Show Gist options
  • Save drankard/4c84121aab14fbd3b1977fcd1491db7f to your computer and use it in GitHub Desktop.
Save drankard/4c84121aab14fbd3b1977fcd1491db7f to your computer and use it in GitHub Desktop.
A small helper script to make the anoying copy paste a bit less anoying....
#!/bin/bash
CREDENTIALS_FILE=~/.aws/credentials
remove_profile() {
PROFILE=${1}
echo "Paste profile data from SSO"
sed -i -e "/\[${PROFILE}\]/,+3d" ${CREDENTIALS_FILE}
}
add_profile() {
PROFILE=${1}
echo "[${PROFILE}]" >> ${CREDENTIALS_FILE}
for i in `seq 1 4`; do
read INPUT
if [[ $i -ne 1 ]] ; then
echo $INPUT >> ${CREDENTIALS_FILE}
fi
done
echo "" >> ${CREDENTIALS_FILE}
echo
echo "[${PROFILE}] updated..."
}
menu_for_accounts () {
select account; do
# Check the selected account
if [ 1 -le "$REPLY" ] && [ "$REPLY" -le $# ]; then
remove_profile $account
add_profile $account
break;
else
echo "Wrong selection: Select any number from 1-$#"
fi
done
}
accounts=('master' 'infrastructure' 'sfb' 'non-prod' 'hotfix' 'prod' 'pre-prod' 'default')
menu_for_accounts "${accounts[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment