Skip to content

Instantly share code, notes, and snippets.

@allaryin
Last active January 3, 2016 00:09
Show Gist options
  • Save allaryin/8380709 to your computer and use it in GitHub Desktop.
Save allaryin/8380709 to your computer and use it in GitHub Desktop.
Generate a useful baseline for building an MCU serverpack.
#!/bin/bash
FORGE_VERSION='9.11.1.965'
MC_VERSION='1.6.4'
SERVER_ID='example'
SERVER_NAME='Example Server'
SERVER_REVISION=`date +%Y%m%d.%H%M`
SERVER_ADDRESS=''
ICON_URL=''
NEWS_URL=''
CONFIG_DIRS='config'
MOD_DIRS='mods optional'
URL_PREFIX='http://example.com/'${SERVER_ID}'/'
##########
echo '<?xml version="1.0" encoding="UTF-8"?>'
echo '<ServerPack version="3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.mcupdater.com" xsi:schemaLocation="http://files.mcupdater.com/ServerPackv2.xsd">'
echo '<Server id="'${SERVER_ID}'" name="'${SERVER_NAME}'" newsURL="'${NEWS_URL}'" iconUrl="'${ICON_URL}'" serverAddress="'${SERVER_ADDRESS}'" generateList="true" autoConnect="false" mainClass="net.minecraft.launchwrapper.Launch" version="'${MC_VERSION}'" revision="'${SERVER_REVISION}'">'
echo ' <Import url="http://files.mcupdater.com/example/forge.php?mc='${MC_VERSION}'&amp;forge='${FORGE_VERSION}'">forge</Import>'
SAVE_IFS=${IFS}
for MOD_DIR in ${MOD_DIRS}
do
find ${MOD_DIR} -print0 -type f -name '*.jar' -o -name '*.zip' | while read -d $'\0' MOD_FILE
do
IFS=$(echo -en "\n\b")
MD5=`md5sum ${MOD_FILE} | cut -f 1 -d ' '`
IFS=${SAVE_IFS}
BASE=`basename ${MOD_FILE}`
echo '<Module id="'${BASE}'" name="'${BASE}'">'
echo ' <URL>'${URL_PREFIX}${MOD_FILE}'</URL>'
echo ' <Required>true</Required>'
echo ' <ModType>Regular</ModType>'
echo ' <MD5>'${MD5}'</MD5>'
echo '</Module>'
done
done
for CONFIG_DIR in ${CONFIG_DIRS}
do
ZIP_FILE="${CONFIG_DIR}.zip"
if [ -f "${ZIP_FILE}" ]; then
mv ${ZIP_FILE} ${ZIP_FILE}.bak
fi
zip --quiet -r ${ZIP_FILE} ${CONFIG_DIR}
MD5=`md5sum ${ZIP_FILE} | cut -f 1 -d ' '`
echo '<Module id="'${CONFIG_DIR}'" name="'${CONFIG_DIR}' Zip">'
echo ' <URL>'${URL_PREFIX}${ZIP_FILE}'</URL>'
echo ' <Required>true</Required>'
echo ' <ModType inRoot="true">Extract</ModType>'
echo ' <MD5>'${MD5}'</MD5> <!-- auto:'${ZIP_FILE}' -->'
echo '</Module>'
done
echo '</Server>'
echo '</ServerPack>'
#!/bin/bash
rm config.zip
zip -r config.zip config/
MD5=`md5sum config.zip | cut -f 1 -d ' '`
sed -i.bak 's#<MD5>.*</MD5> <!-- auto:config.zip#<MD5>'${MD5}'</MD5> <!-- auto:config.zip#' ServerPack.xml
diff ServerPack.xml.bak ServerPack.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment