Skip to content

Instantly share code, notes, and snippets.

@sfan5
Last active July 10, 2022 20:20
Show Gist options
  • Save sfan5/6351560 to your computer and use it in GitHub Desktop.
Save sfan5/6351560 to your computer and use it in GitHub Desktop.
Collects media files from mods/games and puts them in a media directory, also creates an index.mth file in the MTHS format
#!/bin/bash
###### Options ######
MINETESTDIR=/home/username/minetest
GAMENAME=minetest_game
WORLDDIR=none
MEDIADIR=./media
LEGACY_SYMLINKS=0
# When settings this up be aware that the Minetest client
# will send a POST request to index.mth. You need to configure
# your web server to serve the file on POST requests for this to work.
#####################
die () {
echo "$1" >&2
exit 1
}
collect_from () {
echo "Processing media from: $1"
find -L "$1" -type f -name "*.png" -o -name "*.ogg" -o -name "*.x" -o -name "*.b3d" | while read f; do
basename "$f"
hash=`openssl dgst -sha1 <"$f" | cut -d " " -f 2`
cp "$f" $MEDIADIR/$hash
[ $LEGACY_SYMLINKS -eq 1 ] && ln -nsf $hash $MEDIADIR/`basename "$f"`
done
}
[ -d "$MINETESTDIR" ] || die "Specify a valid Minetest directory!"
which openssl &>/dev/null || die "OpenSSL not installed."
mkdir -p $MEDIADIR
[ ! $GAMENAME == none ] && collect_from "$MINETESTDIR/games/$GAMENAME/mods"
[ ! "$WORLDDIR" == none ] && collect_from "$WORLDDIR/worldmods"
[ -d "$MINETESTDIR/mods" ] && collect_from "$MINETESTDIR/mods"
printf "Creating index.mth... "
printf "MTHS\x00\x01" >$MEDIADIR/index.mth
find $MEDIADIR -type f -not -name index.mth | while read f; do
openssl dgst -binary -sha1 <$f >>$MEDIADIR/index.mth
done
echo "done"
@Cat5TV
Copy link

Cat5TV commented Aug 16, 2016

K thanks sfan5. Not perfect, but still will help offload the game server itself.

@ShadowNinja
Copy link

@taikedz
Copy link

taikedz commented Jan 16, 2017

I'd like to edit this a little and share - what license do you wish to detail please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment