summarylogtreecommitdiffstats
path: root/cuberite.install
blob: 3f1b17efd9b4759464990c6d219b81a88ca3b8e6 (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
_game="cuberite"
_user="cuberite"
_server_root="/srv/cuberite"

post_install() {
	getent group "${_user}" &>/dev/null
	if [ $? -ne 0 ]; then
		echo "Adding ${_user} system group..."
		groupadd -r ${_user} 1>/dev/null
	fi

	getent passwd "${_user}" &>/dev/null
	if [ $? -ne 0 ]; then
		echo "Adding ${_user} system user..."
		useradd -r -g ${_user} -d "${_server_root}" ${_user} 1>/dev/null
	fi

	chown -R ${_user}:${_user} "${_server_root}"

	echo "The world data is stored under ${_server_root} and the server runs as ${_user} user to increase security."
}

post_upgrade() {
	chown -R ${_user}:${_user} "${_server_root}"
}

pre_remove() {
	echo "Stopping and disabling ${_game}..."
	systemctl stop ${_game}.service
	systemctl disable ${_game}.service
}

post_remove() {
	# Notifying the user of kept dirs
	[[ -d "${_server_root}" ]] && chown -R root:root "${_server_root}" && echo "Game saves in ${_server_root} were kept on your system."

	echo "Removing ${_user} system user and group..."
	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
}