aboutsummarylogtreecommitdiffstats
path: root/spigot.install
blob: ea9aaf50127844575cb2c421e72f4f75a986c9b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
USER="craftbukkit"
SERVER_ROOT="/srv/craftbukkit"

_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 spigot script under /usr/bin/spigot 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/spigot 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() {
    _update
}

post_upgrade() {
    _update
}

pre_remove() {
	echo -e "\e[34;1m==>\e[39;1m Stopping and disabling spigot daemon... \e[0m"
	systemctl stop spigot.service
    systemctl disable spigot.service

	/usr/bin/spigot stop > /dev/null
}

post_remove() {
	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/spigot ] && echo -e "\e[34;1m==>\e[39;1m NOTE: Your configuration file /etc/conf.d/spigot was kept on your system.\e[0m"
}