Skip to content

Instantly share code, notes, and snippets.

@dkorotych
Last active June 10, 2017 18:43
Show Gist options
  • Save dkorotych/d2da642c8df3ac4a751d5a74b1293e7b to your computer and use it in GitHub Desktop.
Save dkorotych/d2da642c8df3ac4a751d5a74b1293e7b to your computer and use it in GitHub Desktop.
Execute heroku-cli without local install
#!/bin/bash
set -e
set -u
readonly image='wingrunr21/alpine-heroku-cli'
readonly bashrc="${HOME}/.bashrc"
readonly netrc="${HOME}/.netrc"
readonly heroku_alias="alias heroku='docker run --rm --interactive --tty --volume ${HOME}/.netrc:/root/.netrc --volume '/etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt:ro' ${image}'"
readonly regexp='^alias heroku.+$'
docker pull ${image}
readonly alias_from_file=$(grep -E "${regexp}" ${bashrc})
if [[ ${alias_from_file} == '' ]]; then
echo ${heroku_alias} >> ${bashrc}
source ${bashrc}
else
if [[ ${alias_from_file} != ${heroku_alias} ]]; then
readonly replace_slash_pattern="s#/#\\\/#g"
readonly safe_alias_from_file=$(echo ${alias_from_file} | sed -e ${replace_slash_pattern})
readonly safe_alias=$(echo ${heroku_alias} | sed -e ${replace_slash_pattern})
sed -i "s/${safe_alias_from_file}/${safe_alias}/g" ${bashrc}
source ${bashrc}
fi
fi
eval ${heroku_alias}
shopt -s expand_aliases
touch ${netrc}
heroku login
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment