From 1b9cc58339010db6cb956f11cf34e2dd9427025f Mon Sep 17 00:00:00 2001 From: David McNett Date: Thu, 25 Nov 2021 13:18:37 -0600 Subject: [PATCH 1/6] Script to sync files from remote/hosted server This is a sample script which can sync the necessary files over FTP from a remote or hosted Minecraft server. --- contrib/ftpsync.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 contrib/ftpsync.sh diff --git a/contrib/ftpsync.sh b/contrib/ftpsync.sh new file mode 100644 index 00000000..e287a321 --- /dev/null +++ b/contrib/ftpsync.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +# This script will pull the necessary stats files from a remote or hosted +# Minecraft server using ftp and mirror them locally so that the MinecraftStats +# script can successfully run. +# +# This script requires the `lftp` utility which is almost certainly available +# in your OS package repository. +# +# Update the values below to your local environment and you should be good +# to go! +# + +# Location of MinecraftStats webroot +WEBROOT=/var/www/MinecraftStats + +# Target destination for synched files from Minecraft server +MIRRORPATH=/var/minecraft/serverroot + +# Minecraft server "level-name" in server.properties (usually "world") +LEVELNAME='world' + +FTPHOST=ftp.example.com +FTPUSER=username +FTPPASS=password + +# Sync files group and world readable so that the web server can view them +umask 022 + +# Create the mirror path if it doesn't already exist +mkdir -p "$MIRRORPATH" + +# Sync the files from the Minecraft Server +cd "$MIRRORPATH" +lftp -u $FTPUSER,$FTPPASS $FTPHOST -e "mirror -r -I ops.json -I usercache.json -I server.properties -I banned-players.json -I server-icon.png . .; mirror -r $LEVELNAME/stats $LEVELNAME/; mirror -r $LEVELNAME/advancements $LEVELNAME/; bye" + +# Run MinecraftStats +cd "$WEBROOT" +python3 update.py config.json From 256d1465d83becbaf9f5eb3a0859ef7beacf05fb Mon Sep 17 00:00:00 2001 From: David McNett Date: Thu, 25 Nov 2021 18:39:38 -0600 Subject: [PATCH 2/6] Reference the script in the root level README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 0dd7e461..1e92b899 100644 --- a/README.md +++ b/README.md @@ -162,6 +162,10 @@ Typically, a cronjob for *MinecraftStats* will look like this: */10 * * * * cd /path/to/mcstats ; python3 update.py config.json ``` +#### Mirroring Remote Files + +An example script is available in the `contrib` directory to sync the required files from a remote or hosted Minecraft server using the FTP protocol. + #### Windows If you're using Windows to run your server... figure something out! There's probably some task scheduler available that you can use. From 17c727bd449f684765cd4dec7ac87da54a77976f Mon Sep 17 00:00:00 2001 From: David McNett Date: Thu, 25 Nov 2021 18:41:20 -0600 Subject: [PATCH 3/6] Add detail to lftp operation --- contrib/ftpsync.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/ftpsync.sh b/contrib/ftpsync.sh index e287a321..ab471d18 100644 --- a/contrib/ftpsync.sh +++ b/contrib/ftpsync.sh @@ -5,7 +5,8 @@ # script can successfully run. # # This script requires the `lftp` utility which is almost certainly available -# in your OS package repository. +# in your OS package repository. This tool will only transfer new or changed +# files, making it very efficient and fast on subsequent runs. # # Update the values below to your local environment and you should be good # to go! From 130bccfb396cff61509be0569fa6490c57e9bb65 Mon Sep 17 00:00:00 2001 From: David McNett Date: Fri, 26 Nov 2021 11:53:30 -0600 Subject: [PATCH 4/6] Move configuration to seperate file --- contrib/ftpsync.config.example | 12 ++++++++++++ contrib/ftpsync.sh | 34 ++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 contrib/ftpsync.config.example mode change 100644 => 100755 contrib/ftpsync.sh diff --git a/contrib/ftpsync.config.example b/contrib/ftpsync.config.example new file mode 100644 index 00000000..f4494462 --- /dev/null +++ b/contrib/ftpsync.config.example @@ -0,0 +1,12 @@ +# Location of MinecraftStats webroot +WEBROOT=/var/www/MinecraftStats + +# Target destination for synched files from Minecraft server +MIRRORPATH=/var/minecraft/serverroot + +# Minecraft server "level-name" in server.properties (usually "world") +LEVELNAME='world' + +FTPHOST=ftp.example.com +FTPUSER=username +FTPPASS=password diff --git a/contrib/ftpsync.sh b/contrib/ftpsync.sh old mode 100644 new mode 100755 index ab471d18..a99080dc --- a/contrib/ftpsync.sh +++ b/contrib/ftpsync.sh @@ -8,22 +8,24 @@ # in your OS package repository. This tool will only transfer new or changed # files, making it very efficient and fast on subsequent runs. # -# Update the values below to your local environment and you should be good -# to go! -# - -# Location of MinecraftStats webroot -WEBROOT=/var/www/MinecraftStats - -# Target destination for synched files from Minecraft server -MIRRORPATH=/var/minecraft/serverroot - -# Minecraft server "level-name" in server.properties (usually "world") -LEVELNAME='world' - -FTPHOST=ftp.example.com -FTPUSER=username -FTPPASS=password +# Edit the config values in the `ftpsync.config` file and then run this +# script: + +CONFIGFILE="$(dirname $0)/ftpsync.config" + +if [ -e $CONFIGFILE ]; then + # Configuration file found, load it up + source $CONFIGFILE +else + # Cannot find configuration file in expected location + echo "Configuration file $CONFIGFILE not found" + exit 1 +fi + +if [ -z "$MIRRORPATH" ]; then + echo "Configuration not loaded" + exit 1 +fi # Sync files group and world readable so that the web server can view them umask 022 From e65b7f51faabe23ba2f31ea3b88ccb1e7c98e3ea Mon Sep 17 00:00:00 2001 From: David McNett Date: Fri, 26 Nov 2021 11:55:30 -0600 Subject: [PATCH 5/6] Abort if we can't create the mirror directory --- contrib/ftpsync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/ftpsync.sh b/contrib/ftpsync.sh index a99080dc..24ff5f62 100755 --- a/contrib/ftpsync.sh +++ b/contrib/ftpsync.sh @@ -31,7 +31,7 @@ fi umask 022 # Create the mirror path if it doesn't already exist -mkdir -p "$MIRRORPATH" +mkdir -p "$MIRRORPATH" || exit 1 # Sync the files from the Minecraft Server cd "$MIRRORPATH" From 8420143bace8ead52c4ad1ebcdcee5c0f3fd0137 Mon Sep 17 00:00:00 2001 From: David McNett Date: Fri, 26 Nov 2021 12:06:13 -0600 Subject: [PATCH 6/6] Move configuration to ftpsync.config file --- contrib/.gitignore | 1 + contrib/ftpsync.sh | 18 ++---------------- 2 files changed, 3 insertions(+), 16 deletions(-) create mode 100644 contrib/.gitignore diff --git a/contrib/.gitignore b/contrib/.gitignore new file mode 100644 index 00000000..143c6468 --- /dev/null +++ b/contrib/.gitignore @@ -0,0 +1 @@ +*.config diff --git a/contrib/ftpsync.sh b/contrib/ftpsync.sh index 24ff5f62..adfa9266 100755 --- a/contrib/ftpsync.sh +++ b/contrib/ftpsync.sh @@ -9,23 +9,9 @@ # files, making it very efficient and fast on subsequent runs. # # Edit the config values in the `ftpsync.config` file and then run this -# script: +# script. -CONFIGFILE="$(dirname $0)/ftpsync.config" - -if [ -e $CONFIGFILE ]; then - # Configuration file found, load it up - source $CONFIGFILE -else - # Cannot find configuration file in expected location - echo "Configuration file $CONFIGFILE not found" - exit 1 -fi - -if [ -z "$MIRRORPATH" ]; then - echo "Configuration not loaded" - exit 1 -fi +. "$(dirname -- "$0")/ftpsync.config" || exit 1 # Sync files group and world readable so that the web server can view them umask 022