feat: create user and db

This commit is contained in:
2026-02-22 15:11:58 +01:00
parent ade97d52e6
commit 1c492aa683
3 changed files with 11 additions and 2 deletions

View File

@@ -18,7 +18,7 @@ jobs:
env: env:
GIT_REFERENCE: ${{ github.ref }} GIT_REFERENCE: ${{ github.ref }}
- name: Build rpm package - name: Build rpm package
run: rpmbuild -ba netoik-db.spec run: rpmbuild -ba "%(make name).spec"
- name: Upload rpm package - name: Upload rpm package
run: make upload run: make upload
env: env:

View File

@@ -17,4 +17,4 @@ jobs:
- name: Build tarball - name: Build tarball
run: make tarball run: make tarball
- name: Build rpm file - name: Build rpm file
run: rpmbuild -ba netoik-db.spec run: rpmbuild -ba "$(make name).spec"

View File

@@ -22,6 +22,15 @@ Install the database management system called postgresql with a predefined confi
%make_install %make_install
%post %post
# Create databases and users from DB_USERS variable (separator is ",") if not existing
echo "$DB_USERS" | IFS="," read -ra users
for user in "${users[@]}"; do
if ! runuser --user=postgres -- psql --quiet --tuples-only --command='\du' | grep --invert-match postgres | grep --quiet "$user"; then
runuser --user=postgres -- createuser "$user"
runuser --user=postgres -- createdb --owner="$user" "$user"
fi
done
# Restart services # Restart services
systemctl daemon-reload systemctl daemon-reload
systemctl reenable --now postgresql.service systemctl reenable --now postgresql.service