Repository navigation
Expand file tree
/
Copy pathinstall_dependency.sh
More file actions
executable file
·266 lines (236 loc) · 6.21 KB
/
Copy pathinstall_dependency.sh
File metadata and controls
executable file
·266 lines (236 loc) · 6.21 KB
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
264
265
266
#!/bin/bash
set -euo pipefail # Enable strict error checking
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Logging functions
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1" >&2
}
# Cleanup function
cleanup() {
local exit_code=$?
if [[ ${exit_code} -ne 0 ]]; then
log_error "Script failed with exit code ${exit_code}"
fi
cd "${CURR_DIR}"
exit "${exit_code}"
}
trap cleanup EXIT
# Help message
show_help() {
echo "Usage: $0 [OPTIONS]"
echo "Install dependencies for libCacheSim"
echo
echo "Options:"
echo " -h, --help Show this help message"
echo " -c, --cmake-only Install only CMake"
echo " -z, --zstd-only Install only Zstd"
echo " -x, --xgboost-only Install only XGBoost"
echo " -l, --lightgbm-only Install only LightGBM"
echo
echo "If no options are specified, all dependencies will be installed"
}
# Parse command line arguments
INSTALL_ALL=true
INSTALL_CMAKE=false
INSTALL_ZSTD=false
INSTALL_XGBOOST=false
INSTALL_LIGHTGBM=false
while [[ $# -gt 0 ]]; do
case $1 in
-h | --help)
show_help
exit 0
;;
-c | --cmake-only)
INSTALL_ALL=false
INSTALL_CMAKE=true
shift
;;
-z | --zstd-only)
INSTALL_ALL=false
INSTALL_ZSTD=true
shift
;;
-x | --xgboost-only)
INSTALL_ALL=false
INSTALL_XGBOOST=true
shift
;;
-l | --lightgbm-only)
INSTALL_ALL=false
INSTALL_LIGHTGBM=true
shift
;;
*)
log_error "Unknown option: $1"
show_help
exit 1
;;
esac
done
# Store current directory
CURR_DIR=$(pwd)
# Check if running with sudo
if [[ ${EUID} -eq 0 ]]; then
log_warn "Please do not run this script as root/sudo"
exit 1
fi
# OS detection and setup
setup_ubuntu() {
log_info "Setting up Ubuntu dependencies..."
sudo apt update
sudo apt install -yqq build-essential xxhash ninja-build
sudo apt install -yqq libglib2.0-dev libunwind-dev
sudo apt install -yqq libgoogle-perftools-dev
}
setup_centos() {
log_info "Setting up CentOS dependencies..."
sudo yum install centos-release-scl
sudo yum install -y glib2-devel google-perftools-devel
# For the older llvm-toolset-7 (Clang 5.0.1)
sudo yum install llvm-toolset-7-clang-tools-extra
# Or for llvm-toolset-10 (Clang 10)
# sudo yum install llvm-toolset-10.0-clang-tools-extra
sudo scl enable llvm-toolset-10 bash
}
setup_macOS() {
log_info "Setting up macOS dependencies..."
if ! command -v brew &>/dev/null; then
log_error "Homebrew is not installed. Please install Homebrew first."
exit 1
fi
# tcmalloc is packaged as gperftools on Homebrew; libgoogle-perftools-dev is the apt package
brew install glib gperftools argp-standalone xxhash llvm wget cmake ninja zstd xgboost lightgbm pkgconf
}
# Install CMake
install_cmake() {
log_info "Installing CMake..."
local cmake_version="3.31.0"
local cmake_dir="${HOME}/software/cmake"
pushd /tmp/ >/dev/null
if [[ ! -f "cmake-${cmake_version}-linux-x86_64.sh" ]]; then
wget "https://github.com/Kitware/CMake/releases/download/v${cmake_version}/cmake-${cmake_version}-linux-x86_64.sh"
fi
mkdir -p "${cmake_dir}" 2>/dev/null || true
bash "cmake-${cmake_version}-linux-x86_64.sh" --skip-license --prefix="${cmake_dir}"
# Add to shell config files if not already present
for shell_rc in "${HOME}/.bashrc" "${HOME}/.zshrc"; do
# trunk-ignore(shellcheck/SC2016)
if [[ -f ${shell_rc} ]] && ! grep -q 'PATH=$HOME/software/cmake/bin:$PATH' "${shell_rc}"; then
# trunk-ignore(shellcheck/SC2016)
echo 'export PATH=$HOME/software/cmake/bin:$PATH' >>"${shell_rc}"
fi
done
# Source the updated PATH
export PATH="${cmake_dir}/bin:${PATH}"
popd >/dev/null
}
# Install XGBoost
install_xgboost() {
log_info "Installing XGBoost..."
pushd /tmp/ >/dev/null
if [[ ! -d "xgboost" ]]; then
git clone --recursive https://github.com/dmlc/xgboost
fi
pushd xgboost >/dev/null
mkdir -p build
pushd build >/dev/null
cmake -G Ninja ..
ninja
sudo ninja install
popd >/dev/null
popd >/dev/null
popd >/dev/null
}
# Install LightGBM
install_lightgbm() {
log_info "Installing LightGBM..."
pushd /tmp/ >/dev/null
if [[ ! -d "LightGBM" ]]; then
git clone --recursive https://github.com/microsoft/LightGBM
fi
pushd LightGBM >/dev/null
mkdir -p build
pushd build >/dev/null
cmake -G Ninja ..
ninja
sudo ninja install
popd >/dev/null
popd >/dev/null
popd >/dev/null
}
# Install Zstd
install_zstd() {
log_info "Installing Zstd..."
local zstd_version="1.5.0"
# Check if Zstd exists
if command -v zstd &>/dev/null; then
local installed_version
installed_version=$(zstd --version | grep -oE 'v[0-9.]+' | sed 's/^v//')
if [[ $installed_version == "$zstd_version" ]]; then
log_info "Zstd version $zstd_version already installed."
return 0
else
log_info "Zstd is installed but version is $installed_version (expecting $zstd_version). Proceeding to install..."
fi
fi
# Install
pushd /tmp/ >/dev/null
if [[ ! -f "zstd-${zstd_version}.tar.gz" ]]; then
wget "https://github.com/facebook/zstd/releases/download/v${zstd_version}/zstd-${zstd_version}.tar.gz"
tar xf "zstd-${zstd_version}.tar.gz"
fi
pushd "zstd-${zstd_version}/build/cmake/" >/dev/null
mkdir -p _build
pushd _build >/dev/null
cmake -G Ninja ..
ninja
sudo ninja install
popd >/dev/null
popd >/dev/null
popd >/dev/null
}
# Main installation logic
main() {
# Detect OS and setup basic dependencies
if uname -a | grep -qE "Ubuntu|Debian|WSL"; then
setup_ubuntu
elif uname -a | grep -q Darwin; then
setup_macOS
else
setup_centos
fi
# Install requested components only on non macOS computers
# Libraries already installed on macOS using brew in setup_macOS
if ! uname -a | grep -q Darwin; then
if [[ ${INSTALL_ALL} == true ]] || [[ ${INSTALL_CMAKE} == true ]]; then
install_cmake
fi
if [[ ${INSTALL_ALL} == true ]] || [[ ${INSTALL_ZSTD} == true ]]; then
install_zstd
fi
if [[ ${INSTALL_ALL} == true ]] || [[ ${INSTALL_XGBOOST} == true ]]; then
if [[ ${GITHUB_ACTIONS-} != "true" ]]; then
install_xgboost
fi
fi
if [[ ${INSTALL_ALL} == true ]] || [[ ${INSTALL_LIGHTGBM} == true ]]; then
if [[ ${GITHUB_ACTIONS-} != "true" ]]; then
install_lightgbm
fi
fi
fi
log_info "Installation completed successfully!"
}
# Run main function
main