-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.sh
executable file
·155 lines (129 loc) · 4.66 KB
/
setup.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
#!/bin/bash
set -e # Exit immediately if a command exits with a non-zero status.
# Set BASE_PATH
BASE_PATH="$(pwd)"
# Define directories
BUILD_DIR="$BASE_PATH/build"
SRC_DIR="$BASE_PATH/src"
TEST_DIR="$BASE_PATH/test"
EXTERNAL_LIBRARIES_DIR="$BASE_PATH/external_libraries"
COVERAGE_DIR="$BUILD_DIR/coverage"
# Create external_libraries directory if it doesn't exist
mkdir -p "$EXTERNAL_LIBRARIES_DIR"
# Install external libraries
echo "Starting the download of external libraries..."
cd "$EXTERNAL_LIBRARIES_DIR" || { echo "Failed to change to external libraries directory"; exit 1; }
# Function to download and extract library
download_and_extract() {
local name=$1 url=$2 dir=$3 file="${4:-${name}.tar.gz}"
if [ ! -d "$dir" ]; then
echo "Downloading $name..."
curl -L "$url" -o "$file"
tar -xzf "$file"
mv "${dir%-*}" "$dir"
rm "$file"
else
echo "$name library already exists, skipping download."
fi
}
# Download libraries
[ ! -d "Crow" ] && git clone --recurse-submodules https://github.com/CrowCpp/Crow.git Crow || echo "Crow library already exists, skipping download."
download_and_extract "Boost" "https://archives.boost.io/release/1.86.0/source/boost_1_86_0.tar.gz" "boost" "boost_1_86_0.tar.gz"
download_and_extract "Asio" "https://sourceforge.net/projects/asio/files/asio/1.30.2%20%28Stable%29/asio-1.30.2.tar.gz/download" "asio" "asio-1.30.2.tar.gz"
# Download and install MongoDB C++ Driver
if [ ! -d "mongo-cxx-driver" ]; then
echo "Installing MongoDB C++ Driver..."
download_and_extract "MongoDB C++ Driver" "https://github.com/mongodb/mongo-cxx-driver/releases/download/r3.11.0/mongo-cxx-driver-r3.11.0.tar.gz" "mongo-cxx-driver" "mongo-cxx-driver-r3.11.0.tar.gz"
cd mongo-cxx-driver/build
cmake .. -DCMAKE_BUILD_TYPE=Release -DMONGOCXX_OVERRIDE_DEFAULT_INSTALL_PREFIX=OFF
sudo cmake --build . --target install
cd ../..
else
echo "MongoDB C++ Driver already exists, skipping installation."
fi
# Download and install jwt-cpp
if [ ! -d "jwt-cpp" ]; then
echo "Installing jwt-cpp..."
git clone https://github.com/Thalhammer/jwt-cpp.git
cd jwt-cpp
mkdir build && cd build
cmake ..
sudo make install
cd ../..
else
echo "jwt-cpp already exists, skipping installation."
fi
# Download and install bcrypt
if [ ! -d "bcrypt" ]; then
echo "Installing bcrypt..."
git clone https://github.com/trusch/libbcrypt.git bcrypt
cd bcrypt
mkdir build && cd build
cmake ..
make
sudo make install
cd ../..
else
echo "bcrypt already exists, skipping installation."
fi
# Download and install spdlog
if [ ! -d "spdlog" ]; then
echo "Installing spdlog..."
git clone https://github.com/gabime/spdlog.git
cd spdlog
mkdir build && cd build
cmake .. -DCMAKE_POSITION_INDEPENDENT_CODE=ON
sudo make install
cd ../..
else
echo "spdlog already exists, skipping installation."
fi
# Download and install Poco library
if [ ! -d "Poco" ]; then
echo "Downloading and installing Poco library..."
git clone https://github.com/pocoproject/poco.git Poco
cd Poco || { echo "Failed to change to Poco directory"; exit 1; }
mkdir -p cmake-build
cd cmake-build || { echo "Failed to change to Poco build directory"; exit 1; }
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
make install
cd ../../
else
echo "Poco library already exists, skipping download and installation."
fi
echo "All external libraries processed successfully."
# Return to external libraries directory
cd "$EXTERNAL_LIBRARIES_DIR" || { echo "Failed to return to external libraries directory"; exit 1; }
# Clean up downloaded archives if they exist
for archive in asio-1.30.2.tar.gz boost_1_86_0.tar.gz mongo-cxx-driver-r3.11.0.tar.gz
do
if [ -f "$archive" ]; then
rm "$archive"
echo "Removed $archive"
else
echo "$archive not found, skipping removal"
fi
done
echo "All external libraries downloaded and installed successfully."
# Return to the base directory
cd "$BASE_PATH" || { echo "Failed to return to base directory"; exit 1; }
# Create build directory if it doesn't exist
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR" || { echo "Failed to change to build directory"; exit 1; }
cmake ..
# Compile the project
make -C "$BUILD_DIR" || { echo "Compilation failed"; exit 1; }
sudo apt-get update
sudo apt-get install libmongoc-1.0-0
# Clean up downloaded archives if they exist
for archive in asio-1.30.2.tar.gz boost_1_86_0.tar.gz mongo-cxx-driver-r3.11.0.tar.gz
do
if [ -f "$archive" ]; then
rm "$archive"
echo "Removed $archive"
else
echo "$archive not found, skipping removal"
fi
done
echo "Setup complete!"