Skip to content

Instantly share code, notes, and snippets.

@ImIOImI
Last active May 9, 2024 15:46
Show Gist options
  • Save ImIOImI/06a49a61f8634a8200565b4708826219 to your computer and use it in GitHub Desktop.
Save ImIOImI/06a49a61f8634a8200565b4708826219 to your computer and use it in GitHub Desktop.
AWS Cloudshell init script
#!/bin/sh
defaultUser="ImIOImI"
defaultEmail="troy.knapp@gmail.com"
rsaKeyFile=/home/cloudshell-user/.ssh/id_rsa
if [ ! -f "$rsaKeyFile" ]; then
#add rsa key
ssh-keygen -b 2048 -t rsa -f "$rsaKeyFile" -q -N ""
echo "Please copy the following into your GitHub profile here: https://github.com/settings/ssh/new
"
cat /home/cloudshell-user/.ssh/id_rsa.pub
read -r -p "Press any key to continue...
"
fi
read -p "GitHub Username: [$defaultUser]" uservar
read -p "GitHub Email: [$defaultEmail]" emailvar
uservar=${uservar:-${defaultUser}}
emailvar=${emailvar:-${defaultEmail}}
echo "Using...
username: $uservar
email: $emailvar
"
git config --global user.name $uservar
git config --global user.email $emailvar
git config --global credential.helper cache
sshConfig=<<EOD
Host github.com
User git
Hostname github.com
PreferredAuthentications publickey
IdentityFile /home/cloudshell-user/.ssh/id_rsa
EOD
echo $sshConfig >> /home/cloudshell-user/.ssh/config
chmod 600 /home/cloudshell-user/.ssh/config
eval $(ssh-agent -s)
ssh-add /home/cloudshell-user/.ssh/id_rsa
#get cloud extensions script
sudo ssh-keyscan -H github.com >> ~/.ssh/known_hosts
git clone git@github.com:ImIOImI/extensions-for-aws-managed-shells.git
#run cloud extensions script
cd extensions-for-aws-managed-shells
sh extensions-for-aws-managed-shells.sh
cd ~
#add all the eks clusters you have access to
clusters=$(aws eks list-clusters | grep -oP '"(.*?)"' | sed 's/"clusters"//' | sed -e 's/^"//' -e 's/"$//')
echo $clusters
for val in $clusters; do
aws eks update-kubeconfig --name $val --alias $val
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment