From 524bc0d4bd0fa77b6f470ab76de577671c9c109c Mon Sep 17 00:00:00 2001 From: leca Date: Sun, 29 Sep 2024 17:49:23 +0300 Subject: [PATCH] Done setting --- .env | 9 ------- .gitignore | 3 ++- Dockerfile | 25 ++++++++++--------- docker-compose.yml | 10 +++++--- entrypoint.sh | 12 +++++++++ install.sh | 62 +++++++++++----------------------------------- sample.env | 16 ++++++++++++ 7 files changed, 63 insertions(+), 74 deletions(-) delete mode 100644 .env create mode 100755 entrypoint.sh create mode 100644 sample.env diff --git a/.env b/.env deleted file mode 100644 index 9e7fb99..0000000 --- a/.env +++ /dev/null @@ -1,9 +0,0 @@ -SERVER_GAME="minetest" -# Must be specified like , 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" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6320cd2..3f8be5f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -data \ No newline at end of file +data +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index bb1c58d..69b1b20 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] \ No newline at end of file +USER minetest +# COPY sample.env /usr/local/share/mientest/.env +WORKDIR /usr/local/share/minetest + +EXPOSE 30000/udp +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 586ce6b..a5c2ab0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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" diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..3e91bf8 --- /dev/null +++ b/entrypoint.sh @@ -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 \ No newline at end of file diff --git a/install.sh b/install.sh index 0b9c9fc..6e06059 100755 --- a/install.sh +++ b/install.sh @@ -1,11 +1,11 @@ #!/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 '"') - cd games || exit + 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 rm 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 '"') @@ -104,7 +69,7 @@ get_dependencies () { mapfile -t deps_array < <(echo "$deps" | jq ".[] | length") amount_of_deps="${#deps_array[@]}" - if [ "$amount_of_deps" -eq 0 ]; then + if [ "$amount_of_deps" -eq 0 ]; then echo "No deps for mod" return fi @@ -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 @@ -139,7 +102,7 @@ get_dependencies () { #Check if candidate is game that is not installed if [ "$(is_game "$current_candidate")" = "true" ] && [ "$current_candidate" != "$gameid" ]; then - if [ "${current_candidate}" = "" ] || [ "${current_candidate}" = "null" ]; then + if [ "${current_candidate}" = "" ] || [ "${current_candidate}" = "null" ]; then continue; 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}") diff --git a/sample.env b/sample.env new file mode 100644 index 0000000..e1cf8ae --- /dev/null +++ b/sample.env @@ -0,0 +1,16 @@ +# Must be specified like , i.e. Minetest/minetest_game +# Example: +# SERVER_GAME="Minetest/minetest_game" +SERVER_GAME="" + +# Must be specified like , 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="" \ No newline at end of file