summarylogtreecommitdiffstats
path: root/forge-server.install
blob: d4a3d577d8c2f9bc92675825eb32a7260c86b050 (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
_forge_name="forge-1.10.2"
_forge_user="forge-1-10-2"
_conflict_ver="1.10.2_12.18.3.2185-3"
_good_ver="1.10.2_12.18.3.2185-7"
_server_root="/srv/${_forge_name}"

post_install() {
	if ! getent group "$_forge_user" &>/dev/null; then
		echo "Adding ${_forge_user} system group..."
		groupadd -r "$_forge_user" 1>/dev/null
	fi

	if ! getent passwd "$_forge_user" &>/dev/null; then
		echo "Adding ${_forge_user} system user..."
		useradd -r -g "${_forge_user}" -d "$_server_root" "$_forge_user" 1>/dev/null
	fi

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

	echo "The world data is stored under ${_server_root} and the server runs as the forge user to increase security."
	echo "Use the forged script under /usr/bin/${_forge_name}d to start, stop or backup the server."
	echo "Adjust the configuration file under /etc/conf.d/${_forge_name} to your liking."
	echo "Make sure to change the SERVER_START_CMD variable if you want to use a JVM other than OpenJDK 8."
	echo "Please note that you need Java 8 in order to run Forge."
	echo "For the server to start you have to accept the EULA in ${_server_root}/eula.txt!"
	echo "The EULA file is generated after the first server start."
}

post_upgrade() {
	if [ "$(vercmp "$2" "$_conflict_ver")" -ge 0 ] && [ "$(vercmp "$2" "$_good_ver")" -lt 0 ]; then
		post_install

		echo "==> NOTICE: All filenames have been changed from \"forged\" to \"${_forge_name}d\"!"
		echo "==> For example:"
		echo "==> /usr/lib/systemd/system/forged.service -> /usr/lib/systemd/system/${_forge_name}d.service"
		echo "==> /usr/bin/forged -> /usr/bin/${_forge_name}d"
		echo "==> /srv/forge -> ${_server_root}"

		if [ -d "/srv/forge" ]; then
			find "/srv/forge" -mindepth 1 -maxdepth 1 | while read -r _file; do
				mv "$_file" "${_server_root}${_file#"/srv/forge"}"
			done
			rm -rf "/srv/forge"
			echo "==> Game saves in /srv/forge were moved to ${_server_root}."
		fi

		echo "==> The forge user was preserved on your system."
	fi
	chown -R "${_forge_user}:${_forge_user}" "${_server_root}"
}

post_remove() {
	[ -d "$_server_root" ] && echo "Game saves in ${_server_root} were kept on your system."
	echo "The ${_forge_user} user was preserved on your system."
}