2015-09-20 14:23:34 -07:00
USER="minecraft"
SERVER_ROOT="/srv/minecraft"
2016-01-23 03:45:46 -08:00
post_install() {
2015-09-20 14:23:34 -07:00
getent group "${USER}" &>/dev/null
2015-12-13 06:32:38 -08:00
if [ $? -ne 0 ]; then
echo -e "\e[34;1m==>\e[39;1m Adding ${USER} system group... \e[0m"
2015-09-20 14:23:34 -07:00
groupadd -r ${USER} 1>/dev/null
fi
getent passwd "${USER}" &>/dev/null
if [ $? -ne 0 ]; then
2015-12-13 06:32:38 -08:00
echo -e "\e[34;1m==>\e[39;1m Adding ${USER} system user... \e[0m"
2015-09-20 14:23:34 -07:00
useradd -r -g ${USER} -d "${SERVER_ROOT}" ${USER} 1>/dev/null
fi
2015-12-13 06:32:38 -08:00
chown -R ${USER}:${USER} "${SERVER_ROOT}"
2015-09-20 14:23:34 -07:00
echo -e "\e[34;1m==>\e[39;1m NOTE: The world data is stored under ${SERVER_ROOT} and the server runs \e[0m"
2015-12-13 06:32:38 -08:00
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/minecraftd to start, stop or backup the server \e[0m"
2015-09-20 14:23:34 -07:00
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"
2015-12-13 06:32:38 -08:00
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"
2015-09-20 14:23:34 -07:00
}
2015-07-03 10:16:00 -07:00
post_upgrade() {
2016-01-23 03:45:46 -08:00
chown -R ${USER}:${USER} "${SERVER_ROOT}"
if [[ -f /etc/conf.d/minecraft.pacnew ]]; then
2016-01-25 15:18:20 -08:00
echo -e "\e[34;1m==>\e[39;1m NOTE: There was a new change on how backup files are handled! Unfortunately this makes \e[0m"
echo -e "\e[34;1m==>\e[39;1m old backups incompatible with the newly implemeted restore feature. Bare in mind that no data is lost \e[0m"
echo -e "\e[34;1m==>\e[39;1m neither are those backups useless. They just will not work with the restore capability of the management script. \e[0m"
echo -e "\e[34;1m==>\e[39;1m NOTE: Please merge the new configuration file into /etc/conf.d/minecraft by e.g. using pacdiff. \e[0m"
2016-01-23 03:45:46 -08:00
fi
2015-09-20 14:23:34 -07:00
}
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
2015-07-03 10:16:00 -07:00
}
post_remove() {
2015-09-20 14:23:34 -07:00
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
2016-01-23 03:45:46 -08:00
[[ -d "${SERVER_ROOT}" ]] && chown -R 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"
[[ -f "/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"
2015-07-03 10:16:00 -07:00
}