Last active
July 18, 2023 07:42
-
-
Save Rmlyy/a99fe9a1513e3e0dee5c32eedc5d88c1 to your computer and use it in GitHub Desktop.
Easily add servers to Minetrack's server list.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
serverName="$1" | |
serverIp="$2" | |
serverType="$3" | |
serverPosition="$4" | |
serversFile="$5" | |
tempFile="$6" | |
exampleUsage="Example: ./$(basename "$0") Hypixel mc.hypixel.net (PC) (bottom) (servers.json) (temp.json)\n* Arguments between () are optional." | |
if [[ ! $(command -v jq) ]]; then | |
echo "Error: jq not found." | |
exit 1 | |
fi | |
if [[ -z "$serverName" ]]; then | |
echo -e $exampleUsage | |
echo "You need to enter the server name." | |
exit | |
fi | |
if [[ -z "$serverIp" ]]; then | |
echo -e $exampleUsage | |
echo "You need to enter the server IP address." | |
exit | |
fi | |
if [[ -z "$serverType" ]]; then | |
serverType="PC" | |
fi | |
if [[ -z "$serversFile" ]]; then | |
serversFile="servers.json" | |
fi | |
if [[ -z "$tempFile" ]]; then | |
tempFile="temp.json" | |
fi | |
if [[ -z "$serverPosition" ]] || [[ $serverPosition = "bottom" ]]; then | |
serverPosition="bottom" | |
filesOrder="$serversFile $tempFile" | |
else | |
serverPosition="top" | |
filesOrder="$tempFile $serversFile" | |
fi | |
# For some reason I can't pipe jq output to the same file it added to, so here is a workaround. | |
serversNew="$(basename $serversFile)New.json" | |
jq -n --arg name "$serverName" --arg ip "$serverIp" --arg type "$serverType" '[{"name": $ARGS.named["name"], "ip": $ARGS.named["ip"], "type": $ARGS.named["type"]}]' > $tempFile | |
jq -s add $filesOrder > $serversNew | |
mv $serversNew $serversFile | |
rm -rf $tempFile | |
echo -e "Name: $serverName\nIP: $serverIp\nType: $serverType\nPosition: $serverPosition" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment