Skip to content

Instantly share code, notes, and snippets.

@ipimpat
Last active August 29, 2015 14:21
Show Gist options
  • Save ipimpat/83cd68dd44ec5a159ee3 to your computer and use it in GitHub Desktop.
Save ipimpat/83cd68dd44ec5a159ee3 to your computer and use it in GitHub Desktop.
Spigotmc Ubuntu Installation Script (tested on Ubuntu 14.04)
echo '+------------------------------------------------------------------------+'
echo ' Spigotmc installation script for Ubuntu based Linux distros'
echo -e '\n'
echo ' Copyright © 2015 Kim Henriksen'
echo -e '\n'
echo ' All rights reserved, use this script at your own risk'
echo '+------------------------------------------------------------------------+'
# Installation parameters
DOWNLOAD_URL=https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
SERVICE_NAME=spigotmc
RUN_AS=spigotmc
INSTALL_PATH=/opt/spigotmc
INSTALL_REVISION=1.8.4
HEAP_MEM_MIN=512M
HEAP_MEM_MAX=1024M
# Pre-flight checks
echo 'This will install Spigot and Craftbukkit to: '$INSTALL_PATH' and create a new user:' $RUN_AS
echo 'It will also install the required dependencies: Oracle Java 8 and Git'
read -p 'Are you sure? ' -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]] then
echo -e '\n'
exit 1
else
echo -e '\n'
# Check if the username is available
if id -u "$RUN_AS" > /dev/null 2>&1; then
echo 'The username is already in use ... bailing'
exit 1
fi
# Check if the install directory is available
if [ -d "$INSTALL_PATH" ]; then
echo 'The install path already exist ... bailing'
exit 1
fi
echo 'Beginning the installation'
fi
# install required dependencies
echo -n 'Installing required dependencies'
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections > /dev/null
sudo add-apt-repository -y ppa:webupd8team/java > /dev/null 2>&1
sudo apt-get update > /dev/null
sudo apt-get install -y oracle-java8-installer git > /dev/null 2>&1
echo ' ... done'
# Create the user
echo -n 'Creating new system user:' $RUN_AS
sudo adduser --quiet --disabled-login --system --group --home $INSTALL_PATH $RUN_AS > /dev/null
echo ' ... done'
# Unset line ending git setting
echo -n 'Unsetting core.autocrlf Git setting locally for user:' $RUN_AS
sudo -H -u $RUN_AS git config --unset core.autocrlf > /dev/null 2>&1
echo ' ... done'
# Download Spigotmc BuildTools
echo -n 'Downloading Spigotmc BuildTools'
sudo -u $RUN_AS mkdir $INSTALL_PATH/src > /dev/null 2>&1
cd $INSTALL_PATH/src
sudo -u $RUN_AS wget --quiet $DOWNLOAD_URL > /dev/null 2>&1
echo ' ... done'
# Run BuildTools which will build the CraftBukkit and Spigotmc server files
echo -n 'Compiling CraftBukkit and Spigotmc server files (this might take some time)'
sudo -u $RUN_AS java -jar BuildTools.jar --rev $INSTALL_REVISION > /dev/null 2>&1
echo ' ... done'
# Copy compiled java archives to install path
echo -n 'Copying server files to installation path'
sudo -u $RUN_AS cp craftbukkit-$INSTALL_REVISION.jar $INSTALL_PATH > /dev/null 2>&1
sudo -u $RUN_AS cp spigot-$INSTALL_REVISION.jar $INSTALL_PATH > /dev/null 2>&1
echo 'eula=true' | sudo tee $INSTALL_PATH/eula.txt > /dev/null 2>&1
echo ' ... done'
# Create upstart job
echo -n 'Creating upstart job'
echo -e 'description "start and stop the Spigotmc daemon"\n' | sudo tee /etc/init/$SERVICE_NAME.conf > /dev/null 2>&1
echo 'start on runlevel [2345]' | sudo tee --append /etc/init/$SERVICE_NAME.conf > /dev/null 2>&1
echo -e 'stop on runlevel [^2345]\n' | sudo tee --append /etc/init/$SERVICE_NAME.conf > /dev/null 2>&1
echo 'console log' | sudo tee --append /etc/init/$SERVICE_NAME.conf > /dev/null 2>&1
echo 'chdir '$INSTALL_PATH | sudo tee --append /etc/init/$SERVICE_NAME.conf > /dev/null 2>&1
echo 'setuid '$RUN_AS | sudo tee --append /etc/init/$SERVICE_NAME.conf > /dev/null 2>&1
echo -e 'setgid '$RUN_AS'\n' | sudo tee --append /etc/init/$SERVICE_NAME.conf > /dev/null 2>&1
echo 'respawn' | sudo tee --append /etc/init/$SERVICE_NAME.conf > /dev/null 2>&1
echo -e 'respawn limit 20 5\n' | sudo tee --append /etc/init/$SERVICE_NAME.conf > /dev/null 2>&1
echo 'exec /usr/lib/jvm/java-8-oracle/jre/bin/java -Xms'$HEAP_MEM_MIN' -Xmx'$HEAP_MEM_MAX' -jar spigot-'$INSTALL_REVISION'.jar nogui' | sudo tee --append /etc/init/$SERVICE_NAME.conf > /dev/null 2>&1
echo ' ... done'
echo 'Installation complete'
echo '+------------------------------------------------------------------------+'
echo ' Status: Spigotmc was successfully installed'
echo ' Install path: '$INSTALL_PATH
echo ' Upstart job: /etc/init/'$SERVICE_NAME.conf
echo ' Use "service '$SERVICE_NAME' start|stop|restart" to start/stop/restart'
echo '+------------------------------------------------------------------------+'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment