[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 |
|
---|
| 20 | sdtdCommandUpdateengine() {
|
---|
[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)
|
---|
[478] | 78 | local REMOTE=$(getRemoteBuildId $(getLocalBranch))
|
---|
| 79 | local REMOTETIME=$(getRemoteBuildUpdateTime $(getLocalBranch))
|
---|
[308] | 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
|
---|
[478] | 93 | local BUILD=$(getRemoteBuildId $I)
|
---|
| 94 | local CREATED=$(getRemoteBuildUpdateTime $I)
|
---|
[308] | 95 | printf "%-*s | %*s | %2s\n" 22 "$I" 8 "$BUILD" "$CREATED"
|
---|
| 96 | fi
|
---|
| 97 | done | sort -k 3 -n -r
|
---|
| 98 |
|
---|
| 99 | echo
|
---|
| 100 |
|
---|
[479] | 101 | if [ "$REMOTE" = "?" ]; then
|
---|
| 102 | echo "Could not fetch remote build information"
|
---|
| 103 | return
|
---|
| 104 | fi
|
---|
| 105 |
|
---|
[308] | 106 | if [ $REMOTE -gt $LOCAL ]; then
|
---|
| 107 | echo "Newer engine version available on the currently installed branch (build id $REMOTE from $REMOTETIME)."
|
---|
| 108 | else
|
---|
| 109 | local MAXREMOTE=0
|
---|
| 110 | local MAXREMOTEBRANCH=0
|
---|
| 111 | local MAXREMOTETIME=0
|
---|
| 112 | for I in $(getBranchNames); do
|
---|
| 113 | if [[ $I != test* ]] || [ "$SHOWINTERNAL" = "yes" ]; then
|
---|
[478] | 114 | local BUILD=$(getRemoteBuildId $I)
|
---|
| 115 | local CREATED=$(getRemoteBuildUpdateTime $I)
|
---|
[308] | 116 | if [ $BUILD -gt $MAXREMOTE ]; then
|
---|
| 117 | MAXREMOTE=$BUILD
|
---|
| 118 | MAXREMOTETIME=$CREATED
|
---|
| 119 | MAXREMOTEBRANCH=$I
|
---|
| 120 | fi
|
---|
| 121 | fi
|
---|
| 122 | done
|
---|
| 123 | if [ $MAXREMOTE -gt $LOCAL ]; then
|
---|
| 124 | echo "Newer engine version available on the branch \"$MAXREMOTEBRANCH\" (build id $MAXREMOTE from $MAXREMOTETIME)."
|
---|
| 125 | else
|
---|
| 126 | echo "Engine on the latest build."
|
---|
| 127 | fi
|
---|
| 128 | fi
|
---|
| 129 | return
|
---|
| 130 | fi
|
---|
| 131 |
|
---|
[53] | 132 | for I in $(getInstanceList); do
|
---|
| 133 | if [ $(isRunning $I) -eq 1 ]; then
|
---|
| 134 | echo "At least one instance is still running (\"$I\")."
|
---|
| 135 | echo "Before updating the engine please stop all instances!"
|
---|
| 136 | return
|
---|
| 137 | fi
|
---|
| 138 | done
|
---|
[17] | 139 |
|
---|
[53] | 140 | local LOCAL=$(getLocalEngineVersion)
|
---|
[478] | 141 | local REMOTE=$(getRemoteBuildId $BRANCHNAME)
|
---|
[479] | 142 |
|
---|
| 143 | if [ "$REMOTE" = "?" ]; then
|
---|
| 144 | echo "Could not fetch remote build information, assuming update to be available"
|
---|
| 145 | REMOTE=30123456
|
---|
| 146 | fi
|
---|
[35] | 147 |
|
---|
[308] | 148 | if [ "$FORCED" = "yes" -o $REMOTE -gt $LOCAL ]; then
|
---|
| 149 | echo "A newer version of the engine is available."
|
---|
| 150 | echo "Local build id: $LOCAL (installed on $(getLocalEngineUpdateTime))"
|
---|
[478] | 151 | echo "Available build id: $REMOTE (from $(getRemoteBuildUpdateTime $BRANCHNAME))"
|
---|
[53] | 152 | echo
|
---|
[87] | 153 |
|
---|
[53] | 154 | while : ; do
|
---|
| 155 | local CONTINUE
|
---|
| 156 | read -p "Continue? (yn) " CONTINUE
|
---|
| 157 | case $CONTINUE in
|
---|
| 158 | y)
|
---|
| 159 | echo "Updating..."
|
---|
| 160 | break
|
---|
| 161 | ;;
|
---|
| 162 | n)
|
---|
| 163 | echo "Canceled"
|
---|
| 164 | return
|
---|
| 165 | ;;
|
---|
| 166 | *)
|
---|
| 167 | echo "Wrong input"
|
---|
| 168 | esac
|
---|
| 169 | done
|
---|
[229] | 170 |
|
---|
[308] | 171 | cd $SDTD_BASE/steamcmd
|
---|
| 172 | local PASSWORDARG=
|
---|
| 173 | if [ -n "$BRANCHPASSWORD" ]; then
|
---|
[495] | 174 | PASSWORDARG="-betapassword $BRANCHPASSWORD"
|
---|
[265] | 175 | fi
|
---|
[481] | 176 | #echo ./steamcmd.sh +force_install_dir $SDTD_BASE/engine +login anonymous +app_update 294420 -validate -beta $BRANCHNAME $PASSWORDARG +quit
|
---|
| 177 | ./steamcmd.sh +force_install_dir $SDTD_BASE/engine +login anonymous +app_update 294420 -validate -beta $BRANCHNAME $PASSWORDARG +quit
|
---|
[53] | 178 |
|
---|
[248] | 179 | if [ -d /usr/local/lib/7dtd/server-fixes ]; then
|
---|
[257] | 180 | cp /usr/local/lib/7dtd/server-fixes/* $SDTD_BASE/engine/ -R
|
---|
[248] | 181 | fi
|
---|
[53] | 182 |
|
---|
[480] | 183 | chown $SDTD_USER:$SDTD_GROUP -R $SDTD_BASE/engine
|
---|
[308] | 184 | else
|
---|
| 185 | echo "Engine is already at the newest build on the selected branch \"$BRANCHNAME\" (local: $LOCAL, remote: $REMOTE)."
|
---|
| 186 | echo "Run with the --force parameter to update/validate the engine files anyway."
|
---|
| 187 | echo "Run with --experimental, --stable or --branch to switch to a different branch."
|
---|
| 188 | fi
|
---|
[17] | 189 | }
|
---|
| 190 |
|
---|
| 191 | sdtdCommandUpdateengineHelp() {
|
---|
[308] | 192 | echo "Usage: $(basename $0) updateengine [--check [--showinternal]] [--experimental | --stable] [--branch BRANCHNAME [--password BRANCHPASSWORD]] [--force]"
|
---|
[17] | 193 | echo
|
---|
[53] | 194 | echo "Check for a newer version of engine (aka game) files of 7dtd. If there is a newer"
|
---|
[229] | 195 | echo "version they will be updated by this command."
|
---|
[265] | 196 | echo
|
---|
[308] | 197 | echo "If neither --stable, nor --experimental nor --branch is specified the server will"
|
---|
| 198 | echo "updated to the latest build on the currently installed Steam branch of the game."
|
---|
| 199 | echo
|
---|
| 200 | echo "If --stable is specified the server will be switched to the"
|
---|
| 201 | echo "default public stable Steam branch of the game."
|
---|
| 202 | echo
|
---|
| 203 | echo "If --experimental is specified the server will be switched to the"
|
---|
[265] | 204 | echo "latest_experimental Steam branch of the game."
|
---|
[308] | 205 | echo
|
---|
| 206 | echo "If --branch SOMEBRANCH is specified the server will be switched to the"
|
---|
| 207 | echo "given Steam branch of the game. Additionally if password is required to acess"
|
---|
| 208 | echo "the branch this can be specified with the --password argument."
|
---|
| 209 | echo "NOTE that --password is also required if you previously switched to a branch that"
|
---|
| 210 | echo "requires a password and want to update to the latest build on that branch now."
|
---|
| 211 | echo
|
---|
| 212 | echo "If --force is specified you are asked if you want to redownload the engine"
|
---|
| 213 | echo "even if there is no new version detected."
|
---|
| 214 | echo
|
---|
| 215 | echo "If --check is specified it will only output the current local and remote build ids"
|
---|
| 216 | echo "and if an update is available."
|
---|
| 217 | echo "TFP internal branches are only shown if --showinternal is also given."
|
---|
[17] | 218 | }
|
---|
| 219 |
|
---|
| 220 | sdtdCommandUpdateengineDescription() {
|
---|
| 221 | echo "Update the 7dtd engine files"
|
---|
| 222 | }
|
---|
[53] | 223 |
|
---|
| 224 | sdtdCommandUpdateengineExpects() {
|
---|
[308] | 225 | if [ "$2" = "--password" ]; then
|
---|
| 226 | echo ""
|
---|
| 227 | elif [ "$2" = "--branch" ]; then
|
---|
| 228 | updateRemoteEngineInfo
|
---|
| 229 | getBranchNames
|
---|
| 230 | else
|
---|
| 231 | echo "--check --showinternal --experimental --branch --password --stable --force"
|
---|
| 232 | fi
|
---|
[53] | 233 | }
|
---|