forked from kus/cs2-modded-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
169 lines (149 loc) · 6.04 KB
/
install.sh
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
#!/usr/bin/env bash
# Variables
user="steam"
IP="0.0.0.0"
PUBLIC_IP=$(dig +short myip.opendns.com @resolver1.opendns.com)
CUSTOM_FILES="${CUSTOM_FOLDER:-custom_files}"
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release
DISTRO_OS=$NAME
DISTRO_VERSION=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
# linuxbase.org
DISTRO_OS=$(lsb_release -si)
DISTRO_VERSION=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release
DISTRO_OS=$DISTRIB_ID
DISTRO_VERSION=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
# Older Debian/Ubuntu/etc.
DISTRO_OS=Debian
DISTRO_VERSION=$(cat /etc/debian_version)
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
DISTRO_OS=$(uname -s)
DISTRO_VERSION=$(uname -r)
fi
# Download latest stop script
curl --silent --output "stop.sh" "https://raw.githubusercontent.com/kus/csgo-modded-server/master/stop.sh" && chmod +x stop.sh
# Check distrib
if ! command -v apt-get &> /dev/null; then
echo "ERROR: OS distribution not supported... $DISTRO_OS $DISTRO_VERSION"
exit 1
fi
# Check root
if [ "$EUID" -ne 0 ]; then
echo "ERROR: Please run this script as root..."
exit 1
fi
if [ -z "$PUBLIC_IP" ]; then
echo "ERROR: Cannot retrieve your public IP address..."
exit 1
fi
echo "Updating Operating System..."
apt update -y -q && apt upgrade -y -q >/dev/null
if [ "$?" -ne "0" ]; then
echo "ERROR: Updating Operating System..."
exit 1
fi
echo "Adding i386 architecture..."
dpkg --add-architecture i386 >/dev/null
if [ "$?" -ne "0" ]; then
echo "ERROR: Cannot add i386 architecture..."
exit 1
fi
echo "Installing required packages for $DISTRO_OS $DISTRO_VERSION..."
apt-get update -y -q >/dev/null
if [ "${DISTRO_OS}" == "Ubuntu" ]; then
if [ "${DISTRO_VERSION}" == "16.04" ]; then
apt-get install -y -q curl wget screen nano file tar bzip2 gzip unzip hostname bsdmainutils python3 util-linux xz-utils ca-certificates binutils bc jq tmux netcat lib32stdc++6 libsdl2-2.0-0:i386 lib32gcc1 steamcmd >/dev/null
elif [ "${DISTRO_VERSION}" == "18.04" ]; then
apt-get install -y -q curl wget screen nano file tar bzip2 gzip unzip hostname bsdmainutils python3 util-linux xz-utils ca-certificates binutils bc jq tmux netcat lib32stdc++6 libsdl2-2.0-0:i386 distro-info lib32gcc1 steamcmd >/dev/null
elif [ "${DISTRO_VERSION}" == "20.04" ]; then
apt-get install -y -q curl wget screen nano file tar bzip2 gzip unzip hostname bsdmainutils python3 util-linux xz-utils ca-certificates binutils bc jq tmux netcat lib32stdc++6 libsdl2-2.0-0:i386 distro-info lib32gcc1 steamcmd >/dev/null
elif [ "${DISTRO_VERSION}" == "22.04" ]; then
apt-get install -y -q curl wget screen nano file tar bzip2 gzip unzip hostname bsdmainutils python3 util-linux xz-utils ca-certificates binutils bc jq tmux netcat lib32stdc++6 libsdl2-2.0-0:i386 distro-info lib32gcc-s1 steamcmd >/dev/null
else
echo "$DISTRO_OS $DISTRO_VERSION not officially supported; using Ubuntu 22.04 config"
apt-get install -y -q curl wget screen nano file tar bzip2 gzip unzip hostname bsdmainutils python3 util-linux xz-utils ca-certificates binutils bc jq tmux netcat lib32stdc++6 libsdl2-2.0-0:i386 distro-info lib32gcc-s1 steamcmd >/dev/null
fi
else
echo "ERROR: OS distribution not supported. $DISTRO_OS $DISTRO_VERSION"
exit 1
fi
echo "Checking $user user exists..."
getent passwd ${user} >/dev/null 2&>1
if [ "$?" -ne "0" ]; then
echo "Adding $user user..."
addgroup ${user} && \
adduser --system --home /home/${user} --shell /bin/false --ingroup ${user} ${user} && \
usermod -a -G tty ${user} && \
mkdir -m 777 /home/${user}/csgo && \
chown -R ${user}:${user} /home/${user}/csgo
if [ "$?" -ne "0" ]; then
echo "ERROR: Cannot add user $user..."
exit 1
fi
fi
echo "Checking steamcmd exists..."
if [ ! -d "/steamcmd" ]; then
mkdir /steamcmd && cd /steamcmd
wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz
tar -xvzf steamcmd_linux.tar.gz
mkdir -p /root/.steam/sdk32/
ln -s /steamcmd/linux32/steamclient.so /root/.steam/sdk32/steamclient.so
fi
echo "Downloading any updates for CS:GO..."
/steamcmd/steamcmd.sh +login anonymous \
+force_install_dir /home/${user}/csgo \
+app_update 740 \
+quit
cd /home/${user}/csgo/csgo/warmod/ && python3 -m http.server 80 </dev/null &>/dev/null &
cd /home/${user}
if [ "${DISTRO_OS}" == "Ubuntu" ]; then
if [ "${DISTRO_VERSION}" == "22.04" ]; then
# https://forums.alliedmods.net/showthread.php?t=336183
rm /home/${user}/csgo/bin/libgcc_s.so.1
fi
fi
echo "Downloading mod files..."
wget --quiet https://github.com/kus/csgo-modded-server/archive/master.zip
unzip -o -qq master.zip
cp -rlf csgo-modded-server-master/csgo/ /home/${user}/csgo/
cp -R csgo-modded-server-master/custom_files/ /home/${user}/csgo/custom_files/
cp -R csgo-modded-server-master/custom_files_example/ /home/${user}/csgo/custom_files_example/
rm -r csgo-modded-server-master master.zip
echo "Dynamically writing /home/$user/csgo/csgo/cfg/secrets.cfg"
if [ ! -z "$RCON_PASSWORD" ]; then
echo "rcon_password \"$RCON_PASSWORD\"" > /home/${user}/csgo/csgo/cfg/secrets.cfg
fi
if [ ! -z "$STEAM_ACCOUNT" ]; then
echo "sv_setsteamaccount \"$STEAM_ACCOUNT\" // Required for online https://steamcommunity.com/dev/managegameservers" >> /home/${user}/csgo/csgo/cfg/secrets.cfg
fi
if [ ! -z "$SERVER_PASSWORD" ]; then
echo "sv_password \"$SERVER_PASSWORD\"" >> /home/${user}/csgo/csgo/cfg/secrets.cfg
fi
echo "" >> /home/${user}/csgo/csgo/cfg/secrets.cfg
echo "echo \"secrets.cfg executed\"" >> /home/${user}/csgo/csgo/cfg/secrets.cfg
echo "Merging in custom files from ${CUSTOM_FILES}"
cp -RT /home/${user}/csgo/${CUSTOM_FILES}/ /home/${user}/csgo/csgo/
chown -R ${user}:${user} /home/${user}/csgo
cd /home/${user}/csgo
echo "Starting server on $PUBLIC_IP:$PORT"
./srcds_run \
-console \
-usercon \
-autoupdate \
-game csgo \
-tickrate $TICKRATE \
-port $PORT \
+map de_dust2 \
-maxplayers_override $MAXPLAYERS \
-authkey $API_KEY
+ip $IP \
+game_type 0 \
+game_mode 0 \
+mapgroup mg_active