Minecraft One-Click

by linode
7 deployments · 7 still active · last rev. 2 days ago

Compatible with: Debian 9
						#!/bin/bash
#
#<UDF name="pubkey" Label="SSH public key" example="ssh-rsa..." default="" />
# Game config options:
#https://minecraft.gamepedia.com/Server.properties

#<UDF name="allowflight" label="allowflight" default="false" />
#<UDF name="allownether" label="allownether" default="true" />
#<UDF name="announceplayerachievements" label="announceplayerachievements" default="true" />
#<UDF name="difficulty" label="difficulty" default="1" />
#<UDF name="enablecommandblock" label="enablecommandblock" default="false" />
#<UDF name="enablequery" label="enablequery" default="true" />
#<UDF name="forcegamemode" label="forcegamemode" default="false" />
#<UDF name="gamemode" label="gamemode" default="0" />
#<UDF name="generatestructures" label="generatestructures" default="true" />
#<UDF name="generatorsettings" label="generatorsettings" default="" />
#<UDF name="hardcore" label="hardcore" default="false" />
#<UDF name="levelname" label="levelname" default="world" />
#<UDF name="levelseed" label="levelseed" default="" />
#<UDF name="leveltype" label="leveltype" default="DEFAULT" />
#<UDF name="maxbuildheight" label="maxbuildheight" default="256" />
#<UDF name="maxplayers" label="maxplayers" default="20" />
#<UDF name="maxticktime" label="maxticktime" default="60000" />
#<UDF name="maxworldsize" label="maxworldsize" default="29999984" />
#<UDF name="networkcompressionthreshold" label="networkcompressionthreshold" default="256" />
#<UDF name="onlinemode" label="onlinemode" default="true" />
#<UDF name="oppermissionlevel" label="oppermissionlevel" default="4" />
#<UDF name="playeridletimeout" label="playeridletimeout" default="0" />
#<UDF name="pvp" label="pvp" default="true" />
#<UDF name="port" label="port" default="25565" />
#<UDF name="snooperenabled" label="snooperenabled" default="true" />
#<UDF name="spawnanimals" label="spawnanimals" default="true" />
#<UDF name="spawnmonsters" label="spawnmonsters" default="true" />
#<UDF name="spawnnpcs" label="spawnnpcs" default="true" />
#<UDF name="usenativetransport" label="usenativetransport" default="true" />
#<UDF name="viewdistance" label="viewdistance" default="10" />
#<UDF name="whitelist" label="whitelist" default="false" />
#<UDF name="motd" label="motd" default="Powered by Linode!" />


#Non-MVP Options
#name="resourcepack" label="resourcepack" default=""
#name="enablercon" label="enablercon" default="false"
#name="rconpassword" label="rconpassword" default="adminU74EVnZv"
#name="rconport" label="rconport" default="25575"


source <ssinclude StackScriptID="349139">
source <ssinclude StackScriptID="370022">

exec 1> >(tee -a "/var/log/stackscript.log") 2>&1

GAMESERVER="mcserver"

set_hostname
apt_setup_update

if [[ "$PUBKEY" != "" ]]; then
  add_pubkey
fi

# Minecraft specific dependencies
debconf-set-selections <<< "postfix postfix/main_mailer_type string 'No Configuration'"
debconf-set-selections <<< "postfix postfix/mailname string `hostname`"
dpkg --add-architecture i386
apt update
sudo apt -q -y install mailutils postfix curl \
wget file bzip2 gzip unzip bsdmainutils python \
util-linux ca-certificates binutils bc jq tmux default-jre
add-apt-repository -y ppa:webupd8team/java
apt -q -y purge openjdk-11*
apt -q -y install openjdk-8-jre-headless
update-ca-certificates -f

# Install linuxGSM
linuxgsm_install

# Install Minecraft
game_install

# Minecraft config

sed -i s/server-ip=/server-ip="$IP"/ /home/"$GAMESERVER"/serverfiles/server.properties

#Customer config
sed -i s/allow-flight=false/allow-flight="$ALLOWFLIGHT"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/allow-nether=true/allow-nether="$ALLOWNETHER"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/announce-player-achievements=true/announce-player-achievements="$ANNOUNCEPLAYERACHIEVEMENTS"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/difficulty=1/difficulty="$DIFFICULTY"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/enable-command-block=false/enable-command-block="$ENABLECOMMANDBLOCK"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/enable-query=true/enable-query="$ENABLEQUERY"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/force-gamemode=false/force-gamemode="$FORCEGAMEMODE"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/gamemode=0/gamemode="$GAMEMODE"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/generate-structures=true/generate-structures="$GENERATESTRUCTURES"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/generator-settings=/generator-settings="$GENERATORSETTINGS"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/hardcore=false/hardcore="$HARDCORE"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/level-name=world/level-name="$LEVELNAME"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/level-seed=/level-seed="$LEVELSEED"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/level-type=DEFAULT/level-type="$LEVELTYPE"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/max-build-height=256/max-build-height="$MAXBUILDHEIGHT"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/max-players=20/max-players="$MAXPLAYERS"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/max-tick-time=60000/max-tick-time="$MAXTICKTIME"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/max-world-size=29999984/max-world-size="$MAXWORLDSIZE"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/motd=.*/motd="$MOTD"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/network-compression-threshold=256/network-compression-threshold="$NETWORKCOMPRESSIONTHRESHOLD"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/online-mode=true/online-mode="$ONLINEMODE"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/op-permission-level=4/op-permission-level="$OPPERMISSIONLEVEL"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/player-idle-timeout=0/player-idle-timeout="$PLAYERIDLETIMEOUT"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/pvp=true/pvp="$PVP"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/resource-pack-sha1=/resource-pack-sha1="$RESOURCEPACKSHA1"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/server-port=25565/server-port="$PORT"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/snooper-enabled=true/snooper-enabled="$SNOOPERENABLED"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/spawn-animals=true/spawn-animals="$SPAWNANIMALS"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/spawn-monsters=true/spawn-monsters="$SPAWNMONSTERS"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/spawn-npcs=true/spawn-npcs="$SPAWNNPCS"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/use-native-transport=true/use-native-transport="$USENATIVETRANSPORT"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/view-distance=10/view-distance="$VIEWDISTANCE"/ /home/"$GAMESERVER"/serverfiles/server.properties
sed -i s/white-list=false/white-list="$WHITELIST"/ /home/"$GAMESERVER"/serverfiles/server.properties

#Non-MVP configs
#sed -i s/enable-rcon=false/enable-rcon="$ENABLERCON"/ /home/"$GAMESERVER"/serverfiles/server.properties
#sed -i s/rcon.password=adminU74EVnZv/rcon.password="$RCONPASSWORD"/ /home/"$GAMESERVER"/serverfiles/server.properties
#sed -i s/rcon.port=25575/rcon.port="$RCONPORT"/ /home/"$GAMESERVER"/serverfiles/server.properties
#sed -i s/resource-pack=/resource-pack="$RESOURCEPACK"/ /home/"$GAMESERVER"/serverfiles/server.properties

# Setup crons and create systemd service file
service_config

# Start the service and setup firewall
ufw_install
ufw allow "$PORT"
ufw enable
fail2ban_install
systemctl start "$GAMESERVER".service
systemctl enable "$GAMESERVER".service
stackscript_cleanup