diff --git a/config-file b/config-file index ff85fad7..5b2827e1 100644 --- a/config-file +++ b/config-file @@ -1 +1,6 @@ mt_version="5.3.0" +first_install=Y + +#This settings are applied only when first_install is set to Y +psql_postgres_user_password="ExamplePassword" +psql_minetest_user_password="ExamplePassword" diff --git a/setup-mt b/setup-mt index df7af213..0b0f8ac4 100755 --- a/setup-mt +++ b/setup-mt @@ -68,5 +68,32 @@ echo "RestartSec=3" >> /etc/systemd/system/minetestsrv.service echo "[Install]" >> /etc/systemd/system/minetestsrv.service echo "WantedBy=multi-user.target" >> /etc/systemd/system/minetestsrv.service systemctl daemon-reload + +if [ $first_install = "Y" ]; then +echo "Configuring firstinstall config" +apt install postgresql postgresql-contrib -y +pg_ctlcluster 12 main start + +sudo -u postgres createuser minetest +sudo -u postgres createdb minetest +sudo -u postgres createdb minetest_players +sudo -u postgres createdb minetest_auth +sudo -u postgres psql -U postgres -d postgres -c "alter user postgres with password '$psql_postgres_user_password';" +sudo -u postgres psql -U postgres -d postgres -c "alter user minetest with password '$psql_minetest_user_password';" + +sudo -u postgres psql -U postgres -d postgres -c "grant all privileges on database 'minetest' to minetest;" +sudo -u postgres psql -U postgres -d postgres -c "grant all privileges on database 'minetest_players' to minetest;" +sudo -u postgres psql -U postgres -d postgres -c "grant all privileges on database 'minetest_auth' to minetest;" + +echo "gameid = minetest" > /home/minetest/.minetest/worlds/world/world.mt +echo "backend = postgresql" >> /home/minetest/.minetest/worlds/world/world.mt +echo "creative_mode = false" >> /home/minetest/.minetest/worlds/world/world.mt +echo "enable_damage = true" >> /home/minetest/.minetest/worlds/world/world.mt +echo "player_backend = postgresql" >> /home/minetest/.minetest/worlds/world/world.mt +echo "auth_backend = postgresql" >> /home/minetest/.minetest/worlds/world/world.mt +echo "pgsql_connection = host=127.0.0.1 user=minetest password=$psql_minetest_user_password dbname=minetest" >> /home/minetest/.minetest/worlds/world/world.mt +echo "pgsql_player_connection = host=127.0.0.1 user=minetest password=$psql_minetest_user_password dbname=minetest_players" >> /home/minetest/.minetest/worlds/world/world.mt +echo "pgsql_auth_connection = host=127.0.0.1 user=minetest password=$psql_minetest_user_password dbname=minetest_auth" >> /home/minetest/.minetest/worlds/world/world.mt +fi systemctl start minetestsrv systemctl enable minetestsrv