source: scripts/usr/local/lib/7dtd/commands/updateengine.sh@ 356

Last change on this file since 356 was 344, checked in by alloc, 6 years ago

Linux scripts 111

File size: 8.7 KB
RevLine 
[17]1#!/bin/bash
2
[258]3# Copyright 2016 Christian 'Alloc' Illy
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17
[48]18# Downloads SteamCMD, downloads/updates the 7dtd engine
[17]19
20sdtdCommandUpdateengine() {
[308]21 local FORCED=no
22 local CHECKONLY=no
23 local SHOWINTERNAL=no
24
25 local BRANCHNAME="$(getLocalBranch)"
26 local BRANCHPASSWORD=""
27
28 while test $# -gt 0; do
29 case "$1" in
30 --check)
31 CHECKONLY=yes
32 ;;
33 --showinternal)
34 SHOWINTERNAL=yes
35 ;;
36 --experimental)
37 BRANCHNAME="latest_experimental"
38 ;;
39 --stable)
40 BRANCHNAME="public"
41 ;;
42 --branch)
43 if [ -z "$2" ]; then
44 echo "Argument --branch not followed by a branch name. Aborting."
45 return
46 fi
47 BRANCHNAME=$2
48 shift
49 ;;
50 --password)
51 if [ -z "$2" ]; then
52 echo "Argument --password not followed by a branch password value. Aborting."
53 return
54 fi
55 BRANCHPASSWORD=$2
56 shift
57 ;;
58 --force)
59 FORCED=yes
60 ;;
61 esac
62 shift
63 done
64
[28]65 if [ ! -e $SDTD_BASE/steamcmd ]; then
66 mkdir $SDTD_BASE/steamcmd
[17]67 cd /tmp
68 wget http://media.steampowered.com/installer/steamcmd_linux.tar.gz
[28]69 tar -xvzf steamcmd_linux.tar.gz -C $SDTD_BASE/steamcmd
70 cd $SDTD_BASE/steamcmd
[17]71 ./steamcmd.sh +quit
72 fi
[308]73
74 updateRemoteEngineInfo
[17]75
[308]76 if [ "$CHECKONLY" = "yes" ]; then
77 local LOCAL=$(getLocalEngineVersion)
78 local REMOTE=$(getBuildId $(getLocalBranch))
79 local REMOTETIME=$(getBuildUpdateTime $(getLocalBranch))
80
81 echo "Installed:"
82 echo " Build ID: $(getLocalEngineVersion)"
83 echo " Installed on: $(getLocalEngineUpdateTime)"
84 echo " From branch: $(getLocalBranch)"
85 echo
[17]86
[308]87 echo "Available branches:"
88 printf "%-*s | %-*s | %-*s\n" 22 "Branch" 8 "Build ID" 19 "Build set on"
89 printf -v line "%*s-+-%*s-+-%*s\n" 22 " " 8 " " 19 " "
90 echo ${line// /-}
91 for I in $(getBranchNames); do
92 if [[ $I != test* ]] || [ "$SHOWINTERNAL" = "yes" ]; then
93 local BUILD=$(getBuildId $I)
94 local CREATED=$(getBuildUpdateTime $I)
95 printf "%-*s | %*s | %2s\n" 22 "$I" 8 "$BUILD" "$CREATED"
96 fi
97 done | sort -k 3 -n -r
98
99 echo
100
101 if [ $REMOTE -gt $LOCAL ]; then
102 echo "Newer engine version available on the currently installed branch (build id $REMOTE from $REMOTETIME)."
103 else
104 local MAXREMOTE=0
105 local MAXREMOTEBRANCH=0
106 local MAXREMOTETIME=0
107 for I in $(getBranchNames); do
108 if [[ $I != test* ]] || [ "$SHOWINTERNAL" = "yes" ]; then
109 local BUILD=$(getBuildId $I)
110 local CREATED=$(getBuildUpdateTime $I)
111 if [ $BUILD -gt $MAXREMOTE ]; then
112 MAXREMOTE=$BUILD
113 MAXREMOTETIME=$CREATED
114 MAXREMOTEBRANCH=$I
115 fi
116 fi
117 done
118 if [ $MAXREMOTE -gt $LOCAL ]; then
119 echo "Newer engine version available on the branch \"$MAXREMOTEBRANCH\" (build id $MAXREMOTE from $MAXREMOTETIME)."
120 else
121 echo "Engine on the latest build."
122 fi
123 fi
124 return
125 fi
126
[53]127 for I in $(getInstanceList); do
128 if [ $(isRunning $I) -eq 1 ]; then
129 echo "At least one instance is still running (\"$I\")."
130 echo "Before updating the engine please stop all instances!"
131 return
132 fi
133 done
[17]134
[53]135 local LOCAL=$(getLocalEngineVersion)
[308]136 local REMOTE=$(getBuildId $BRANCHNAME)
[35]137
[308]138 if [ "$FORCED" = "yes" -o $REMOTE -gt $LOCAL ]; then
139 echo "A newer version of the engine is available."
140 echo "Local build id: $LOCAL (installed on $(getLocalEngineUpdateTime))"
141 echo "Available build id: $REMOTE (from $(getBuildUpdateTime $BRANCHNAME))"
[53]142 echo
[87]143
[53]144 while : ; do
145 local CONTINUE
146 read -p "Continue? (yn) " CONTINUE
147 case $CONTINUE in
148 y)
149 echo "Updating..."
150 break
151 ;;
152 n)
153 echo "Canceled"
154 return
155 ;;
156 *)
157 echo "Wrong input"
158 esac
159 done
[229]160
[308]161 cd $SDTD_BASE/steamcmd
162 local PASSWORDARG=
163 if [ -n "$BRANCHPASSWORD" ]; then
164 PASSWORDARG=-betapassword $BRANCHPASSWORD
[265]165 fi
[308]166 #echo ./steamcmd.sh +login anonymous +force_install_dir $SDTD_BASE/engine +app_update 294420 -validate -beta $BRANCHNAME $PASSWORDARG +quit
167 ./steamcmd.sh +login anonymous +force_install_dir $SDTD_BASE/engine +app_update 294420 -validate -beta $BRANCHNAME $PASSWORDARG +quit
[53]168
[248]169 if [ -d /usr/local/lib/7dtd/server-fixes ]; then
[257]170 cp /usr/local/lib/7dtd/server-fixes/* $SDTD_BASE/engine/ -R
[248]171 fi
[53]172
173 chown $SDTD_USER.$SDTD_GROUP -R $SDTD_BASE/engine
[308]174 else
175 echo "Engine is already at the newest build on the selected branch \"$BRANCHNAME\" (local: $LOCAL, remote: $REMOTE)."
176 echo "Run with the --force parameter to update/validate the engine files anyway."
177 echo "Run with --experimental, --stable or --branch to switch to a different branch."
178 fi
[17]179}
180
181sdtdCommandUpdateengineHelp() {
[308]182 echo "Usage: $(basename $0) updateengine [--check [--showinternal]] [--experimental | --stable] [--branch BRANCHNAME [--password BRANCHPASSWORD]] [--force]"
[17]183 echo
[53]184 echo "Check for a newer version of engine (aka game) files of 7dtd. If there is a newer"
[229]185 echo "version they will be updated by this command."
[265]186 echo
[308]187 echo "If neither --stable, nor --experimental nor --branch is specified the server will"
188 echo "updated to the latest build on the currently installed Steam branch of the game."
189 echo
190 echo "If --stable is specified the server will be switched to the"
191 echo "default public stable Steam branch of the game."
192 echo
193 echo "If --experimental is specified the server will be switched to the"
[265]194 echo "latest_experimental Steam branch of the game."
[308]195 echo
196 echo "If --branch SOMEBRANCH is specified the server will be switched to the"
197 echo "given Steam branch of the game. Additionally if password is required to acess"
198 echo "the branch this can be specified with the --password argument."
199 echo "NOTE that --password is also required if you previously switched to a branch that"
200 echo "requires a password and want to update to the latest build on that branch now."
201 echo
202 echo "If --force is specified you are asked if you want to redownload the engine"
203 echo "even if there is no new version detected."
204 echo
205 echo "If --check is specified it will only output the current local and remote build ids"
206 echo "and if an update is available."
207 echo "TFP internal branches are only shown if --showinternal is also given."
[17]208}
209
210sdtdCommandUpdateengineDescription() {
211 echo "Update the 7dtd engine files"
212}
[53]213
214sdtdCommandUpdateengineExpects() {
[308]215 if [ "$2" = "--password" ]; then
216 echo ""
217 elif [ "$2" = "--branch" ]; then
218 updateRemoteEngineInfo
219 getBranchNames
220 else
221 echo "--check --showinternal --experimental --branch --password --stable --force"
222 fi
[53]223}
224
[308]225# Get the latest remote (on Steam) engine version numbers etc
226updateRemoteEngineInfo() {
227 local DOCHECK=no
228 if [ ! -e /tmp/7dtd-appinfo ]; then
229 DOCHECK=yes
230 else
231 AGE=$((`date +%s` - `stat -L --format %Y /tmp/7dtd-appinfo`))
232 if [ $AGE -gt 600 ]; then
233 DOCHECK=yes
234 fi
235 fi
236 if [ "$DOCHECK" = "yes" ]; then
[344]237 echo "Updating version information..."
[310]238 rm /root/Steam/appcache/appinfo.vdf
[308]239 cd $SDTD_BASE/steamcmd
240
[310]241 ./steamcmd.sh +login anonymous +app_info_request 294420 +app_info_update +app_info_update 1 +app_info_print 294420 +quit | grep -A 1000 \"294420\" 2>/dev/null > /tmp/7dtd-appinfo
[308]242
243 local BUILDID=$(grep -A 1000 \"branches\" /tmp/7dtd-appinfo | grep -A 1000 \"public\" | grep -B 10 \} --max-count=1 | grep \"buildid\" | cut -d\" -f4)
244
245 if [ $(isANumber "$BUILDID") -eq 0 ]; then
246 rm -f /tmp/7dtd-appinfo
247 fi
248 fi
249}
250
251# Get the latest build id (on Steam)
252# Params:
253# 1. Branch name
254# Returns:
255# "?" if data could not be retrieved
256# BuildId otherwise
257getBuildId() {
258 local BUILDID=$(grep -A 1000 \"branches\" /tmp/7dtd-appinfo | grep -A 1000 \"$1\" | grep -B 10 \} --max-count=1 | grep \"buildid\" | cut -d\" -f4)
259
260 if [ $(isANumber "$BUILDID") -eq 0 ]; then
261 echo "?"
262 else
263 echo $BUILDID
264 fi
265}
266
267# Get the update time of the latest build (on Steam)
268# Params:
269# 1. Branch name
270# Returns:
271# "?" if data could not be retrieved
272# Update timestamp otherwise
273getBuildUpdateTime() {
274 local TIMESTAMP=$(grep -A 1000 \"branches\" /tmp/7dtd-appinfo | grep -A 1000 \"$1\" | grep -B 10 \} --max-count=1 | grep \"timeupdated\" | cut -d\" -f4)
275
276 if [ $(isANumber "$TIMESTAMP") -eq 0 ]; then
277 echo "?"
278 else
279 date --date="@${TIMESTAMP}" "+%Y-%m-%d %H:%M:%S"
280 fi
281}
282
283# Get a list of available branch names, blank separated
284# Returns:
285# Blank separated list of branch names (can be empty if an error occured)
286getBranchNames() {
287 grep -A 1000 \"branches\" /tmp/7dtd-appinfo | grep -E '^[[:space:]]*"[^"]+"[[:space:]]*$' | tail --lines=+2 | cut -d\" -f2
288}
289
Note: See TracBrowser for help on using the repository browser.