Created
January 3, 2020 18:24
-
-
Save enly1/b812c34a2659fc59d4a6d84c7d02d971 to your computer and use it in GitHub Desktop.
Script to be used for creating an awslogin capability with coloured profiles (persistent).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function awslogin { | |
# set to yes to create one-time use profiles in /tmp | |
# anything else will create them in $HOME/.aws/awschrome | |
TEMP_PROFILE="no" | |
# set to yes to always start in a new window | |
NEW_WINDOW="no" | |
profile="$1" | |
if [[ -z "$profile" ]]; then | |
echo "Profile is a required argument" >&2 | |
return 1 | |
fi | |
themecolor="$2, $3, $4" | |
themepath="${HOME}/.aws/themes" | |
if [[ "$4" ]]; then | |
mkdir "$themepath/$2-$3-$4" 2&>1 >/dev/null | |
echo "{ \"manifest_version\": 2, \"version\": \"0.1\", \"name\": \"AWSLogin\", \"theme\": { \"colors\": { \"frame\": [$themecolor] } } }" > $themepath/$2-$3-$4/manifest.json | |
themeswitch="--load-extension=$themepath/$2-$3-$4" | |
fi | |
# replace non word and not - with __ | |
profile_dir_name=${profile//[^a-zA-Z0-9_-]/__} | |
user_data_dir="${HOME}/.aws/awschrome/${profile_dir_name}" | |
new_window_arg='' | |
if [[ "$TEMP_PROFILE" = "yes" ]]; then | |
user_data_dir=$(mktemp -d /tmp/awschrome_userdata.XXXXXXXX) | |
fi | |
if [[ "$NEW_WINDOW" = "yes" ]]; then | |
new_window_arg='--new-window' | |
fi | |
# run aws-vault | |
# --prompt osascript only works on OSX | |
url=$(aws-vault login $profile --stdout) | |
status=$? | |
if [[ ${status} -ne 0 ]]; then | |
# bash will also capture stderr, so echo $url | |
echo ${url} | |
return ${status} | |
fi | |
mkdir -p ${user_data_dir} | |
disk_cache_dir=$(mktemp -d /tmp/awschrome_cache.XXXXXXXX) | |
/opt/google/chrome/chrome \ | |
--no-first-run \ | |
--user-data-dir=${user_data_dir} \ | |
--disk-cache-dir=${disk_cache_dir} \ | |
--disk-cache-size=10240 \ | |
--start-maximized \ | |
$themeswitch \ | |
${new_window_arg} \ | |
${url} \ | |
>/dev/null 2>&1 & | |
} | |
awslogin $@ |
Original code fragment from blog post - modified to add color theme support - v.hacky, but was busy.
https://www.cloudar.be/awsblog/using-aws-vault-with-mulitple-browser-windows/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note - param 1 is aws-vault profile name to use - if 3 additional params supplied, used as rgb values for chrome title bar ...
NB. only need rgb values once as theme is installed in new chrome profile the first time.