Install/provision from command line

Hello Forum,

Thank you for bringing this painless self-hosted Git service to us!

In an effort to make it even more painless i’m having a shot at making it in to a module for a centos based server. It’s has on a stock old configuration layer called e-smith; in short it configures apps with {bash, perl, python} scripts.

So far gitea is packed in a nice rpm/sprm, and it works like a charm authenticating against openLdap or samba AD, now i’m stuck at provisioning/install/init gitea from the command line.

Two main questions to start with::grinning:

  1. just cannot figure out how to update the security tokens gitea generate secret SECRET_KEY does not do the job for me, what is my wrong doing?
  2. How to setup the ldap bits and pieces from the command line?

thnx in advance

Just a heads up of my finding and maybe it is usefull for others…

This is my bad: i’m working from the stable 1.4.x branch, sould have mentioned that. The “generate” feature is implemented in the 1.5.x branch.

After encountering this too (initialization of database) : :sob:

Settled for PAM with a workaround i promised myself never to do again.

prerequisite: i am using mysql, or to be accurate mariadb. And complied gitea with pam

  • make a dump of the db structure/tables of a running gitea instance to gitea-sample-mysql.sql (in my case mysqldump --defaults-file=/root/.my.cnf -d gitea > mysql-sample.sql)
  • on a new install create a empty mysql database for gitea
  • and load the tables ( in my case mysql --defaults-file=/root/.my.cnf gitea < mysql-sample.sql)
  • write a record in the data base for PAM authentication

In my case this look like this::

/usr/bin/mysql --defaults-file=/root/.my.cnf -e \
"INSERT INTO gitea . login_source (id, type, name, is_actived, is_sync_enabled, cfg, created_unix, updated_unix) 
VALUES ('1', '4', 'PAM_Auth', '1', '0', '{\"ServiceName\":\"password-auth\"}', '$epoch', '$epoch');"

NOTE: you need to build gitea with pam enabled, by default it is omitted (for good reasons)


However (with or without PAM) if you included your mysql credentials in your app.ini you can add local (admin) user(s) before running gitea for the first time.

In my case this looks like this

pushd /var/lib/gitea
su gitea -c "/bin/gitea admin create-user --name username --password 'userpassword' --email username@example.com --admin --config /etc/gitea/app.ini"
popd

(running user is gitea; is installed in /bin/gitea; working_dir is /var/lib/gitea; app.ini lives in /etc/gitea)


In conclusion:

  • A functionality like gitea --init , which initializes databases and security tokens would be appreciated very much! :grinning:
  • Meanwhile it would be a nice gesture to include de db-schema’s in the source. You can omit the first step of making a dump of a running instance. (maybe it is there and did not find it :sleepy:)

Grzt Mark

Hi @mark,

The reason why this isn’t included is because it is generated via code, you can find the DB migrations here: https://github.com/go-gitea/gitea/tree/master/models/migrations this allows Gitea to support multiple DBs such as MySQL/MariaDB, Postgresql, MSSQL, and even sqlite.

I’ve just created a PR to allow adding (oauth, so PAM would still need to be added) login sources via cli so you don’t need to insert directly into the DB.

Several of Gitea’s cli commands (such as web) will automatically generate the DB for you as long as it has a config file that has DB information in it

Hope that helps,
@techknowlogick

1 Like

Yes it helps, thank you!

I will follow the development with great interest, meanwhile the first dev version of the module is running for further refinements.