Browse Source

feat(cfmc): add support for CurseForge Minecraft server packs

pull/4879/head
Ezra Dowd 4 months ago
parent
commit
2cafed8264
  1. 189
      lgsm/config-default/config-lgsm/cfmcserver/_default.cfg
  2. 1
      lgsm/data/almalinux-8.csv
  3. 1
      lgsm/data/almalinux-9.csv
  4. 1
      lgsm/data/centos-7.csv
  5. 1
      lgsm/data/centos-8.csv
  6. 1
      lgsm/data/centos-9.csv
  7. 1
      lgsm/data/debian-10.csv
  8. 1
      lgsm/data/debian-11.csv
  9. 1
      lgsm/data/debian-12.csv
  10. 1
      lgsm/data/debian-13.csv
  11. 1
      lgsm/data/debian-9.csv
  12. BIN
      lgsm/data/gameicons/cfmc-icon.png
  13. 1
      lgsm/data/rhel-7.csv
  14. 1
      lgsm/data/rhel-8.csv
  15. 1
      lgsm/data/rhel-9.csv
  16. 1
      lgsm/data/rocky-8.csv
  17. 1
      lgsm/data/rocky-9.csv
  18. 1
      lgsm/data/serverlist.csv
  19. 1
      lgsm/data/ubuntu-16.04.csv
  20. 1
      lgsm/data/ubuntu-18.04.csv
  21. 1
      lgsm/data/ubuntu-20.04.csv
  22. 1
      lgsm/data/ubuntu-22.04.csv
  23. 1
      lgsm/data/ubuntu-23.04.csv
  24. 1
      lgsm/data/ubuntu-23.10.csv
  25. 1
      lgsm/data/ubuntu-24.04.csv
  26. 2
      lgsm/modules/check_system_requirements.sh
  27. 2
      lgsm/modules/command_check_update.sh
  28. 2
      lgsm/modules/command_update.sh
  29. 5
      lgsm/modules/core_modules.sh
  30. 2
      lgsm/modules/info_game.sh
  31. 4
      lgsm/modules/info_messages.sh
  32. 2
      lgsm/modules/install_config.sh
  33. 4
      lgsm/modules/install_eula.sh
  34. 4
      lgsm/modules/install_server_files.sh
  35. 463
      lgsm/modules/update_cfmc.sh

189
lgsm/config-default/config-lgsm/cfmcserver/_default.cfg

@ -0,0 +1,189 @@
##################################
######## Default Settings ########
##################################
# DO NOT EDIT, ANY CHANGES WILL BE OVERWRITTEN!
# Copy settings from here and use them in either:
# common.cfg - applies settings to every instance.
# [instance].cfg - applies settings to a specific instance.
#### Game Server Settings ####
## Predefined Parameters | https://docs.linuxgsm.com/configuration/start-parameters
javaram="1024" # -Xmx$1024M
## Server Parameters | https://docs.linuxgsm.com/configuration/start-parameters#additional-parameters
startparameters="nogui"
## CurseForge Settings
# Source mode (api|url)
cfmcsource="api"
# CurseForge project ID.
curseforgemodid=""
# CurseForge file ID.
curseforgefileid=""
# Direct archive URL or CurseForge file page URL.
curseforgeurl=""
# Start mode (auto|manual)
cfmcstartmode="auto"
# Extra paths to preserve during updates, separated by semicolons.
cfmcpreservepaths=""
# Set "curseforgeapikey" in secrets-common.cfg or secrets-${selfname}.cfg.
#### LinuxGSM Settings ####
## LinuxGSM Stats
# Send useful stats to LinuxGSM developers.
# https://docs.linuxgsm.com/configuration/linuxgsm-stats
# (on|off)
stats="off"
## Notification Alerts
# (on|off)
# Display IP | https://docs.linuxgsm.com/alerts#display-ip
displayip=""
# More info | https://docs.linuxgsm.com/alerts#more-info
postalert="off"
# Alert on Start/Stop/Restart
statusalert="off"
# Discord Alerts | https://docs.linuxgsm.com/alerts/discord
discordalert="off"
discordwebhook="webhook"
# Email Alerts | https://docs.linuxgsm.com/alerts/email
emailalert="off"
email="[email protected]"
emailfrom=""
# Gotify Alerts | https://docs.linuxgsm.com/alerts/gotify
gotifyalert="off"
gotifytoken="token"
gotifywebhook="webhook"
# IFTTT Alerts | https://docs.linuxgsm.com/alerts/ifttt
iftttalert="off"
ifttttoken="accesstoken"
iftttevent="linuxgsm_alert"
# Pushbullet Alerts | https://docs.linuxgsm.com/alerts/pushbullet
pushbulletalert="off"
pushbullettoken="accesstoken"
channeltag=""
# Pushover Alerts | https://docs.linuxgsm.com/alerts/pushover
pushoveralert="off"
pushovertoken="accesstoken"
pushoveruserkey="userkey"
# Rocket.Chat Alerts | https://docs.linuxgsm.com/alerts/rocket.chat
rocketchatalert="off"
rocketchatwebhook="webhook"
# Slack Alerts | https://docs.linuxgsm.com/alerts/slack
slackalert="off"
slackwebhook="webhook"
# Telegram Alerts | https://docs.linuxgsm.com/alerts/telegram
# You can add a custom cURL string eg proxy (useful in Russia) in "curlcustomstring".
# For example "--socks5 ipaddr:port" for socks5 proxy see more in "curl --help all".
telegramapi="api.telegram.org"
telegramalert="off"
telegramtoken="accesstoken"
telegramchatid=""
telegramthreadid=""
telegramsilentnotification="false"
curlcustomstring=""
## Updating | https://docs.linuxgsm.com/commands/update
updateonstart="off"
## Backup | https://docs.linuxgsm.com/commands/backup
maxbackups="4"
maxbackupdays="30"
stoponbackup="on"
## Logging | https://docs.linuxgsm.com/features/logging
consolelogging="on"
logdays="7"
## Monitor | https://docs.linuxgsm.com/commands/monitor
# Query delay time
querydelay="1"
## ANSI Colors | https://docs.linuxgsm.com/features/ansi-colors
ansi="on"
#### Advanced Settings ####
## Message Display Time | https://docs.linuxgsm.com/features/message-display-time
sleeptime="0.5"
## Stop Mode | https://docs.linuxgsm.com/features/stop-mode
# 1: tmux kill
# 2: CTRL+c
# 3: quit
# 4: quit 120s
# 5: stop
# 6: q
# 7: exit
# 8: 7 Days to Die
# 9: GoldSrc
# 10: Avorion
# 11: end
stopmode="5"
## Query mode
# 1: session only
# 2: gamedig (gsquery fallback)
# 3: gamedig
# 4: gsquery
# 5: tcp
querymode="2"
querytype="minecraft"
## Console type
consoleverbose="yes"
consoleinteract="yes"
## Game Server Details
# Do not edit
gamename="CurseForge Minecraft"
engine="lwjgl2"
glibc="null"
#### Directories ####
# Edit with care
## Game Server Directories
systemdir="${serverfiles}"
executabledir="${serverfiles}"
preexecutable="java -Xmx${javaram}M -jar"
executable="./minecraft_server.jar"
servercfgdir="${systemdir}"
servercfg="server.properties"
servercfgdefault=""
servercfgfullpath="${servercfgdir}/${servercfg}"
## Backup Directory
backupdir="${lgsmdir}/backup"
## Logging Directories
[ -n "${LGSM_LOGDIR}" ] && logdir="${LGSM_LOGDIR}" || logdir="${rootdir}/log"
gamelogdir="${systemdir}/logs"
lgsmlogdir="${logdir}/script"
consolelogdir="${logdir}/console"
lgsmlog="${lgsmlogdir}/${selfname}-script.log"
consolelog="${consolelogdir}/${selfname}-console.log"
alertlog="${lgsmlogdir}/${selfname}-alert.log"
postdetailslog="${lgsmlogdir}/${selfname}-postdetails.log"
## Logs Naming
lgsmlogdate="${lgsmlogdir}/${selfname}-script-$(date '+%Y-%m-%d-%H:%M:%S').log"
consolelogdate="${consolelogdir}/${selfname}-console-$(date '+%Y-%m-%d-%H:%M:%S').log"
## Log Parameters
logtimestamp="off"
logtimestampformat="%Y-%m-%d %H:%M:%S"

1
lgsm/data/almalinux-8.csv

@ -19,6 +19,7 @@ bs
bt,libicu,dos2unix,libxml2
btl
cc
cfmc,java-21-openjdk
ck,xorg-x11-server-Xvfb
cmw
cod,compat-libstdc++-33.i686

Can't render this file because it has a wrong number of fields in line 2.

1
lgsm/data/almalinux-9.csv

@ -19,6 +19,7 @@ bs
bt,libicu,dos2unix,libxml2
btl
cc
cfmc,java-21-openjdk
ck,xorg-x11-server-Xvfb
cmw
cod,compat-libstdc++-33.i686

Can't render this file because it has a wrong number of fields in line 2.

1
lgsm/data/centos-7.csv

@ -19,6 +19,7 @@ bs
bt,libicu,dos2unix,libxml2
btl
cc
cfmc,java-21-openjdk
ck,xorg-x11-server-Xvfb
cmw
cod,compat-libstdc++-33.i686

Can't render this file because it has a wrong number of fields in line 2.

1
lgsm/data/centos-8.csv

@ -19,6 +19,7 @@ bs
bt,libicu,dos2unix,libxml2
btl
cc
cfmc,java-21-openjdk
ck,xorg-x11-server-Xvfb
cmw
cod,compat-libstdc++-33.i686

Can't render this file because it has a wrong number of fields in line 2.

1
lgsm/data/centos-9.csv

@ -19,6 +19,7 @@ bs
bt,libicu,dos2unix,libxml2
btl
cc
cfmc,java-17-openjdk
ck,xorg-x11-server-Xvfb
cmw
cod,compat-libstdc++-33.i686

Can't render this file because it has a wrong number of fields in line 2.

1
lgsm/data/debian-10.csv

@ -18,6 +18,7 @@ bs
bt,libicu-dev,dos2unix,libxml2-utils
btl
cc
cfmc,openjdk-11-jre
ck,xvfb,libxi6
cmw
cod,libstdc++5:i386

Can't render this file because it has a wrong number of fields in line 4.

1
lgsm/data/debian-11.csv

@ -19,6 +19,7 @@ bs
bt,libicu-dev,dos2unix,libxml2-utils
btl
cc
cfmc,openjdk-17-jre
ck,xvfb,libxi6
cmw
cod,libstdc++5:i386

Can't render this file because it has a wrong number of fields in line 2.

1
lgsm/data/debian-12.csv

@ -19,6 +19,7 @@ bs
bt,libicu-dev,dos2unix,libxml2-utils
btl
cc
cfmc,openjdk-17-jre
ck,xvfb,libxi6
cmw
cod,libstdc++5:i386

Can't render this file because it has a wrong number of fields in line 2.

1
lgsm/data/debian-13.csv

@ -19,6 +19,7 @@ bs
bt,libicu-dev,dos2unix,libxml2-utils
btl
cc
cfmc,openjdk-25-jre
ck,xvfb,libxi6
cmw
cod,libstdc++5:i386

Can't render this file because it has a wrong number of fields in line 2.

1
lgsm/data/debian-9.csv

@ -19,6 +19,7 @@ bs
bt,libicu-dev,dos2unix,libxml2-utils
btl
cc
cfmc,openjdk-8-jre
ck,xvfb,libxi6
cmw
cod,libstdc++5:i386

Can't render this file because it has a wrong number of fields in line 2.

BIN
lgsm/data/gameicons/cfmc-icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

1
lgsm/data/rhel-7.csv

@ -20,6 +20,7 @@ bs
bt,libicu,dos2unix,libxml2
btl
cc
cfmc,java-11-openjdk
ck,xorg-x11-server-Xvfb
cmw
cod,compat-libstdc++-33.i686

Can't render this file because it has a wrong number of fields in line 2.

1
lgsm/data/rhel-8.csv

@ -19,6 +19,7 @@ bs
bt,libicu,dos2unix,libxml2
btl
cc
cfmc,java-21-openjdk
ck,xorg-x11-server-Xvfb
cmw
cod,compat-libstdc++-33.i686

Can't render this file because it has a wrong number of fields in line 2.

1
lgsm/data/rhel-9.csv

@ -19,6 +19,7 @@ bs
bt,libicu,dos2unix,libxml2
btl
cc
cfmc,java-21-openjdk
ck,xorg-x11-server-Xvfb
cmw
cod,compat-libstdc++-33.i686

Can't render this file because it has a wrong number of fields in line 2.

1
lgsm/data/rocky-8.csv

@ -19,6 +19,7 @@ bs
bt,libicu,dos2unix,libxml2
btl
cc
cfmc,java-21-openjdk
ck,xorg-x11-server-Xvfb
cmw
cod,compat-libstdc++-33.i686

Can't render this file because it has a wrong number of fields in line 2.

1
lgsm/data/rocky-9.csv

@ -19,6 +19,7 @@ bs
bt,libicu,dos2unix,libxml2
btl
cc
cfmc,java-21-openjdk
ck,xorg-x11-server-Xvfb
cmw
cod,compat-libstdc++-33.i686

Can't render this file because it has a wrong number of fields in line 2.

1
lgsm/data/serverlist.csv

@ -18,6 +18,7 @@ bs,bsserver,Blade Symphony,ubuntu-24.04
bt,btserver,Barotrauma,ubuntu-24.04
btl,btlserver,BATTALION: Legacy,ubuntu-20.04
cc,ccserver,Codename CURE,ubuntu-24.04
cfmc,cfmcserver,CurseForge Minecraft,ubuntu-24.04
ck,ckserver,Core Keeper,ubuntu-24.04
cmw,cmwserver,Chivalry: Medieval Warfare,ubuntu-24.04
cod,codserver,Call of Duty,ubuntu-24.04

1 shortname gameservername gamename os
18 bt btserver Barotrauma ubuntu-24.04
19 btl btlserver BATTALION: Legacy ubuntu-20.04
20 cc ccserver Codename CURE ubuntu-24.04
21 cfmc cfmcserver CurseForge Minecraft ubuntu-24.04
22 ck ckserver Core Keeper ubuntu-24.04
23 cmw cmwserver Chivalry: Medieval Warfare ubuntu-24.04
24 cod codserver Call of Duty ubuntu-24.04

1
lgsm/data/ubuntu-16.04.csv

@ -20,6 +20,7 @@ bs
bt,libicu-dev,dos2unix,libxml2-utils
btl
cc
cfmc,openjdk-8-jre
ck,xvfb,libxi6
cmw
cod,libstdc++5:i386

Can't render this file because it has a wrong number of fields in line 2.

1
lgsm/data/ubuntu-18.04.csv

@ -20,6 +20,7 @@ bs
bt,libicu-dev,dos2unix,libxml2-utils
btl
cc
cfmc,openjdk-11-jre
ck,xvfb,libxi6
cmw
cod,libstdc++5:i386

Can't render this file because it has a wrong number of fields in line 2.

1
lgsm/data/ubuntu-20.04.csv

@ -19,6 +19,7 @@ bs
bt,libicu-dev,dos2unix,libxml2-utils
btl
cc
cfmc,openjdk-21-jre
ck,xvfb,libxi6
cmw
cod,libstdc++5:i386

Can't render this file because it has a wrong number of fields in line 2.

1
lgsm/data/ubuntu-22.04.csv

@ -19,6 +19,7 @@ bs
bt,libicu-dev,dos2unix,libxml2-utils
btl
cc
cfmc,openjdk-21-jre
ck,xvfb,libxi6
cmw
cod,libstdc++5:i386

Can't render this file because it has a wrong number of fields in line 2.

1
lgsm/data/ubuntu-23.04.csv

@ -19,6 +19,7 @@ bs
bt,libicu-dev,dos2unix,libxml2-utils
btl
cc
cfmc,openjdk-21-jre
ck,xvfb,libxi6
cmw
cod,libstdc++5:i386

Can't render this file because it has a wrong number of fields in line 2.

1
lgsm/data/ubuntu-23.10.csv

@ -19,6 +19,7 @@ bs
bt,libicu-dev,dos2unix,libxml2-utils
btl
cc
cfmc,openjdk-21-jre
ck,xvfb,libxi6
cmw
cod,libstdc++5:i386

Can't render this file because it has a wrong number of fields in line 2.

1
lgsm/data/ubuntu-24.04.csv

@ -19,6 +19,7 @@ bs
bt,libicu-dev,dos2unix,libxml2-utils
btl
cc
cfmc,openjdk-21-jre
ck,xvfb,libxi6
cmw
cod,libstdc++5:i386

Can't render this file because it has a wrong number of fields in line 2.

2
lgsm/modules/check_system_requirements.sh

@ -35,6 +35,8 @@ elif [ "${shortname}" == "mc" ]; then
ramrequirementgb="1"
elif [ "${shortname}" == "pmc" ]; then
ramrequirementgb="2"
elif [ "${shortname}" == "cfmc" ]; then
ramrequirementgb="4"
elif [ "${shortname}" == "mh" ]; then
ramrequirementgb="4"
elif [ "${shortname}" == "ns2" ] || [ "${shortname}" == "ns2c" ]; then

2
lgsm/modules/command_check_update.sh

@ -18,6 +18,8 @@ if [ "${shortname}" == "ts3" ]; then
update_ts3.sh
elif [ "${shortname}" == "mc" ]; then
update_mc.sh
elif [ "${shortname}" == "cfmc" ]; then
update_cfmc.sh
elif [ "${shortname}" == "mcb" ]; then
update_mcb.sh
elif [ "${shortname}" == "pmc" ] || [ "${shortname}" == "vpmc" ] || [ "${shortname}" == "wmc" ]; then

2
lgsm/modules/command_update.sh

@ -19,6 +19,8 @@ if [ "${shortname}" == "ts3" ]; then
update_ts3.sh
elif [ "${shortname}" == "mc" ]; then
update_mc.sh
elif [ "${shortname}" == "cfmc" ]; then
update_cfmc.sh
elif [ "${shortname}" == "mcb" ]; then
update_mcb.sh
elif [ "${shortname}" == "pmc" ] || [ "${shortname}" == "vpmc" ] || [ "${shortname}" == "wmc" ]; then

5
lgsm/modules/core_modules.sh

@ -670,6 +670,11 @@ update_mc.sh() {
fn_fetch_module
}
update_cfmc.sh() {
modulefile="${FUNCNAME[0]}"
fn_fetch_module
}
update_mcb.sh() {
modulefile="${FUNCNAME[0]}"
fn_fetch_module

2
lgsm/modules/info_game.sh

@ -2387,7 +2387,7 @@ elif [ "${shortname}" == "kf" ]; then
fn_info_game_kf
elif [ "${shortname}" == "kf2" ]; then
fn_info_game_kf2
elif [ "${shortname}" == "mc" ] || [ "${shortname}" == "pmc" ]; then
elif [ "${shortname}" == "mc" ] || [ "${shortname}" == "cfmc" ] || [ "${shortname}" == "pmc" ]; then
fn_info_game_mc
elif [ "${shortname}" == "mcb" ]; then
fn_info_game_mcb

4
lgsm/modules/info_messages.sh

@ -754,7 +754,7 @@ fn_info_messages_ports() {
portcommand="ss -tuplwn | grep enfMain"
elif [ "${shortname}" == "q4" ]; then
portcommand="ss -tuplwn | grep q4ded.x86"
elif [ "${shortname}" == "mc" ] || [ "${shortname}" == "nec" ] || [ "${shortname}" == "pmc" ] || [ "${shortname}" == "vpmc" ] || [ "${shortname}" == "wmc" ]; then
elif [ "${shortname}" == "mc" ] || [ "${shortname}" == "cfmc" ] || [ "${shortname}" == "nec" ] || [ "${shortname}" == "pmc" ] || [ "${shortname}" == "vpmc" ] || [ "${shortname}" == "wmc" ]; then
portcommand="ss -tuplwn | grep java"
elif [ "${shortname}" == "terraria" ]; then
portcommand="ss -tuplwn | grep Main"
@ -1874,7 +1874,7 @@ fn_info_messages_select_engine() {
fn_info_messages_kf
elif [ "${shortname}" == "kf2" ]; then
fn_info_messages_kf2
elif [ "${shortname}" == "mc" ] || [ "${shortname}" == "pmc" ] || [ "${shortname}" == "wmc" ]; then
elif [ "${shortname}" == "mc" ] || [ "${shortname}" == "cfmc" ] || [ "${shortname}" == "pmc" ] || [ "${shortname}" == "wmc" ]; then
fn_info_messages_mc
elif [ "${shortname}" == "mcb" ]; then
fn_info_messages_mcb

2
lgsm/modules/install_config.sh

@ -537,6 +537,8 @@ elif [ "${shortname}" == "mc" ] || [ "${shortname}" == "pmc" ]; then
fn_default_config_remote
fn_set_config_vars
fn_list_config_locations
elif [ "${shortname}" == "cfmc" ]; then
fn_list_config_locations
elif [ "${shortname}" == "mcb" ]; then
array_configs+=(server.properties)
fn_default_config_remote

4
lgsm/modules/install_eula.sh

@ -9,7 +9,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
if [ "${shortname}" == "ts3" ]; then
eulaurl="https://www.teamspeak.com/en/privacy-and-terms"
elif [ "${shortname}" == "mc" ] || [ "${shortname}" == "pmc" ]; then
elif [ "${shortname}" == "mc" ] || [ "${shortname}" == "cfmc" ] || [ "${shortname}" == "pmc" ]; then
eulaurl="https://account.mojang.com/documents/minecraft_eula"
elif [ "${shortname}" == "ut" ]; then
eulaurl="https://www.epicgames.com/unrealtournament/unreal-tournament-pre-alpha-test-development-build-eula"
@ -38,7 +38,7 @@ fi
if [ "${shortname}" == "ts3" ]; then
touch "${executabledir}/.ts3server_license_accepted"
elif [ "${shortname}" == "mc" ] || [ "${shortname}" == "pmc" ]; then
elif [ "${shortname}" == "mc" ] || [ "${shortname}" == "cfmc" ] || [ "${shortname}" == "pmc" ]; then
touch "${serverfiles}/eula.txt"
echo -e "eula=true" > "${serverfiles}/eula.txt"
elif [ "${shortname}" == "ut" ]; then

4
lgsm/modules/install_server_files.sh

@ -241,7 +241,7 @@ fn_install_server_files() {
fn_clear_tmp
}
if [ "${shortname}" == "mc" ] || [ "${shortname}" == "pmc" ] || [ "${shortname}" == "ut" ]; then
if [ "${shortname}" == "mc" ] || [ "${shortname}" == "cfmc" ] || [ "${shortname}" == "pmc" ] || [ "${shortname}" == "ut" ]; then
install_eula.sh
fi
@ -260,6 +260,8 @@ if [ "${shortname}" == "ts3" ]; then
update_ts3.sh
elif [ "${shortname}" == "mc" ]; then
update_mc.sh
elif [ "${shortname}" == "cfmc" ]; then
update_cfmc.sh
elif [ "${shortname}" == "mcb" ]; then
update_mcb.sh
elif [ "${shortname}" == "pmc" ]; then

463
lgsm/modules/update_cfmc.sh

@ -0,0 +1,463 @@
#!/bin/bash
# LinuxGSM update_cfmc.sh module
# Author: Daniel Gibbs
# Contributors: https://linuxgsm.com/contrib
# Website: https://linuxgsm.com
# Description: Handles updating of CurseForge Minecraft server packs.
moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
fn_cfmc_parse_fileid_from_url() {
local input_url="${1}"
echo "${input_url}" | sed -n 's#.*[\/?&]files/\([0-9]\+\).*#\1#p' | head -n 1
}
fn_cfmc_validate_config() {
cfmcsource="${cfmcsource:-api}"
local parsed_fileid
local missing_settings=()
if [ "${cfmcsource}" != "api" ] && [ "${cfmcsource}" != "url" ]; then
fn_print_failure "Invalid cfmcsource: ${cfmcsource}"
fn_script_log_fail "Invalid cfmcsource: ${cfmcsource}"
echo -e "Supported values: api | url"
echo -e "Set in: ${configdirserver}/${selfname}.cfg"
core_exit.sh
fi
if [ -n "${curseforgeurl}" ]; then
parsed_fileid="$(fn_cfmc_parse_fileid_from_url "${curseforgeurl}")"
if [ -n "${parsed_fileid}" ] && [ -z "${curseforgefileid}" ]; then
curseforgefileid="${parsed_fileid}"
fi
fi
if [ "${cfmcsource}" == "api" ]; then
[ -n "${curseforgemodid}" ] || missing_settings+=("curseforgemodid")
[ -n "${curseforgefileid}" ] || missing_settings+=("curseforgefileid")
[ -n "${curseforgeapikey}" ] || missing_settings+=("curseforgeapikey")
elif [ "${cfmcsource}" == "url" ]; then
[ -n "${curseforgeurl}" ] || missing_settings+=("curseforgeurl")
fi
if [ "${#missing_settings[@]}" -gt 0 ]; then
fn_print_failure "Missing required CurseForge settings"
fn_script_log_fail "Missing required CurseForge settings"
echo -e "Set the following value(s):"
for setting in "${missing_settings[@]}"; do
echo -e "* ${setting}"
done
echo -e ""
echo -e "Set non-secret values in: ${configdirserver}/${selfname}.cfg"
echo -e "Set curseforgeapikey in: ${configdirserver}/secrets-common.cfg or ${configdirserver}/secrets-${selfname}.cfg"
core_exit.sh
fi
}
fn_cfmc_api_get_file_data() {
local fileid="${1}"
local apiurl="https://api.curseforge.com/v1/mods/${curseforgemodid}/files/${fileid}"
local apiresponse
local apiid
apiresponse=$(curl -sSL -H "x-api-key: ${curseforgeapikey}" "${apiurl}")
exitcode=$?
if [ "${exitcode}" -ne 0 ] || [ -z "${apiresponse}" ]; then
fn_print_failure "Unable to query CurseForge API for file ID ${fileid}"
fn_script_log_fail "Unable to query CurseForge API for file ID ${fileid}"
core_exit.sh
fi
apiid=$(echo "${apiresponse}" | jq -r '.data.id // empty')
if [ -z "${apiid}" ]; then
fn_print_failure "Unable to resolve CurseForge file ID ${fileid}"
fn_script_log_fail "Unable to resolve CurseForge file ID ${fileid}"
core_exit.sh
fi
echo "${apiresponse}"
}
fn_cfmc_resolve_api_source() {
local source_fileid="${1:-${curseforgefileid}}"
local apiresponse
local server_pack_fileid
apiresponse="$(fn_cfmc_api_get_file_data "${source_fileid}")"
server_pack_fileid=$(echo "${apiresponse}" | jq -r '.data.serverPackFileId // 0')
resolvedfileid="${source_fileid}"
if [[ "${server_pack_fileid}" =~ ^[0-9]+$ ]] && [ "${server_pack_fileid}" -gt 0 ]; then
resolvedfileid="${server_pack_fileid}"
apiresponse="$(fn_cfmc_api_get_file_data "${resolvedfileid}")"
fi
remotebuildurl=$(echo "${apiresponse}" | jq -r '.data.downloadUrl // empty')
remotebuildfilename=$(echo "${apiresponse}" | jq -r '.data.fileName // empty')
if [ -z "${remotebuildfilename}" ] || [ "${remotebuildfilename}" == "null" ]; then
remotebuildfilename="curseforge-${resolvedfileid}.zip"
fi
if [ -z "${remotebuildurl}" ] || [ "${remotebuildurl}" == "null" ]; then
fn_print_failure "CurseForge API did not return a downloadable server pack URL for file ${resolvedfileid}"
fn_script_log_fail "CurseForge API did not return a downloadable server pack URL for file ${resolvedfileid}"
core_exit.sh
fi
remotelocation="curseforge.com"
localpackpath=""
}
fn_cfmc_resolve_url_source() {
local parsed_fileid
parsed_fileid="$(fn_cfmc_parse_fileid_from_url "${curseforgeurl}")"
if echo "${curseforgeurl}" | grep -Eq '^https?://(www\.)?curseforge\.com/'; then
if [ -z "${parsed_fileid}" ]; then
fn_print_failure "Unsupported CurseForge URL: ${curseforgeurl}"
fn_script_log_fail "Unsupported CurseForge URL: ${curseforgeurl}"
echo -e "Use a direct archive URL, local archive path, or a CurseForge URL containing /files/<id>."
core_exit.sh
fi
if [ -z "${curseforgemodid}" ] || [ -z "${curseforgeapikey}" ]; then
fn_print_failure "CurseForge page URL requires curseforgemodid and curseforgeapikey"
fn_script_log_fail "CurseForge page URL requires curseforgemodid and curseforgeapikey"
echo -e "Set non-secret values in: ${configdirserver}/${selfname}.cfg"
echo -e "Set curseforgeapikey in: ${configdirserver}/secrets-common.cfg or ${configdirserver}/secrets-${selfname}.cfg"
core_exit.sh
fi
curseforgefileid="${parsed_fileid}"
fn_cfmc_resolve_api_source "${parsed_fileid}"
return
fi
if echo "${curseforgeurl}" | grep -Eq '^https?://'; then
local url_no_query="${curseforgeurl%%\?*}"
remotebuildfilename="$(basename "${url_no_query}")"
if [ -z "${remotebuildfilename}" ] || [ "${remotebuildfilename}" == "/" ] || [ "${remotebuildfilename}" == "." ]; then
remotebuildfilename="curseforge-server-pack.zip"
fi
remotebuildurl="${curseforgeurl}"
remotelocation="$(echo "${curseforgeurl}" | awk -F/ '{print $3}')"
resolvedsource="${curseforgeurl}"
localpackpath=""
elif [ -f "${curseforgeurl}" ]; then
localpackpath="${curseforgeurl}"
remotebuildfilename="$(basename "${localpackpath}")"
remotebuildurl=""
remotelocation="local file"
resolvedsource="${localpackpath}"
else
fn_print_failure "Invalid curseforgeurl value: ${curseforgeurl}"
fn_script_log_fail "Invalid curseforgeurl value: ${curseforgeurl}"
echo -e "Set curseforgeurl to a direct archive URL, a local archive path, or a CurseForge file page URL."
core_exit.sh
fi
}
fn_cfmc_build_remote_marker() {
local marker_source
local sourcehash
if [ "${cfmcsource}" == "api" ]; then
remotebuildversion="cfapi:${curseforgemodid}:${resolvedfileid}"
else
marker_source="${curseforgeurl}"
if [ -z "${marker_source}" ]; then
marker_source="${resolvedsource}"
fi
sourcehash=$(echo -n "${marker_source}" | sha1sum | awk '{print $1}')
remotebuildversion="cfurl:${sourcehash}"
fi
}
fn_cfmc_collect_preserve_paths() {
local levelname
local preserve_entries
local preserve_path
local preserve_raw_paths=()
cfmc_preserve_paths=()
levelname=$(sed -n -e 's/^level-name=//p' "${serverfiles}/server.properties" 2> /dev/null | tail -n 1)
if [ -z "${levelname}" ]; then
levelname="world"
fi
preserve_entries="local;journeymap;kubejs;serverconfig;server.properties;eula.txt;ops.json;whitelist.json;banned-ips.json;banned-players.json;usercache.json;${levelname};${levelname}_nether;${levelname}_the_end;${cfmcpreservepaths}"
IFS=';' read -r -a preserve_raw_paths <<< "${preserve_entries}"
for preserve_path in "${preserve_raw_paths[@]}"; do
preserve_path="$(echo "${preserve_path}" | xargs)"
preserve_path="${preserve_path#./}"
preserve_path="${preserve_path#/}"
preserve_path="${preserve_path%/}"
if [ -z "${preserve_path}" ]; then
continue
fi
if echo "${preserve_path}" | grep -Eq '(^|/)\.\.(/|$)'; then
fn_script_log_warn "Skipping unsafe preserve path: ${preserve_path}"
continue
fi
if [[ " ${cfmc_preserve_paths[*]} " != *" ${preserve_path} "* ]]; then
cfmc_preserve_paths+=("${preserve_path}")
fi
done
}
fn_cfmc_backup_preserve() {
local relpath
local srcpath
fn_cfmc_collect_preserve_paths
cfmc_preserve_dir="${tmpdir}/cfmc-preserve"
rm -rf "${cfmc_preserve_dir}"
mkdir -p "${cfmc_preserve_dir}"
for relpath in "${cfmc_preserve_paths[@]}"; do
srcpath="${serverfiles}/${relpath}"
if [ -e "${srcpath}" ]; then
mkdir -p "${cfmc_preserve_dir}/$(dirname "${relpath}")"
cp -a "${srcpath}" "${cfmc_preserve_dir}/${relpath}"
fi
done
}
fn_cfmc_restore_preserve() {
local relpath
local targetpath
local backup_path
for relpath in "${cfmc_preserve_paths[@]}"; do
targetpath="${serverfiles}/${relpath}"
backup_path="${cfmc_preserve_dir}/${relpath}"
if [ -e "${backup_path}" ]; then
rm -rf "${targetpath}"
mkdir -p "$(dirname "${targetpath}")"
cp -a "${backup_path}" "${targetpath}"
fi
done
}
fn_cfmc_upsert_setting() {
local setting_name="${1}"
local setting_value="${2}"
local config_file="${configdirserver}/${selfname}.cfg"
local escaped_value
touch "${config_file}"
escaped_value=$(echo -n "${setting_value}" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/[&|]/\\&/g')
if grep -qE "^[[:blank:]]*${setting_name}=" "${config_file}"; then
sed -i "s|^[[:blank:]]*${setting_name}=.*|${setting_name}=\"${escaped_value}\"|g" "${config_file}"
else
echo "${setting_name}=\"${escaped_value}\"" >> "${config_file}"
fi
}
fn_cfmc_persist_start_command() {
if [ "${cfmcstartmode}" != "auto" ] || [ -z "${detected_executable}" ]; then
return
fi
fn_cfmc_upsert_setting "preexecutable" "${detected_preexecutable}"
fn_cfmc_upsert_setting "executable" "${detected_executable}"
fn_cfmc_upsert_setting "startparameters" "${detected_startparameters}"
preexecutable="${detected_preexecutable}"
executable="${detected_executable}"
startparameters="${detected_startparameters}"
}
fn_cfmc_detect_start_command() {
local script_name
local jar_name
detected_preexecutable=""
detected_executable=""
detected_startparameters=""
if [ "${cfmcstartmode}" != "auto" ]; then
return
fi
for script_name in startserver.sh start.sh run.sh; do
if [ -f "${serverfiles}/${script_name}" ]; then
chmod +x "${serverfiles}/${script_name}" 2> /dev/null
detected_executable="./${script_name}"
break
fi
done
if [ -z "${detected_executable}" ]; then
if [ -f "${serverfiles}/server.jar" ]; then
jar_name="server.jar"
elif [ -f "${serverfiles}/minecraft_server.jar" ]; then
jar_name="minecraft_server.jar"
else
jar_name=$(find "${serverfiles}" -maxdepth 1 -type f -name "*.jar" ! -name "*installer*.jar" -printf "%f\n" 2> /dev/null | sort | head -n 1)
fi
if [ -n "${jar_name}" ]; then
detected_preexecutable="java -Xmx${javaram}M -jar"
detected_executable="./${jar_name}"
detected_startparameters="nogui"
fi
fi
fn_cfmc_persist_start_command
}
fn_update_dl() {
local archive_filename="${remotebuildfilename}"
if [ -n "${localpackpath}" ]; then
cp -f "${localpackpath}" "${tmpdir}/${archive_filename}"
else
fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${archive_filename}" "nochmodx" "norun" "force" "nohash"
fi
fn_cfmc_backup_preserve
fn_dl_extract "${tmpdir}" "${archive_filename}" "${serverfiles}"
fn_cfmc_restore_preserve
echo "${remotebuildversion}" > "${serverfiles}/build.txt"
fn_cfmc_detect_start_command
fn_clear_tmp
}
fn_update_localbuild() {
fn_print_dots "Checking local build: ${remotelocation}"
localbuild=$(head -n 1 "${serverfiles}/build.txt" 2> /dev/null)
if [ -z "${localbuild}" ]; then
fn_print_error "Checking local build: ${remotelocation}: missing local build info"
fn_script_log_error "Missing local build info"
fn_script_log_error "Set localbuild to 0"
localbuild="0"
else
fn_print_ok "Checking local build: ${remotelocation}"
fn_script_log_pass "Checking local build"
fi
}
fn_update_remotebuild() {
fn_cfmc_validate_config
if [ "${cfmcsource}" == "api" ]; then
fn_cfmc_resolve_api_source
else
fn_cfmc_resolve_url_source
fi
fn_cfmc_build_remote_marker
if [ "${firstcommandname}" != "INSTALL" ]; then
fn_print_dots "Checking remote build: ${remotelocation}"
if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
fn_print_fail "Checking remote build: ${remotelocation}"
fn_script_log_fail "Checking remote build"
core_exit.sh
else
fn_print_ok "Checking remote build: ${remotelocation}"
fn_script_log_pass "Checking remote build"
fi
else
if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
fn_print_failure "Unable to get remote build"
fn_script_log_fail "Unable to get remote build"
core_exit.sh
fi
fi
}
fn_update_compare() {
fn_print_dots "Checking for update: ${remotelocation}"
if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then
date '+%s' > "${lockdir:?}/update.lock"
fn_print_ok_nl "Checking for update: ${remotelocation}"
echo -en "\n"
echo -e "Update available"
echo -e "* Local build: ${red}${localbuild}${default}"
echo -e "* Remote build: ${green}${remotebuildversion}${default}"
if [ -f "${rootdir}/.dev-debug" ]; then
echo -e "Remote build info"
echo -e "* remotebuildfilename: ${remotebuildfilename}"
echo -e "* remotebuildurl: ${remotebuildurl}"
echo -e "* remotebuildversion: ${remotebuildversion}"
fi
echo -en "\n"
fn_script_log_info "Update available"
fn_script_log_info "Local build: ${localbuild}"
fn_script_log_info "Remote build: ${remotebuildversion}"
fn_script_log_info "${localbuild} > ${remotebuildversion}"
if [ "${commandname}" == "UPDATE" ]; then
date +%s > "${lockdir}/last-updated.lock"
unset updateonstart
check_status.sh
if [ "${status}" == "0" ]; then
fn_update_dl
if [ "${localbuild}" == "0" ]; then
exitbypass=1
command_start.sh
fn_firstcommand_reset
exitbypass=1
fn_sleep_time_5
command_stop.sh
fn_firstcommand_reset
fi
else
fn_print_restart_warning
exitbypass=1
command_stop.sh
fn_firstcommand_reset
exitbypass=1
fn_update_dl
exitbypass=1
command_start.sh
fn_firstcommand_reset
fi
unset exitbypass
alert="update"
elif [ "${commandname}" == "CHECK-UPDATE" ]; then
alert="check-update"
fi
alert.sh
else
fn_print_ok_nl "Checking for update: ${remotelocation}"
echo -en "\n"
echo -e "No update available"
echo -e "* Local build: ${green}${localbuild}${default}"
echo -e "* Remote build: ${green}${remotebuildversion}${default}"
echo -en "\n"
fn_script_log_info "No update available"
fn_script_log_info "Local build: ${localbuild}"
fn_script_log_info "Remote build: ${remotebuildversion}"
if [ -f "${rootdir}/.dev-debug" ]; then
echo -e "Remote build info"
echo -e "* remotebuildfilename: ${remotebuildfilename}"
echo -e "* remotebuildurl: ${remotebuildurl}"
echo -e "* remotebuildversion: ${remotebuildversion}"
fi
fi
}
remotelocation="curseforge.com"
resolvedfileid=""
resolvedsource=""
localpackpath=""
cfmc_preserve_dir=""
cfmc_preserve_paths=()
if [ ! "$(command -v jq 2> /dev/null)" ]; then
fn_print_fail_nl "jq is not installed"
fn_script_log_fail "jq is not installed"
core_exit.sh
fi
if [ "${firstcommandname}" == "INSTALL" ]; then
fn_update_remotebuild
fn_update_dl
else
fn_print_dots "Checking for update"
fn_print_dots "Checking for update: ${remotelocation}"
fn_script_log_info "Checking for update: ${remotelocation}"
fn_update_localbuild
fn_update_remotebuild
fn_update_compare
fi
Loading…
Cancel
Save