Last active
July 10, 2022 20:20
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
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
I made this as an alternative: https://github.com/ShadowNinja/mt_media_collector