2025-09-18 16:15:35 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
2025-12-23 13:20:03 +01:00
|
|
|
# Constants
|
|
|
|
|
|
2025-12-22 20:51:46 +01:00
|
|
|
# port of the server in standalone mode, aka the open port
|
|
|
|
|
STANDALONE_PORT=25565
|
|
|
|
|
# port of the server in proxy mode, aka the internal port
|
|
|
|
|
PROXY_PORT=25566
|
2025-12-23 12:40:45 +01:00
|
|
|
# installs ViaVersion on BungeeCord and standalone mode, removes it in Velocity mode
|
2025-12-23 13:30:30 +01:00
|
|
|
MANAGE_VIA_VERSION=false
|
2025-12-23 12:40:45 +01:00
|
|
|
# installs ViaBackwards on BungeeCord and standalone mode, removes it in Velocity mode
|
|
|
|
|
MANAGE_VIA_BACKWARDS=$MANAGE_VIA_VERSION
|
|
|
|
|
|
|
|
|
|
# Prefix of the ViaVersion jar
|
|
|
|
|
VIA_VERSION_NAME="ViaVersion"
|
|
|
|
|
# Prefix of the ViaBackwards jar
|
|
|
|
|
VIA_BACKWARDS_NAME="ViaBackwards"
|
|
|
|
|
# Github repo of ViaVersion project
|
|
|
|
|
VIA_VERSION_REPO="ViaVersion/ViaVersion"
|
|
|
|
|
# Github repo of ViaBackwards project
|
|
|
|
|
VIA_BACKWARDS_REPO="ViaVersion/ViaBackwards"
|
2025-12-22 20:51:46 +01:00
|
|
|
|
2025-12-23 13:20:03 +01:00
|
|
|
# Runtime variables
|
|
|
|
|
|
|
|
|
|
quiet=false
|
|
|
|
|
|
|
|
|
|
|
2025-12-22 17:18:32 +01:00
|
|
|
function main {
|
|
|
|
|
|
|
|
|
|
# parse arguments
|
2025-12-23 12:40:45 +01:00
|
|
|
local velocity=false
|
|
|
|
|
local bungeecord=false
|
|
|
|
|
local standalone=false
|
|
|
|
|
local fetch=false
|
|
|
|
|
local help=false
|
2025-12-22 17:18:32 +01:00
|
|
|
|
2025-12-22 20:53:51 +01:00
|
|
|
for arg in "$@"; do
|
2025-12-22 17:18:32 +01:00
|
|
|
case "$arg" in
|
|
|
|
|
"velocity")
|
|
|
|
|
velocity=true
|
|
|
|
|
if $bungeecord || $standalone; then
|
2025-12-23 13:20:03 +01:00
|
|
|
err "argument velocity can't be used together with bungeecord or standalone"
|
2025-12-22 17:18:32 +01:00
|
|
|
fi
|
|
|
|
|
;;
|
2025-12-22 20:57:41 +01:00
|
|
|
"bungeecord")
|
2025-12-22 17:18:32 +01:00
|
|
|
bungeecord=true
|
|
|
|
|
if $velocity || $standalone; then
|
2025-12-23 13:20:03 +01:00
|
|
|
err "argument bungeecord can't be used together with velocity or standalone"
|
2025-12-22 17:18:32 +01:00
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
"standalone")
|
|
|
|
|
standalone=true
|
|
|
|
|
if $bungeecord || $velocity; then
|
2025-12-23 13:20:03 +01:00
|
|
|
err "argument standalone can't be used together with bungeecord or velocity"
|
2025-12-22 17:18:32 +01:00
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
"--fetch")
|
|
|
|
|
fetch=true
|
2025-12-23 13:20:03 +01:00
|
|
|
quiet=true
|
|
|
|
|
;;
|
|
|
|
|
"--quiet" | "-q")
|
|
|
|
|
quiet=true
|
2025-12-22 17:18:32 +01:00
|
|
|
;;
|
|
|
|
|
"--help")
|
|
|
|
|
help=true
|
|
|
|
|
;;
|
2025-12-22 20:57:41 +01:00
|
|
|
*)
|
2025-12-23 13:20:03 +01:00
|
|
|
err "Unknown argument: $arg"
|
2025-12-22 20:57:41 +01:00
|
|
|
;;
|
2025-12-22 17:18:32 +01:00
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if $help; then
|
|
|
|
|
echo "Configure the server to be used with BungeeCord, Velcity or in standalone mode."
|
|
|
|
|
echo ""
|
2025-12-22 20:51:46 +01:00
|
|
|
echo "Usage: $0 [OPTIONS] <mode>"
|
2025-12-22 17:18:32 +01:00
|
|
|
echo ""
|
|
|
|
|
echo "mode:"
|
|
|
|
|
echo " velocity"
|
|
|
|
|
echo " bungeecord"
|
|
|
|
|
echo " standalone"
|
|
|
|
|
echo ""
|
|
|
|
|
echo "OPTIONS:"
|
|
|
|
|
echo " --fetch - print the current mode before reconfiguring the server. Nothing else will be printed."
|
|
|
|
|
echo " --help - show this message"
|
2025-12-23 13:20:03 +01:00
|
|
|
echo " -q --quiet - Dont print any output, except for output which is caused by --fetch"
|
2025-12-22 17:18:32 +01:00
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# fetch current configuration
|
|
|
|
|
if $fetch; then
|
|
|
|
|
if [ "$(yq '.proxies.velocity.enabled // false' config/paper-global.yml)" = "true" ]; then
|
|
|
|
|
echo "velocity"
|
|
|
|
|
elif [ "$(yq '.settings.bungeecord // false' spigot.yml)" = "true" ]; then
|
|
|
|
|
echo "bungeecord"
|
|
|
|
|
else
|
|
|
|
|
echo "standalone"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2025-12-22 20:51:46 +01:00
|
|
|
# Do the actual configuration
|
2025-12-23 12:40:45 +01:00
|
|
|
|
|
|
|
|
# Velocity
|
2025-12-22 17:18:32 +01:00
|
|
|
if $velocity; then
|
2025-12-23 13:30:30 +01:00
|
|
|
info "Configuring for Velocity"
|
2025-12-22 20:51:46 +01:00
|
|
|
enable_online_mode false
|
|
|
|
|
set_port "$PROXY_PORT"
|
|
|
|
|
enable_velocity true
|
|
|
|
|
enable_bungeecord false
|
2025-12-23 12:40:45 +01:00
|
|
|
if $MANAGE_VIA_VERSION; then
|
|
|
|
|
remove_plugin "$VIA_VERSION_NAME"
|
|
|
|
|
fi
|
|
|
|
|
if $MANAGE_VIA_BACKWARDS; then
|
|
|
|
|
remove_plugin "$VIA_BACKWARDS_NAME"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# BungeeCord
|
2025-12-22 17:18:32 +01:00
|
|
|
elif $bungeecord; then
|
2025-12-23 13:30:30 +01:00
|
|
|
info "Configuring for BungeeCord"
|
2025-12-22 20:51:46 +01:00
|
|
|
enable_online_mode false
|
|
|
|
|
set_port "$PROXY_PORT"
|
|
|
|
|
enable_velocity false
|
|
|
|
|
enable_bungeecord true
|
2025-12-23 12:40:45 +01:00
|
|
|
if $MANAGE_VIA_VERSION; then
|
|
|
|
|
update_plugin "$VIA_VERSION_NAME" "$VIA_VERSION_REPO"
|
|
|
|
|
fi
|
|
|
|
|
if $MANAGE_VIA_BACKWARDS; then
|
|
|
|
|
update_plugin "$VIA_BACKWARDS_NAME" "$VIA_BACKWARDS_REPO"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# standalone
|
2025-12-22 17:18:32 +01:00
|
|
|
elif $standalone; then
|
2025-12-23 13:30:30 +01:00
|
|
|
info "Configuring for standalone mode"
|
2025-12-22 20:51:46 +01:00
|
|
|
enable_online_mode true
|
|
|
|
|
set_port "$STANDALONE_PORT"
|
|
|
|
|
enable_velocity false
|
|
|
|
|
enable_bungeecord false
|
2025-12-23 12:40:45 +01:00
|
|
|
if $MANAGE_VIA_VERSION; then
|
|
|
|
|
update_plugin "$VIA_VERSION_NAME" "$VIA_VERSION_REPO"
|
|
|
|
|
fi
|
|
|
|
|
if $MANAGE_VIA_BACKWARDS; then
|
|
|
|
|
update_plugin "$VIA_BACKWARDS_NAME" "$VIA_BACKWARDS_REPO"
|
|
|
|
|
fi
|
2025-12-22 17:18:32 +01:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-22 20:51:46 +01:00
|
|
|
# Enables or disables online mode
|
|
|
|
|
#
|
|
|
|
|
# Usage: enable_online_mode <true|false>
|
|
|
|
|
function enable_online_mode {
|
|
|
|
|
sed -ie "/online-mode/c\online-mode=$1" server.properties
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Set the port of the server
|
|
|
|
|
#
|
|
|
|
|
# Usage: set_port <port>
|
|
|
|
|
function set_port {
|
|
|
|
|
sed -ie "/server-port/c\server-port=$1" server.properties
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Enables or disables velocity in the paper config.
|
|
|
|
|
# Does NOT configure the forwarding secret!
|
|
|
|
|
#
|
|
|
|
|
# Usage: enable_velocity <true|false>
|
|
|
|
|
function enable_velocity {
|
|
|
|
|
yq -iy ".proxies.velocity.enabled = $1" config/paper-global.yml
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Enables or disables bungeecord in spigot.yml.
|
|
|
|
|
#
|
|
|
|
|
# Usage: enable_bungeecord <true|false>
|
|
|
|
|
function enable_bungeecord {
|
|
|
|
|
yq -iy ".settings.bungeecord = $1" spigot.yml
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-23 12:40:45 +01:00
|
|
|
# Removes a plugin
|
|
|
|
|
#
|
|
|
|
|
# Usage: remove_plugin <jar-prefix>
|
|
|
|
|
function remove_plugin {
|
|
|
|
|
local plugin_name=$1
|
|
|
|
|
rm plugins/"$plugin_name"*.jar 2>/dev/null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Update the latest release of a plugin from github
|
|
|
|
|
#
|
|
|
|
|
# Usage: update_plugin <jar-prefix> <repo>
|
|
|
|
|
function update_plugin {
|
|
|
|
|
local plugin_name=$1
|
|
|
|
|
local repo=$2
|
|
|
|
|
remove_plugin $plugin_name
|
2025-12-23 13:30:30 +01:00
|
|
|
info "Downloading latest version of $plugin_name..."
|
2025-12-23 12:40:45 +01:00
|
|
|
download_jar_from_github $repo "plugins/"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Download the jar files from the latest release of a github repo
|
|
|
|
|
#
|
|
|
|
|
# Usage: download_jar_from_github <repo> <destination>
|
|
|
|
|
function download_jar_from_github {
|
|
|
|
|
local repo=$1
|
|
|
|
|
local dst=$2
|
|
|
|
|
local url=$(curl -s "https://api.github.com/repos/$repo/releases/latest" | jq -r '.assets[] | select(.name | endswith(".jar")) | .browser_download_url')
|
2025-12-23 13:20:03 +01:00
|
|
|
if $quiet; then
|
|
|
|
|
wget -qP "$dst" "$url"
|
|
|
|
|
else
|
|
|
|
|
wget -P "$dst" "$url"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-23 13:30:30 +01:00
|
|
|
# Print something unless quiet flag has been set
|
|
|
|
|
#
|
|
|
|
|
# Usage: info <msg>
|
|
|
|
|
function info {
|
|
|
|
|
if ! $quiet; then
|
|
|
|
|
echo "$1"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-23 13:20:03 +01:00
|
|
|
# Shows ans error message and exits the program with code 1
|
|
|
|
|
#
|
|
|
|
|
# Usage: err <msg>
|
|
|
|
|
function err {
|
|
|
|
|
echo "$1"
|
|
|
|
|
exit 1
|
2025-12-23 12:40:45 +01:00
|
|
|
}
|
|
|
|
|
|
2025-12-22 20:53:51 +01:00
|
|
|
main "$@"
|