2024-09-21 20:14:52 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2024-09-22 02:50:10 +03:00
|
|
|
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}"
|