#!/bin/bash

name=$1
app=$name
remote=$name
env=$name.env
rndm=$(echo $RANDOM | md5sum | head -c 32; echo)
config=$(heroku config -s -a my-kv-prod | grep -v '^HEROKU_' | grep -v 'VUE_APP_TITLE' | grep -v 'PAPERTRAIL' | grep -v 'DATABASE' | sed "s/'//g")
heroku git:remote --app $app --remote $remote
heroku config:set --app $app $config
heroku config:set --app $app  APP_NAME=$app NEW_RELIC_APP_NAME=$app SECRET_KEY=$rndm `cat $env | sed "s/'//g"`
heroku config:unset --app $app BACKUP_AWS_ACCESS_KEY_ID BACKUP_AWS_SECRET_ACCESS_KEY BACKUP_S3_BUCKET_NAME PG_BACKUP_KEY SENTRY_DSN 
heroku buildpacks:set --app $app heroku/nodejs
heroku buildpacks:add --app $app heroku/python
heroku buildpacks:add --app $app heroku-community/awscli
heroku buildpacks:add --app $app heroku-community/cli
heroku addons:attach papertrail-shaped-25288 --app $app
heroku pg:backups:schedule --app $app --at '01:00 UTC'
