Skip to content

Instantly share code, notes, and snippets.

@kpheasey
Last active July 27, 2023 20:12
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save kpheasey/35360b1a083870fac3ec to your computer and use it in GitHub Desktop.
Save kpheasey/35360b1a083870fac3ec to your computer and use it in GitHub Desktop.
DO Ubuntu 14.04 Droplet to ARK Server
#!/bin/bash
# Updating Ubunut
echo "updating ubunutu... please be patient"
apt-get update && apt-get upgrade -y
echo "installing required packages... please be patient"
apt-get install htop lib32gcc1 -y
# Create steam user if needed
echo "creating steam user"
read -s -p "User Password: " password
echo
adduser steam --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password
echo "steam:$password" | chpasswd
gpasswd -a steam sudo
# Configure SSH
echo "configuring ssh"
port=$((1025 + $RANDOM))
echo "using port $port"
file=/etc/ssh/sshd_config
cp -p $file $file.old &&
awk '
$1=="Port" {$2="'$port'"}
$1=="PermitRootLogin" {$2="no"}
{print}
' $file.old > $file
service ssh restart
# Create the swap
echo "creating swap"
fallocate -l 6G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
sh -c 'echo "/swapfile none swap sw 0 0" >> /etc/fstab'
# Increase file usage limit
echo "increasing file usage limits"
sh -c 'echo "* soft nofile 1000000" >> /etc/security/limits.conf'
sh -c 'echo "* hard nofile 1000000" >> /etc/security/limits.conf'
sh -c 'echo "session required pam_limits.so" >> /etc/security/limits.conf'
# Install SteamCMD if needed
if [ ! -d "/home/steam/steamcmd" ]; then
echo "installing SteamCMD"
mkdir /home/steam/steamcmd
cd /home/steam/steamcmd
wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz
tar -xvzf steamcmd_linux.tar.gz
rm steamcmd_linux.tar.gz
chown -R steam:steam /home/steam/steamcmd
fi
# Install ark
echo "installing ark"
curl -sL http://git.io/vtf5N | bash -s steam
su - steam -c "arkmanager install"
# Configure the server
# server name
while true; do
read -p "ARK Server Name (no special characters): " ark_SessionName
if ! [[ "$ark_SessionName" =~ [^(a-zA-Z0-9|[:blank])] ]]; then
if [[ -z "${ark_SessionName// }" ]]; then
echo "Cannot be empty"
else
break
fi
else
echo 'Invalid input!'
fi
done
# server password
while true; do
read -p "ARK Server Password (blank for none, no special characters): " ark_ServerPassword
if ! [[ "$ark_ServerPassword" =~ [^a-zA-Z0-9] ]]; then
break
else
echo 'Invalid input!'
fi
done
# server admin password
while true; do
read -p "ARK Server Admin Password (no special characters): " ark_ServerAdminPassword
if ! [[ "$ark_ServerAdminPassword" =~ [^a-zA-Z0-9] ]]; then
if [[ -z "${ark_ServerAdminPassword// }" ]]; then
echo "Cannot be empty"
else
break
fi
else
echo 'Invalid input!'
fi
done
file="/etc/arkmanager/arkmanager.cfg"
tmp_file="/etc/arkmanager/_arkmanager.cfg"
awk '{gsub("ark_SessionName=\"ARK Server Tools\"", "ark_SessionName=\"'"$ark_SessionName"'\""); print $0}' $file > $tmp_file && mv $tmp_file $file
awk '{gsub("ark_ServerPassword=\"\"", "ark_ServerPassword=\"'"$ark_ServerPassword"'\""); print $0}' $file > $tmp_file && mv $tmp_file $file
awk '{gsub("ark_ServerAdminPassword=\"keyboardcat\"", "ark_ServerAdminPassword=\"'"$ark_ServerAdminPassword"'\""); print $0}' $file > $tmp_file && mv $tmp_file $file
awk '{gsub("ark_MaxPlayers=\"70\"", "ark_MaxPlayers=\"10\""); print $0}' $file > $tmp_file && mv $tmp_file $file
su - steam -c "arkmanager start"
echo "installation finished, please note the following important information"
echo "ssh port: $port"
echo "ssh user: steam"
echo "ssh user password: $password"
echo "ark server name: $ark_SessionName"
echo "ark server password: $ark_ServerPassword"
echo "ark server admin password: $ark_ServerAdminPassword"
@klightspeed
Copy link

Wouldn't it also be a good idea to configure iptables to only accept connections to established/related connections, SSH port, and to the ARK server ports?

i.e.

apt-get install iptables-persistent
serverport=$(( 16384 + $RANDOM ))
queryport=$(( serverport + 4 ))
awk '{gsub("ark_Port=\"7778\"", ark_Port=\"'"$serverport"'\""); print $0}' $file > $tmp_file && mv $tmp_file $file
awk '{gsub("ark_QueryPort=\"27016\"", ark_Port=\"'"$queryport"'\""); print $0}' $file > $tmp_file && mv $tmp_file $file
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport $port -j ACCEPT
iptables -A INPUT -p udp -m udp --dport $serverport -j ACCEPT
iptables -A INPUT -p udp -m udp --dport $queryport -j ACCEPT
iptables -P INPUT DROP

@timjrobinson
Copy link

Gave the following errors for me on a new Ubuntu 14.04 droplet:

installing ark
ARK Server Tools were correctly installed in your system inside the home directory of steam!
[  WARN  ]      Your ARK server exec could not be found.
[  ERROR  ]     You have not rights to write in the log directory.
Creating the ARK server root directory (/home/steam/ARK)
Redirecting stderr to '/home/steam/Steam/logs/stderr.txt'
ILocalize::AddFile() failed to load file "public/steambootstrapper_english.txt".
[  0%] Checking for available update...
[  0%] Downloading update (0 of 10,131 KB)...
...
[ 99%] Downloading update (10,131 of 10,131 KB)...
[100%] Download Complete.
[----] Applying update...
[----] Extracting package...
[----] Extracting package...
[----] Extracting package...
[----] Installing update...
[----] Installing update...
[----] Installing update...
[----] Cleaning up...
[----] Update complete, launching...
./steamcmd.sh: line 30: 20675 Segmentation fault      (core dumped) $DEBUGGER "$STEAMROOT/$PLATFORM/$STEAMEXE" "$@"
ARK Server Name (no special characters):
ARK Server Password (blank for none, no special characters): 
ARK Server Admin Password (no special characters):
[  WARN  ]      Your ARK server exec could not be found.
[  ERROR  ]     You have not rights to write in the log directory.
The server is starting...
/usr/local/bin/arkmanager: line 591: /var/log/arktools/arkserver.log: Permission denied
/usr/local/bin/arkmanager: line 592: /var/log/arktools/arkmanager.log: Permission denied
The server is now up
installation finished, please note the following important information

@phellipeandrade
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment