I’am working an a new feature Gitea, which is nice to have and fun to run on a RPI.
It not so easy to setup from the command-line because most of the initialization is done at the first visit to the web interface. I figured out how to do it any way but encounter on problem which i just can’t solve.
in short the problem is the order of setup which can be done manual but can figure out how to do it with e-smith:
- create a new mysql database and load tables in to it
- write record to database with Pam login source
- expand templates with the mysql credentials
- run (bash) script to add local admin user
- start service
in bash scrips doing it manually it looks like this:
#!/bin/bash
# create new data base
password=`perl -e "use NethServer::Password; print NethServer::Password::store('giteaPass');"`
/usr/bin/mysql --defaults-file=/root/.my.cnf -e \
"CREATE DATABASE IF NOT EXISTS gitea DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
/usr/bin/mysql --defaults-file=/root/.my.cnf -e \
"CREATE USER gitea@localhost IDENTIFIED BY '$password';"
/usr/bin/mysql --defaults-file=/root/.my.cnf -e \
"GRANT ALL PRIVILEGES ON gitea .* TO gitea@localhost;"
# write tables to it
mysql --defaults-file=/root/.my.cnf gitea < gitea-mysql-sample.sql
# Add PAM login source
epoch=$(date +%s)
/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', 'Nethserver', '1', '0', '{\"ServiceName\":\"password-auth\"}', '$epoch', '$epoch');"
now (3) expand templates, then (4)
#!/bin/bash
# Add local admin user
pushd /var/lib/gitea
su gitea -c "/bin/gitea/gitea admin create-user --name gitea --password 'gitea' --email gitea@havak.lan --admin --config /etc/gitea/app.ini"
popd
A little bit to much information, my curllpit is to do (4) run a script after expanding templates.
Any directions?