-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·172 lines (134 loc) · 5 KB
/
install
File metadata and controls
executable file
·172 lines (134 loc) · 5 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
set -euo pipefail
[[ "$(id -u)" -ne 0 ]] && exec sudo "${0}" "${@}"
export server_user="hlds"
export home_dir="/var/${server_user}"
export tmp_dir="/tmp/cs16-server"
bin_dir="/usr/bin"
config_dir="/etc/hlds"
man_dir="/usr/share/man/man1"
service_dir="/usr/lib/systemd/system"
abort_install() {
pgrep steamcmd &> /dev/null && pkill -SIGINT steamcmd &> /dev/null
printf "\nInstallation aborted\n" 1>&2
exit 1
}
trap abort_install SIGINT
remove_server() {
if ! id "${server_user}" &> /dev/null; then
printf "Server isn't installed\n" 1>&2
exit 1
elif pgrep -u "${server_user}" &> /dev/null; then
printf "%s user has processes running\n" "${server_user}" 1>&2
printf "Stop them before uninstalling the server\n" 1>&2
exit 1
fi
rm -vrf "${config_dir}"
rm -vf "${bin_dir}/cs16-server"
rm -vf "${man_dir}/cs16-server.1.gz"
[[ -x "$(command -v systemctl)" ]] && rm -vf "${service_dir}/cs16-server.service"
userdel -r "${server_user}" &> /dev/null
}
check_depends() {
if ! grep -q 'libstdc++.so.6 (libc6)' < <(ldconfig -p); then
printf "Install 32-bit libstdc++\n" 1>&2
printf "See README.md for details\n" 1>&2
exit 1
fi
pkgs=("xz" "curl")
missing_pkgs=""
for pkg in "${pkgs[@]}"; do
[[ -x "$(command -v "${pkg}")" ]] || missing_pkgs="${missing_pkgs} ${pkg}"
done
if [[ -x "$(command -v sestatus)" ]] && [[ ! -x "$(command -v semanage)" ]]; then
missing_pkgs="${missing_pkgs} policycoreutils-python-utils"
fi
if [[ -n "${missing_pkgs}" ]]; then
printf "Install the following packages:%s\n" "${missing_pkgs}" 1>&2
exit 1
fi
}
install_stage_one() {
if id "${server_user}" &> /dev/null; then
printf "Server is already installed\n" 1>&2
exit 1
fi
[[ -d "${tmp_dir}" ]] && rm -vrf "${tmp_dir}"
mkdir -vp "${tmp_dir}"
pushd "${tmp_dir}"
links=(
"https://steamcdn-a.akamaihd.net/client/steamcmd_linux.tar.gz"
"https://github.com/Bots-United/metamod-p/releases/download/v1.21p38/metamod_i686_linux_win32-1.21p38.tar.xz"
"https://www.amxmodx.org/amxxdrop/1.10/amxmodx-1.10.0-git5474-base-linux.tar.gz"
"https://www.amxmodx.org/amxxdrop/1.10/amxmodx-1.10.0-git5474-cstrike-linux.tar.gz"
"https://github.com/yapb/yapb/releases/download/4.4.957/yapb-4.4.957-linux.tar.xz"
)
for link in "${links[@]}"; do
printf "==> Downloading %s\n" "${link}"
if ! curl -fLO "${link}"; then
printf "Failed to download %s\n" "${link}" 1>&2
exit 1
fi
done
popd
mkdir -v "${home_dir}"
chmod -v 700 "${home_dir}"
useradd -r -M -s "$(command -v nologin)" -d "${home_dir}" -c "Counter-Strike 1.6 Dedicated Server" "${server_user}"
chown -v "${server_user}":"${server_user}" "${home_dir}"
}
install_stage_two() {
set -euo pipefail
mkdir -v "${home_dir}/.steam"
cd "${home_dir}/.steam"
ln -sfv . steam
for arc in "${tmp_dir}/"*.tar.*; do
tar xvf "${arc}"
done
# Needs to run a few times to download and validate everything
for _i in {1..3}; do
# steamcmd update returns an error on first tries, redirect stderr to stdout
./steamcmd.sh +force_install_dir "${home_dir}/cs16" +login anonymous +app_update 90 validate +quit 2>&1
done
# Temporary fix for 4.4.957
chmod -v 755 addons/yapb/data/*
mv -vf addons ../cs16/cstrike
mkdir -vp ../cs16/cstrike/addons/metamod/dlls
mv -vf metamod.so ../cs16/cstrike/addons/metamod/dlls
# Remove part for Windows
rm -vf metamod.dll
# amxmodx: on
# yapb bots: off
printf "linux addons/amxmodx/dlls/amxmodx_mm_i386.so\n" > ../cs16/cstrike/addons/metamod/plugins.ini
printf ";;linux addons/yapb/bin/yapb.so\n" >> ../cs16/cstrike/addons/metamod/plugins.ini
ln -sfv linux32 sdk32
# Create empty files so hlds_run won't complain
touch ../cs16/cstrike/{listip.cfg,banned.cfg}
}
install_stage_three(){
rm -vrf "${tmp_dir}"
install -vm 755 cs16-server/cs16-server -t "${bin_dir}"
install -vDm 644 cs16-server/cs16-server.conf -t "${config_dir}"
install -vm 644 cs16-server/cs16-server.1 -t "${man_dir}"
gzip -vf "${man_dir}/cs16-server.1"
if [[ -x "$(command -v semanage)" ]]; then
semanage fcontext -a -t bin_t "${home_dir}/cs16/hlds_run"
restorecon -v "${home_dir}/cs16/hlds_run"
fi
if [[ -x "$(command -v systemctl)" ]]; then
install -m 644 cs16-server/cs16-server.service -t "${service_dir}"
printf "\nRun \"systemctl enable cs16-server\" to start server on boot"
fi
printf "\nhlds parameters can be set in %s/cs16-server.conf\n" "${config_dir}"
printf "\nInstallation completed\n\n"
}
case "${1:-}" in
"remove")
remove_server
;;
"")
check_depends
install_stage_one
runuser -u "${server_user}" -- /bin/bash -c "$(declare -f install_stage_two) && install_stage_two"
install_stage_three
;;
esac