#!/usr/bin/env bash 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 cd ../ # data } get_dependencies 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}" #Downloading mods #Array to store aaaaaall the mods to be installed, including their dependencies, dependencies of their dependencies, etc... mods_to_install=("") oIFS="$IFS" IFS=";" mods_to_install=($SERVER_MODS) IFS="$oIFS" #TODO: #1. Iterate over all mods in an array #2. For every mod, check all deps. (including required and optional) #3. Ask for required deps, i.e. # 3.1 Check for satisfied deps and dont touch them (user has specified them in .env, SERVER_MODS) # 3.2 Check for unsatisfiend deps and give user a list of possible candidates for that dep. # 3.2.1 go to step 3, treating a dependency as a mod. # 3.3 Check for optional deps, as user if they want to install these, "-1" or "no(t)" if they dont want to and number of package to install #4. Download all mods for array formed during these steps