1 | #!/bin/bash
|
---|
2 |
|
---|
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 |
|
---|
18 | # Checks for newer scripts version and downloads them
|
---|
19 |
|
---|
20 | sdtdCommandUpdatescripts() {
|
---|
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)
|
---|
23 |
|
---|
24 | local LOCAL_BUILD=$(getLocalEngineVersion)
|
---|
25 |
|
---|
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
|
---|
33 | echo "A newer version of the scripts is available."
|
---|
34 | echo "Local: v.$LOCAL"
|
---|
35 | echo "Available: v.$REMOTE"
|
---|
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 |
|
---|
58 | wget -q http://illy.bz/fi/7dtd/management_scripts.tar.gz -O /tmp/management_scripts.tar.gz
|
---|
59 | rm -f /usr/local/lib/7dtd/VERSION /usr/local/lib/7dtd/*.sh /usr/local/lib/7dtd/commands/* /usr/local/bin/7dtd.sh
|
---|
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 | if [[ $SRCFILE != etc* ]] || [[ $SRCFILE == etc/bash_completion+ ]]; then
|
---|
65 | DESTFOLDER=/`dirname $SRCFILE`
|
---|
66 | mkdir -p $DESTFOLDER
|
---|
67 | cp -a $SRCFILE $DESTFOLDER/
|
---|
68 | fi
|
---|
69 | done
|
---|
70 | rm -R $TMPPATH
|
---|
71 |
|
---|
72 | # chown root:root /etc/init.d/7dtd.sh
|
---|
73 | chown root:root /etc/bash_completion.d/7dtd
|
---|
74 | chown root:root /usr/local/bin/7dtd.sh
|
---|
75 | chown root:root /usr/local/lib/7dtd -R
|
---|
76 | # chmod 0755 /etc/init.d/7dtd.sh
|
---|
77 | chmod 0755 /etc/bash_completion.d/7dtd
|
---|
78 | chmod 0755 /usr/local/bin/7dtd.sh
|
---|
79 | chmod 0755 /usr/local/lib/7dtd -R
|
---|
80 |
|
---|
81 | if [ -d $SDTD_BASE/engine ]; then
|
---|
82 | if [ -d /usr/local/lib/7dtd/server-fixes ]; then
|
---|
83 | cp /usr/local/lib/7dtd/server-fixes/* $SDTD_BASE/engine/ -R
|
---|
84 | chown $SDTD_USER:$SDTD_GROUP -R $SDTD_BASE/engine/
|
---|
85 | fi
|
---|
86 | fi
|
---|
87 |
|
---|
88 | echo "Update done."
|
---|
89 | echo
|
---|
90 | echo "Note: This updated only script files. If the global config file"
|
---|
91 | echo "/etc/7dtd.conf contains changes for the newer version or there"
|
---|
92 | echo "were new files added to the user folder /home/sdtd those changes"
|
---|
93 | echo "have not been applied!"
|
---|
94 | else
|
---|
95 | echo "Scripts are already at the newest version (v.$LOCAL)."
|
---|
96 | fi
|
---|
97 | }
|
---|
98 |
|
---|
99 | sdtdCommandUpdatescriptsHelp() {
|
---|
100 | echo "Usage: $(basename $0) updatescripts [--force]"
|
---|
101 | echo
|
---|
102 | echo "Check for a newer version of the management scripts. If there is a newer"
|
---|
103 | echo "version they can be updated by this command."
|
---|
104 | echo
|
---|
105 | echo "If --force is specified you are asked if you want to redownload the scripts"
|
---|
106 | echo "even if there is no new version available."
|
---|
107 | }
|
---|
108 |
|
---|
109 | sdtdCommandUpdatescriptsDescription() {
|
---|
110 | echo "Update these scripts"
|
---|
111 | }
|
---|
112 |
|
---|
113 | sdtdCommandUpdatescriptsExpects() {
|
---|
114 | case $1 in
|
---|
115 | 2)
|
---|
116 | echo "--force"
|
---|
117 | ;;
|
---|
118 | esac
|
---|
119 | }
|
---|
120 |
|
---|