Skip to content

Instantly share code, notes, and snippets.

@reallistic
Last active August 29, 2015 14:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reallistic/022aaf41a7ef4bce57c3 to your computer and use it in GitHub Desktop.
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
#!/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