Teaspeak-Server/server/repro/generate_libraries.sh
2020-01-25 15:05:48 +01:00

81 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
#Required libraries:
# "libssl.so"
# "libcrypto.so"
# "libDataPipes.so"
# "libjemalloc.so.2"
# "libsqlite3.so.0"
# "libTeaMusic.so"
# "libnice.so.10"
# "libpcre.so.3" (only for web)
[[ -z "${build_os_type}" ]] && { echo "missing build os type"; exit 1; }
[[ -z "${build_os_arch}" ]] && { echo "missing build os arch"; exit 1; }
build_path="out/${build_os_type}_${build_os_arch}/"
function query_system_link() {
data=$(ldd ../../../environment/TeaSpeakServer | grep "$1")
# shellcheck disable=SC2206
data=($data)
library_path=${data[2]}
[[ -z "${library_path}" ]] && { echo "failed to resolve library path for $1"; exit 1; }
[[ "${library_path}" == "not" ]] && { echo "failed to resolve library path for $1"; exit 1; }
}
cd $(dirname $0) || exit 1
cd env || { echo "failed to enter env"; exit 1; }
[[ -d libs ]] && {
rm -r libs || { echo "failed to delete old lib folder"; exit 1; }
}
mkdir libs || { echo "failed to create lib directory"; exit 1; }
cd libs || { echo "failed to enter lib directory"; exit 1; }
# Creating copied
library_base=$(realpath ../../../../../libraries)
# Setting up ssl
library_path=$(realpath "${library_base}/boringssl/${build_path}/ssl/libssl.so")
cp "$library_path" . || { echo "failed to copy libssl.so"; exit 1; }
# Setting up crypto
library_path=$(realpath "${library_base}/boringssl/${build_path}/crypto/libcrypto.so")
cp "$library_path" . || { echo "failed to copy libcrypto.so"; exit 1; }
# Setting up DataPipes
library_path=$(realpath "${library_base}//DataPipes/${build_path}/lib/libDataPipes.so")
cp "$library_path" . || { echo "failed to copy libDataPipes.so"; exit 1; }
# Setting up Sqlite3
query_system_link "libsqlite3.so.0"
cp "${library_path}" . || { echo "failed to copy libsqlite3.so.0"; exit 1; }
# Setting up jemalloc
query_system_link "libjemalloc.so.2"
cp "${library_path}" . || { echo "failed to copy libjemalloc.so.2"; exit 1; }
# Setting up TeaMusic
library_path=$(realpath "../../../../MusicBot/libs/libTeaMusic.so")
cp "$library_path" . || { echo "failed to copy libTeaMusic.so"; exit 1; }
if ldd "../../../environment/TeaSpeakServer" | grep -q "libnice.so.10"; then
echo "Adding web libraries"
# Setting up libnice
library_path=$(realpath "${library_base}/libnice/${build_os_type}_${build_os_arch}/lib/libnice.so.10")
cp "$library_path" . || { echo "failed to copy libnice.so.10"; exit 1; }
# Setting up libpcre
query_system_link "libpcre.so.3"
cp "${library_path}" . || { echo "failed to copy libpcre.so.3"; exit 1; }
fi
# Fix rpaths
for file in *.so*; do
echo "Editing rpath for $file"
patchelf --set-rpath "./libs/:./" "$file"
done
echo "All libraries have been linked successfully"