Automatically create admin user on install


#1

Gogs version: 0.9.20
System: Docker
Database: sqlite3

Is there a default admin user or any way to set up an admin user automatically on install? I have INSTALL_LOCK = true and have tried creating an admin user through REST api but have not had success.

# not working gives 500 Internal Server Error
curl -v -X POST -H "Content-Type: application/json" -d "{
    \"source_id\": 1,
    \"login_name\": \"go\",
    \"username\": \"go\",
    \"password\": \"Password1\",
    \"email\": \"example@example.com\"
  }" "http://localhost:3000/api/v1/admin/users"

#2

I remember there was default admin account in earlier version. Looks like default admin feature got removed in recent versions.

I would suggest have a button option on the Web GUI to delete the default admin account once config is finished.


#3

If you check what the element names are in the /install form, you may be able to POST the entries to complete the installation. I can look further into it this evening, but it would be similar to your curl operation but generating a payload to POST to http://localhost:3000/install


#4

The form you’re looking for is auth.InstallForm in modules/auth/user_form.go:14


#5

@tcarrio generating a payload to POST to http://localhost:3000/install worked. Thanks!


#6

How did you get this to work exactly. Doesn’t work for me…


#7

Here’s how I got it going:

curl -X POST 'http://localhost:3000/install' \
     -d @gogs_preseed_installer.properties

This is the content of the payload file:

$ cat gogs_preseed_installer.properties
db_type=SQLite3&db_path=data/gogs.db&app_name=Gogs&repo_root_path=/data/git/gogs-repositories&run_user=git&domain=localhost&ssh_port=22&http_port=3000&app_url=http://localhost:3000/&log_root_path=/app/gogs/log&smtp_host=&smtp_from=&smtp_user=&smtp_passwd=&disable_gravatar=true&enable_captcha=false&register_confirm=false&admin_name=username&admin_passwd=your_password&admin_confirm_passwd=your_password&admin_email=admin@example.com

HTH