-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoolite-update.src
executable file
·142 lines (126 loc) · 4.71 KB
/
oolite-update.src
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#
# Oolite Updater Script
# Dylan Smith, 2005-09-10
#
# Konstantinos Sykas
# 2009-09-22: rsync to alternative server
# 2009-10-13: x86_64 support
# 2010-04-23: 1) Improved x86_64 detection
# 2) Improved exit-message when no new Oolite version is available
# 2011-03-22: Removed TOPLEVEL environment variable. A small fix in the default.*.apspec file
# made TOPLEVEL obsolete. OOLITE_ROOT is more than enough.
# 2011-03-26: Updated to support the new self-extractable package
# 2011-04-03: Updated to facilitate rsync repository setup for oolite-update script
# 2013-08-27: Updated new network name of terrastorage to terrastorage.dyndns.info
# 2013-11-13: Updated version comparison to use "build date" as per new version format (i.e. maj.min.rev.gitrev-builddate-githash)
# 2014-05-01: Updated new network name of terrastorage to terrastorage.no-ip.info
#
RSYNC_SERVER_PRIMARY="terrastorage.no-ip.info"
RSYNC_SERVER_SECONDARY="rsync.alioth.net"
RSYNC_ERR=0
if [ `id -u` -eq 0 ]
then
USER_IS_ROOT=1
fi
OOLITE_ROOT=$(cd $(dirname $0); cd ..; pwd -P)
HOST_ARCH=`uname -m | sed -e s/amd64/x86_64/`
if [ "$HOST_ARCH" = "x86_64" ]; then
OOLITE_RSYNC_FOLDER="oolite${TRUNK}-linux-64"
STATUS_ARCH="_AMD64"
else
OOLITE_RSYNC_FOLDER="oolite${TRUNK}-linux"
fi
# Check if rsync client is available
which rsync 2>/dev/null >/dev/null
if [ $? != 0 ]
then
echo "No rsync, no Oolite${TRUNK} update!"
echo "---------------------------"
echo "Sorry, you don't seem to have rsync installed."
echo "To install it, depending on your distro, run one of the following:"
echo "Debian-style distros: apt-get install rsync"
echo "Redhattish distros: up2date -i rsync"
echo "Other RPM distros: yum install rsync"
echo "Gentoo users should know what to do already"
echo
echo "Then run oolite${TRUNK}-update again."
echo
exit 1
fi
if [ $SELF_PACKAGER ]
then
# Refuse automated update of a relocated installation
if [ "${OOLITE_ROOT}" != "$HOME/${INSTALL_ROOT_USERHOME}/${OOLITE_ROOT_NAME}" ] && [ "${OOLITE_ROOT}" != "${INSTALL_ROOT_SYSTEMWIDE}/${OOLITE_ROOT_NAME}" ]
then
echo "Error: Oolite${TRUNK} installation has been relocated from its original path."
exit 1
fi
# Check if we have the right privileges to proceed with update
if [ "${OOLITE_ROOT}" = "${INSTALL_ROOT_SYSTEMWIDE}/${OOLITE_ROOT_NAME}" ] && [ ! ${USER_IS_ROOT} ]
then
echo "Error: Oolite${TRUNK} was installed by root, so you must be root to update it."
exit 1
fi
else # Remove the "else" section if autopackager will be dismissed
if [ "${OOLITE_ROOT}" = "/usr/lib/Oolite${TRUNK}" ] && [ ! ${USER_IS_ROOT} ]
then
echo "Error: Oolite${TRUNK} was installed by root, so you must be root to update it."
exit 1
fi
fi
# Start update
cd ${OOLITE_ROOT}
CURRENTVER=`cat release.txt`
BUILDDATE=`echo ${CURRENTVER} | cut -d '-' -f 2`
# Backup release.txt
cp -p ${OOLITE_ROOT}/release.txt ${OOLITE_ROOT}/release.txt.backup
# Try rsync from primary server
echo Trying rsync://${RSYNC_SERVER_PRIMARY}/$OOLITE_RSYNC_FOLDER...
rsync -rlvz --progress rsync://${RSYNC_SERVER_PRIMARY}/$OOLITE_RSYNC_FOLDER/* . 2> /dev/null
RSYNC_ERR=$?
if [ ${RSYNC_ERR} != 0 ];
then
# Try rsync from secondary server
echo [${RSYNC_SERVER_PRIMARY} died and returned ${RSYNC_ERR}]
echo
echo Trying rsync://${RSYNC_SERVER_SECONDARY}/$OOLITE_RSYNC_FOLDER...
rsync -rlvz --progress rsync://${RSYNC_SERVER_SECONDARY}/$OOLITE_RSYNC_FOLDER/* . 2> /dev/null
RSYNC_ERR=$?
fi
if [ ${RSYNC_ERR} != 0 ]; then
echo [${RSYNC_SERVER_SECONDARY} died and returned ${RSYNC_ERR}]
echo
echo "If the problem was caused by network or other transient issues, "
echo "try running oolite${TRUNK}-update again."
echo "Alternatively you may download the full package from "
if [ ${TRUNK} ]
then
echo "http://${RSYNC_SERVER_PRIMARY}/oolite/status${STATUS_ARCH}.html"
else
echo "http://www.oolite.org/download.shtml"
fi
echo
# Restore release.txt and exit
mv release.txt.backup release.txt
exit 1
fi
# rsync was successful; release.txt.backup can be removed
rm -f release.txt.backup
# Inform the user about what happened during update
NEW_CURRENTVER=`cat release.txt`
NEW_BUILDDATE=`echo ${NEW_CURRENTVER} | cut -d '-' -f 2`
if [ ${NEW_BUILDDATE} -gt ${BUILDDATE} ]
then
echo "Oolite${TRUNK} has been upgraded from ${CURRENTVER} to ${NEW_CURRENTVER}"
exit 0
else
if [ ${NEW_BUILDDATE} -lt ${BUILDDATE} ] # TODO - Do not downgrade
then
echo "Oolite${TRUNK} has been downgraded from ${CURRENTVER} to ${NEW_CURRENTVER}"
exit 0
else
echo "Your Oolite${TRUNK} installation is already up to date."
echo "Any missing or altered Oolite${TRUNK} installation files have been restored."
exit 0
fi
fi