Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8da6db1193 | |||
| 29cc37a309 | |||
| 96b493f8ba | |||
| 62d2e1fcd2 | |||
| 5743b1f231 | |||
| da4d4b495a | |||
| 946366309c | |||
| 216cde95c5 | |||
| 32c93e5118 | |||
| b0e9e161c0 | |||
| 1d45883976 | |||
| 95c7c2e60c | |||
| cacfc920f2 | |||
| 072d049a6d | |||
| 8a675e4152 | |||
| ebaee023cd |
Executable
+61
@@ -0,0 +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
|
||||
|
||||
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..."
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env nix-shell
|
||||
#! nix-shell -i bash --pure
|
||||
#! nix-shell -p gnutar xz
|
||||
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/tarball/nixos-25.11
|
||||
|
||||
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"
|
||||
@@ -0,0 +1,59 @@
|
||||
#Minecraft server properties
|
||||
#Tue Mar 10 21:38:12 EET 2026
|
||||
allow-flight=true
|
||||
allow-nether=false
|
||||
broadcast-console-to-ops=true
|
||||
broadcast-rcon-to-ops=true
|
||||
difficulty=hard
|
||||
enable-command-block=false
|
||||
enable-jmx-monitoring=false
|
||||
enable-query=false
|
||||
enable-rcon=false
|
||||
enable-status=true
|
||||
enforce-secure-profile=false
|
||||
enforce-whitelist=false
|
||||
entity-broadcast-range-percentage=100
|
||||
force-gamemode=false
|
||||
function-permission-level=2
|
||||
gamemode=survival
|
||||
generate-structures=true
|
||||
generator-settings={}
|
||||
hardcore=false
|
||||
hide-online-players=false
|
||||
initial-disabled-packs=
|
||||
initial-enabled-packs=vanilla
|
||||
level-name=world
|
||||
level-seed=
|
||||
level-type=tfc\:overworld
|
||||
max-chained-neighbor-updates=1000000
|
||||
max-players=64
|
||||
max-tick-time=600000
|
||||
max-world-size=29999984
|
||||
motd=[TerraFirmaGreg-Modern] Server 0.11.21
|
||||
network-compression-threshold=256
|
||||
online-mode=false
|
||||
op-permission-level=4
|
||||
player-idle-timeout=0
|
||||
prevent-proxy-connections=false
|
||||
pvp=true
|
||||
query.port=25565
|
||||
rate-limit=0
|
||||
rcon.ip=0.0.0.0
|
||||
rcon.password=
|
||||
rcon.port=25575
|
||||
require-resource-pack=false
|
||||
resource-pack=
|
||||
resource-pack-prompt=
|
||||
resource-pack-sha1=
|
||||
server-ip=0.0.0.0
|
||||
server-port=25565
|
||||
simulation-distance=8
|
||||
spawn-animals=true
|
||||
spawn-monsters=true
|
||||
spawn-npcs=true
|
||||
spawn-protection=16
|
||||
sync-chunk-writes=true
|
||||
text-filtering-config=
|
||||
use-native-transport=true
|
||||
view-distance=8
|
||||
white-list=false
|
||||
@@ -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
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#!/bin/sh
|
||||
|
||||
# ---- Clone the config repo ----
|
||||
cd /root
|
||||
|
||||
git clone 'https://gitea.20111511.xyz/h3lp/autodeploy.git' --branch cavemen
|
||||
|
||||
cd autodeploy
|
||||
|
||||
# ---- Initialize nixos config ----
|
||||
mkfs.ext4 -F -L nixos /dev/sda1
|
||||
mount /dev/sda1 /mnt/
|
||||
mkdir -p /mnt/boot
|
||||
mount -o umask=077 /dev/sda15 /mnt/boot
|
||||
nixos-generate-config --root /mnt
|
||||
|
||||
|
||||
# ---- Replace configuration with modified one ----
|
||||
mv /mnt/etc/nixos/configuration.nix /mnt/etc/nixos/configuration.nix.bak
|
||||
cp root/etc/nixos/configuration.nix /mnt/etc/nixos/configuration.nix
|
||||
|
||||
# ---- User configuration ----
|
||||
mkdir --parents /mnt/home/h3lp
|
||||
cp root/home/h3lp/shell.nix /mnt/home/h3lp/shell.nix
|
||||
|
||||
|
||||
# ---- Install NixOS ----
|
||||
nixos-install --no-root-passwd
|
||||
@@ -0,0 +1,4 @@
|
||||
SERVERPACK=https://20111511.xyz/serverpack.tar.xz
|
||||
WORLD=https://20111511.xyz/world.tar.xz
|
||||
MEMORY_MAX=6192
|
||||
MEMORY_MIN=1024
|
||||
@@ -0,0 +1,11 @@
|
||||
1) Fetch https://gitea.20111511.xyz/h3lp/autodeploy.git and checkout cavemen branch
|
||||
2) minecraft.env will contain the following urls:
|
||||
SERVERPACK=https://20111511.xyz/TerraFirmaGreg-Modern-0.11.21-serverpack.zip
|
||||
WORLD=https://20111511.xyz/world.tar.xz
|
||||
and a cavemen folder with following structure
|
||||
.
|
||||
├── nixrunserver.sh
|
||||
└── server.properties
|
||||
3) Download and extract SERVERPACK to /home/h3lp/mineserver
|
||||
4) Download and extract WORLD to /home/h3lp/mineserver/world
|
||||
5) Move and overwrite all files from cloned git repository cavemen/* to /home/h3lp/mineserver/
|
||||
@@ -75,10 +75,6 @@
|
||||
|
||||
# List packages installed in system profile.
|
||||
# You can use https://search.nixos.org/ to find more packages (and options).
|
||||
# environment.systemPackages = with pkgs; [
|
||||
# vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
|
||||
# wget
|
||||
# ];
|
||||
|
||||
# Some programs need SUID wrappers, can be configured further or are
|
||||
# started in user sessions.
|
||||
@@ -90,31 +86,12 @@
|
||||
|
||||
# List services that you want to enable:
|
||||
|
||||
# Enable the OpenSSH daemon.
|
||||
services.openssh = {
|
||||
enable = true;
|
||||
ports = [ 22 ];
|
||||
};
|
||||
|
||||
users.users.h3lp = {
|
||||
isNormalUser = true;
|
||||
home = "/home/h3lp";
|
||||
description = "Personal account";
|
||||
extraGroups = [
|
||||
"wheel"
|
||||
"networkmanager"
|
||||
"h3lp"
|
||||
];
|
||||
openssh.authorizedKeys.keys = [ "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCzvHaN1tZOfEIM/XYJCKMrVjs6AUcB8Lr7P2qWjEdp9Hoy1ELDyhCnjSr6BaMriP0F1puEBG8qqccYDOH3Y6bJbde94H6FSQ6dTjXPDko51E21HiY11xa2Dr7n8cxyc37tpL4WLYNihFHQPSHX4K7u9NCNR8jrLM486kaK5mIjB9VKWvArrJSzgbrogXvCmSMP6f5YTw4/jBlUs2ZLVqzJ7yCMHfpoUAiUhVtumDVZ2BcZa3OuWlI6eUl45lA1YyOLc8YhrqxKzUrucsMgQ6Xyx+8s7LshVpIrL7IJ6pg/z9U6RZf2cAt0o/njJkbEkplHFk7UyY63H1mDLtOe28+kfNlLQyPU8KCeYucI1ZL4LwMe/YbmI05WSieDRXkjQ0EV4wa2AnNcBofJeBnueDu86vnH08+ULi4JmM2F/PgNXyaw76vx/Ulopim4I1MlvTeY9sC44Lph2XWrnmq1hdir7z5RuGUDvB5Sk2w/AvnqSNEiZPTbEVezH1gcv/ai+uk= trilolol@trilolol-LINUX" ];
|
||||
};
|
||||
|
||||
users.groups.h3lp.gid = 1000;
|
||||
|
||||
# Open ports in the firewall.
|
||||
# networking.firewall.allowedTCPPorts = [ ... ];
|
||||
# networking.firewall.allowedUDPPorts = [ ... ];
|
||||
# Or disable the firewall altogether.
|
||||
networking.firewall.enable = false;
|
||||
|
||||
# Copy the NixOS configuration file and link it from the resulting system
|
||||
# (/run/current-system/configuration.nix). This is useful in case you
|
||||
@@ -140,5 +117,121 @@
|
||||
# For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion .
|
||||
system.stateVersion = "25.11"; # Did you read the comment?
|
||||
|
||||
}
|
||||
|
||||
# Custom part start
|
||||
environment.systemPackages = with pkgs; [
|
||||
neovim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
|
||||
wget
|
||||
tmux
|
||||
git
|
||||
curl
|
||||
unzip
|
||||
xz
|
||||
nginx
|
||||
];
|
||||
|
||||
# Enable the OpenSSH daemon.
|
||||
services.openssh = {
|
||||
enable = true;
|
||||
ports = [ 22 ];
|
||||
};
|
||||
|
||||
users.users.h3lp = {
|
||||
isNormalUser = true;
|
||||
home = "/home/h3lp";
|
||||
description = "Personal account";
|
||||
extraGroups = [
|
||||
"wheel"
|
||||
"networkmanager"
|
||||
"h3lp"
|
||||
];
|
||||
openssh.authorizedKeys.keys = [ "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCzvHaN1tZOfEIM/XYJCKMrVjs6AUcB8Lr7P2qWjEdp9Hoy1ELDyhCnjSr6BaMriP0F1puEBG8qqccYDOH3Y6bJbde94H6FSQ6dTjXPDko51E21HiY11xa2Dr7n8cxyc37tpL4WLYNihFHQPSHX4K7u9NCNR8jrLM486kaK5mIjB9VKWvArrJSzgbrogXvCmSMP6f5YTw4/jBlUs2ZLVqzJ7yCMHfpoUAiUhVtumDVZ2BcZa3OuWlI6eUl45lA1YyOLc8YhrqxKzUrucsMgQ6Xyx+8s7LshVpIrL7IJ6pg/z9U6RZf2cAt0o/njJkbEkplHFk7UyY63H1mDLtOe28+kfNlLQyPU8KCeYucI1ZL4LwMe/YbmI05WSieDRXkjQ0EV4wa2AnNcBofJeBnueDu86vnH08+ULi4JmM2F/PgNXyaw76vx/Ulopim4I1MlvTeY9sC44Lph2XWrnmq1hdir7z5RuGUDvB5Sk2w/AvnqSNEiZPTbEVezH1gcv/ai+uk= trilolol@trilolol-LINUX" ];
|
||||
initialHashedPassword = "$y$j9T$ELYt.wXZ1vXZK0vBuTBI1/$WuYQxV.CanOyEvVAKC2AaAEY0KNTAnBgQ/RrPxaBAsB";
|
||||
};
|
||||
|
||||
users.groups.h3lp.gid = 1000;
|
||||
|
||||
networking.firewall.enable = false;
|
||||
|
||||
systemd.services.minecraft-setup = {
|
||||
description = "Minecraft Server Initial Setup";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
|
||||
# Only run if setup hasn't been completed yet
|
||||
unitConfig.ConditionPathExists = "!/home/h3lp/mineserver/.setup-done";
|
||||
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
User = "h3lp";
|
||||
RemainAfterExit = true;
|
||||
};
|
||||
|
||||
script = ''
|
||||
set -e
|
||||
|
||||
MINESERVER=/home/h3lp/mineserver
|
||||
TMPDIR=$(mktemp -d)
|
||||
|
||||
# 1) Clone repo and checkout cavemen branch
|
||||
${pkgs.git}/bin/git clone --branch cavemen \
|
||||
https://gitea.20111511.xyz/h3lp/autodeploy.git "$TMPDIR/autodeploy"
|
||||
|
||||
# 2) Read env vars from minecraft.env
|
||||
source "$TMPDIR/autodeploy/minecraft.env"
|
||||
|
||||
# 3) Download and extract server pack to /home/h3lp/mineserver
|
||||
mkdir -p "$MINESERVER"
|
||||
${pkgs.curl}/bin/curl -L "$SERVERPACK" -o "$TMPDIR/serverpack.tar.xz"
|
||||
${pkgs.xz}/bin/xz -d "$TMPDIR/serverpack.tar.xz" --stdout | ${pkgs.gnutar}/bin/tar -x -C "$MINESERVER"
|
||||
|
||||
# 4) Download and extract world to /home/h3lp/mineserver/world
|
||||
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/world"
|
||||
|
||||
# 5) Copy cavemen/* files over, overwriting existing
|
||||
cp -rf "$TMPDIR/autodeploy/cavemen/." "$MINESERVER/"
|
||||
chmod +x "$MINESERVER/nixrunserver.sh"
|
||||
# Also copy minecraft.env for future reference
|
||||
cp "$TMPDIR/autodeploy/minecraft.env" "$MINESERVER/minecraft.env"
|
||||
|
||||
# Cleanup and mark setup as done
|
||||
rm -rf "$TMPDIR"
|
||||
touch "$MINESERVER/.setup-done"
|
||||
'';
|
||||
};
|
||||
|
||||
systemd.services.minecraft = {
|
||||
description = "Minecraft Server";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network.target" "minecraft-setup.service" ]; # wait for setup
|
||||
requires = [ "minecraft-setup.service" ]; # and fail if setup fails
|
||||
|
||||
serviceConfig = {
|
||||
Type = "forking";
|
||||
User = "h3lp";
|
||||
WorkingDirectory = "/home/h3lp/mineserver";
|
||||
Environment = "PATH=/run/current-system/sw/bin:/usr/bin:/bin";
|
||||
ExecStart = "${pkgs.tmux}/bin/tmux new-session -d -s minecraft /home/h3lp/mineserver/nixrunserver.sh";
|
||||
ExecStop = "${pkgs.tmux}/bin/tmux send-keys -t minecraft 'stop' Enter";
|
||||
RemainAfterExit = true;
|
||||
};
|
||||
};
|
||||
|
||||
services.nginx = {
|
||||
enable = true;
|
||||
virtualHosts."_" = {
|
||||
root = "/var/www/hostedfiles";
|
||||
locations."/" = {
|
||||
extraConfig = "autoindex on;";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
"d /var/www/hostedfiles 0755 h3lp h3lp -"
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user