Done setting

This commit is contained in:
leca 2024-09-29 17:49:23 +03:00
parent eb8695f037
commit 524bc0d4bd
7 changed files with 63 additions and 74 deletions

9
.env
View File

@ -1,9 +0,0 @@
SERVER_GAME="minetest"
# Must be specified like <username/modname>, i.e. mt-mods/i3, separated by a semicolon (;)
# Example:
# SERVER_MODS="mt-mods/i3;ElCeejo/animalia"
SERVER_MODS="ElCeejo/animalia"
# SERVER_MODS="mt-mods/technic_plus_beta"
API_URL="https://content.minetest.net/api"
#Nickname of server admin. Must be specified in order to launch server with --terminal option. Either specify it or remove '--terminal' from Dockerfile
SERVER_ADMIN="leca"

1
.gitignore vendored
View File

@ -1 +1,2 @@
data
.env

View File

@ -1,8 +1,5 @@
FROM debian:12
ARG gameid
ARG serveradmin
RUN echo "Building image with gameid: $gameid"
#Update
@ -24,14 +21,18 @@ USER root
WORKDIR /home/minetest/minetest-source/build
RUN make install
RUN mkdir -p /usr/local/share/minetest/games/$gameid
RUN echo "name = $serveradmin" > /usr/local/share/minetest/games/$gameid/minetest.conf
COPY ./entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
RUN chown -R minetest:minetest /usr/local/share/minetest
# RUN mkdir -p /usr/local/share/minetest/games/$gameid
# RUN echo "name = $serveradmin" > /usr/local/share/minetest/games/$gameid/minetest.conf
USER root
ENTRYPOINT ["bash"]
# USER root
# ENTRYPOINT ["bash"]
# USER minetest
# EXPOSE 30000/udp
# RUN echo "#!/bin/bash\n/usr/local/bin/minetestserver --gameid $gameid --terminal" > ./entrypoint.sh
# RUN chmod +x entrypoint.sh
# ENTRYPOINT ["./entrypoint.sh"]
USER minetest
# COPY sample.env /usr/local/share/mientest/.env
WORKDIR /usr/local/share/minetest
EXPOSE 30000/udp
ENTRYPOINT ["/entrypoint.sh"]

View File

@ -2,15 +2,17 @@ services:
minetest_server:
environment:
- SERVER_GAME
- SERVER_ADMIN
build:
context: .
args:
gameid: ${SERVER_GAME}
serveradmin: ${SERVER_ADMIN}
restart: always
network_mode: host
volumes:
- ./data/games:/usr/local/share/minetest/games
# - type: bind
# source: ./data/.env
# target: /usr/local/share/minetest.env
- ${PWD}/sample.env:/usr/local/share/minetest/.env
- ${PWD}/data/games:/usr/local/share/minetest/games
ports:
- "30000:30000/udp"
- "127.0.0.1:30000:30000/tcp"

12
entrypoint.sh Executable file
View File

@ -0,0 +1,12 @@
#!/bin/bash
#Parse gamename from $SERVER_GAME
IFS='/'
read -r -a servergame <<< $SERVER_GAME
gameid="${servergame[1]}"
echo $SERVER_ADMIN
#Set up admin name
echo "name = ${SERVER_ADMIN}" > /usr/local/share/minetest/minetest.conf
/usr/local/bin/minetestserver --gameid $gameid --config /usr/local/share/minetest/minetest.conf

View File

@ -1,10 +1,10 @@
#!/usr/bin/env bash
source ./.env
source .env
# 1 = json of the game
download_and_install_game() {
download_url=$(echo "${1}" | jq ".url" | tr -d '"')
download_url=$(curl -X GET --silent "$API_URL/packages/${1}/" | jq ".url" | tr -d '"')
cd games || exit
wget -O game.zip "${download_url}"
unzip game.zip
@ -17,7 +17,6 @@ cd data || exit
# All mods with their dependencies
calculated_dependencies=()
#Checking for input
if [[ $SERVER_MODS == "" || $SERVER_GAME == "" ]]; then
echo "Please, fill server.env file before launching this script!"
@ -31,51 +30,17 @@ SERVER_MODS=("$SERVER_MODS")
IFS="$oIFS"
#Downloading game
results=$(curl --silent -X GET "$API_URL/packages/?type=game&q=$SERVER_GAME")
oIFS="$IFS"
IFS=$'\n'
mapfile -t authors < <(echo "$results" | jq '.[].author')
IFS=$'/'
read -r -a servergame <<< "$SERVER_GAME"
IFS="$oIFS"
result_amount="${#authors[@]}"
for i in $(seq 0 $((result_amount-1))); do
author=$(echo "$results" | jq ".[${i}].author" | tr -d '"')
name=$(echo "$results" | jq ".[${i}].name" | tr -d '"')
desc=$(echo "$results" | jq ".[${i}].short_description" | tr -d '"')
echo "{${i}} [${author}] (${name}): ${desc}"
done
chosen=""
while true
do
read -r answer
chosen=$(echo "$results" | jq ".[${answer}]")
if [[ "$chosen" = null ]]; then
echo "Incorrect answer. Try again"
else
break
fi
done
chosen_author=$(echo "$chosen" | jq ".author" | tr -d '"')
chosen_packet_name=$(echo "$chosen" | jq ".name" | tr -d '"')
request_url="${API_URL}/packages/${chosen_author}/${chosen_packet_name}/"
chosen_game=$(curl --silent -X GET "$request_url")
# download_and_install_game "${chosen_game}"
#gameid (as is a modid) is a string identifying a mod. For example, ElCeejo/animalia or Minetest/minetest_game
game_author=$(echo "$chosen_game" | jq ".author" | tr -d '"')
game_name=$(echo "$chosen_game" | jq ".name" | tr -d '"')
gameid="${game_author}/${game_name}"
#Path to directory where installed mods are stored
gameid="${SERVER_GAME}"
game_name="${servergame[1]}"
mods_path="games/${game_name}/mods"
download_and_install_game "${gameid}"
# 1 = mod id
is_game () {
type=$(curl --silent -X GET "$API_URL/packages/{$1}/" | jq ".type" | tr -d '"')
@ -121,10 +86,8 @@ get_dependencies () {
calculated_dependencies_amount=${#calculated_dependencies[@]}
dependency_satisfied_with_game=false
# for j in $(seq 0 $((possible_candidates_amount-1))); do
for (( j = 0 ; j < possible_candidates_amount-1 ; j++ )); do
current_candidate=$(echo "$possible_candidates" | jq ".[${j}]" | tr -d '"')
# possible_candidates_amount=$(echo "${possible_candidates}" | jq "length")
if [[ $possible_candidates_amount -eq 1 ]]; then
break
fi
@ -152,6 +115,7 @@ get_dependencies () {
if [[ $possible_candidates_amount = "" ]]; then
possible_candidates_amount=0
fi
if [[ "$dependency_satisfied_with_game" = true ]]; then
continue
fi
@ -168,9 +132,11 @@ get_dependencies () {
# If there's only one candidate for that dependency, then install it without user's confirmation
fi
if (( possible_candidates_amount == 0 )); then
continue
fi
if (( possible_candidates_amount == 1)); then
candidate=$(echo "${possible_candidates[0]}" | jq ".[0]" | tr -d '"')
calculated_dependencies+=("${candidate}")

16
sample.env Normal file
View File

@ -0,0 +1,16 @@
# Must be specified like <username/gamename>, i.e. Minetest/minetest_game
# Example:
# SERVER_GAME="Minetest/minetest_game"
SERVER_GAME=""
# Must be specified like <username/modname>, i.e. mt-mods/i3, separated by a semicolon (;)
# Example:
# SERVER_MODS="mt-mods/i3;ElCeejo/animalia"
SERVER_MODS=""
# SERVER_MODS="mt-mods/technic_plus_beta"
API_URL="https://content.minetest.net/api"
# Nickname of server admin. Must be specified in order to launch server with --terminal option.
# Either specify it or remove '--terminal' from entrypoint.sh
SERVER_ADMIN=""