setup-mt 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/bin/bash
  2. source config-file
  3. install_pwd=$(pwd)
  4. if [ $first_install = "y" ]; then
  5. echo "Create minetest user"
  6. useradd minetest
  7. mkdir -p /home/minetest/.minetest
  8. echo "Allow sources repo and install dependecies for build"
  9. perl -pi.orig -0e 's/^(deb .*\n)# (deb-src)/$1$2/mg' /etc/apt/sources.list
  10. apt update
  11. apt-get build-dep minetest -y
  12. fi
  13. echo "Compile libspatialindex"
  14. rm -rf /tmp/spatialindex
  15. git clone https://github.com/libspatialindex/libspatialindex /tmp/spatialindex
  16. cd /tmp/spatialindex
  17. cmake . -DCMAKE_INSTALL_PREFIX=/usr
  18. make -j$(nproc)
  19. make install
  20. echo "Compile minetest version $mt_version"
  21. rm -rf /tmp/minetest
  22. git clone --depth 1 --branch "$mt_version" https://github.com/minetest/minetest.git /tmp/minetest
  23. cp -n /tmp/minetest/minetest.conf.example /home/minetest/.minetest/minetest.conf
  24. cd /tmp/minetest
  25. cmake . \
  26. -DBUILD_CLIENT=0 \
  27. -DBUILD_SERVER=1 \
  28. -DCMAKE_INSTALL_PREFIX=/usr \
  29. -DCUSTOM_BINDIR=/usr/bin \
  30. -DCUSTOM_DOCDIR="/usr/share/doc/minetest" \
  31. -DCUSTOM_SHAREDIR="/usr/share/minetest" \
  32. -DENABLE_CURL=1 \
  33. -DENABLE_LEVELDB=1 \
  34. -DENABLE_LUAJIT=1 \
  35. -DENABLE_REDIS=1 \
  36. -DENABLE_SOUND=0 \
  37. -DENABLE_SYSTEM_GMP=1 \
  38. -DENABLE_POSTGRESQL=1 \
  39. -DPOSTGRESQL_CONFIG_EXECUTABLE=/usr/bin/pg_config \
  40. -DPOSTGRESQL_LIBRARY=/usr/lib/libpq.so \
  41. -DRUN_IN_PLACE=0
  42. make -j$(nproc)
  43. echo "Stop minetestsrv service(upgrade case)"
  44. systemctl stop minetestsrv
  45. make install
  46. echo "Clone minetest_game $mt_version"
  47. mkdir -p /home/minetest/.minetest/games/
  48. rm -rf /home/minetest/.minetest/games/minetest
  49. git clone --depth 1 --branch "$mt_version" https://github.com/minetest/minetest_game.git /home/minetest/.minetest/games/minetest
  50. echo "Fix privileges on /home/minetest"
  51. chown minetest:minetest /home/minetest/ -cR
  52. if [ $first_install = "y" ]; then
  53. echo "Configuring firstinstall config"
  54. echo "Creating minetestsrv systemd service"
  55. echo "[Unit]" > /etc/systemd/system/minetestsrv.service
  56. echo "Description=MinetestSRV" >> /etc/systemd/system/minetestsrv.service
  57. echo "After=postgresql.service" >> /etc/systemd/system/minetestsrv.service
  58. echo "[Service]" >> /etc/systemd/system/minetestsrv.service
  59. echo "Type=simple" >> /etc/systemd/system/minetestsrv.service
  60. echo "User=minetest" >> /etc/systemd/system/minetestsrv.service
  61. echo "Group=minetest" >> /etc/systemd/system/minetestsrv.service
  62. echo "ExecStart=/usr/bin/minetestserver" >> /etc/systemd/system/minetestsrv.service
  63. echo "Restart=always" >> /etc/systemd/system/minetestsrv.service
  64. echo "RestartSec=3" >> /etc/systemd/system/minetestsrv.service
  65. echo "[Install]" >> /etc/systemd/system/minetestsrv.service
  66. echo "WantedBy=multi-user.target" >> /etc/systemd/system/minetestsrv.service
  67. systemctl daemon-reload
  68. apt install postgresql postgresql-contrib -y
  69. pg_ctlcluster 12 main start
  70. sudo -u postgres createuser minetest
  71. sudo -u postgres createdb minetest
  72. sudo -u postgres createdb minetest_players
  73. sudo -u postgres createdb minetest_auth
  74. sudo -u postgres psql -U postgres -d postgres -c "alter user postgres with password '$psql_postgres_user_password';"
  75. sudo -u postgres psql -U postgres -d postgres -c "alter user minetest with password '$psql_minetest_user_password';"
  76. sudo -u postgres psql -U postgres -d postgres -c "grant all privileges on database "minetest" to minetest;"
  77. sudo -u postgres psql -U postgres -d postgres -c "grant all privileges on database "minetest_players" to minetest;"
  78. sudo -u postgres psql -U postgres -d postgres -c "grant all privileges on database "minetest_auth" to minetest;"
  79. mkdir -p /home/minetest/.minetest/worlds/world/
  80. echo "gameid = minetest" > /home/minetest/.minetest/worlds/world/world.mt
  81. echo "backend = postgresql" >> /home/minetest/.minetest/worlds/world/world.mt
  82. echo "creative_mode = false" >> /home/minetest/.minetest/worlds/world/world.mt
  83. echo "enable_damage = true" >> /home/minetest/.minetest/worlds/world/world.mt
  84. echo "player_backend = postgresql" >> /home/minetest/.minetest/worlds/world/world.mt
  85. echo "auth_backend = postgresql" >> /home/minetest/.minetest/worlds/world/world.mt
  86. echo "pgsql_connection = host=127.0.0.1 user=minetest password=$psql_minetest_user_password dbname=minetest" >> /home/minetest/.minetest/worlds/world/world.mt
  87. 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
  88. 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
  89. cd "$install_pwd"
  90. cat mods-list >> /home/minetest/.minetest/worlds/world/world.mt
  91. cp -r mods /home/minetest/.minetest/mods
  92. echo "disable_fire = true" >> /home/minetest/.minetest/minetest.conf
  93. echo "enable_tnt = false" >> /home/minetest/.minetest/minetest.conf
  94. echo "server_name = "$mt_server_name"" >> /home/minetest/.minetest/minetest.conf
  95. echo "server_description = "$mt_server_description"" >> /home/minetest/.minetest/minetest.conf
  96. echo "server_address = "$mt_server_address"" >> /home/minetest/.minetest/minetest.conf
  97. echo "server_url = "$mt_server_url"" >> /home/minetest/.minetest/minetest.conf
  98. echo "server_announce = "$mt_server_announce"" >> /home/minetest/.minetest/minetest.conf
  99. echo "ipv6_server = "$mt_ipv6_server"" >> /home/minetest/.minetest/minetest.conf
  100. echo "default_game = minetest" >> /home/minetest/.minetest/minetest.conf
  101. echo "motd = "$mt_motd"" >> /home/minetest/.minetest/minetest.conf
  102. echo "max_users = "$mt_max_users"" >> /home/minetest/.minetest/minetest.conf
  103. echo "name = "$mt_admin"" >> /home/minetest/.minetest/minetest.conf
  104. echo "language = "$mt_language"" >> /home/minetest/.minetest/minetest.conf
  105. echo "port = "$mt_port"" >> /home/minetest/.minetest/minetest.conf
  106. echo "enable_rollback_recording = "$mt_enable_rollback_recording"" >> /home/minetest/.minetest/minetest.conf
  107. echo "default_privs = "$mt_default_privs"" >> /home/minetest/.minetest/minetest.conf
  108. echo "mg_name = "$mt_mg_name"" >> /home/minetest/.minetest/minetest.conf
  109. echo "protector_hurt = "$mt_protector_hurt"" >> /home/minetest/.minetest/minetest.conf
  110. echo "protector_flip = "$mt_protector_flip"" >> /home/minetest/.minetest/minetest.conf
  111. echo "protector_pvp = "$mt_protector_pvp"" >> /home/minetest/.minetest/minetest.conf
  112. echo "tubelib_machine_aging_value = "$mt_tubelib_machine_aging_value"" >> /home/minetest/.minetest/minetest.conf
  113. echo "unlimited_player_transfer_distance = false" >> /home/minetest/.minetest/minetest.conf
  114. echo "enable_damage = "$mt_enable_damage"" >> /home/minetest/.minetest/minetest.conf
  115. echo "enable_pvp = "$mt_enable_pvp"" >> /home/minetest/.minetest/minetest.conf
  116. echo "Fix privileges on /home/minetest"
  117. chown minetest:minetest /home/minetest/ -cR
  118. if [ $ufw_enable = "y" ]; then
  119. apt install ufw -y
  120. ufw allow proto tcp to any port $ufw_ssh_port_for_accept
  121. ufw allow proto udp to any port $mt_port
  122. ufw enable
  123. fi
  124. fi
  125. systemctl start minetestsrv
  126. systemctl enable minetestsrv