Skip to content

Instantly share code, notes, and snippets.

@jakeatwork
Forked from ktec/heroku_env_copy.sh
Created May 18, 2018 02:53
Show Gist options
  • Save jakeatwork/fc38a0340b56e24e247b797e97ffc4a8 to your computer and use it in GitHub Desktop.
Save jakeatwork/fc38a0340b56e24e247b797e97ffc4a8 to your computer and use it in GitHub Desktop.

Revisions

  1. @ktec ktec revised this gist Nov 25, 2016. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions heroku_env_copy.sh
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,8 @@ main() {
    TARGET="${2}"
    vars=""

    echo "Select the ENV variables you want to copy from $SOURCE to $TARGET:"
    echo "Please choose the ENV variables you wish to copy from $SOURCE to $TARGET:"
    echo ""

    while read key value; do
    key=${key%%:}
    @@ -46,9 +47,14 @@ main() {
    fi
    done < <(heroku config --app "$SOURCE" | sed -e '1d')

    echo ""
    echo "--------------------------------------------------------------------"
    echo "This is the command you need to run to update your heroku app:"
    echo "This script will not do your dirty work for you. Below is the script"
    echo "you will need to run to update your heroku app instance. Good luck! "
    echo "--------------------------------------------------------------------"
    echo ""
    echo "heroku config:set$vars --app $TARGET"
    echo ""
    }

    set -e # exit on command errors
  2. @ktec ktec revised this gist Nov 25, 2016. 1 changed file with 10 additions and 10 deletions.
    20 changes: 10 additions & 10 deletions heroku_env_copy.sh
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,12 @@
    #!/usr/bin/env bash

    # Original Source: http://blog.nonuby.com/blog/2012/07/05/copying-env-vars-from-one-heroku-app-to-another/

    ## Usage: heroku_env_copy [options] SOURCE TARGET
    ##
    ## NOTE: This script will only output the command, you should run it yourself.
    ##
    ## Options:
    ## -h, --help Display this message.
    ## -n Dry-run; only show what would be done.
    ##

    usage() {
    @@ -18,7 +18,6 @@ usage() {
    main() {
    while [ $# -gt 0 ]; do
    case $1 in
    (-n) DRY_RUN=1;;
    (-h|--help) usage 2>&1;;
    (--) break;;
    (-*) usage "$1: unknown option";;
    @@ -29,26 +28,27 @@ main() {

    SOURCE="${1}"
    TARGET="${2}"
    vars=""

    echo "Would you like me to copy the following ENV variables from $SOURCE to $TARGET:"
    echo "Select the ENV variables you want to copy from $SOURCE to $TARGET:"

    while read key value; do
    key=${key%%:}
    read -p "Copy: $key=$value ? [Y/n] (default yes) " -u 1 response
    read -p "Include: $key=$value ? [Y/n] (default yes) " -u 1 response
    if printf "%s\n" "$response" | grep -Eq "$(locale noexpr)"
    then
    tput cuu 1 && tput el
    echo -e "$(tput setaf 9)Copy: $key=$value ? No$(tput sgr0)"
    else
    tput cuu 1 && tput el
    echo -e "$(tput setaf 2)Copy: $key=$value ? Yes$(tput sgr0)"
    if [[ ! DRY_RUN ]]; then
    heroku config:set "$key=$value" --app "$TARGET"
    else
    echo "action: heroku config:set "$key=$value" --app "$TARGET""
    fi
    vars=$vars" $key=\"$value\""
    fi
    done < <(heroku config --app "$SOURCE" | sed -e '1d')

    echo "--------------------------------------------------------------------"
    echo "This is the command you need to run to update your heroku app:"
    echo "heroku config:set$vars --app $TARGET"
    }

    set -e # exit on command errors
  3. @ktec ktec created this gist Nov 25, 2016.
    56 changes: 56 additions & 0 deletions heroku_env_copy.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    #!/usr/bin/env bash

    # Original Source: http://blog.nonuby.com/blog/2012/07/05/copying-env-vars-from-one-heroku-app-to-another/

    ## Usage: heroku_env_copy [options] SOURCE TARGET
    ##
    ## Options:
    ## -h, --help Display this message.
    ## -n Dry-run; only show what would be done.
    ##

    usage() {
    [ "$*" ] && echo "$0: $*"
    sed -n '/^##/,/^$/s/^## \{0,1\}//p' "$0"
    exit 2
    } 2>/dev/null

    main() {
    while [ $# -gt 0 ]; do
    case $1 in
    (-n) DRY_RUN=1;;
    (-h|--help) usage 2>&1;;
    (--) break;;
    (-*) usage "$1: unknown option";;
    (*) break;;
    esac
    shift
    done

    SOURCE="${1}"
    TARGET="${2}"

    echo "Would you like me to copy the following ENV variables from $SOURCE to $TARGET:"

    while read key value; do
    key=${key%%:}
    read -p "Copy: $key=$value ? [Y/n] (default yes) " -u 1 response
    if printf "%s\n" "$response" | grep -Eq "$(locale noexpr)"
    then
    tput cuu 1 && tput el
    echo -e "$(tput setaf 9)Copy: $key=$value ? No$(tput sgr0)"
    else
    tput cuu 1 && tput el
    echo -e "$(tput setaf 2)Copy: $key=$value ? Yes$(tput sgr0)"
    if [[ ! DRY_RUN ]]; then
    heroku config:set "$key=$value" --app "$TARGET"
    else
    echo "action: heroku config:set "$key=$value" --app "$TARGET""
    fi
    fi
    done < <(heroku config --app "$SOURCE" | sed -e '1d')
    }

    set -e # exit on command errors

    main $@