forked from TIGERs-Mannheim/vision-processor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·133 lines (115 loc) · 4.65 KB
/
setup.sh
File metadata and controls
executable file
·133 lines (115 loc) · 4.65 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
#!/bin/bash
#
# Copyright 2025 Felix Weinmann
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Stop script execution with any error
set -e
if [[ -v SKIP_DRIVERS ]]; then
echo -e "\e[92m » Skipping OpenCL drivers\e[39m"
opencl_arch=
opencl_debian=
else
# Default fallback for a CPU and GPU vendor independent OpenCL runtime
opencl_arch=pocl
opencl_debian=pocl-opencl-icd
# Determine graphics card vendor
for dir in /sys/bus/pci/devices/*/; do
# Search for graphics card devices
if [[ $(< $dir/class) == 0x030000 ]]; then
vendor=$(< $dir/vendor)
if [[ $vendor == 0x10de ]]; then
echo -e "\e[92m » NVIDIA graphics card selected\e[39m"
opencl_arch='opencl-nvidia nvidia-utils'
# opencl_debian=nvidia-opencl-icd
opencl_debian=libnvidia-compute-590
elif [[ $vendor == 0x1002 ]]; then
echo -e "\e[92m » AMD graphics card selected\e[39m"
opencl_arch='rocm-opencl-runtime mesa'
opencl_debian=mesa-opencl-icd
elif [[ $vendor == 0x8086 ]]; then
echo -e "\e[92m » Intel graphics card selected\e[39m"
opencl_arch='intel-compute-runtime intel-media-driver'
opencl_debian='intel-opencl-icd intel-media-va-driver-non-free'
# Add user to render group to allow screenless gpu access (https://github.com/intel/compute-runtime/issues/701)
sudo usermod -a -G render $(whoami)
else
echo -e "\e[91m » Could not determine graphics card vendor, skipping OpenCL driver check and installation\e[39m" >&2
opencl_arch=
opencl_debian=
fi
fi
done
fi
# Determine distribution/package manager
if [[ -f /etc/arch-release ]]; then
echo -e "\e[92m » Arch based distribution\e[39m"
packages="gcc make cmake pkgconf eigen opencv yaml-cpp opencl-clhpp python-protobuf python-yaml $opencl_arch"
check_cmd="pacman -Qi $packages"
install_cmd="sudo pacman -S $packages"
elif [[ -f /etc/debian_version ]]; then
echo -e "\e[92m » Debian based distribution\e[39m"
packages="build-essential cmake pkg-config libyaml-cpp-dev ocl-icd-opencl-dev libeigen3-dev libopencv-dev protobuf-compiler libprotobuf-dev ffmpeg libavcodec-dev libavformat-dev libavutil-dev python3-protobuf python3-yaml $opencl_debian"
check_cmd="dpkg -s $packages"
install_cmd="sudo apt install --no-install-recommends $packages"
else
echo -e "\e[91m » Could not determine current operating system, skipping dependency check and installation\e[39m" >&2
check_cmd=true
fi
# Check and install necessary packages
if $($check_cmd &>/dev/null); then
echo -e "\e[92m » Dependencies already installed\e[39m"
else
echo " » Installing dependencies and OpenCL drivers"
$install_cmd
fi
# Compile vision_processor
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "$SCRIPT_DIR"
cmake -B build .
make -j -C build vision_processor
# Install systemd service(s)
function install_service {
echo -e "\e[92m » Enabling and (re-)starting $1 service\e[39m"
systemd_folder="$HOME/.local/share/systemd/user"
mkdir -p "$systemd_folder"
cat > "$systemd_folder/$1.service" <<EOL
[Unit]
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
Restart=always
ExecStart=$SCRIPT_DIR/$2
WorkingDirectory=$SCRIPT_DIR
[Install]
WantedBy=default.target
EOL
systemctl --user enable "$1.service"
systemctl --user daemon-reload
systemctl --user restart "$1.service"
}
read -p " » Install systemd service(s)? [yn]» " enable_systemd
if [ "$enable_systemd" = "y" ]; then
install_service vision_processor build/vision_processor
read -p " » Enable geom_publisher service? [yN]» " enable_geom
if [ "$enable_geom" = "y" ]; then
install_service geom_publisher "python/geom_publisher.py geometry.yml"
else
echo " » Skipping geom_publisher service installationa"
fi
else
echo " » Skipping systemd service installation"
fi
echo -e "\e[92m » Done\e[39m"