Skip to content

Instantly share code, notes, and snippets.

@zunda
Last active December 12, 2019 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zunda/a60075ebf30497888e224fcce938c2e7 to your computer and use it in GitHub Desktop.
Save zunda/a60075ebf30497888e224fcce938c2e7 to your computer and use it in GitHub Desktop.
Herokuアプリのデータベースをリセットしてadminアカウントを作成して登録を閉じる
#!/bin/sh
set -e
run () {
echo \$ "$*"
eval "$*"
}
while getopts 'e:u:a:' c; do
case $c in
e) email=$OPTARG;;
u) username=$OPTARG;;
a) appname=$OPTARG;;
esac
done
if test -z "$appname"; then
appname=$HEROKU_APP
fi
if test -z "$email" || test -z "$username" || test -z "$appname"; then
echo Please specify all of -e email -u username -a appname
exit 1
fi
echo "Resetting and creating account $username <$email> on $appname"
run heroku pg:reset -a $appname
run heroku run -a $appname rake db:migrate
# Create an account, capture the password and set it as a config var
result=`mktemp`
run heroku run -a $appname\
tootctl accounts create $username --email $email --confirmed --role admin |\
tee $result
password=`awk '/New password:/{print $NF}' $result`
rm -f $result
if test -z "$password"; then
exit 1
fi
run heroku run -a $appname \
"tootctl settings registrations close\; tootctl accounts approve $username"
run heroku config:set -a $appname USER_PASSWORD=$password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment