Last active
July 7, 2023 19:38
-
-
Save meyt/4043f93f92fbb2d86faec9d6d4416cfc to your computer and use it in GitHub Desktop.
Setup CSGO server on linux/ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## | |
# Setup CSGO Server | |
# | |
# os: ubuntu 20.04 | |
## | |
HOSTNAME="csgo.meyti.ir" | |
ADMINPASS="adminpass" | |
SERVERPASS="serverpass" | |
CSGOTOKEN="thetoken" | |
set -x | |
set -e | |
# prepare | |
sudo apt install lib32gcc1 | |
sudo useradd -m steam || true | |
sudo -u steam mkdir -p /home/steam/Steam | |
sudo -u steam wget -O /home/steam/steamcmd_linux.tar.gz http://media.steampowered.com/client/steamcmd_linux.tar.gz | |
sudo -u steam tar xfvz /home/steam/steamcmd_linux.tar.gz -C /home/steam | |
# install | |
sudo -u steam /home/steam/steamcmd.sh \ | |
+login anonymous \ | |
+force_install_dir /home/steam/csgo-server/ \ | |
+app_update 740 validate \ | |
+quit | |
# configs | |
sudo -u steam cat > /home/steam/csgo-server/csgo/cfg/server.cfg << EOL | |
// Hostname - Name of the server. | |
hostname "${HOSTNAME}" | |
// RCON - remote console password. | |
rcon_password "${ADMINPASS}" | |
// Server password - for private servers. | |
sv_password "${SERVERPASS}" | |
// Email - Server admin email. | |
// Example: sv_contact "email@example.com" | |
// sv_contact "" | |
// LAN mode - Server is a LAN server; can't connect from the internet. VAC (Valve Anti-Cheat) is disabled in this mode. | |
// Default: sv_lan 0 | |
sv_lan 0 | |
// Cheats mode - Server is disabled to use cheats by default;Commands like noclip,god are disabled to be exploited by the players. VAC (Valve Anti-Cheat) is disabled in this mode when value is set to '1'. | |
// Default: sv_cheats 0 | |
// Cheats ON: sv_cheats 1 | |
sv_cheats 0 | |
// Tags - Used to provide extra information to clients when they're browsing for servers. Separate tags with a comma. | |
// Example: sv_tags "128-tick,deathmatch,dm,ffa,pistol,dust2" | |
sv_tags "" | |
// Region - The region of the world to report this server in. | |
// Default: -1 | |
// 0 - US East, 1 - US West, 2 - South America, 3 - Europe, 4 - Asia, 5 - Australia, 6 - Middle East, 7 - Africa | |
sv_region -1 | |
// ............................. Server Logging ............................. // | |
// Enable log - Enables logging to file, console, and udp < on | off >. | |
// Recommended: log on | |
log on | |
// Log bans - Log server bans in the server logs. | |
// Default: sv_logbans 1 | |
// Recommended: sv_logbans 1 | |
sv_logbans 1 | |
// Log echo - Display log information to the server console. | |
// Default: sv_logecho 1 | |
// Recommended: sv_logecho 1 | |
sv_logecho 1 | |
// Log file - Log server information in the log file. | |
// Default: sv_logfile 1 | |
// Recommended: sv_logfile 1 | |
sv_logfile 1 | |
// One file log - Log server information to only one file. | |
// Default: sv_log_onefile 0 | |
// Recommended: sv_log_onefile 0 | |
sv_log_onefile 0 | |
// Server Hibernation | |
sv_hibernate_when_empty 1 | |
sv_hibernate_ms 5 | |
// ............................. Server Query ............................. // | |
// More info at: https://www.gametracker.com/games/csgo/forum.php?thread=91691 | |
host_name_store 1 | |
host_info_show 1 | |
host_players_show 2 | |
// ................................ Ban List ................................ // | |
// User ban - Server banlist based on user steam ID. | |
// Recommended: exec banned_user.cfg | |
exec banned_user.cfg | |
// IP ban - Server banlist based on user IP. | |
// Recommended: exec banned_ip.cfg | |
exec banned_ip.cfg | |
// Write ID - Writes a list of permanently-banned user IDs to banned_user.cfg. | |
writeid | |
// Write IP - Save the ban list to banned_ip.cfg. | |
writeip | |
EOL | |
sudo cat > /etc/systemd/system/csgoserver.service << EOL | |
[Unit] | |
Description="csgo server" | |
After=network.target | |
[Service] | |
User=steam | |
Group=users | |
Environment="LANG=en_US.UTF-8" | |
Environment="LC_ALL=en_US.UTF-8" | |
WorkingDirectory=/home/steam/csgo-server | |
ExecStart=/home/steam/csgo-server/srcds_run -game csgo -console -usercon +game_type 1 +game_mode 2 +mapgroup mg_bomb +map de_dust +sv_setsteamaccount ${CSGOTOKEN} -net_port_try 1 | |
[Install] | |
WantedBy=multi-user.target | |
EOL | |
sudo cat > /usr/bin/csgoupdate << EOL | |
#!/bin/bash | |
systemctl stop csgoserver | |
sudo -u steam /home/steam/steamcmd.sh +login anonymous +force_install_dir /home/steam/csgo-server/ +app_update 740 +quit | |
systemctl start csgoserver | |
EOL | |
chmod +x /usr/bin/csgoupdate | |
sudo cat > /usr/bin/csgocheck << EOL | |
#!/bin/bash | |
curl -s "https://api.steampowered.com/ISteamApps/UpToDateCheck/v0001/?appid=730&version=\$(grep -Po '^(?:PatchVersion=)\K([0-9.]*)' /home/steam/csgo-server/csgo/steam.inf)&format\=json" | |
EOL | |
chmod +x /usr/bin/csgocheck | |
# finalize | |
sudo systemctl daemon-reload | |
sudo systemctl enable csgoserver | |
sudo systemctl start csgoserver |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
generating token for CSGO (appid: 730): http://steamcommunity.com/dev/managegameservers
https://partner.steamgames.com/doc/webapi/ISteamApps#UpToDateCheck
https://developer.valvesoftware.com/wiki/Counter-Strike:_Global_Offensive_Dedicated_Servers