-
Notifications
You must be signed in to change notification settings - Fork 0
/
googletest.sh
executable file
·46 lines (31 loc) · 1.09 KB
/
googletest.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
#!/bin/bash
function is_root {
[ "${EUID:-$(id -u)}" -eq 0 ];
}
if ! is_root; then
echo -e "\x1B[31m[ERROR] This script requires root privileges."
exit 1
fi
PARENT_DIR="${1}"
CURRENT_USER=$(who | awk 'NR==1{print $1}')
if [ -z "${PARENT_DIR}" ]; then
PARENT_DIR="/opt"
fi
GOOGLETEST_DIR="${PARENT_DIR}/googletest"
TMP_GIT_REPO_DIR="/tmp/googletest"
echo -e "\x1B[01;93mInstalling git...\n\u001b[0m"
apt install git -y
echo -e "\x1B[01;93m\nInstalling or updating googletest...\n\u001b[0m"
rm -rf "${TMP_GIT_REPO_DIR}"
mkdir -p "${TMP_GIT_REPO_DIR}"
git clone --recurse-submodules https://github.com/google/googletest.git -o googletest "${TMP_GIT_REPO_DIR}"
mkdir -p "${TMP_GIT_REPO_DIR}/build"
rm -rf "${GOOGLETEST_DIR}" # removes the directory if it exists to avoid errors
mkdir -p "${GOOGLETEST_DIR}"
pushd "${TMP_GIT_REPO_DIR}/build" || exit 1
cmake .. -DCMAKE_INSTALL_PREFIX="${GOOGLETEST_DIR}"
make -j "$(nproc)"
make install
popd || exit 1
rm -rf "${TMP_GIT_REPO_DIR}"
chown "${CURRENT_USER}":"${CURRENT_USER}" "${GOOGLETEST_DIR}" -R # changes the owner of the directory to the current user