[48] | 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 | # Checks for newer scripts version and downloads them
|
---|
| 19 |
|
---|
| 20 | sdtdCommandUpdatescripts() {
|
---|
[53] | 21 | local LOCAL=$(cat /usr/local/lib/7dtd/VERSION | grep "Version" | cut -d\ -f2)
|
---|
| 22 | local REMOTE=$(wget -qO- http://illy.bz/fi/7dtd/VERSION | grep "Version" | cut -d\ -f2)
|
---|
[48] | 23 |
|
---|
[87] | 24 | local LOCAL_BUILD=$(getLocalEngineVersion)
|
---|
| 25 |
|
---|
[53] | 26 | local FORCED
|
---|
| 27 | if [ "$1" = "--force" ]; then
|
---|
| 28 | FORCED=yes
|
---|
| 29 | else
|
---|
| 30 | FORCED=no
|
---|
| 31 | fi
|
---|
| 32 | if [ "$FORCED" = "yes" -o $REMOTE -gt $LOCAL ]; then
|
---|
[48] | 33 | echo "A newer version of the scripts is available."
|
---|
[248] | 34 | echo "Local: v.$LOCAL"
|
---|
| 35 | echo "Available: v.$REMOTE"
|
---|
[48] | 36 | echo
|
---|
| 37 | echo "Please check the release notes before continuing:"
|
---|
| 38 | echo " https://7dtd.illy.bz/wiki/Release%20Notes"
|
---|
| 39 | echo
|
---|
| 40 |
|
---|
| 41 | while : ; do
|
---|
| 42 | local CONTINUE
|
---|
| 43 | read -p "Continue? (yn) " CONTINUE
|
---|
| 44 | case $CONTINUE in
|
---|
| 45 | y)
|
---|
| 46 | echo "Updating..."
|
---|
| 47 | break
|
---|
| 48 | ;;
|
---|
| 49 | n)
|
---|
| 50 | echo "Canceled"
|
---|
| 51 | return
|
---|
| 52 | ;;
|
---|
| 53 | *)
|
---|
| 54 | echo "Wrong input"
|
---|
| 55 | esac
|
---|
| 56 | done
|
---|
| 57 |
|
---|
[50] | 58 | wget -q http://illy.bz/fi/7dtd/management_scripts.tar.gz -O /tmp/management_scripts.tar.gz
|
---|
[59] | 59 | rm -f /usr/local/lib/7dtd/VERSION /usr/local/lib/7dtd/*.sh /usr/local/lib/7dtd/commands/* /usr/local/bin/7dtd.sh
|
---|
[264] | 60 | TMPPATH=`mktemp -d`
|
---|
| 61 | tar --touch --no-overwrite-dir -xzf /tmp/management_scripts.tar.gz -C $TMPPATH
|
---|
| 62 | cd $TMPPATH
|
---|
| 63 | for SRCFILE in `find * -type f`; do
|
---|
| 64 | DESTFOLDER=/`dirname $SRCFILE`
|
---|
| 65 | mkdir -p $DESTFOLDER
|
---|
| 66 | cp -a $SRCFILE $DESTFOLDER/
|
---|
| 67 | done
|
---|
| 68 | rm -R $TMPPATH
|
---|
[48] | 69 |
|
---|
| 70 | chown root.root /etc/init.d/7dtd.sh
|
---|
| 71 | chown root.root /etc/bash_completion.d/7dtd
|
---|
| 72 | chown root.root /usr/local/bin/7dtd.sh
|
---|
| 73 | chown root.root /usr/local/lib/7dtd -R
|
---|
| 74 | chmod 0755 /etc/init.d/7dtd.sh
|
---|
| 75 | chmod 0755 /etc/bash_completion.d/7dtd
|
---|
| 76 | chmod 0755 /usr/local/bin/7dtd.sh
|
---|
| 77 | chmod 0755 /usr/local/lib/7dtd -R
|
---|
| 78 |
|
---|
[248] | 79 | if [ -d $SDTD_BASE/engine ]; then
|
---|
| 80 | if [ -d /usr/local/lib/7dtd/server-fixes ]; then
|
---|
| 81 | cp /usr/local/lib/7dtd/server-fixes/* $SDTD_BASE/engine/ -R
|
---|
| 82 | chown $SDTD_USER.$SDTD_GROUP -R $SDTD_BASE/engine/
|
---|
| 83 | fi
|
---|
[87] | 84 | fi
|
---|
| 85 |
|
---|
[48] | 86 | echo "Update done."
|
---|
| 87 | echo
|
---|
| 88 | echo "Note: This updated only script files. If the global config file"
|
---|
| 89 | echo "/etc/7dtd.conf contains changes for the newer version or there"
|
---|
| 90 | echo "were new files added to the user folder /home/sdtd those changes"
|
---|
| 91 | echo "have not been applied!"
|
---|
| 92 | else
|
---|
| 93 | echo "Scripts are already at the newest version (v.$LOCAL)."
|
---|
| 94 | fi
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | sdtdCommandUpdatescriptsHelp() {
|
---|
[53] | 98 | echo "Usage: $(basename $0) updatescripts [--force]"
|
---|
[48] | 99 | echo
|
---|
| 100 | echo "Check for a newer version of the management scripts. If there is a newer"
|
---|
| 101 | echo "version they can be updated by this command."
|
---|
[53] | 102 | echo
|
---|
| 103 | echo "If --force is specified you are asked if you want to redownload the scripts"
|
---|
| 104 | echo "even if there is no new version available."
|
---|
[48] | 105 | }
|
---|
| 106 |
|
---|
| 107 | sdtdCommandUpdatescriptsDescription() {
|
---|
| 108 | echo "Update these scripts"
|
---|
| 109 | }
|
---|
| 110 |
|
---|
[53] | 111 | sdtdCommandUpdatescriptsExpects() {
|
---|
| 112 | case $1 in
|
---|
| 113 | 2)
|
---|
| 114 | echo "--force"
|
---|
| 115 | ;;
|
---|
| 116 | esac
|
---|
| 117 | }
|
---|
| 118 |
|
---|