diff options
author | Gordian Edenhofer | 2015-09-20 23:23:34 +0200 |
---|---|---|
committer | Gordian Edenhofer | 2015-09-20 23:23:34 +0200 |
commit | d897c06c8606636185dc36099a59a9fb00140ec3 (patch) | |
tree | 75874fe273afc6456857c20973d35ad7235d58c1 /minecraft-server.install | |
parent | f2bd9cf1fca19865f0ddc44e8ee235d7291076ed (diff) | |
download | aur-d897c06c8606636185dc36099a59a9fb00140ec3.tar.gz |
Rewriting package + Updating pkgrel
Diffstat (limited to 'minecraft-server.install')
-rw-r--r-- | minecraft-server.install | 72 |
1 files changed, 47 insertions, 25 deletions
diff --git a/minecraft-server.install b/minecraft-server.install index 3031324e0028..97c66de3dae1 100644 --- a/minecraft-server.install +++ b/minecraft-server.install @@ -1,33 +1,55 @@ +USER="minecraft" +SERVER_ROOT="/srv/minecraft" + +_update() { + getent group "${USER}" &>/dev/null + if [ $? -ne 0 ]; then + echo -e "\e[34;1m==>\e[39;1m Adding ${USER} system group... \e[0m" + groupadd -r ${USER} 1>/dev/null + fi + + getent passwd "${USER}" &>/dev/null + if [ $? -ne 0 ]; then + echo -e "\e[34;1m==>\e[39;1m Adding ${USER} system user... \e[0m" + useradd -r -g ${USER} -d "${SERVER_ROOT}" ${USER} 1>/dev/null + fi + + chown -R ${USER}:${USER} "${SERVER_ROOT}" + + echo -e "\e[34;1m==>\e[39;1m NOTE: The world data is stored under ${SERVER_ROOT} and the server runs \e[0m" + echo -e "\e[34;1m==>\e[39;1m as ${USER} user to increase security. \e[0m" + echo -e "\e[34;1m==>\e[39;1m NOTE: Use the minecraft script under /usr/bin/minecraft to start, stop or backup the server \e[0m" + echo -e "\e[34;1m==>\e[39;1m and the configuration file under /etc/conf.d/minecraft to adjust it to your liking. \e[0m" + echo -e "\e[34;1m==>\e[39;1m NOTE: For the server to start you have to accept the EULA in ${SERVER_ROOT}/eula.txt \e[0m" + echo -e "\e[34;1m==>\e[39;1m which is generated after the first server start. \e[0m" +} + post_install() { - post_upgrade + _update } post_upgrade() { - getent group "minecraft" &>/dev/null || groupadd -r minecraft 1>/dev/null - getent passwd "minecraft" &>/dev/null && usermod -s "/usr/bin/nologin" minecraft &>/dev/null || useradd -r -g minecraft -d "/srv/minecraft" -s "/usr/bin/nologin" minecraft 1>/dev/null - touch /srv/minecraft/server.log - chown -R minecraft:minecraft "/srv/minecraft" 1>/dev/null - ln -s /srv/minecraft/server.log /var/log/minecraft.log &>/dev/null - # Removes old data from previous version - cat << EOF -==> World data is stored under /srv/minecraft -==> The server runs as "minecraft", not root -==> You can access the server's console as root with: - $ screen -r minecraft -==> The systemd service is called "minecraftd.service" -==> Calling "stop" or "restart" with systemctl will gracefully exit the server, saving world data -==> Modify /etc/conf.d/minecraft to change the invocation of the server if you wish -==> A script at /usr/bin/minecraftctl is also provided. See the wiki for details on its usage. -==> For the server to start you have to accept the EULA in /srv/minecraft/eula.txt - -EOF + _update +} + +pre_remove() { + echo -e "\e[34;1m==>\e[39;1m Stopping and disabling minecraftd... \e[0m" + systemctl stop minecrafd.service + systemctl disable minecraftd.service + + /usr/bin/minecraftd stop > /dev/null } post_remove() { - if getent passwd "minecraft" >/dev/null; then - userdel minecraft >/dev/null - fi - if getent group "minecraft" >/dev/null; then - groupdel minecraft >/dev/null - fi + echo -e "\e[34;1m==>\e[39;1m Removing ${USER} system user and group... \e[0m" + if getent passwd ${USER} >/dev/null 2>&1; then + userdel ${USER} 2>/dev/null + fi + if getent group ${USER} >/dev/null 2>&1; then + groupdel ${USER} + fi + + # Notifying the user of kept dirs + [ -d ${SERVER_ROOT} ] && chown root:root ${SERVER_ROOT} && echo -e "\e[34;1m==>\e[39;1m NOTE: Game saves in ${SERVER_ROOT} were kept on your system.\e[0m" + [ -d /etc/conf.d/minecraft ] && echo -e "\e[34;1m==>\e[39;1m NOTE: Your configuration file /etc/conf.d/minecraft was kept on your system.\e[0m" } |