Skip to content

Commit

Permalink
Fixed FORGE (#25)
Browse files Browse the repository at this point in the history
* Allow env MC_COMMAND

Changed mcserver.sh to allow a user specified environment variable MC_COMMAND to substitute for the default jar execution.

.gitignore now ignores docker-compose.yml for testing purposes

* Revert "Allow env MC_COMMAND"

This reverts commit 974fea4.

* Fixed Forge Servers

.gitignore
add docker-compose.yml

mcerver.sh
made a Forge Install
Changed EULA generation
Added $RUN_COMMAND handling
Added Forge 1.17.1+ start.sh scraping
Added server.properties Generation
Changed Server Launch Handler  to use $RUN_COMMAND

README.MD
added advanced variable RUN_COMMAND Documentation
  • Loading branch information
wolfeservices committed Feb 2, 2024
1 parent 4ae3ced commit 81f8ebf
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,4 @@ ASALocalRun/

# MFractors (Xamarin productivity tool) working folder
.mfractor/
docker-compose.yml
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ This image has seven environment variables:
- Set to any additional Java command line options that you would like to include.
- By default, this environment variable is set to the empty string.
- `-e JAVA_OPTS="<-XX:+UseConcMarkSweepGC -XX:+UseParNewGC>"`
- Custom Run command
- **Name:** `RUN_COMMAND`
- **ADVANCED USERS ONLY**
- Set to the name of the custom server jar you want to use.
- also allows pointing to a scrpt file, this reqires the full path to the file.
- For more information, see [Lazymc's documentation](https://github.com/timvisee/lazymc/blob/master/docs/command-bash.md).
- By default, this environment variable is set to the empty string.
- `-e RUN_COMMAND="<custom.jar>"` or `-e RUN_COMMAND="/mcserver/<custom.sh>"`

## Further Setup
From this point, the server should be configured in the same way as any other Minecraft server. The server's files, including `server.properties`, can be found in the volume that was specified earlier. The port that was specified earlier will probably need to be forwarded as well. For details on how to do this and other such configuration, Google it, because it works the same as any other Minecraft server.
Expand Down
83 changes: 68 additions & 15 deletions mcserver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -166,26 +166,79 @@ then
exit 1
fi

# If this is the first run, accept the EULA
if [ ! -e eula.txt ]
# install forge if necessary
if [ "$SERVER_PROVIDER" = "forge" ]
then
# Run the server once to generate eula.txt
echo "\033[0;33mGenerating EULA... \033[0m"
echo ""
if [ "$SERVER_PROVIDER" == "forge" ]; then
java -jar ${JAR_NAME} --installServer > /dev/null 2>&1
# .installed file is used to check if forge is already installed by a previous run of the container
if [ ! -e .installed ]
then
echo "\033[0;33mInstalling Forge... This will take a while...\033[0m"
echo ""
if ! java -jar $JAR_NAME --installServer > /dev/null 2>&1
then
echo "\033[0;31mError: Could not install Forge. Exiting... \033[0m" | tee server_cfg.txt
exit 1
fi
touch .installed
else
java -jar ${JAR_NAME} > /dev/null 2>&1
echo "\033[0;33mForge already installed. Skipping installation... \033[0m"
echo ""
fi
fi

if [ $? -ne 0 ]; then
echo "\033[0;31mError: Cannot generate EULA. Exiting... \033[0m" | tee server_cfg.txt
#determine run command
if [ -z "$RUN_COMMAND" ]
then
if [ "$SERVER_PROVIDER" = "forge" ]
then
#parse the mincraft verison if it is 1.17.0 or higher we need to use the new forge run command
mcmajor=$(echo $MC_VERSION | cut -d'.' -f1)
mcminor=$(echo $MC_VERSION | cut -d'.' -f2)
mcpatch=$(echo $MC_VERSION | cut -d'.' -f3)
if [ $mcmajor -ge 1 ] && [ $mcminor -ge 17 ] && [ $mcpatch -ge 0 ]
then
#grep the java line from the Run.sh file
echo "\033[0;33mGetting new forge run command from run.sh... \033[0m"
echo ""
rcmd=$(grep -m 1 "java" /mcserver/run.sh)
#strip the "$@" from the end of the line and add nogui to the end
rcmd=$(echo $rcmd | sed 's/"$@"/nogui/')
printf '\033[0;33mNew forge run command: %s \033[0m' "$rcmd"
echo ""
#if user has set MC_RAM then we will use it by appending it to the user_jvm_args.txt file
if [ ! -z "${MC_RAM}" ]
then
echo "\033[0;33mSetting user RAM Limit args... \033[0m"
echo ""
echo "-Xms512M -Xmx${MC_RAM}" >> /mcserver/user_jvm_args.txt
fi
RUN_COMMAND=$rcmd
else
RUN_COMMAND="java ${JAVA_OPTS} -jar $JAR_NAME nogui"
fi
fi
else
echo "\033[0;33mUsing custom run command... \033[0m"
fi

# Generate eula.txt if necessary
if [ ! -e eula.txt ]
then
echo "\033[0;33mGenerating eula.txt \033[0m"
echo ""
if ! echo "eula=true" > eula.txt
then
echo "\033[0;31mError: Could not generate eula.txt. Exiting... \033[0m" | tee server_cfg.txt
exit 1
fi
# Edit eula.txt to accept the EULA
echo "\033[0;33mAccepting EULA... \033[0m"
fi

# Generate server.properties if not present, Prevents the server from failing to start on first run
if [ ! -e server.properties ]
then
echo "\033[0;33mGenerating server.properties \033[0m"
echo ""
sed -i 's/false/true/g' eula.txt
touch server.properties
fi

# Add RAM options to Java options if necessary
Expand Down Expand Up @@ -221,7 +274,7 @@ then
# Add the comment to the file
sed -i '/Command to start the server/i # Managed by mcserver-lazymc-docker, please do not edit this!' lazymc.toml
fi
if ! sed -i "s~command = .*~command = \"java $JAVA_OPTS -jar $JAR_NAME nogui\"~" lazymc.toml
if ! sed -i "s~command = .*~command = \"$RUN_COMMAND\"~" lazymc.toml
then
echo "\033[0;31mError: Could not update lazymc.toml. Exiting... \033[0m" | tee server_cfg.txt
exit 1
Expand All @@ -234,7 +287,7 @@ then
# Start directly the server when lazymc is disabled
echo "\033[0;33mStarting the server! \033[0m"
echo ""
if ! java $JAVA_OPTS -jar $JAR_NAME nogui
if ! $RUN_COMMAND
then
echo "\033[0;31mError: Could not start the server. Exiting... \033[0m" | tee server_cfg.txt
exit 1
Expand Down

0 comments on commit 81f8ebf

Please sign in to comment.