-
Notifications
You must be signed in to change notification settings - Fork 16
/
bootstrap.sh
263 lines (233 loc) · 7.56 KB
/
bootstrap.sh
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/bin/bash
# Echo tags
RED="\033[0;31m"
GREEN="\033[0;32m"
ORANGE="\033[31;33m"
END="\033[0;0m"
premake_cmd="premake5"
premake_args=""
# Prerequisite packages
debian_install="apt -y install git zip build-essential uuid-dev"
arch_install="pacman -Syu git zip"
fedora_install="dnf install git make gcc-c++ libuuid-devel perl-IPC-Cmd"
suse_install="zypper install git-core make gcc-c++ libuuid-devel"
# https://stackoverflow.com/questions/45125516/possible-values-for-uname-m
arch=$(uname -m)
build_arch="64"
case "$arch" in
aarch64 | armv8* | armv9* | arm64)
build_arch="arm64"
# https://github.com/Black-Tek/BlackTek-Server/pull/5
export VCPKG_FORCE_SYSTEM_BINARIES=1
debian_install="${debian_install} cmake ninja-build"
arch_install="${arch_install} cmake ninja"
fedora_install="${fedora_install} cmake ninja-build"
suse_install="${suse_install} cmake ninja-build"
;;
arm | armv7*)
build_arch="arm"
premake_args="${premake_args} --use-system-libs --use-lua=lua5.4"
debian_install="${debian_install} liblua5.4-dev libmysqlclient-dev libboost-system-dev libboost-iostreams-dev libpugixml-dev libcrypto++-dev libfmt-dev"
skip_vcpkg=true
;;
armv6* | i386 | i686)
echo -e "${RED}=== 32 bit systems are not supported ===${END}"
exit 1
;;
x86_64)
build_arch="64"
;;
*)
echo -e "${ORANGE}Unknown processor architecture ${arch}. If your OS is 64 bit it may still work."
echo -e "32 bit systems are not supported.${END}"
read -p "Press [Enter] to continue or [Ctrl + C] to cancel." _
;;
esac
check_deps () {
if ! command -v "git" &> /dev/null \
|| ! command -v "make" &> /dev/null \
|| ! command -v "zip" &> /dev/null \
|| ( command -v "pkg-config" &> /dev/null && ! pkg-config --exists uuid &> /dev/null ); then
echo "Missing build dependency. Make sure the prerequisite software is installed."
echo
echo "Debian/Ubuntu: ${debian_install}"
echo "Arch: ${arch_install}"
echo "Fedora: ${fedora_install}"
echo "OpenSUSE: ${suse_install}"
return 1
fi
if [ "$build_arch" = "ARM64" ] && ( ! command -v "cmake" &> /dev/null || ! command -v "ninja" &> /dev/null ); then
echo "Missing build dependency. Make sure the prerequisite software is installed."
echo
echo "Debian/Ubuntu: ${debian_install}"
echo "Arch: ${arch_install}"
echo "Fedora: ${fedora_install}"
echo "OpenSUSE: ${suse_install}"
return 1
fi
return 0
}
if ! check_deps; then
echo "Some required software could not be found."
echo "Attempt automatic install? (y/n): " do_install
if [ ! $do_install ] || [ $do_install == "n" ]; then
echo "Please install the prerequisite software using your package manager."
echo
echo "Debian/Ubuntu: ${debian_install}"
echo "Arch: ${arch_install}"
echo "Fedora: ${fedora_install}"
echo "OpenSUSE: ${suse_install}"
exit 1
fi
if command -v "apt" &> /dev/null; then
echo -e ${GREEN}Installing required software${END}
sudo apt -y update
if ! sudo $debian_install; then
echo "Missing dependencies were not installed."
echo -e "${RED}=== Configuration is not finished ===${END}"
exit 1
fi
elif command -v "pacman" &> /dev/null; then
echo -e ${GREEN}Installing required software${END}
if ! sudo $arch_install; then
echo "Missing dependencies were not installed."
echo -e "${RED}=== Configuration is not finished ===${END}"
exit 1
fi
elif command -v "dnf" &> /dev/null; then
echo -e ${GREEN}Installing required software${END}
if ! sudo $fedora_install; then
echo "Missing dependencies were not installed."
echo -e "${RED}=== Configuration is not finished ===${END}"
exit 1
fi
elif command -v "zypper" &> /dev/null; then
echo -e ${GREEN}Installing required software${END}
if ! sudo $suse_install; then
echo "Missing dependencies were not installed."
echo -e "${RED}=== Configuration is not finished ===${END}"
exit 1
fi
else
echo "Automatic install is not supported on your distribution."
echo "Please install the prerequisite software using your package manager."
echo
echo "Debian/Ubuntu: ${debian_install}"
echo "Arch: ${arch_install}"
echo "Fedora: ${fedora_install}"
echo "OpenSUSE: ${suse_install}"
echo
echo -e "${RED}=== Configuration is not finished ===${END}"
exit 1
fi
fi
gcc_version=`gcc --version | awk 'NR==1 {print $3}' | cut -f 1 -d "."`
if (( gcc_version < 11 )); then
echo -e "${RED}=== GCC version 11 or above is required. ===${END}"
exit 1
fi
dir=`pwd`
if [ ! -d ~/.local/bin ]; then
mkdir -p ~/.local/bin
fi
if ! command -v "${premake_cmd}" &> /dev/null; then
echo -e "${GREEN}Installing premake${END}"
already_uptodate=false
if [ ! -d ../premake-core ]; then
git clone https://github.com/premake/premake-core ../premake-core
cd ../premake-core
else
cd ../premake-core
if [[ "$(git pull --ff-only)" = "Already up to date." ]]; then
already_uptodate=true
fi
fi
if [[ ! $already_uptodate ]] || [ ! -f ../premake-core/bin/release/premake5 ]; then
if make -f Bootstrap.mak linux; then
cp -f ./bin/release/premake5 ~/.local/bin/premake5
else
echo -e "${RED}=== An error occured while compiling premake. Configuration is not complete. ===${END}"
exit 1
fi
else
echo "Found existing premake"
fi
premake_cmd="${HOME}/premake-core/bin/release/premake5"
fi
if [ ! skip_vcpkg ]; then
# Check for vcpkg in env
if ! printenv VCPKG_ROOT &> /dev/null; then
if [ -d $HOME/vcpkg ]; then
export VCPKG_ROOT=$HOME/vcpkg
else
export VCPKG_ROOT=../vcpkg
fi
fi
if [ ! -d $VCPKG_ROOT ] || [ ! -f $VCPKG_ROOT/vcpkg ]; then
echo -e "${GREEN}Installing vcpkg${END}"
if [ ! -d $VCPKG_ROOT ]; then
git clone https://github.com/microsoft/vcpkg ../vcpkg
fi
cd $VCPKG_ROOT
if ! ./bootstrap-vcpkg.sh -disableMetrics; then
echo -e "${RED}=== An error occured while installing vcpkg. Configuration is not complete. ===${END}"
exit 1
fi
cp ./vcpkg ~/.local/bin/vcpkg
fi
fi
cd $dir
# In case .local/bin is not in path we use the path where we installed it instead
if ! ${premake_cmd} gmake2 ${premake_args}; then
echo -e "${RED}=== An error occured while executing premake. Configuration is not complete. ===${END}"
exit 1
fi
if [ ! skip_vcpkg ]; then
if ! $VCPKG_ROOT/vcpkg install; then
echo -e "${RED}=== An error occured while executing vcpkg. Configuration is not complete. ===${END}"
exit 1
fi
fi
echo -e "${GREEN}=== Configuration Finished ===${END}"
echo
make_debug="make -j \$(nproc) config=debug_${build_arch}"
make_release="make -j \$(nproc) config=release_${build_arch}"
read -p "Would you like to compile the server now? (n: No, d: Debug, r: Release) " compile
if [ ! $compile ] || [ $compile == "n" ]; then
echo "To compile the server run:"
echo "Debug: ${make_debug}"
echo "Release: ${make_release}"
exit 0
elif [ $compile == "d" ]; then
if make -j `nproc` "config=debug_${build_arch}"; then
echo
echo -e "${GREEN}=== Compilation Successful ===${END}"
echo
echo "To start the server: ./Black-Tek-Server"
echo "Remember to configure MySQL details in config.lua!"
echo
echo "To re-compile:"
echo "Debug: ${make_debug}"
echo "Release: ${make_release}"
echo "Alternatively re-run bootstrap.sh"
else
echo
echo -e "${RED}=== Compilation Failed ===${END}"
fi
elif [ $compile == "r" ]; then
if make -j `nproc` "config=release_${build_arch}"; then
echo
echo -e "${GREEN}=== Compilation Successful ===${END}"
echo
echo "To start the server: ./Black-Tek-Server"
echo "Remember to configure MySQL details in config.lua!"
echo
echo "To re-compile:"
echo "Debug: ${make_debug}"
echo "Release: ${make_release}"
echo "Alternatively re-run bootstrap.sh"
else
echo
echo -e "${RED}=== Compilation Failed ===${END}"
fi
fi