-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsetup.sh
247 lines (220 loc) · 7.23 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
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
#!/bin/bash
set -e # Exit on error
# Function to prompt user for yes/no input
prompt_yes_no() {
while true; do
printf "%s (yes/no): " "$1"
read yn
case $yn in
[Yy]* ) return 0;;
[Nn]* ) return 1;;
* ) echo "Please answer yes or no.";;
esac
done
}
# Detect shell and set appropriate configuration file
#!/bin/bash
detect_shell() {
# Detect shell and set appropriate configuration file
local shell_name
# Try to detect the shell from $SHELL first
if [[ -n "$SHELL" ]]; then
shell_name=$(basename "$SHELL")
else
# Fallback to parsing the parent process name if $SHELL is not set
shell_name=$(basename "$(ps -o comm= -p $PPID)")
fi
local shell_config
case $shell_name in
zsh)
shell_config="$HOME/.zshrc"
;;
bash)
shell_config="$HOME/.bashrc"
;;
fish)
shell_config="$HOME/.config/fish/config.fish"
;;
tcsh)
shell_config="$HOME/.tcshrc"
;;
*)
shell_config="$HOME/.profile"
;;
esac
echo "$shell_config"
}
SHELL_CONFIG=$(detect_shell)
echo "-- Detected shell: $SHELL, using config file: $SHELL_CONFIG"
# Set non-interactive frontend for apt
export DEBIAN_FRONTEND=noninteractive
# Add NVIDIA package repository and install CUDA 11.8
echo "-- Setting up NVIDIA CUDA 11.8 repository..."
sudo apt-get update -y
sudo apt-get install -y --no-install-recommends \
gnupg2 \
software-properties-common \
curl
# Add NVIDIA CUDA 11.8 repository
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda-11-8
# Install CUDA Toolkit 11.8
echo "-- Installing CUDA Toolkit 11.8..."
sudo apt-get update -y
sudo apt-get install -y --no-install-recommends \
cuda-toolkit-11-8 \
cuda-libraries-dev-11-8 \
cuda-command-line-tools-11-8 \
cuda-compiler-11-8 \
cuda-cudart-dev-11-8 \
cuda-cupti-dev-11-8 \
cuda-nvml-dev-11-8 \
cuda-nvtx-11-8
# Update environment variables for CUDA
echo "-- Updating environment variables for CUDA..."
if [[ "$SHELL_NAME" == "fish" ]]; then
echo "set -x PATH /usr/local/cuda-11.8/bin \$PATH" >> $SHELL_CONFIG
echo "set -x LD_LIBRARY_PATH /usr/local/cuda-11.8/lib64 \$LD_LIBRARY_PATH" >> $SHELL_CONFIG
else
echo "export PATH=/usr/local/cuda-11.8/bin:\$PATH" >> $SHELL_CONFIG
echo "export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64:\$LD_LIBRARY_PATH" >> $SHELL_CONFIG
fi
source $SHELL_CONFIG
# Install general dependencies
echo "-- Installing general dependencies..."
sudo apt-get install -y --no-install-recommends \
build-essential \
cmake \
g++ \
ninja-build \
git \
pkg-config \
gfortran \
python3-dev \
python3-pip \
libglew-dev \
libboost-all-dev \
libssl-dev \
wget \
unzip \
curl \
libgl1-mesa-dev \
libwayland-dev \
libxkbcommon-dev \
wayland-protocols \
libegl1-mesa-dev \
libc++-dev \
libepoxy-dev \
libglew-dev \
libeigen3-dev \
libgtk-3-dev \
libavcodec-dev \
libavformat-dev \
libswscale-dev \
libv4l-dev \
libxvidcore-dev \
libx264-dev \
libjpeg-dev \
libpng-dev \
libtiff-dev \
openexr \
libatlas-base-dev \
libopencv-dev \
python3-opencv \
libyaml-cpp-dev
# Install CUDA-related packages
echo "-- Installing TensorRT and cuDNN for CUDA 11.8..."
sudo apt-get install -y --no-install-recommends \
libcudnn8=8.9.7.29-1+cuda11.8 \
libcudnn8-dev=8.9.7.29-1+cuda11.8 \
libnvinfer8=8.5.3-1+cuda11.8 \
libnvinfer-plugin8=8.5.3-1+cuda11.8 \
libnvinfer-plugin-dev=8.5.3-1+cuda11.8 \
libnvinfer-bin=8.5.3-1+cuda11.8 \
libnvinfer-dev=8.5.3-1+cuda11.8 \
libnvinfer-samples=8.5.3-1+cuda11.8 \
libnvonnxparsers8=8.5.3-1+cuda11.8 \
libnvonnxparsers-dev=8.5.3-1+cuda11.8 \
libnvparsers8=8.5.3-1+cuda11.8 \
libnvparsers-dev=8.5.3-1+cuda11.8 \
tensorrt=8.5.3.1-1+cuda11.8 \
tensorrt-dev=8.5.3.1-1+cuda11.8 \
tensorrt-libs=8.5.3.1-1+cuda11.8
# Optional ROS 2 Humble installation
if prompt_yes_no "-- Do you want to install ROS 2 Humble and run ROS 2 examples?"; then
echo "-- Installing ROS 2 Humble..."
sudo apt-get install -y software-properties-common
sudo add-apt-repository universe -y
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
sudo apt-get update && sudo apt-get install -y --no-install-recommends \
ros-humble-desktop \
python3-colcon-common-extensions
# Source ROS in shell config
echo "-- Configuring ROS 2 environment for $SHELL_NAME..."
if [[ "$SHELL_NAME" == "fish" ]]; then
echo "source /opt/ros/humble/setup.fish" >> $SHELL_CONFIG
else
echo "source /opt/ros/humble/setup.bash" >> $SHELL_CONFIG
fi
source $SHELL_CONFIG
else
echo "-- Skipping ROS 2 Humble installation."
fi
# Set repository directory
SUPER_SLAM_DIR=$(pwd)
echo "-- Running setup in repository directory: $SUPER_SLAM_DIR"
# Download and extract libtorch
echo "-- Downloading libtorch..."
mkdir -p thirdparty
wget -q https://download.pytorch.org/libtorch/cu118/libtorch-cxx11-abi-shared-with-deps-2.1.0%2Bcu118.zip
unzip libtorch-cxx11-abi-shared-with-deps-2.1.0+cu118.zip -d thirdparty
rm libtorch-cxx11-abi-shared-with-deps-2.1.0+cu118.zip
# Download and setup Pangolin
echo "-- Setting up Pangolin..."
wget https://github.com/stevenlovegrove/Pangolin/archive/refs/tags/v0.9.2.zip
unzip v0.9.2.zip -d thirdparty
mv thirdparty/Pangolin-0.9.2 thirdparty/Pangolin
rm v0.9.2.zip
# Build third-party dependencies in parallel
echo "-- Building third-party dependencies..."
(
cd thirdparty/Pangolin
mkdir -p build && cd build
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release
ninja -j$(nproc)
) &
(
cd thirdparty/g2o
mkdir -p build && cd build
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release
ninja -j$(nproc)
) &
(
cd thirdparty/DBoW3
mkdir -p build && cd build
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release
ninja -j$(nproc)
) &
wait # Wait for all background processes
# Set environment variables
echo "-- Setting environment variables for $SHELL_NAME..."
if [[ "$SHELL_NAME" == "fish" ]]; then
echo "set -x LD_LIBRARY_PATH /usr/local/cuda/lib64 ${SUPER_SLAM_DIR}/thirdparty/libtorch/lib \$LD_LIBRARY_PATH" >> $SHELL_CONFIG
else
echo "export LD_LIBRARY_PATH=/usr/local/cuda/lib64:${SUPER_SLAM_DIR}/thirdparty/libtorch/lib:\$LD_LIBRARY_PATH" >> $SHELL_CONFIG
fi
source $SHELL_CONFIG
# Verification
echo "-- Verifying installations:"
nvcc --version
dpkg -l | grep tensorrt
if command -v ros2 &> /dev/null; then
source /opt/ros/humble/setup.bash
ros2 run demo_nodes_cpp talker
fi
echo ""
echo "-- Setup complete! Please run 'source $SHELL_CONFIG' or restart your terminal."
echo "-- Then build the project with: sh build.sh"