Compare commits

...

3 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
3 changed files with 51 additions and 4 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"
+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/"