source: scripts/usr/local/lib/7dtd/commands/updatescripts.sh @ 258

Last change on this file since 258 was 258, checked in by alloc, 3 years ago

Scripts: License

File size: 3.2 KB
Line 
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
20sdtdCommandUpdatescripts() {
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                tar --touch --no-overwrite-dir --exclude=etc --exclude=home -xzf /tmp/management_scripts.tar.gz -C /
61
62                chown root.root /etc/init.d/7dtd.sh
63                chown root.root /etc/bash_completion.d/7dtd
64                chown root.root /usr/local/bin/7dtd.sh
65                chown root.root /usr/local/lib/7dtd -R
66                chmod 0755 /etc/init.d/7dtd.sh
67                chmod 0755 /etc/bash_completion.d/7dtd
68                chmod 0755 /usr/local/bin/7dtd.sh
69                chmod 0755 /usr/local/lib/7dtd -R
70               
71                if [ -d $SDTD_BASE/engine ]; then
72                        if [ -d /usr/local/lib/7dtd/server-fixes ]; then
73                                cp /usr/local/lib/7dtd/server-fixes/* $SDTD_BASE/engine/ -R
74                                chown $SDTD_USER.$SDTD_GROUP -R $SDTD_BASE/engine/
75                        fi
76                fi
77
78                echo "Update done."
79                echo
80                echo "Note: This updated only script files. If the global config file"
81                echo "/etc/7dtd.conf contains changes for the newer version or there"
82                echo "were new files added to the user folder /home/sdtd those changes"
83                echo "have not been applied!"
84        else
85                echo "Scripts are already at the newest version (v.$LOCAL)."
86        fi
87}
88
89sdtdCommandUpdatescriptsHelp() {
90        echo "Usage: $(basename $0) updatescripts [--force]"
91        echo
92        echo "Check for a newer version of the management scripts. If there is a newer"
93        echo "version they can be updated by this command."
94        echo
95        echo "If --force is specified you are asked if you want to redownload the scripts"
96        echo "even if there is no new version available."
97}
98
99sdtdCommandUpdatescriptsDescription() {
100        echo "Update these scripts"
101}
102
103sdtdCommandUpdatescriptsExpects() {
104        case $1 in
105                2)
106                        echo "--force"
107                        ;;
108        esac
109}
110
Note: See TracBrowser for help on using the repository browser.