#!/bin/bash
source config-file
systemctl stop minetestsrv
rm -rf /home/minetest/.minetest/mods
cp -r mods /home/minetest/.minetest/mods

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

echo "
load_mod_interact = false
load_mod_wieldview = true
load_mod_shields = true
load_mod_3d_armor_ui = true
load_mod_3d_armor = true
load_mod_3d_armor_sfinv = true
load_mod_3d_armor_ip = true
load_mod_3d_armor_stand = true
load_mod_unified_inventory = true
load_mod_xdecor = true
load_mod_xban2 = true
load_mod_workbench = true
load_mod_vehicle_mash = true
load_mod_unifiedbricks = true
load_mod_ts_workshop = true
load_mod_ts_paper = true
load_mod_moreores = true
load_mod_throwing_arrows = true
load_mod_drinks = true
load_mod_carpets = true
load_mod_enchanting = true
load_mod_ghost = true
load_mod_computer = true
load_mod_castle_masonry = true
load_mod_mymillwork = true
load_mod_stained_glass = true
load_mod_jukebox = true
load_mod_crops = true
load_mod_mysheetmetal = true
load_mod_mywoodslopes = true
load_mod_throwing = true
load_mod_letters = true
load_mod_lib_mount = true
load_mod_moreblocks = true
load_mod_chicken = true
load_mod_creatures = true
load_mod_oerrki = true
load_mod_mycorners = true
load_mod_zombie = true
load_mod_mtfoods = true
load_mod_chat2 = true
load_mod_mydeck = true
load_mod_mywalls = true
load_mod_mymasonhammer = true
load_mod_mypaths = true
load_mod_trash_can = true
load_mod_myroofs = true
load_mod_ropes = true
load_mod_playeranim = true
load_mod_signs_api = true
load_mod_sheep = true
load_mod_skinsdb = true
load_mod_stargate = true
load_mod_ts_furniture = true
load_mod_ts_doors = true
load_mod_unifieddyes = true
load_mod_font_api = true
load_mod_display_api = true
load_mod_basic_materials = true
load_mod_trees_lib = true
load_mod_biome_lib = true
load_mod_moretrees = true
load_mod_vines = true
load_mod_intllib = true
" >> /home/minetest/.minetest/worlds/world/world.mt

chown minetest:minetest /home/minetest/ -cR

echo "Start minetestsrv service"
systemctl start minetestsrv
