Non-interactive installs


#1

Is it possible to install gogs non-interactively? That is, without the initial database settings needing to be manually entered. I notice that there’s a mysql.sql template in the scripts directory, but it doesn’t contain any table definitions.


#2

The closest I’ve come with is building a git repo to build gogs and golang from source, however it installs gogs so far as the initial installation screen to make you setup/finalize gogs with your username and password settings.

If you are interested give it a try:

https://github.com/richardskumat/gogsi

It sets up nginx(on port 80 and 443) in front of gogs(which is listening on localhost port 3000 only) with a self-signed ssl certificate.

Build time roughly 8-10 minutes on Digitalocean’s $5/m plan.


#3

I’m thinking of the final stage where you enter database password and such. If there’s a command where those options can be set then this will make self-hosted installs simpler and reduce the chance of user errors.

I suppose an alternative might be to make a default mysql database, and then change the admin user details with a query.


#4

I am interested on this subject also. The outcome of the non-interactive install (script) can be reused in a post-install action like rpm pkg. I tried out “gogs dump” the other day on my test gogs. It does have sql part to describe existing gogs db and its tables. This can be cleanup to be a template sql( (mysql-default-install.sql)) for fresh install.


#5

I might try modifying install.go to see if I can turn it into a command or accept options.


#6

pls turn install.go into command line code. Currently it is for use with webGUI.


#7

You can generate custom/conf/app.ini directly, that is the file Gogs recognizes if show install page or not.


#8

You can, but the install page remains and it looks like the database has no tables.


#9

Looks like I was just modifying the wrong app.ini. I’ll still need to create an initial admin user though. Presumably passwd in the user table is hashed (and salted?). What algorithm is used for hashing?


#10

The first record in database automatically becomes admin.


#11

Indeed, but how to get that first record non-interactively? Is there any command to add users?


#12

Hmm, no. You would have to hack the database. But have a command to add user can be a feature request to report on GitHub.


#13

I’ve just ran a new install(Gogs Version: 0.9.25.0506) on a throwaway Debian 8 with mysql and here are the Database logs(/home/git/go/src/github.com/gogits/gogs/log/xorm.log):

raw paste:

https://gist.githubusercontent.com/richardskumat/e10dd4e8eec55466bb7509dcb5e91a8d/raw/000d42fd3365a3ec031d8979b3e600728662230f/Gogs%20Database%20Log

http://paste.ee/r/nQa89

Database name:

gogs_production

Database user:
git

Database password:
UKY3NekV0cEmQ0Ndl78X
This seems to be it. Looks like md5 hashing.

======

[xorm] [info] 2016/05/12 14:57:49.944033 [sql] BEGIN TRANSACTION
[xorm] [info] 2016/05/12 14:57:49.944219 [sql] INSERT INTO user (lower_name,name,full_name,email,passwd,login_type,login_source,login_name,type,location,website,rands,salt,created_unix,updated_unix,last_repo_visibility,max_repo_creation,is_active,is_admin,allow_git_hook,allow_import_local,avatar,avatar_email,use_custom_avatar,num_followers,num_following,num_stars,num_repos,description,num_teams,num_members) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [args] [asd asd asd@asd.asd ff68487527398465ac68ae3db4d806d2eddd78c91573818d3d8dc3b557d4747fa232cc05738af8be36a8f18fb4e4960160fe 0 0 0 mci2niuf5E mJfUIraaL9 1463079469 1463079469 false -1 true true false false 6f370c8c7109534c3d5c394123a477d7 asd@asd.asd false 0 0 0 0 0 0]
[xorm] [info] 2016/05/12 14:57:49.945167 [sql] COMMIT

======

You’ll have to wade through the junk to see the user creaton part. I’m blind to sql.

Edit:

Removed junk from here.

Mysql select * from gogs_production.user; (or something like that):

https://gist.githubusercontent.com/richardskumat/9722bd8d58765e5fc5ff7485d9c3eb1e/raw/8df5b5c7837333a82c6fa0ae751a54f2f84093a3/Gogs%20mysql

http://paste.ee/r/Ggzge


#14

With bash, it would be rather easy.

As root(let’s assume you have root access with ~/.my.cnf file) to mysql:

mysql <<-EOF
use gogs_production;
mysql command here;
EOF

#15

That’s ok, but I’d need to generate the password hash, rather than using a fixed default password. For deploying self-hosted systems each has unique passwords generated on first boot, since default passwords are a security risk.


#16

tr -d -c “a-zA-Z0-9” < /dev/urandom | head -c 20 | md5sum | awk ‘{print $1}’

For password generation, I use in my git repo:

tr -d -c “a-zA-Z0-9” < /dev/urandom | head -c 20

You can pipe it into md5sum and just get the first part with awk.


#17

Does Gogs use md5 hashes? It doesn’t look like it from the code. Md5 is weak and was considered broken in 2012.


#18

Hm more likely no, seems the hash is a lot longer than the md5sums generated.

The lead dev have to confirm what it used.


#19

I think I’ve found what mysql queries are used for new user creation and making them admins.

Of course, the question remains how the hash is created. It’s clear it has a salt value.

See my comment here: