minetest-mm/setup-mt
2020-10-25 10:01:45 +00:00

102 lines
4.6 KiB
Bash
Executable file

#!/bin/bash
source config-file
echo "Create minetest user"
useradd minetest
mkdir -p /home/minetest/.minetest
echo "Allow sources repo and install dependecies for build"
perl -pi.orig -0e 's/^(deb .*\n)# (deb-src)/$1$2/mg' /etc/apt/sources.list
apt update
apt-get build-dep minetest -y
echo "Compile libspatialindex"
rm -rf /tmp/spatialindex
git clone https://github.com/libspatialindex/libspatialindex /tmp/spatialindex
cd /tmp/spatialindex
cmake . -DCMAKE_INSTALL_PREFIX=/usr
make -j$(nproc)
make install
echo "Compile minetest version $mt_version"
rm -rf /tmp/minetest
git clone --depth 1 --branch "$mt_version" https://github.com/minetest/minetest.git /tmp/minetest
cp -n /tmp/minetest/minetest.conf.example /home/minetest/.minetest/minetest.conf
cd /tmp/minetest
cmake . \
-DBUILD_CLIENT=0 \
-DBUILD_SERVER=1 \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCUSTOM_BINDIR=/usr/bin \
-DCUSTOM_DOCDIR="/usr/share/doc/minetest" \
-DCUSTOM_SHAREDIR="/usr/share/minetest" \
-DENABLE_CURL=1 \
-DENABLE_LEVELDB=1 \
-DENABLE_LUAJIT=1 \
-DENABLE_REDIS=1 \
-DENABLE_SOUND=0 \
-DENABLE_SYSTEM_GMP=1 \
-DENABLE_POSTGRESQL=1 \
-DPOSTGRESQL_CONFIG_EXECUTABLE=/usr/bin/pg_config \
-DPOSTGRESQL_LIBRARY=/usr/lib/libpq.so \
-DRUN_IN_PLACE=0
make -j$(nproc)
echo "Stop minetestsrv service(upgrade case)"
systemctl stop minetestsrv
make install
echo "Clone minetest_game $mt_version"
mkdir -p /home/minetest/.minetest/games/
rm -rf /home/minetest/.minetest/games/minetest
git clone --depth 1 --branch "$mt_version" https://github.com/minetest/minetest_game.git /home/minetest/.minetest/games/minetest
echo "Fix privileges on /home/minetest"
chown minetest:minetest /home/minetest/ -cR
echo "Creating minetestsrv systemd service"
echo "[Unit]" > /etc/systemd/system/minetestsrv.service
echo "Description=MinetestSRV" >> /etc/systemd/system/minetestsrv.service
echo "After=postgresql.service" >> /etc/systemd/system/minetestsrv.service
echo "[Service]" >> /etc/systemd/system/minetestsrv.service
echo "Type=simple" >> /etc/systemd/system/minetestsrv.service
echo "User=minetest" >> /etc/systemd/system/minetestsrv.service
echo "Group=minetest" >> /etc/systemd/system/minetestsrv.service
echo "ExecStart=/usr/bin/minetestserver" >> /etc/systemd/system/minetestsrv.service
echo "Restart=always" >> /etc/systemd/system/minetestsrv.service
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;"
mkdir -p /home/minetest/.minetest/worlds/world/
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 "Fix privileges on /home/minetest"
chown minetest:minetest /home/minetest/ -cR
fi
systemctl start minetestsrv
systemctl enable minetestsrv