From cc20da589ee5294b578fa996b139a5a188d605c4 Mon Sep 17 00:00:00 2001 From: leca Date: Sun, 22 Sep 2024 02:50:10 +0300 Subject: [PATCH] Dockerfile, docker-compose.yml and downloading of game in install.sh --- .env | 3 +++ .gitignore | 3 +-- Dockerfile | 29 ++++++--------------- docker-compose.yml | 9 +++++-- install.sh | 63 +++++++++++++++++++++++++++++++++++++++++++++- server.env | 2 -- 6 files changed, 80 insertions(+), 29 deletions(-) create mode 100644 .env delete mode 100644 server.env diff --git a/.env b/.env new file mode 100644 index 0000000..b882b40 --- /dev/null +++ b/.env @@ -0,0 +1,3 @@ +SERVER_GAME="minetest" +SERVER_MODS="i3;animalia" +API_URL="https://content.minetest.net/api" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 942dbdd..6320cd2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -data -conf \ No newline at end of file +data \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index a9ab062..ce83b91 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,9 @@ FROM debian:12 +ARG gameid + +RUN echo "Building image with gameid: $gameid" + #Update RUN apt update -y && apt upgrade -y @@ -19,29 +23,10 @@ USER root WORKDIR /home/minetest/minetest-source/build RUN make install -#Install game & mods - -#Planned to do script for game & mod installation - -# USER minetest -# RUN mkdir /home/minetest/.minetest -# WORKDIR /home/minetest/.minetest - -# RUN wget https://content.minetest.net/packages/Minetest/minetest_game/releases/27207/download/ -# RUN mv index.html minetest_game.zip -# # RUN unzip minetest_game.zip -# # RUN rm minetest_game.zip -# USER root -# RUN mkdir -p /usr/local/share/minetest/games -# RUN mv /home/minetest/.minetest/minetest_game.zip /usr/local/share/minetest/games -# WORKDIR /usr/local/share/minetest/games -# RUN unzip minetest_game.zip -# RUN rm minetest_game.zip - RUN mkdir -p /usr/local/share/minetest/games USER minetest EXPOSE 30000/udp -ENTRYPOINT ["/usr/local/bin/minetestserver", "--gameid", "minetest"] -# USER root -# ENTRYPOINT ["/bin/bash"] \ No newline at end of file +RUN echo "#!/bin/bash\n/usr/local/bin/minetestserver --gameid $gameid" > ./entrypoint.sh +RUN chmod +x entrypoint.sh +ENTRYPOINT ["./entrypoint.sh"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index bc1c270..75d9ef6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,15 @@ services: minetest_server: - build: . + environment: + - SERVER_GAME + build: + context: . + args: + gameid: ${SERVER_GAME} restart: always network_mode: host volumes: - - ./data:/use/local/share/minetest + - ./data/games:/usr/local/share/minetest/games ports: - "30000:30000/udp" - "127.0.0.1:30000:30000/tcp" diff --git a/install.sh b/install.sh index 6e0a9b7..a4b3df6 100755 --- a/install.sh +++ b/install.sh @@ -1,3 +1,64 @@ #!/usr/bin/env bash -echo 1 \ No newline at end of file +source ./server.env + +# 1 = json of the game +download_and_install_game() { + download_url=$(echo "${1}" | jq ".url" | tr -d '"') + cd games + wget -O game.zip "${download_url}" + unzip game.zip +} + +mkdir -p data/games +cd data + +#Checking for input +if [[ $SERVER_MODS == "" || $SERVER_GAME == "" ]]; then + echo "Please, fill server.env file before launching this script!" + exit -1 +fi + +#Parsing mode names +oIFS="$IFS" +IFS=";" +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' +authors=($(echo $results | jq '.[].author')) +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 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=$(curl --silent -X GET $API_URL/packages/${chosen_author}/${chosen_packet_name}/) + +download_and_install_game "${chosen}" diff --git a/server.env b/server.env deleted file mode 100644 index 8f74864..0000000 --- a/server.env +++ /dev/null @@ -1,2 +0,0 @@ -SERVER_GAME="" -SERVER_MODS="" \ No newline at end of file