Install/provision from command line

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 --admin --config /etc/gitea/app.ini"

(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