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. 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.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 new file mode 100755 index 00000000..adfa9266 --- /dev/null +++ b/contrib/ftpsync.sh @@ -0,0 +1,28 @@ +#!/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. This tool will only transfer new or changed +# files, making it very efficient and fast on subsequent runs. +# +# Edit the config values in the `ftpsync.config` file and then run this +# script. + +. "$(dirname -- "$0")/ftpsync.config" || exit 1 + +# 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" || exit 1 + +# 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