Compare commits

...

5 Commits

Author SHA1 Message Date
h3lp 8da6db1193 Make pack optional; add upnp 2026-03-29 07:11:07 +03:00
h3lp 29cc37a309 Set world subdirectory in minecraft setup service 2026-03-14 01:36:15 +02:00
h3lp 96b493f8ba Fix world packing 2026-03-14 01:11:24 +02:00
h3lp 62d2e1fcd2 Add user jvm args 2026-03-13 21:40:21 +02:00
h3lp 5743b1f231 Lower RAM args 2026-03-13 21:34:29 +02:00
5 changed files with 62 additions and 6 deletions
+49 -3
View File
@@ -1,15 +1,61 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash --pure
#! nix-shell -p javaPackages.compiler.openjdk17
#! nix-shell -p miniupnpc
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/tarball/nixos-25.11
PACK_AFTER=0
UPNP=0
for arg in "$@"; do
[[ "$arg" == "--pack-after" ]] && PACK_AFTER=1
[[ "$arg" == "--upnp" ]] && UPNP=1
done
source /home/h3lp/mineserver/minecraft.env
if [[ "$UPNP" == 1 ]]; then
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROPERTIES="$SCRIPT_DIR/server.properties"
if [[ -f "$PROPERTIES" ]]; then
PORT=$(grep -oP '(?<=^server-port=)\d+' "$PROPERTIES")
fi
PORT="${PORT:-25565}"
LOCAL_IP="$(upnpc -s 2>/dev/null | grep -oP '(?<=Local LAN ip address : ).*')"
echo "Opening port $PORT/TCP via UPnP..."
upnpc -a "$LOCAL_IP" "$PORT" "$PORT" TCP
TCP_OK=$?
echo "Opening port $PORT/UDP via UPnP..."
upnpc -a "$LOCAL_IP" "$PORT" "$PORT" UDP
UDP_OK=$?
if [[ $TCP_OK -ne 0 || $UDP_OK -ne 0 ]]; then
echo "Warning: One or more UPnP port mappings failed. The port may not be reachable from outside."
fi
cleanup() {
echo "Removing UPnP port mappings for $PORT..."
upnpc -d "$PORT" TCP
upnpc -d "$PORT" UDP
}
trap cleanup EXIT
fi
java -Xmx${MEMORY_MAX}M -Xms${MEMORY_MIN}M -jar minecraft_server.jar nogui
read -rp "Pack and publish world? [y/N] " answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
/home/h3lp/mineserver/packworld.sh
if [[ "$PACK_AFTER" == 1 ]]; then
read -rp "Pack and publish world? [y/N] " answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
set -e
WORLD=/home/h3lp/mineserver/world
OUTPUT=/var/www/hostedfiles/world.tar.xz
TMP=$(mktemp)
tar -cJf "$TMP" -C "$WORLD" .
mv "$TMP" "$OUTPUT"
chmod 644 "$OUTPUT"
echo "Done: $OUTPUT"
set +e
fi
fi
read -rp "Press Enter to continue..."
+1
View File
@@ -11,5 +11,6 @@ TMP=$(mktemp)
tar -cJf "$TMP" -C "$WORLD" .
mv "$TMP" "$OUTPUT"
chmod 644 "$OUTPUT"
echo "Done: $OUTPUT"
+9
View File
@@ -0,0 +1,9 @@
# Xmx and Xms set the maximum and minimum RAM usage, respectively.
# They can take any number, followed by an M or a G.
# M means Megabyte, G means Gigabyte.
# For example, to set the maximum to 3GB: -Xmx3G
# To set the minimum to 2.5GB: -Xms2500M
# A good default for a modded server is 4GB.
# Uncomment the next line to set it.
-Xmx6G
+2 -2
View File
@@ -1,4 +1,4 @@
SERVERPACK=https://20111511.xyz/serverpack.tar.xz
WORLD=https://20111511.xyz/world.tar.xz
MEMORY_MAX=8192
MEMORY_MIN=6144
MEMORY_MAX=6192
MEMORY_MIN=1024
+1 -1
View File
@@ -190,7 +190,7 @@
mkdir -p "$MINESERVER/world"
${pkgs.curl}/bin/curl -L "$WORLD" -o "$TMPDIR/world.tar.xz"
# world.tar.xz contains world folder, otherwise use "$MINESERVER/world"
${pkgs.xz}/bin/xz -d "$TMPDIR/world.tar.xz" --stdout | ${pkgs.gnutar}/bin/tar -x -C "$MINESERVER"
${pkgs.xz}/bin/xz -d "$TMPDIR/world.tar.xz" --stdout | ${pkgs.gnutar}/bin/tar -x -C "$MINESERVER/world"
# 5) Copy cavemen/* files over, overwriting existing
cp -rf "$TMPDIR/autodeploy/cavemen/." "$MINESERVER/"