-
Notifications
You must be signed in to change notification settings - Fork 13
/
mangos-installer
executable file
·229 lines (209 loc) · 6.25 KB
/
mangos-installer
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/bin/bash
#
# Copyright (c) 2013-2017, Dimitri Savineau <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG_APT="git cmake make gcc g++ libmariadbd-dev libmariadb-dev-compat libboost-all-dev zlib1g-dev libssl-dev"
PKG_RPM="git cmake make gcc gcc-c++ mysql-devel boost-devel zlib-devel openssl-devel"
LOG_FILE="$PWD/mangos-installer.log"
CMAKE="cmake"
DEBUG=0
JOBS=1
GREEN="\033[32m"
RED="\033[31m"
RESET="\033[0m"
function Usage {
cat << EOF
Usage: $0: [OPTIONS]
-p <path> : Path to MaNGOS (default: /opt/mangos-<version>)
-d : Set in debug mode
-j <number> : Number of jobs for make (default: 1)
-v <version> : Set MaNGOS version (classic|tbc|wotlk|cata)
-h : Print this help
EOF
exit 1
}
function GetOSInfo {
if [[ -x $(command -v uname 2>/dev/null) ]]; then
os_ARCH=$(uname -m)
else
echo "Can't get architecture"
exit 1
fi
case "$os_ARCH" in
i?86|x86_64)
;;
*)
echo "Unsupported architecture ($os_ARCH)"
exit 1
;;
esac
if [[ -x $(command -v lsb_release 2>/dev/null) ]]; then
os_VENDOR=$(lsb_release -i -s)
os_RELEASE=$(lsb_release -r -s)
os_CODENAME=$(lsb_release -c -s)
os_PACKAGE="rpm"
if [[ "$os_VENDOR" =~ (Debian|Ubuntu) ]]; then
os_PACKAGE="deb"
elif [[ $os_VENDOR =~ Red.*Hat ]]; then
os_VENDOR="Red Hat"
fi
elif [ -r /etc/redhat-release ]; then
os_PACKAGE="rpm"
for os_VENDOR in "Red Hat" CentOS Fedora; do
if [[ -n "`grep \"$os_VENDOR\" /etc/redhat-release`" ]]; then
ver=`sed -e 's/^.* \(.*\) (\(.*\)).*$/\1\|\2/' /etc/redhat-release`
os_CODENAME=${ver#*|}
os_RELEASE=${ver%|*}
os_RELEASE=${os_RELEASE%.*}
break
fi
done
elif [ -r /etc/debian_version ]; then
os_PACKAGE="deb"
os_VENDOR="Debian"
os_RELEASE=$(cat /etc/debian_version)
if [[ "$os_RELEASE" =~ ^"9." ]]; then
os_CODENAME="stretch"
elif [[ "$os_RELEASE" =~ ^"10." ]]; then
os_CODENAME="buster"
elif [[ "$os_RELEASE" =~ ^"11." ]]; then
os_CODENAME="bullseye"
else
echo "Unsupported Debian release ($os_RELEASE)"
exit 1
fi
fi
if [ "$os_VENDOR" = "CentOS" ]; then
if [[ "$os_RELEASE" =~ ^"7" ]]; then
CMAKE="cmake3"
PKG_RPM=$(echo $PKG_RPM|sed -e "s/cmake/cmake3/;s/boost-devel/boost169-devel/")
else
echo "Unsupported CentOS release ($os_RELEASE)"
exit 1
fi
fi
echo "-- GNU/Linux $os_VENDOR"
echo "-- Codename : $os_CODENAME"
echo "-- Release : $os_RELEASE"
echo "-- Package : $os_PACKAGE"
echo "-- Platform : $os_ARCH"
}
function InstallDependencies {
echo -n "Installing dep... "
if [[ "$os_VENDOR" =~ (Ubuntu|Debian) ]]; then
apt-get -q=2 update >> $LOG_FILE 2>&1
AptGetInstall $PKG_APT
elif [[ "$os_VENDOR" =~ (Red Hat|Fedora|CentOS) ]]; then
if [ "$os_VENDOR" = "CentOS" ]; then
YumInstall "epel-release"
fi
YumInstall $PKG_RPM
else
echo -e "[${RED}fail${RESET}]"
echo "Support for $os_VENDOR is incomplete."
exit 1
fi
CheckStatus
}
function AptGetInstall {
DEBIAN_FRONTEND=noninteractive \
apt-get install --option "Dpkg::Options::=--force-confold" --assume-yes "$@" >> $LOG_FILE 2>&1
if [ $? -ne 0 ]; then
echo -e "[${RED}fail${RESET}]"
echo "Unable to install $@ with apt-get"
exit 1
fi
}
function YumInstall {
yum install -y "$@" >> $LOG_FILE 2>&1
if [ $? -ne 0 ]; then
echo -e "[${RED}fail${RESET}]"
echo "Unable to install $@ with yum"
exit 1
fi
}
function GetSources {
[ ! -d mangos ] || rm -rf mangos
echo -n "Cloning MaNGOS... "
git clone $MANGOS mangos >> $LOG_FILE 2>&1
CheckStatus
if [ "$VERSION" = "cata" ]; then
MANGOS_VERSION=$(cat mangos/version.txt)
else
MANGOS_VERSION=$(grep VERSION mangos/src/shared/revision.h.in|awk '{print $3}'|tr -d '"')
fi
}
function ConfigureCmake {
mkdir -p mangos/build && cd mangos/build
echo -n "Configuration... "
$CMAKE .. -DCMAKE_INSTALL_PREFIX=$PREFIX -DDEBUG=$DEBUG \
-DPCH=1 >> $LOG_FILE 2>&1
CheckStatus
}
function BuildMangos {
echo -n "Compiling... "
make -j $JOBS >> $LOG_FILE 2>&1
CheckStatus
}
function InstallMangos {
echo -n "Installing... "
make install >> $LOG_FILE 2>&1
CheckStatus
}
function CheckStatus {
if [ $? -eq 0 ]; then
echo -e "[${GREEN}OK${RESET}]"
else
echo -e "[${RED}fail${RESET}]"
exit 1
fi
}
while getopts 'hdj:v:p:' OPTION; do
case "$OPTION" in
p)
PREFIX="$OPTARG"
;;
d)
DEBUG=1
;;
j)
JOBS="$OPTARG"
;;
v)
VERSION="$OPTARG"
;;
?)
Usage
;;
esac
done
[ -z "$VERSION" ] && Usage
[ -f $LOG_FILE ] && rm -f $LOG_FILE
if [[ "$VERSION" =~ ^(classic|tbc|wotlk|cata)$ ]]; then
MANGOS=git://github.com/cmangos/mangos-$VERSION.git
[ "$VERSION" = "cata" ] && PKG_APT+=" libbz2-dev" && PKG_RPM+=" bzip2-devel"
[ -z "$PREFIX" ] && PREFIX="/opt/mangos-$VERSION"
else
echo "$VERSION is not a MaNGOS version"
exit 1
fi
GetOSInfo
InstallDependencies
GetSources
ConfigureCmake
BuildMangos
InstallMangos
echo "MaNGOS $MANGOS_VERSION ($VERSION) has been installed !"
exit 0