Add -p/--port for the Minecraft server port
Threads a port through all three scripts. mc-service-setup.sh writes server-port into server.properties (updating in place so a generated file keeps its other settings) and opens the port in firewalld. packwiz-setup.sh renders it into the player guides. The guides print a bare hostname on 25565 and host:port otherwise — Minecraft assumes the default, and a needless ":25565" in the address reliably confuses players. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>main
parent
87b280cc91
commit
debada2b56
|
|
@ -14,6 +14,11 @@ Everything lives on a ZFS dataset mounted at `/minecraft`.
|
||||||
--accept-eula
|
--accept-eula
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Add `-p 25599` to run on a non-default port. It's written into
|
||||||
|
`server.properties`, opened in firewalld, and shown in the player guides — which
|
||||||
|
print a bare hostname on 25565 and `host:port` on anything else, since Minecraft
|
||||||
|
assumes the default and a needless `:25565` confuses people.
|
||||||
|
|
||||||
The NeoForge version is resolved automatically — the newest stable build in the
|
The NeoForge version is resolved automatically — the newest stable build in the
|
||||||
series matching your Minecraft version, from the NeoForged maven. Pin one with
|
series matching your Minecraft version, from the NeoForged maven. Pin one with
|
||||||
`-N 21.1.248` if you'd rather not track latest.
|
`-N 21.1.248` if you'd rather not track latest.
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
NAME=""; AUTHOR=""; BASEURL=""; NFVER="latest"; MCVER="1.21.1"
|
NAME=""; AUTHOR=""; BASEURL=""; NFVER="latest"; MCVER="1.21.1"
|
||||||
SHARE="/minecraft"; XMX="10G"; XMS="10G"; ACCEPT_EULA=""
|
SHARE="/minecraft"; XMX="10G"; XMS="10G"; ACCEPT_EULA=""; PORT="25565"
|
||||||
HERE="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
HERE="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
die() { echo "error: $*" >&2; exit 1; }
|
die() { echo "error: $*" >&2; exit 1; }
|
||||||
|
|
@ -29,6 +29,7 @@ while [ $# -gt 0 ]; do
|
||||||
-N|--neoforge) NFVER="${2:-}"; shift 2 ;;
|
-N|--neoforge) NFVER="${2:-}"; shift 2 ;;
|
||||||
-m|--mc) MCVER="${2:-}"; shift 2 ;;
|
-m|--mc) MCVER="${2:-}"; shift 2 ;;
|
||||||
-s|--share) SHARE="${2:-}"; shift 2 ;;
|
-s|--share) SHARE="${2:-}"; shift 2 ;;
|
||||||
|
-p|--port) PORT="${2:-}"; shift 2 ;;
|
||||||
-X|--xmx) XMX="${2:-}"; shift 2 ;;
|
-X|--xmx) XMX="${2:-}"; shift 2 ;;
|
||||||
-x|--xms) XMS="${2:-}"; shift 2 ;;
|
-x|--xms) XMS="${2:-}"; shift 2 ;;
|
||||||
--accept-eula) ACCEPT_EULA="--accept-eula"; shift ;;
|
--accept-eula) ACCEPT_EULA="--accept-eula"; shift ;;
|
||||||
|
|
@ -51,7 +52,7 @@ sudo -v || die "sudo is required"
|
||||||
|
|
||||||
step "1/2 Minecraft systemd service"
|
step "1/2 Minecraft systemd service"
|
||||||
sudo "$HERE/mc-service-setup.sh" \
|
sudo "$HERE/mc-service-setup.sh" \
|
||||||
-s "$SHARE" -A "$USER" -X "$XMX" -x "$XMS" -m "$MCVER" \
|
-s "$SHARE" -A "$USER" -X "$XMX" -x "$XMS" -m "$MCVER" -p "$PORT" \
|
||||||
${NFVER:+-N "$NFVER"} ${ACCEPT_EULA}
|
${NFVER:+-N "$NFVER"} ${ACCEPT_EULA}
|
||||||
|
|
||||||
step "2/2 packwiz pack and player guides"
|
step "2/2 packwiz pack and player guides"
|
||||||
|
|
@ -59,10 +60,10 @@ step "2/2 packwiz pack and player guides"
|
||||||
# the pack setup under the new group explicitly rather than telling you to log
|
# the pack setup under the new group explicitly rather than telling you to log
|
||||||
# out and back in.
|
# out and back in.
|
||||||
if id -nG "$USER" | tr ' ' '\n' | grep -qx minecraft; then
|
if id -nG "$USER" | tr ' ' '\n' | grep -qx minecraft; then
|
||||||
"$HERE/packwiz-setup.sh" -n "$NAME" -a "$AUTHOR" -m "$MCVER" -u "$BASEURL" -s "$SHARE"
|
"$HERE/packwiz-setup.sh" -n "$NAME" -a "$AUTHOR" -m "$MCVER" -u "$BASEURL" -s "$SHARE" -p "$PORT"
|
||||||
else
|
else
|
||||||
sg minecraft -c "$(printf '%q ' "$HERE/packwiz-setup.sh" -n "$NAME" -a "$AUTHOR" \
|
sg minecraft -c "$(printf '%q ' "$HERE/packwiz-setup.sh" -n "$NAME" -a "$AUTHOR" \
|
||||||
-m "$MCVER" -u "$BASEURL" -s "$SHARE")"
|
-m "$MCVER" -u "$BASEURL" -s "$SHARE" -p "$PORT")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
step "Done"
|
step "Done"
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ set -euo pipefail
|
||||||
|
|
||||||
SHARE="/minecraft"
|
SHARE="/minecraft"
|
||||||
MCUSER="minecraft"
|
MCUSER="minecraft"
|
||||||
|
PORT="25565" # Minecraft server port
|
||||||
XMS="10G"
|
XMS="10G"
|
||||||
XMX="10G"
|
XMX="10G"
|
||||||
NFVER="" # version, or "latest" to resolve one; empty = don't install
|
NFVER="" # version, or "latest" to resolve one; empty = don't install
|
||||||
|
|
@ -36,6 +37,7 @@ while [ $# -gt 0 ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-s|--share) SHARE="${2:-}"; shift 2 ;;
|
-s|--share) SHARE="${2:-}"; shift 2 ;;
|
||||||
-U|--user) MCUSER="${2:-}"; shift 2 ;;
|
-U|--user) MCUSER="${2:-}"; shift 2 ;;
|
||||||
|
-p|--port) PORT="${2:-}"; shift 2 ;;
|
||||||
-x|--xms) XMS="${2:-}"; shift 2 ;;
|
-x|--xms) XMS="${2:-}"; shift 2 ;;
|
||||||
-X|--xmx) XMX="${2:-}"; shift 2 ;;
|
-X|--xmx) XMX="${2:-}"; shift 2 ;;
|
||||||
-N|--neoforge) NFVER="${2:-}"; shift 2 ;;
|
-N|--neoforge) NFVER="${2:-}"; shift 2 ;;
|
||||||
|
|
@ -48,6 +50,8 @@ while [ $# -gt 0 ]; do
|
||||||
done
|
done
|
||||||
|
|
||||||
[ "$(id -u)" -eq 0 ] || die "run this with sudo — it creates a user and writes unit files"
|
[ "$(id -u)" -eq 0 ] || die "run this with sudo — it creates a user and writes unit files"
|
||||||
|
[[ "$PORT" =~ ^[0-9]+$ ]] && [ "$PORT" -ge 1 ] && [ "$PORT" -le 65535 ] \
|
||||||
|
|| die "-p wants a port between 1 and 65535, got: $PORT"
|
||||||
|
|
||||||
# ----------------------------------------------------------------- share ----
|
# ----------------------------------------------------------------- share ----
|
||||||
|
|
||||||
|
|
@ -170,6 +174,31 @@ if [ ! -f "$SHARE/eula.txt" ] || ! grep -q '^eula=true' "$SHARE/eula.txt"; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# ------------------------------------------------------------ properties ----
|
||||||
|
|
||||||
|
# Update in place so a server.properties the server already generated keeps all
|
||||||
|
# its other settings; create the key if it is not there yet.
|
||||||
|
set_prop() {
|
||||||
|
local key="$1" val="$2" f="$SHARE/server.properties"
|
||||||
|
if [ -f "$f" ] && grep -q "^${key}=" "$f"; then
|
||||||
|
sed -i "s|^${key}=.*|${key}=${val}|" "$f"
|
||||||
|
else
|
||||||
|
printf '%s=%s\n' "$key" "$val" >> "$f"
|
||||||
|
fi
|
||||||
|
chown "$MCUSER":"$MCUSER" "$f"
|
||||||
|
}
|
||||||
|
|
||||||
|
info "setting server-port=$PORT"
|
||||||
|
set_prop server-port "$PORT"
|
||||||
|
|
||||||
|
if systemctl is-active --quiet firewalld; then
|
||||||
|
info "opening $PORT/tcp"
|
||||||
|
firewall-cmd --quiet --permanent --add-port="$PORT/tcp"
|
||||||
|
firewall-cmd --quiet --reload
|
||||||
|
else
|
||||||
|
warn "firewalld is not running — make sure $PORT/tcp is reachable"
|
||||||
|
fi
|
||||||
|
|
||||||
# -------------------------------------------------------------- jvm args ----
|
# -------------------------------------------------------------- jvm args ----
|
||||||
|
|
||||||
# Written fresh so -X/-x actually take effect on re-runs. G1 tuning is the
|
# Written fresh so -X/-x actually take effect on re-runs. G1 tuning is the
|
||||||
|
|
@ -258,7 +287,7 @@ echo
|
||||||
info "installed. Start it with:"
|
info "installed. Start it with:"
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
|
||||||
sudo systemctl start minecraft
|
sudo systemctl start minecraft # listening on port $PORT
|
||||||
journalctl -u minecraft -f # watch the console
|
journalctl -u minecraft -f # watch the console
|
||||||
|
|
||||||
echo "say hello" | sudo tee $FIFO # send a console command
|
echo "say hello" | sudo tee $FIFO # send a console command
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ WEBROOT="" # defaults to $SHARE — docroot the site is served fr
|
||||||
SITE_URL="" # defaults to the origin of $BASEURL
|
SITE_URL="" # defaults to the origin of $BASEURL
|
||||||
PACK_URL="" # defaults to $SITE_URL/packs/<slug>
|
PACK_URL="" # defaults to $SITE_URL/packs/<slug>
|
||||||
SERVER_ADDR="" # defaults to the hostname of $SITE_URL
|
SERVER_ADDR="" # defaults to the hostname of $SITE_URL
|
||||||
|
MCPORT="25565" # Minecraft port, shown in the guides
|
||||||
GUIDES=1 # write the player setup guides
|
GUIDES=1 # write the player setup guides
|
||||||
|
|
||||||
die() { echo "error: $*" >&2; exit 1; }
|
die() { echo "error: $*" >&2; exit 1; }
|
||||||
|
|
@ -51,6 +52,7 @@ while [ $# -gt 0 ]; do
|
||||||
-U|--site-url) SITE_URL="${2:-}"; shift 2 ;;
|
-U|--site-url) SITE_URL="${2:-}"; shift 2 ;;
|
||||||
-P|--pack-url) PACK_URL="${2:-}"; shift 2 ;;
|
-P|--pack-url) PACK_URL="${2:-}"; shift 2 ;;
|
||||||
-A|--server) SERVER_ADDR="${2:-}"; shift 2 ;;
|
-A|--server) SERVER_ADDR="${2:-}"; shift 2 ;;
|
||||||
|
-p|--port) MCPORT="${2:-}"; shift 2 ;;
|
||||||
--no-guides) GUIDES=0; shift ;;
|
--no-guides) GUIDES=0; shift ;;
|
||||||
-h|--help) usage 0 ;;
|
-h|--help) usage 0 ;;
|
||||||
*) echo "unknown option: $1" >&2; usage 1 ;;
|
*) echo "unknown option: $1" >&2; usage 1 ;;
|
||||||
|
|
@ -109,6 +111,14 @@ if [ -n "$SITE_URL" ]; then
|
||||||
fi
|
fi
|
||||||
PACK_URL="${PACK_URL%/}"
|
PACK_URL="${PACK_URL%/}"
|
||||||
|
|
||||||
|
# Minecraft assumes 25565, so only show a port when it is not that — a
|
||||||
|
# needless ":25565" in the address is a classic source of player confusion.
|
||||||
|
if [ "$MCPORT" = "25565" ]; then
|
||||||
|
SERVER_DISPLAY="$SERVER_ADDR"
|
||||||
|
else
|
||||||
|
SERVER_DISPLAY="$SERVER_ADDR:$MCPORT"
|
||||||
|
fi
|
||||||
|
|
||||||
[ -n "$WEBROOT" ] || WEBROOT="$SHARE"
|
[ -n "$WEBROOT" ] || WEBROOT="$SHARE"
|
||||||
|
|
||||||
if (( GUIDES )); then
|
if (( GUIDES )); then
|
||||||
|
|
@ -371,7 +381,7 @@ font-size:.84rem;color:var(--muted)}
|
||||||
<li><b>MC</b> <span>$MCVER</span></li>
|
<li><b>MC</b> <span>$MCVER</span></li>
|
||||||
<li><b>Loader</b> <span>NeoForge</span></li>
|
<li><b>Loader</b> <span>NeoForge</span></li>
|
||||||
<li><b>Java</b> <span>21</span></li>
|
<li><b>Java</b> <span>21</span></li>
|
||||||
<li><b>Server</b> <span>$SERVER_ADDR</span></li>
|
<li><b>Server</b> <span>$SERVER_DISPLAY</span></li>
|
||||||
</ul>
|
</ul>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
|
@ -441,7 +451,7 @@ font-size:.84rem;color:var(--muted)}
|
||||||
<div class="body">
|
<div class="body">
|
||||||
<p>Hit <b>Launch</b>. The first run downloads the full mod set, so give it a
|
<p>Hit <b>Launch</b>. The first run downloads the full mod set, so give it a
|
||||||
minute. At the title screen go to <b>Multiplayer</b> → <b>Add Server</b>:</p>
|
minute. At the title screen go to <b>Multiplayer</b> → <b>Add Server</b>:</p>
|
||||||
<div class="cmd"><pre><code>$SERVER_ADDR</code></pre><button class="copy" type="button">Copy</button></div>
|
<div class="cmd"><pre><code>$SERVER_DISPLAY</code></pre><button class="copy" type="button">Copy</button></div>
|
||||||
<p>That's it. From here on just launch normally — updates arrive on their own.</p>
|
<p>That's it. From here on just launch normally — updates arrive on their own.</p>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue