Last active
August 29, 2015 14:19
-
-
Save reallistic/022aaf41a7ef4bce57c3 to your computer and use it in GitHub Desktop.
Simple bash script to copy the config from one heroku app to another
This file contains hidden or 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 | |
OIFS=$IFS | |
print_usage () | |
{ | |
echo "Usage:" | |
echo " $0 source-appname" | |
echo " $0 source-appname dest-appname" | |
} | |
cleanup_and_exit () | |
{ | |
IFS=$OIFS | |
exit 1 | |
} | |
if [ "$#" -lt 1 ]; then | |
echo "Expected at least one parameter: appname" | |
print_usage | |
exit 1 | |
fi | |
if [[ "$1" == "-h" || "$1" == "--help" ]]; then | |
print_usage | |
exit 0 | |
fi | |
from_config=$(heroku config -s -a $1) | |
if [[ $? != 0 ]] ; then | |
echo "Error retreiving config" | |
echo $from_config | |
cleanup_and_exit | |
fi | |
IFS=$'\n' | |
config_vars=( $from_config ) | |
to_config="" | |
count=0 | |
pstr="[=======================================================================]" | |
total=${#config_vars[@]} | |
for ((i=0; i<${#config_vars[@]}; ++i)); | |
do | |
row=${config_vars[$i]} | |
kvp=$(echo $row | tr -s "=" "\n") | |
kvp=( $kvp ) | |
key=${kvp[0]} | |
value=$(heroku config:get ${kvp[0]} -a $1) | |
if [[ $? != 0 ]] ; then | |
printf "\n" | |
echo "Error retreiving config" | |
echo $value | |
cleanup_and_exit | |
fi | |
if [ -z "$to_config" ]; then | |
to_config="$key=\"$value\"" | |
else | |
to_config="$to_config $key=\"$value\"" | |
fi | |
count=$(( $count + 1 )) | |
pd=$(( $count * 73 / $total )) | |
printf "\r%3d.%1d%% %.${pd}s" $(( $count * 100 / $total )) $(( ($count * 1000 / $total) % 10 )) $pstr | |
done | |
IFS=$OIFS | |
printf "\n" | |
if [ "$#" -gt 1 ]; then | |
command="heroku config:set $to_config -a $2" | |
echo "$command" | |
eval $command | |
else | |
echo $to_config | |
echo "done" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment