Last active
March 28, 2020 21:40
-
-
Save NicolasRitouet/ad250255e8187488e5c613d433069328 to your computer and use it in GitHub Desktop.
Single Command Minecraft Install
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 | |
# Minecraft (Spigot) server build script (written by Clay Freeman) | |
# License: http://creativecommons.org/licenses/by-sa/4.0/ | |
# To use this script: | |
# wget -qO- https://gist.github.com/ClayFreeman/a4dae9b7d0fa2c6476eb/raw | sh | |
echo | |
# Store pre-script working directory | |
export PAST_PWD=`pwd` | |
# Store MB of RAM available | |
export RAM_MB=`free -m | egrep '^Mem' | awk '{print $2}'` | |
# Define Spigot download URL (I like short lines, excuse the workaround) | |
export SPIGOT="https://hub.spigotmc.org/jenkins/job/BuildTools/" | |
export SPIGOT="${SPIGOT}lastSuccessfulBuild/artifact/target/BuildTools.jar" | |
# Refuse to build if ~/minecraft/minecraft.jar exists | |
if [ -f ~/minecraft/minecraft.jar ]; | |
then | |
echo "To rebuild Minecraft, run \`mv ~/minecraft/minecraft.jar ~/mc.old.jar\`" | |
else | |
echo "This script can take anywhere from 10 minutes or beyond." | |
echo "Wait 5 seconds, or press Control+C to quit." | |
echo | |
sleep 5 | |
echo "Upgrading this server and installing required packages..." | |
sudo apt-get update > /dev/null 2>&1 | |
sudo apt-get upgrade -y --force-yes > /dev/null 2>&1 | |
sudo apt-get install -y --force-yes git htop iftop iotop iptraf \ | |
openjdk-8-jdk openjdk-8-jre-headless screen vnstat > /dev/null 2>&1 | |
if [ -f ~/.mcbuild ]; | |
then | |
echo "Cleaning previous build..." | |
rm -rf ~/.mcbuild | |
fi | |
echo "Building Spigot (this can take a while)..." | |
mkdir -p ~/.mcbuild | |
wget -qO ~/.mcbuild/BuildTools.jar $SPIGOT > ~/.mcbuild/buildScript.log 2>&1 | |
cd ~/.mcbuild && java -Xmx1024M -jar BuildTools.jar >> ~/.mcbuild/buildScript.log 2>&1 | |
echo "Installing Spigot..." | |
mkdir -p ~/minecraft && \ | |
cp ~/.mcbuild/Spigot/Spigot-Server/target/spigot-*-SNAPSHOT.jar \ | |
~/minecraft/minecraft.jar >> ~/.mcbuild/buildScript.log 2>&1 | |
echo "Creating start script..." | |
echo '#!/bin/bash' > ~/minecraft/start.sh | |
echo "screen -wipe > /dev/null" >> ~/minecraft/start.sh | |
echo "if screen -list | grep -q 'minecraft';" >> ~/minecraft/start.sh | |
echo "then" >> ~/minecraft/start.sh | |
echo " echo 'Minecraft is already running...'" >> ~/minecraft/start.sh | |
echo " echo 'View console: \`screen -dR minecraft\`'" >> ~/minecraft/start.sh | |
echo " exit 1" >> ~/minecraft/start.sh | |
echo "fi" >> ~/minecraft/start.sh | |
echo "cd ~/minecraft && screen -dmS minecraft java -Xmx${RAM_MB}M \\" \ | |
>> ~/minecraft/start.sh | |
echo " -Xms${RAM_MB}M -XX:MaxPermSize=${RAM_MB}M -jar minecraft.jar nogui" \ | |
>> ~/minecraft/start.sh | |
echo "echo 'Minecraft has been started.'" >> ~/minecraft/start.sh | |
echo "echo 'View console: \`screen -dR minecraft\`'" >> ~/minecraft/start.sh | |
chmod +x ~/minecraft/start.sh >> ~/.mcbuild/buildScript.log 2>&1 | |
echo "eula=true" > ~/minecraft/eula.txt | |
echo | |
echo "Install Complete! Check ~/.mcbuild/buildScript.log if you have problems" | |
fi | |
echo | |
echo "To start Minecraft (cmd):" | |
echo " ~/minecraft/start.sh" | |
echo | |
echo "To view the console (cmd):" | |
echo " screen -dR minecraft" | |
# Change to pre-script working directory | |
cd $PAST_PWD | |
echo | |
if [ -f /var/run/reboot-required ]; | |
then | |
cat /var/run/reboot-required | |
echo | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment