How to script the setup wizard?

It looks like I should use rake:admin to create the admin user. Rather, I think the admin user is already created but not approved so I would need to change it so it is approved.

Or maybe I can create an API key with api_key:create_master and use it to create the admin user ?

root@forum:/var/www/discourse# RAILS_DB=secondsite rake 'api_key:create_master[MASTERKEY]'
ad676e7413778aaaaa5d315c35f188591ef0edb4a4d4b2d644b9247a88421cfa

But it looks like I don’t quite understand how this master key is supposed to be used because this does not work:

# curl -X GET "https://forum2/categories" -H "Accept: application/json" -H "Api-Key: ad676e7413778aa3a5d315c35f91ef0edb4a4d4b2d644b924b7a88421cfa"
{"errors":["You are not permitted to view the requested resource. The API username or key is invalid."],"error_type":"invalid_access"}

However, if I create an admin user:

root@forum:/var/www/discourse# RAILS_DB=secondsite rake 'admin:create' 
Email:  loic@dachary.org
Password:  
Repeat password:  

Ensuring account is active!

Account created successfully with username loic
Do you want to grant Admin privileges to this account? (Y/n)  Y

Your account now has Admin privileges!

and then use the same master key specifying the newly created user, it does work:

curl -X GET "https://forum2/categories" -H "Accept: application/json" -H "Api-Key: ad676e7413778aa3a5d315c358591ef0edb4a4d4b2d644b924b7a88421cfa" -H "Api-Username: loic"
{"category_list":{"can...

and has admin privileges since it can also access /admin/site_settings/category/branding