commit e9ecd4ef506891c4a6ec9ad9818dca6448f90358 Author: grey-cat-1908 Date: Tue Jan 30 20:39:50 2024 +0300 first commit yeeah diff --git a/.balena/balena.yml b/.balena/balena.yml new file mode 100644 index 0000000..d9e642c --- /dev/null +++ b/.balena/balena.yml @@ -0,0 +1,4 @@ +name: Minecraft Server +data: + applicationEnvironmentVariables: + - RAM: 1G \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..3df1481 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,13 @@ +Copyright 2024 Viktor K + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..298be85 --- /dev/null +++ b/README.md @@ -0,0 +1,54 @@ +# Your Portable Minecraft Server + +This is a project that allows you to easily install and configure a minecraft server on your Raspberry Pi or other similar device. + +## Advantages + +- Easy and very fast installation +- Does not require any knowledge +- Portable (you can bring your Raspberry Pi wherever you want) +- It is cheap (No need to pay for anything other than electricity if you already have a Raspberry Pi) +- Runs on Raspberry Pi 4 and Raspberry Pi 5 (4G and 8GB model) +- You'll look cool in front of your friends if you run a server on the board (if they don't know what Raspberry Pi is) +- Does not load your computer +- You can control and configure everything (as long as your board has enough power) + +## Setup + +... ToDo...? + +## Connecting to the server + +... ToDo...? + +## Configuring + +You can configure nearly everything by setting up the following Enviroment Variables: + +| Variable | Description | Value | +|---|---|---| +| `RAM` | How much RAM do you want to allocate to the server? | `1G` (default) | +| `MC_VERSION` | What version of Minecraft do you want to install? | `1.20` (default) | +| `SSH_PASSWORD` | SSH password | `admin` (default) | + +**NOTE:** You can set Environment Variable within balenaCloud. On the left, simply click on “Device Variables” and then click the “Add Variable” button. Give it a name, and set the value. + +![set variable demonstration](https://cdn.arbuz.icu/img/balena/balenaSetVariables.png) + +## Connecting to the server using SFTP + +I recommend using FileZilla to connect to the server via SFTP. + +### FileZilla User Guide + +... ToDo...? + +Once the connection is established, remember to navigate to the `/usr/src/mcfiles' directory. + +## Installing plugins + +... ToDo...? + +## Mods...? + +... ToDo...? \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4ee9985 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,31 @@ +version: '2' +services: + minecraft: + network_mode: host + restart: always + build: ./minecraft + privileged: true + labels: + io.balena.features.dbus: 1 + io.balena.features.supervisor-api: 1 + volumes: + - mcfiles:/usr/src/mcfiles + - localcache:/localcache + ports: + - "25565:25565/tcp" + ssh: + network_mode: host + restart: always + build: ./ssh + privileged: false + labels: + io.balena.features.dbus: 1 + volumes: + - mcfiles:/usr/src/mcfiles + - localcache:/localcache + ports: + - "22:22/tcp" + - "22:22/udp" +volumes: + mcfiles: + localcache: \ No newline at end of file diff --git a/minecraft/Dockerfile.template b/minecraft/Dockerfile.template new file mode 100644 index 0000000..7ac15b1 --- /dev/null +++ b/minecraft/Dockerfile.template @@ -0,0 +1,13 @@ +FROM balenalib/%%BALENA_MACHINE_NAME%%-debian:latest + +ENV DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket + +RUN install_packages wget jq openjdk-17-jre + +COPY . / + +COPY run.sh /usr/src/ + +RUN chmod +x /usr/src/run.sh + +CMD ["/bin/bash", "/usr/src/run.sh"] \ No newline at end of file diff --git a/minecraft/mcfiles/eula.txt b/minecraft/mcfiles/eula.txt new file mode 100644 index 0000000..ac74b96 --- /dev/null +++ b/minecraft/mcfiles/eula.txt @@ -0,0 +1 @@ +eula=true \ No newline at end of file diff --git a/minecraft/mcfiles/server.properties b/minecraft/mcfiles/server.properties new file mode 100644 index 0000000..97acd6f --- /dev/null +++ b/minecraft/mcfiles/server.properties @@ -0,0 +1,16 @@ +enable-jmx-monitoring=false +rcon.port=25575 +enable-command-block=true +motd=A Minecraft Server +max-players=20 +online-mode=true +enable-status=true +view-distance=7 +server-ip=0.0.0.0 +server-port=25565 +enable-rcon=false +simulation-distance=5 +rcon.password= +white-list=false +sync-chunk-writes=false +spawn-protection=1 \ No newline at end of file diff --git a/minecraft/run.sh b/minecraft/run.sh new file mode 100644 index 0000000..5266093 --- /dev/null +++ b/minecraft/run.sh @@ -0,0 +1,41 @@ +get_pufferfish_server() { + if [[ -z "$RAM" ]]; then + MC_VERSION="1.20" + fi + majorVersion=$MC_VERSION + PUFFERFISH_BUILD_JSON=$(curl -X GET -s "https://ci.pufferfish.host/job/Pufferfish-${majorVersion}/lastSuccessfulBuild/api/json") + PUFFERFISH_BUILD_URL=$(jq -n "$PUFFERFISH_BUILD_JSON" | jq -jc '.url // empty' ) + PUFFERFISH_BUILD_FILENAME=$(jq -n "$PUFFERFISH_BUILD_JSON" | jq -jc '.artifacts[].fileName // empty' ) + PUFFERFISH_BUILD_DOWNLOAD_URL="${PUFFERFISH_BUILD_URL}artifact/build/libs/${PUFFERFISH_BUILD_FILENAME}" + + shopt -s nullglob + + if [ -f "pufferfish.jar" ]; then + rm "pufferfish.jar" + fi + + wget --quiet -O pufferfish.jar -T 60 $PUFFERFISH_BUILD_DOWNLOAD_URL +} + +if [[ ! -e "/localcache/conf-saved.txt" ]]; then + cp -R /mcfiles /usr/src/ + touch /localcache/conf-saved.txt +fi + +cd /usr/src/mcfiles/ || exit + +if [[ ! -e "pufferfish.jar" ]]; then + get_pufferfish_server +else + if [[ "$FORCE_REINSTALL" -eq 1 ]]; then + get_pufferfish_server + fi +fi + +if [[ -z "$RAM" ]]; then + RAM="1G" +fi + +java -Xms$RAM -Xmx$RAM -XX:+AlwaysPreTouch -XX:+DisableExplicitGC -XX:+ParallelRefProcEnabled -XX:+PerfDisableSharedMem -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1HeapRegionSize=8M -XX:G1HeapWastePercent=5 -XX:G1MaxNewSizePercent=40 -XX:G1MixedGCCountTarget=4 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1NewSizePercent=30 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:G1ReservePercent=20 -XX:InitiatingHeapOccupancyPercent=15 -XX:MaxGCPauseMillis=200 -XX:MaxTenuringThreshold=1 -XX:SurvivorRatio=32 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -jar pufferfish.jar nogui + +sleep 10 \ No newline at end of file diff --git a/ssh/Dockerfile.template b/ssh/Dockerfile.template new file mode 100644 index 0000000..4e21787 --- /dev/null +++ b/ssh/Dockerfile.template @@ -0,0 +1,7 @@ +FROM balenalib/%%BALENA_MACHINE_NAME%%:latest + +RUN install_packages openssh-server + +COPY run.sh /usr/src/ + +CMD ["/bin/bash", "/usr/src/run.sh"] \ No newline at end of file diff --git a/ssh/run.sh b/ssh/run.sh new file mode 100644 index 0000000..ee610f2 --- /dev/null +++ b/ssh/run.sh @@ -0,0 +1,10 @@ +if [[ -z "$SSH_PASSWORD" ]]; then + export SSH_PASSWORD=admin +fi + +mkdir /var/run/sshd +echo "root:$SSH_PASSWORD" | chpasswd +sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config +sed -i 's/UsePAM yes/UsePAM no/' /etc/ssh/sshd_config + +exec /usr/sbin/sshd -D \ No newline at end of file