attempt to add name=

This commit is contained in:
leca 2024-09-28 17:45:44 +03:00
parent c46df01b0d
commit eb8695f037
4 changed files with 44 additions and 21 deletions

8
.env
View File

@ -2,6 +2,8 @@ SERVER_GAME="minetest"
# Must be specified like <username/modname>, i.e. mt-mods/i3, separated by a semicolon (;) # Must be specified like <username/modname>, i.e. mt-mods/i3, separated by a semicolon (;)
# Example: # Example:
# SERVER_MODS="mt-mods/i3;ElCeejo/animalia" # SERVER_MODS="mt-mods/i3;ElCeejo/animalia"
# SERVER_MODS="ElCeejo/animalia" SERVER_MODS="ElCeejo/animalia"
SERVER_MODS="mt-mods/technic_plus_beta" # SERVER_MODS="mt-mods/technic_plus_beta"
API_URL="https://content.minetest.net/api" 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"

View File

@ -1,6 +1,7 @@
FROM debian:12 FROM debian:12
ARG gameid ARG gameid
ARG serveradmin
RUN echo "Building image with gameid: $gameid" RUN echo "Building image with gameid: $gameid"
@ -17,19 +18,20 @@ WORKDIR /home/minetest
RUN git clone --depth 1 https://github.com/minetest/minetest.git minetest-source RUN git clone --depth 1 https://github.com/minetest/minetest.git minetest-source
RUN mkdir /home/minetest/minetest-source/build RUN mkdir /home/minetest/minetest-source/build
WORKDIR /home/minetest/minetest-source/build WORKDIR /home/minetest/minetest-source/build
RUN cmake -DBUILD_SERVER=TRUE -DBUILD_CLIENT=FALSE -DENABLE_CURL=ON -DENABLE_CURSES=ON -DENABLE_POSTGRES=ON -DENABLE_SOUND=OFF.. RUN cmake -DBUILD_SERVER=TRUE -DBUILD_CLIENT=FALSE -DENABLE_CURL=ON -DENABLE_CURSES=ON -DENABLE_POSTGRES=ON -DENABLE_SOUND=OFF ..
RUN make -j 6 RUN make -j 6
USER root USER root
WORKDIR /home/minetest/minetest-source/build WORKDIR /home/minetest/minetest-source/build
RUN make install RUN make install
RUN mkdir -p /usr/local/share/minetest/games RUN mkdir -p /usr/local/share/minetest/games/$gameid
RUN echo "name = $serveradmin" > /usr/local/share/minetest/games/$gameid/minetest.conf
# USER root USER root
# ENTRYPOINT ["bash"] ENTRYPOINT ["bash"]
USER minetest # USER minetest
EXPOSE 30000/udp # EXPOSE 30000/udp
RUN echo "#!/bin/bash\n/usr/local/bin/minetestserver --gameid $gameid --terminal" > ./entrypoint.sh # RUN echo "#!/bin/bash\n/usr/local/bin/minetestserver --gameid $gameid --terminal" > ./entrypoint.sh
RUN chmod +x entrypoint.sh # RUN chmod +x entrypoint.sh
ENTRYPOINT ["./entrypoint.sh"] # ENTRYPOINT ["./entrypoint.sh"]

View File

@ -6,6 +6,7 @@ services:
context: . context: .
args: args:
gameid: ${SERVER_GAME} gameid: ${SERVER_GAME}
serveradmin: ${SERVER_ADMIN}
restart: always restart: always
network_mode: host network_mode: host
volumes: volumes:

View File

@ -68,11 +68,15 @@ chosen_game=$(curl --silent -X GET "$request_url")
# download_and_install_game "${chosen_game}" # download_and_install_game "${chosen_game}"
gameid=$(echo "$chosen_game" | jq ".author" | tr -d '"') #gameid (as is a modid) is a string identifying a mod. For example, ElCeejo/animalia or Minetest/minetest_game
gameid="$gameid/$(echo "$chosen_game" | jq ".name" | tr -d '"')" 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
mods_path="games/${game_name}/mods"
# 1 = mod id # 1 = mod id
is_game () { is_game () {
type=$(curl --silent -X GET "$API_URL/packages/{$1}/" | jq ".type" | tr -d '"') type=$(curl --silent -X GET "$API_URL/packages/{$1}/" | jq ".type" | tr -d '"')
if [[ $type = "mod" ]]; then if [[ $type = "mod" ]]; then
@ -82,9 +86,18 @@ is_game () {
fi fi
} }
# 1 = mod id
download_and_install_mod () {
mod_url=$(curl --silent -X GET "$API_URL/packages/${1}/" | jq ".url" | tr -d '"')
mod_file="${mods_path}/mod.zip"
echo "Writing to ${mod_file} content from url ${mod_url}"
wget -O "${mod_file}" "${mod_url}"
unzip "${mod_file}" -d "${mods_path}"
rm "${mod_file}"
}
# 1 = mod id # 1 = mod id
get_dependencies () { get_dependencies () {
# declare -a calculated_dependencies
echo Checking deps for "$1" echo Checking deps for "$1"
deps=$(curl --silent -X GET "$API_URL/packages/${1}/dependencies/") deps=$(curl --silent -X GET "$API_URL/packages/${1}/dependencies/")
deps=$(echo "$deps" | jq ".\"${1}\"") deps=$(echo "$deps" | jq ".\"${1}\"")
@ -201,7 +214,7 @@ get_dependencies () {
if [ "$chose" = "-1" ] && [ "$is_optional" = true ]; then if [ "$chose" = "-1" ] && [ "$is_optional" = true ]; then
continue continue
fi fi
chosen=$(echo "$possible_candidates" | jq ".[${chose}]") chosen=$(echo "$possible_candidates" | jq ".[${chose}]" | tr -d '"')
if [[ ${calculated_dependencies[*]} =~ $chosen ]]; then if [[ ${calculated_dependencies[*]} =~ $chosen ]]; then
continue continue
else else
@ -220,8 +233,13 @@ IFS=";"
read -r -a mods_to_install <<< "$SERVER_MODS" read -r -a mods_to_install <<< "$SERVER_MODS"
IFS="$oIFS" IFS="$oIFS"
asked_mods_amount=${#mods_to_install[@]} for i in "${mods_to_install[@]}"; do
for i in $(seq 0 $((asked_mods_amount-1))); do get_dependencies "${i}"
get_dependencies "${mods_to_install[${i}]}"
done done
echo "Result: ${calculated_dependencies[*]}"
echo "Following mods will be installed: ${calculated_dependencies[*]}"
for i in "${calculated_dependencies[@]}"; do
echo "Installing ${i}"
download_and_install_mod $i
done