From 6a9340876159ea937b2c1ca2ca7175d7e03a23c3 Mon Sep 17 00:00:00 2001
From: TuRz4m <peps.isima@gmail.com>
Date: Mon, 4 Jan 2016 15:39:28 +0100
Subject: [PATCH 01/22] Fix Typo

---
 README.md | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index 8aabce0..b37c76e 100644
--- a/README.md
+++ b/README.md
@@ -59,9 +59,9 @@ You can easily configure automatic update and backup.
 If you edit the file `/my/path/to/ark/crontab` you can add your crontab job.  
 For example :  
 `# Update the server every hours`  
-`0 * * * * arkmanager update --warn --update-mods >> /ark/log/crontab.log 2&>1`    
+`0 * * * * arkmanager update --warn --update-mods >> /ark/log/crontab.log 2>&1`    
 `# Backup the server each day at 00:00  `  
-`0 0 * * * arkmanager backup >> /ark/log/crontab.log 2&>1`  
+`0 0 * * * arkmanager backup >> /ark/log/crontab.log 2>&1`  
 *You can check [this website](http://www.unix.com/man-page/linux/5/crontab/) for more information on cron.*
 
 To add mods, you only need to change the variable ark_GameModIds in *arkmanager.cfg* with a list of your modIds (like this  `ark_GameModIds="987654321,1234568"`). If UPDATEONSTART is enable, just restart your docker or use `docker exec ark arkmanager update --update-mods`.
@@ -75,8 +75,8 @@ To add mods, you only need to change the variable ark_GameModIds in *arkmanager.
 - Edit */my/path/to/ark/GameUserSetting.ini and Game.ini*
 - Edit */my/path/to/ark/arkserver.cfg* to add mods and configure warning time.
 - Add auto update every day and autobackup by editing */my/path/to/ark/crontab* with this lines :  
-`0 0 * * * arkmanager update --warn --update-mods >> /ark/log/crontab.log 2&>1`  
-`0 0 * * * arkmanager backup >> /ark/log/crontab.log 2&>1`  
+`0 0 * * * arkmanager update --warn --update-mods >> /ark/log/crontab.log 2>&1`  
+`0 0 * * * arkmanager backup >> /ark/log/crontab.log 2>&1`  
 - `docker start ark`
 - Check your server with :  
  `docker exec ark arkmanager status` 

From 7a16e83b09ecd1cfb82b011da9be6afe14ef58d7 Mon Sep 17 00:00:00 2001
From: TuRz4m <peps.isima@gmail.com>
Date: Tue, 5 Jan 2016 10:32:57 +0100
Subject: [PATCH 02/22] Add mods download on first run

---
 run.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/run.sh b/run.sh
index fbe2fe6..fb38aa4 100644
--- a/run.sh
+++ b/run.sh
@@ -33,6 +33,8 @@ if [ ! -d "/ark/server"  ] || [ ! -f "/ark/server/arkversion" ];then
 	arkmanager install
 	# Create mod dir
 	mkdir /ark/server/ShooterGame/Content/Mods
+	# Download mods
+	arkmanager update --update-mods
 else
 
 	if [ ${BACKUPONSTART} -eq 1 ]; then 

From fe31ba1f82eb2a54d8209f12cbf09f7ebdcc69e5 Mon Sep 17 00:00:00 2001
From: Lennart Weller <lhw+github@ring0.de>
Date: Thu, 28 Jan 2016 15:04:19 +0100
Subject: [PATCH 03/22] Add a docker-compose example file

---
 docker-compose.yml | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100644 docker-compose.yml

diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..bf00912
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,17 @@
+ark:
+  image: turzam/ark
+  environment:
+    SESSIONNAME: Ark Docker
+    SERVERMAP: TheIsland
+    SERVERPASSWORD: 
+    ADMINPASSWORD: adminpassword
+    BACKUPONSTART: 1
+    UPDATEONSTART: 1
+  volumes:
+    - /my/path/to/ark:/ark
+  ports:
+   - 7778:7778/udp
+   - 7778:7778
+   - 27015:27015/udp
+   - 27015:27015
+   - 32330:32330

From 6e5e3c2b81742236d91d6b007af71c5189040672 Mon Sep 17 00:00:00 2001
From: TuRz4m <peps.isima@gmail.com>
Date: Wed, 23 Mar 2016 15:31:28 +0100
Subject: [PATCH 04/22] Upgrade to Ark Server Tools 1.5

---
 Dockerfile            |  9 ++++++++-
 arkmanager-system.cfg |  4 ++++
 arkmanager-user.cfg   | 17 ++++++++++++++++-
 docker-compose.yml    |  2 ++
 run.sh                | 34 ++++++++++++++++++++++++----------
 5 files changed, 54 insertions(+), 12 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 054704a..a3dbcab 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -23,6 +23,10 @@ ENV BRANCH master
 ENV SERVERPORT 27015
 # Steam port (you can't remap with docker, it doesn't work)
 ENV STEAMPORT 7778
+# if the server should backup after stopping
+ENV BACKUPONSTOP 0
+# If the server warn the players before stopping
+ENV WARNONSTOP 0
 
 # Install dependencies 
 RUN apt-get update &&\ 
@@ -61,9 +65,12 @@ RUN ./install.sh steam
 # Allow crontab to call arkmanager
 RUN ln -s /usr/local/bin/arkmanager /usr/bin/arkmanager
 
-# Define default config file in /ark
+# Define default config file in /etc/arkmanager
 COPY arkmanager-system.cfg /etc/arkmanager/arkmanager.cfg
 
+# Define default config file in /etc/arkmanager
+COPY instance.cfg /etc/arkmanager/instances/main.cfg
+
 RUN chown steam -R /ark && chmod 755 -R /ark
 
 USER steam 
diff --git a/arkmanager-system.cfg b/arkmanager-system.cfg
index ab328d1..b665a2b 100644
--- a/arkmanager-system.cfg
+++ b/arkmanager-system.cfg
@@ -17,6 +17,7 @@ arkserverroot="/ark/server"                                         # path of yo
 arkserverexec="ShooterGame/Binaries/Linux/ShooterGameServer"        # name of ARK server executable
 arkbackupdir="/ark/backup"  		                            # path to backup directory
 arkautorestartfile="ShooterGame/Saved/.autorestart"                 # path to autorestart file
+arkStagingDir="/ark/staging"  
 
 # config Service
 servicename="arkserv"                                               # Name of the service (don't change if you don't know what are you doing)
@@ -30,5 +31,8 @@ ark_RCONPort="32330"                                                # RCON Port
 
 # steamdb specific
 appid=376030                                                        # Linux server App ID
+mod_appid=346110                                                    # App ID for mods
+
+defaultinstance="main"
 
 source /ark/arkmanager.cfg
diff --git a/arkmanager-user.cfg b/arkmanager-user.cfg
index a972ff4..edd74b1 100644
--- a/arkmanager-user.cfg
+++ b/arkmanager-user.cfg
@@ -3,6 +3,8 @@
 # comment out these values if you want to define them
 # inside your GameUserSettings.ini file
 serverMap=${SERVERMAP}                                          # server map (default TheIsland)
+#serverMapModId="469987622"                                         # Uncomment this to specify the Map Mod Id (<fileid> in http://steamcommunity.com/sharedfiles/filedetails/?id=<fileid>)
+#ark_TotalConversionMod="496735411"                                 # Uncomment this to specify a total-conversion mod
 ark_SessionName=${SESSIONNAME}                                  # if your session name needs special characters please use the .ini instead
 ark_ServerPassword=${SERVERPASSWORD}                            # ARK server password, empty: no password required to login
 ark_ServerAdminPassword=${ADMINPASSWORD}                        # ARK server admin password, KEEP IT SAFE!
@@ -26,10 +28,23 @@ mod_branch=Windows
 # ARK server options - i.e. for -optname=val, use arkopt_optname=val
 #arkopt_StructureDestructionTag=DestroySwampSnowStructures
 
+#ark_AltSaveDirectoryName="SotF"                                    # Uncomment to specify a different save directory name
 
 # Update warning messages
 # Modify as desired, putting the %d replacement operator where the number belongs
 msgWarnUpdateMinutes="This ARK server will shutdown for an update in %d minutes"
 msgWarnUpdateSeconds="This ARK server will shutdown for an update in %d seconds"
+msgWarnRestartMinutes="This ARK server will shutdown for a restart in %d minutes"
+msgWarnRestartSeconds="This ARK server will shutdown for a restart in %d seconds"
+msgWarnShutdownMinutes="This ARK server will shutdown in %d minutes"
+msgWarnShutdownSeconds="This ARK server will shutdown in %d seconds"
+
+# config environment
+arkwarnminutes="60"                                                 # number of minutes to warn players when using update --warn
+arkAutoUpdateOnStart="false"                                        # set this to true if you want to always update before startup
 arkBackupPreUpdate="false"                                          # set this to true if you want to perform a backup before updating
-arkwarnminutes="30" 						    # number of minutes to warn players when using update --warn
+
+# Options to automatically remove old backups to keep backup size in check
+# Each compressed backup is generally about 1-2MB in size.
+arkMaxBackupSizeMB="500"                                            # Set to automatically remove old backups when size exceeds this limit
+#arkMaxBackupSizeGB="2"                                             # Uncomment this and comment the above to specify the limit in whole GB
diff --git a/docker-compose.yml b/docker-compose.yml
index bf00912..8a466d0 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -7,6 +7,8 @@ ark:
     ADMINPASSWORD: adminpassword
     BACKUPONSTART: 1
     UPDATEONSTART: 1
+    BACKUPONSTOP: 0
+    WARNONSTOP: 0
   volumes:
     - /my/path/to/ark:/ark
   ports:
diff --git a/run.sh b/run.sh
index fb38aa4..f235743 100644
--- a/run.sh
+++ b/run.sh
@@ -7,6 +7,19 @@ mkfifo /tmp/FIFO
 
 export TERM=linux
 
+function stop {
+	if [ ${BACKUPONSTOP} -eq 1 ]; then
+		echo "[Backup on stop]"
+		arkmanager backup
+	fi
+	if [ ${WARNONSTOP} -eq 1 ];then 
+	    arkmanager stop --warn
+	else
+	    arkmanager stop
+	fi
+	exit
+}
+
 if [ ! -w /ark ]; then 
 	echo "[Error] Can't access ark directory. Check permissions on your mapped directory with /ark"
 	exit 1
@@ -24,30 +37,27 @@ cp /home/steam/crontab /ark/template/crontab
 [ ! -f /ark/arkmanager.cfg ] && cp /home/steam/arkmanager.cfg /ark/arkmanager.cfg
 [ ! -d /ark/log ] && mkdir /ark/log
 [ ! -d /ark/backup ] && mkdir /ark/backup
+[ ! -d /ark/staging ] && mkdir /ark/staging
 [ ! -f /ark/Game.ini ] && ln -s server/ShooterGame/Saved/Config/LinuxServer/Game.ini Game.ini
 [ ! -f /ark/GameUserSettings.ini ] && ln -s server/ShooterGame/Saved/Config/LinuxServer/GameUserSettings.ini GameUserSettings.ini
+[ ! -f /ark/crontab ] && cp /ark/template/crontab /ark/crontab
 
 
 
 if [ ! -d "/ark/server"  ] || [ ! -f "/ark/server/arkversion" ];then 
+	mkdir /ark/server
 	arkmanager install
 	# Create mod dir
 	mkdir /ark/server/ShooterGame/Content/Mods
-	# Download mods
-	arkmanager update --update-mods
 else
 
 	if [ ${BACKUPONSTART} -eq 1 ]; then 
 		echo "[Backup]"
 		arkmanager backup
 	fi
-
-	if [ ${UPDATEONSTART} -eq 1 ]; then 
-		echo "[Update]"
-		arkmanager update --update-mods
-	fi
 fi
 
+
 # If there is uncommented line in the file
 CRONNUMBER=`grep -v "^#" /ark/crontab | wc -l`
 if [ $CRONNUMBER -gt 0 ]; then
@@ -61,13 +71,17 @@ else
 fi
 
 # Launching ark server
-arkmanager start
+if [ $UPDATEONSTART -eq 0 ]; then
+	arkmanager start -noautoupdate
+else
+	arkmanager start
+fi
 
 
 # Stop server in case of signal INT or TERM
 echo "Waiting..."
-trap 'arkmanager stop;' INT
-trap 'arkmanager stop' TERM
+trap stop INT
+trap stop TERM
 
 read < /tmp/FIFO &
 wait

From 22e5a21e0786dddd291d1d1f19fbbdedce6ba7a0 Mon Sep 17 00:00:00 2001
From: TuRz4m <peps.isima@gmail.com>
Date: Wed, 23 Mar 2016 15:32:02 +0100
Subject: [PATCH 05/22] Add instance.cfg

---
 instance.cfg | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 instance.cfg

diff --git a/instance.cfg b/instance.cfg
new file mode 100644
index 0000000..1585d84
--- /dev/null
+++ b/instance.cfg
@@ -0,0 +1,2 @@
+# Config root directory
+arkserverroot="/ark/server"

From b03fff8ddb4ddca60a0e20b1fd2db94838470813 Mon Sep 17 00:00:00 2001
From: TuRz4m <peps.isima@gmail.com>
Date: Wed, 23 Mar 2016 15:44:04 +0100
Subject: [PATCH 06/22] Update README.md

---
 README.md | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/README.md b/README.md
index b37c76e..998b1bd 100644
--- a/README.md
+++ b/README.md
@@ -100,6 +100,10 @@ Steam server port (can't rebind with docker, it doesn't work) (default : 7778)
 1 : Backup the server when the container is started. 0: no backup (default : 1)
 + __UPDATEPONSTART__
 1 : Update the server when the container is started. 0: no update (default : 1)  
++ __BACKUPONSTOP__
+1 : Backup the server when the container is stopped. 0: no backup (default : 0)
++ __WARNONSTOP__
+1 : Warn the players before the container is stopped. 0: no warning (default : 0)  
 + __TZ__
 Time Zone : Set the container timezone (for crontab). (You can get your timezone posix format with the command `tzselect`. For example, France is "Europe/Paris").
 
@@ -118,6 +122,7 @@ Time Zone : Set the container timezone (for crontab). (You can get your timezone
     + /ark/template : Default config files
     + /ark/template/arkmanager.cfg : default config file for Ark Server Tools
     + /ark/template/crontab : default config file for crontab
+    + /ark/staging : default directory if you use the --downloadonly option when updating.
 
 --- 
 
@@ -146,4 +151,12 @@ Time Zone : Set the container timezone (for crontab). (You can get your timezone
   - You can now config crontab with the file /your/ark/path/crontab
   - Add template directory with default config files.
   - Add documentation on TZ variable.
++ 1.3 :
+  - Add BACKUPONSTOP to backup the server when you stop the server (thanks to *fkoester*)
+  - Add WARNONSTOP to add warning message when you stop the server (default: 60 min)
+  - Uses Ark Server Tools v1.5
+    - Compressing backups so they take up less space
+    - Downloading updates to a staging directory before applying
+    - Added support for automatically updating on restart
+    - Show a spinner when updating
 

From d177be717c73caff8b07ea7a2da9182ecc670028 Mon Sep 17 00:00:00 2001
From: TuRz4m <peps.isima@gmail.com>
Date: Wed, 23 Mar 2016 16:01:54 +0100
Subject: [PATCH 07/22] Checkout the tag v1.5

---
 Dockerfile | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index a3dbcab..670b552 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -17,8 +17,8 @@ ENV NBPLAYERS 70
 ENV UPDATEONSTART 1
 # if the server is backup when start with docker start
 ENV BACKUPONSTART 1
-#  branch on github for ark server tools
-ENV BRANCH master
+#  Tag on github for ark server tools
+ENV GIT_TAG v1.5
 # Server PORT (you can't remap with docker, it doesn't work)
 ENV SERVERPORT 27015
 # Steam port (you can't remap with docker, it doesn't work)
@@ -56,7 +56,9 @@ RUN mkdir  /ark
 
 
 # We use the git method, because api github has a limit ;)
-RUN  git clone -b $BRANCH https://github.com/FezVrasta/ark-server-tools.git /home/steam/ark-server-tools
+RUN  git clone https://github.com/FezVrasta/ark-server-tools.git /home/steam/ark-server-tools
+WORKDIR /home/steam/ark-server-tools/
+RUN  git checkout $GIT_TAG 
 # Install 
 WORKDIR /home/steam/ark-server-tools/tools
 RUN chmod +x install.sh 

From 4b74e14d4ac719e2646d00fac01e841ba00036ec Mon Sep 17 00:00:00 2001
From: TuRz4m <peps.isima@gmail.com>
Date: Wed, 23 Mar 2016 16:06:42 +0100
Subject: [PATCH 08/22] Update README.md

---
 README.md | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index 998b1bd..ec89afe 100644
--- a/README.md
+++ b/README.md
@@ -152,9 +152,9 @@ Time Zone : Set the container timezone (for crontab). (You can get your timezone
   - Add template directory with default config files.
   - Add documentation on TZ variable.
 + 1.3 :
-  - Add BACKUPONSTOP to backup the server when you stop the server (thanks to *fkoester*)
+  - Add BACKUPONSTOP to backup the server when you stop the server (thanks to [fkoester](https://github.com/fkoester))
   - Add WARNONSTOP to add warning message when you stop the server (default: 60 min)
-  - Uses Ark Server Tools v1.5
+  - Works with Ark Server Tools v1.5
     - Compressing backups so they take up less space
     - Downloading updates to a staging directory before applying
     - Added support for automatically updating on restart

From dcf915587f9e6d43d6f70361bb98de8bfb3aa4e7 Mon Sep 17 00:00:00 2001
From: TuRz4m <peps.isima@gmail.com>
Date: Mon, 4 Apr 2016 10:48:55 +0200
Subject: [PATCH 09/22] Fix issue #10 : set the flag arkAutoUpdateOnStart to
 true.

---
 arkmanager-system.cfg | 3 +++
 arkmanager-user.cfg   | 1 -
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/arkmanager-system.cfg b/arkmanager-system.cfg
index b665a2b..86a2945 100644
--- a/arkmanager-system.cfg
+++ b/arkmanager-system.cfg
@@ -33,6 +33,9 @@ ark_RCONPort="32330"                                                # RCON Port
 appid=376030                                                        # Linux server App ID
 mod_appid=346110                                                    # App ID for mods
 
+# Need to be true to work with UPDATEPONSTART (See #10)
+arkAutoUpdateOnStart="true"                                        # set this to true if you want to always update before startup
+
 defaultinstance="main"
 
 source /ark/arkmanager.cfg
diff --git a/arkmanager-user.cfg b/arkmanager-user.cfg
index edd74b1..f5d3ff2 100644
--- a/arkmanager-user.cfg
+++ b/arkmanager-user.cfg
@@ -41,7 +41,6 @@ msgWarnShutdownSeconds="This ARK server will shutdown in %d seconds"
 
 # config environment
 arkwarnminutes="60"                                                 # number of minutes to warn players when using update --warn
-arkAutoUpdateOnStart="false"                                        # set this to true if you want to always update before startup
 arkBackupPreUpdate="false"                                          # set this to true if you want to perform a backup before updating
 
 # Options to automatically remove old backups to keep backup size in check

From 50db7b51b9bd6d584b361d5cf472af774e55e10e Mon Sep 17 00:00:00 2001
From: TuRz4m <peps.isima@gmail.com>
Date: Thu, 7 Jul 2016 16:35:42 +0200
Subject: [PATCH 10/22] Resolve #12 : expose UDP ports.

---
 Dockerfile | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Dockerfile b/Dockerfile
index 670b552..3a3724a 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -87,6 +87,8 @@ RUN mkdir /home/steam/steamcmd &&\
 RUN /home/steam/steamcmd/steamcmd.sh +login anonymous +quit
 
 EXPOSE ${STEAMPORT} 32330 ${SERVERPORT}
+# Add UDP
+EXPOSE ${STEAMPORT}/udp ${SERVERPORT}/udp
 
 VOLUME  /ark 
 

From 142c15a438c04ce30ecb3a6ecc96698c543ecfcb Mon Sep 17 00:00:00 2001
From: TuRz4m <peps.isima@gmail.com>
Date: Fri, 8 Jul 2016 16:12:46 +0200
Subject: [PATCH 11/22] #11 : add UID & GID.

---
 Dockerfile | 11 +++++++++--
 run.sh     | 14 ++++++--------
 user.sh    | 21 +++++++++++++++++++++
 3 files changed, 36 insertions(+), 10 deletions(-)
 create mode 100644 user.sh

diff --git a/Dockerfile b/Dockerfile
index 3a3724a..47b2b50 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -27,6 +27,10 @@ ENV STEAMPORT 7778
 ENV BACKUPONSTOP 0
 # If the server warn the players before stopping
 ENV WARNONSTOP 0
+# UID of the user steam
+ENV UID 1000
+# GID of the user steam
+ENV GID 1000
 
 # Install dependencies 
 RUN apt-get update &&\ 
@@ -48,10 +52,13 @@ RUN usermod -a -G sudo steam
 
 # Copy & rights to folders
 COPY run.sh /home/steam/run.sh
+COPY user.sh /home/steam/user.sh
 COPY crontab /home/steam/crontab
 COPY arkmanager-user.cfg /home/steam/arkmanager.cfg
 
+RUN touch /root/.bash_profile
 RUN chmod 777 /home/steam/run.sh
+RUN chmod 777 /home/steam/user.sh
 RUN mkdir  /ark
 
 
@@ -75,7 +82,7 @@ COPY instance.cfg /etc/arkmanager/instances/main.cfg
 
 RUN chown steam -R /ark && chmod 755 -R /ark
 
-USER steam 
+#USER steam 
 
 # download steamcmd
 RUN mkdir /home/steam/steamcmd &&\ 
@@ -96,4 +103,4 @@ VOLUME  /ark
 WORKDIR /ark
 
 # Update game launch the game.
-ENTRYPOINT ["/home/steam/run.sh"]
+ENTRYPOINT ["/home/steam/user.sh"]
diff --git a/run.sh b/run.sh
index f235743..a6721af 100644
--- a/run.sh
+++ b/run.sh
@@ -1,6 +1,7 @@
 #!/usr/bin/env bash
 echo "###########################################################################"
 echo "# Ark Server - " `date`
+echo "# UID $UID - GID $GID"
 echo "###########################################################################"
 [ -p /tmp/FIFO ] && rm /tmp/FIFO
 mkfifo /tmp/FIFO
@@ -20,10 +21,7 @@ function stop {
 	exit
 }
 
-if [ ! -w /ark ]; then 
-	echo "[Error] Can't access ark directory. Check permissions on your mapped directory with /ark"
-	exit 1
-fi
+
 
 # Change working directory to /ark to allow relative path
 cd /ark
@@ -38,14 +36,14 @@ cp /home/steam/crontab /ark/template/crontab
 [ ! -d /ark/log ] && mkdir /ark/log
 [ ! -d /ark/backup ] && mkdir /ark/backup
 [ ! -d /ark/staging ] && mkdir /ark/staging
-[ ! -f /ark/Game.ini ] && ln -s server/ShooterGame/Saved/Config/LinuxServer/Game.ini Game.ini
-[ ! -f /ark/GameUserSettings.ini ] && ln -s server/ShooterGame/Saved/Config/LinuxServer/GameUserSettings.ini GameUserSettings.ini
+[ ! -L /ark/Game.ini ] && ln -s server/ShooterGame/Saved/Config/LinuxServer/Game.ini Game.ini
+[ ! -L /ark/GameUserSettings.ini ] && ln -s server/ShooterGame/Saved/Config/LinuxServer/GameUserSettings.ini GameUserSettings.ini
 [ ! -f /ark/crontab ] && cp /ark/template/crontab /ark/crontab
 
 
 
-if [ ! -d "/ark/server"  ] || [ ! -f "/ark/server/arkversion" ];then 
-	mkdir /ark/server
+if [ ! -d /ark/server  ] || [ ! -f /ark/server/arkversion ];then 
+	echo "No game files found. Installing..."
 	arkmanager install
 	# Create mod dir
 	mkdir /ark/server/ShooterGame/Content/Mods
diff --git a/user.sh b/user.sh
new file mode 100644
index 0000000..a49bdfc
--- /dev/null
+++ b/user.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+# Change the UID if needed
+if [ ! "$(id -u steam)" -eq "$UID" ]; then 
+	echo "Changing steam uid to $UID."
+	usermod -o -u "$UID" steam ; 
+fi
+# Change gid if needed
+if [ ! "$(id -g steam)" -eq "$GID" ]; then 
+	echo "Changing steam gid to $GID."
+	groupmod -o -g "$GID" steam ; 
+fi
+
+# Put steam owner of directories (if the uid changed, then it's needed)
+chown -R steam:steam /ark /home/steam
+
+# avoid error message when su -p (we need to read the /root/.bash_rc )
+chmod -R 777 /root/
+
+# Launch run.sh with user steam (-p allow to keep env variables)
+su -p - steam -c /home/steam/run.sh

From d82ef8c3d223ca344ab6d82d5f5a7cfb1fa06e23 Mon Sep 17 00:00:00 2001
From: TuRz4m <peps.isima@gmail.com>
Date: Fri, 8 Jul 2016 16:17:02 +0200
Subject: [PATCH 12/22] Update docker-compose

---
 docker-compose.yml | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/docker-compose.yml b/docker-compose.yml
index 8a466d0..0b38819 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,14 +1,16 @@
 ark:
-  image: turzam/ark
+  container_name: ark
+  image: turzam/ark:1.3-dev
   environment:
-    SESSIONNAME: Ark Docker
-    SERVERMAP: TheIsland
-    SERVERPASSWORD: 
-    ADMINPASSWORD: adminpassword
-    BACKUPONSTART: 1
-    UPDATEONSTART: 1
-    BACKUPONSTOP: 0
-    WARNONSTOP: 0
+    - SESSIONNAME=Ark Docker
+    - SERVERMAP=TheIsland
+    - SERVERPASSWORD="" 
+    - ADMINPASSWORD=adminpassword
+    - BACKUPONSTART=1
+    - UPDATEONSTART=1
+    - TZ=Europe/Paris
+    - GID=1000
+    - UID=1000
   volumes:
     - /my/path/to/ark:/ark
   ports:

From 4fa41cd219bb8d4697c8ef4a8c1a55d1725c0ffe Mon Sep 17 00:00:00 2001
From: TuRz4m <peps.isima@gmail.com>
Date: Fri, 8 Jul 2016 16:26:56 +0200
Subject: [PATCH 13/22] Update README.md

---
 README.md | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/README.md b/README.md
index ec89afe..79dc045 100644
--- a/README.md
+++ b/README.md
@@ -106,6 +106,10 @@ Steam server port (can't rebind with docker, it doesn't work) (default : 7778)
 1 : Warn the players before the container is stopped. 0: no warning (default : 0)  
 + __TZ__
 Time Zone : Set the container timezone (for crontab). (You can get your timezone posix format with the command `tzselect`. For example, France is "Europe/Paris").
++ __UID__
+UID of the user used. Owner of the volume /ark
++ __GID__
+GID of the user used. Owner of the volume /ark
 
 
 --- 
@@ -159,4 +163,5 @@ Time Zone : Set the container timezone (for crontab). (You can get your timezone
     - Downloading updates to a staging directory before applying
     - Added support for automatically updating on restart
     - Show a spinner when updating
+  - Add UID & GID to set the uid & gid of the user used in the container (and permissions on the volume /ark)
 

From 119915c382de4a0b4c50507a51448af2921b2a6a Mon Sep 17 00:00:00 2001
From: TuRz4m <peps.isima@gmail.com>
Date: Tue, 12 Jul 2016 13:52:25 +0200
Subject: [PATCH 14/22] Remove steam update in image. Should work with docker
 hub now.

---
 Dockerfile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Dockerfile b/Dockerfile
index 47b2b50..77da103 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -91,7 +91,8 @@ RUN mkdir /home/steam/steamcmd &&\
 
 
 # First run is on anonymous to download the app
-RUN /home/steam/steamcmd/steamcmd.sh +login anonymous +quit
+# We can't download from docker hub anymore -_-
+#RUN /home/steam/steamcmd/steamcmd.sh +login anonymous +quit
 
 EXPOSE ${STEAMPORT} 32330 ${SERVERPORT}
 # Add UDP

From 214494a322d9548c3512fe780ec32979930934cb Mon Sep 17 00:00:00 2001
From: TuRz4m <peps.isima@gmail.com>
Date: Wed, 13 Jul 2016 09:56:38 +0200
Subject: [PATCH 15/22] #12 : Fix Ark Server Tools errors on first start.

---
 arkmanager-system.cfg | 3 +++
 run.sh                | 9 ++++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/arkmanager-system.cfg b/arkmanager-system.cfg
index 86a2945..b15199a 100644
--- a/arkmanager-system.cfg
+++ b/arkmanager-system.cfg
@@ -38,4 +38,7 @@ arkAutoUpdateOnStart="true"                                        # set this to
 
 defaultinstance="main"
 
+# We don't use the dots because it doesn't show.
+progressDisplayType=spinner
+
 source /ark/arkmanager.cfg
diff --git a/run.sh b/run.sh
index a6721af..55aa516 100644
--- a/run.sh
+++ b/run.sh
@@ -9,7 +9,7 @@ mkfifo /tmp/FIFO
 export TERM=linux
 
 function stop {
-	if [ ${BACKUPONSTOP} -eq 1 ]; then
+	if [ ${BACKUPONSTOP} -eq 1 ] && [ "$(ls -A server/ShooterGame/Saved/SavedArks)" ]; then
 		echo "[Backup on stop]"
 		arkmanager backup
 	fi
@@ -44,12 +44,15 @@ cp /home/steam/crontab /ark/template/crontab
 
 if [ ! -d /ark/server  ] || [ ! -f /ark/server/arkversion ];then 
 	echo "No game files found. Installing..."
+	mkdir -p /ark/server/ShooterGame/Saved/SavedArks
+	mkdir -p /ark/server/ShooterGame/Content/Mods
+	mkdir -p /ark/server/ShooterGame/Binaries/Linux/
+	touch /ark/server/ShooterGame/Binaries/Linux/ShooterGameServer
 	arkmanager install
 	# Create mod dir
-	mkdir /ark/server/ShooterGame/Content/Mods
 else
 
-	if [ ${BACKUPONSTART} -eq 1 ]; then 
+	if [ ${BACKUPONSTART} -eq 1 ] && [ "$(ls -A server/ShooterGame/Saved/SavedArks/)" ]; then 
 		echo "[Backup]"
 		arkmanager backup
 	fi

From 76fd195f9194ad3d2b0cb383e8134fdfe300a0f9 Mon Sep 17 00:00:00 2001
From: TuRz4m <peps.isima@gmail.com>
Date: Fri, 15 Jul 2016 14:55:01 +0200
Subject: [PATCH 16/22] Update docker-compose.yml

---
 docker-compose.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/docker-compose.yml b/docker-compose.yml
index 0b38819..71126e9 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,6 +1,6 @@
 ark:
   container_name: ark
-  image: turzam/ark:1.3-dev
+  image: turzam/ark
   environment:
     - SESSIONNAME=Ark Docker
     - SERVERMAP=TheIsland

From 665137a9f076b766b02da32e024edfb41a395f15 Mon Sep 17 00:00:00 2001
From: "Guillaume \"B.B.\" Van Hemmen"
 <GuillaumeHemmen@users.noreply.github.com>
Date: Fri, 14 Feb 2020 22:10:57 +0100
Subject: [PATCH 17/22] Updated git tag for ark server manager

---
 Dockerfile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Dockerfile b/Dockerfile
index 77da103..edf379f 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -18,7 +18,7 @@ ENV UPDATEONSTART 1
 # if the server is backup when start with docker start
 ENV BACKUPONSTART 1
 #  Tag on github for ark server tools
-ENV GIT_TAG v1.5
+ENV GIT_TAG v1.6.48
 # Server PORT (you can't remap with docker, it doesn't work)
 ENV SERVERPORT 27015
 # Steam port (you can't remap with docker, it doesn't work)

From a217aa5a8607b3650240d438d7bf62cc0aad040a Mon Sep 17 00:00:00 2001
From: "Guillaume \"B.B.\" Van Hemmen"
 <GuillaumeHemmen@users.noreply.github.com>
Date: Sun, 14 Jun 2020 12:31:29 +0200
Subject: [PATCH 18/22] update ark-server-tools in docker

---
 Dockerfile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Dockerfile b/Dockerfile
index edf379f..427a200 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -18,7 +18,7 @@ ENV UPDATEONSTART 1
 # if the server is backup when start with docker start
 ENV BACKUPONSTART 1
 #  Tag on github for ark server tools
-ENV GIT_TAG v1.6.48
+ENV GIT_TAG v1.6.52
 # Server PORT (you can't remap with docker, it doesn't work)
 ENV SERVERPORT 27015
 # Steam port (you can't remap with docker, it doesn't work)

From 4fb984b9e2cbe14111220171a3a87ffc6732fa48 Mon Sep 17 00:00:00 2001
From: "Guillaume \"B.B.\" Van Hemmen"
 <GuillaumeHemmen@users.noreply.github.com>
Date: Sat, 28 Nov 2020 20:34:45 +0100
Subject: [PATCH 19/22] update ark-server-tools git tag

---
 Dockerfile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Dockerfile b/Dockerfile
index 427a200..c4ae4f5 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -18,7 +18,7 @@ ENV UPDATEONSTART 1
 # if the server is backup when start with docker start
 ENV BACKUPONSTART 1
 #  Tag on github for ark server tools
-ENV GIT_TAG v1.6.52
+ENV GIT_TAG v1.6.56
 # Server PORT (you can't remap with docker, it doesn't work)
 ENV SERVERPORT 27015
 # Steam port (you can't remap with docker, it doesn't work)

From 87d566639db2171beee6af374f10cf232b5be40b Mon Sep 17 00:00:00 2001
From: "Guillaume \"B.B.\" Van Hemmen"
 <GuillaumeHemmen@users.noreply.github.com>
Date: Sat, 28 Nov 2020 20:53:38 +0100
Subject: [PATCH 20/22] upgraded ubuntu

---
 Dockerfile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Dockerfile b/Dockerfile
index c4ae4f5..c3e5c06 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,4 @@
-FROM ubuntu:14.04
+FROM ubuntu:16.04
 
 MAINTAINER TuRzAm
 

From 59d96997607f4125da9b0f517f5a984f76c4676e Mon Sep 17 00:00:00 2001
From: "Guillaume \"B.B.\" Van Hemmen"
 <GuillaumeHemmen@users.noreply.github.com>
Date: Sat, 28 Nov 2020 21:29:28 +0100
Subject: [PATCH 21/22] added sudo package

---
 Dockerfile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Dockerfile b/Dockerfile
index c3e5c06..e73fcce 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -34,7 +34,7 @@ ENV GID 1000
 
 # Install dependencies 
 RUN apt-get update &&\ 
-    apt-get install -y curl lib32gcc1 lsof git
+    apt-get install -y curl lib32gcc1 lsof git sudo
 
 # Enable passwordless sudo for users under the "sudo" group
 RUN sed -i.bkp -e \

From 94e1ab98bdcd2eac2e85f0584b8aed06c4bd0f78 Mon Sep 17 00:00:00 2001
From: "Guillaume \"B.B.\" Van Hemmen"
 <GuillaumeHemmen@users.noreply.github.com>
Date: Sun, 24 Jan 2021 00:31:25 +0100
Subject: [PATCH 22/22] Update run.sh

---
 run.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/run.sh b/run.sh
index 55aa516..80fff6b 100644
--- a/run.sh
+++ b/run.sh
@@ -42,7 +42,7 @@ cp /home/steam/crontab /ark/template/crontab
 
 
 
-if [ ! -d /ark/server  ] || [ ! -f /ark/server/arkversion ];then 
+if [ ! -d /ark/server  ] || [ ! -f /ark/server/version.txt ];then 
 	echo "No game files found. Installing..."
 	mkdir -p /ark/server/ShooterGame/Saved/SavedArks
 	mkdir -p /ark/server/ShooterGame/Content/Mods