Skip to content

Instantly share code, notes, and snippets.

@stuudmuffin
Last active February 13, 2018 17:22
Show Gist options
  • Save stuudmuffin/ab53d38d8b588480eaa984b9686ab7c3 to your computer and use it in GitHub Desktop.
Save stuudmuffin/ab53d38d8b588480eaa984b9686ab7c3 to your computer and use it in GitHub Desktop.
json output of plugin names and extensions
#!/bin/bash
# I used this to easily export the json to a file for more processing
## bash minecraft_plugin_versions.sh > /var/www/html/info/version.json
## chown www-data:www-data /var/www/html/info/version.json
# this would save the file to my webserver directory, and ensure it had the right permissions to be processed by the server
# I then had a php script that would compare the list in a crude way against the developer sites for my plugins, and display them in a nice format
# that script I likely will not post as it's super dirty... Maybe if I find a better method of doing it.
# REQUIREMENTS
# zip
#this should point to your plugins directory
cd /Minecraft/plugins/
files=($(ls *.jar));
count="${#files[@]}";
count="$(($count-1))";
echo "[";
for ((i=0; i<${#files[@]}; i++)); do
version=$(unzip -c ${files[$i]} plugin.yml | grep "version:" -m1 | sed 's/["]/\\\"/g' | tr -cd '[[:alnum:]]._-' | sed 's/version//g');
if [ $i -lt $count ]; then
echo "{\"name\":\"${files[$i]}\",\"version\":\"$version\"},";
else
echo "{\"name\":\"${files[$i]}\",\"version\":\"$version\"}";
fi
done
echo "]";
#!/bin/bash
# In addition to the script above, I run my webserver on a different server than where the mincraft server is located
# this script will SSH into the server to run the above script, then save the output to a specified file where my webserver
# would have access to later process and display the data
# this requires the DB password to be set and enabled in the "minecraft_plugin_versions" script!
# IP or hostname of your minecraft server with SSH permissions and a public keyfile correctly setup.
ip="192.168.1.100";
# filepath to your script. By default, my usersnames are all the same, and I keep this file in the users home directory.
command="./minecraft_plugin_versions.sh";
# web directory path and filename you want to save the data to
path="/var/www/mc/info/version.json";
ssh $ip $command > $path
# make sure the webserver has permissions to read the file
# only really important on some OS's like centos, but be sure to set to the user your webserver is running with
chown www-data:www-data $path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment