-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·202 lines (177 loc) · 6.36 KB
/
install.sh
File metadata and controls
executable file
·202 lines (177 loc) · 6.36 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
#!/bin/bash
# Get this script's path
pushd "$(dirname "$0")" > /dev/null
SCRIPTPATH=$(pwd)
popd > /dev/null
set -e
source "$SCRIPTPATH/support/fun.cfg"
USAGE="Usage: \n install [OPTIONS...]
\n\n
Help Options:
\n
-h,--help \tShow help options
\n\n
Application Options:
\n
-i,--install \tInstall options [base|app|all], example: -i all
\n
-b,--branch \tBranch to install, example: -b devel
\n
-r,--ros \tROS distro to install, example: -r noetic"
# Default
INSTALL_OPT="all"
BRANCH_OPT="ros1-noetic"
ROS_DISTRO_OPT=
PYTHON_NAME="python3"
UBUNTU=$(lsb_release -cs)
wolf_banner
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
echo -e "$USAGE"
exit 0
fi
while [[ -n "$1" ]]; do
case "$1" in
-i|--install)
INSTALL_OPT="$2"
shift
;;
-b|--branch)
BRANCH_OPT="$2"
shift
;;
-r|--ros)
ROS_DISTRO_OPT="$2"
shift
;;
*)
print_warn "Option $1 not recognized!"
echo -e "$USAGE"
exit 1
;;
esac
shift
done
# Validate install options
if [[ "$INSTALL_OPT" != "base" && "$INSTALL_OPT" != "app" && "$INSTALL_OPT" != "all" ]]; then
print_warn "Wrong install option!"
echo -e "$USAGE"
exit 1
fi
print_info "Selected install option: $INSTALL_OPT"
# Determine ROS distro
if [[ -z "$ROS_DISTRO_OPT" ]]; then
case "$UBUNTU" in
jammy)
ROS_DISTRO_OPT="humble"
;;
focal)
ROS_DISTRO_OPT="noetic"
;;
noble)
ROS_DISTRO_OPT="one"
;;
*)
print_warn "Unsupported Ubuntu version! Only focal (20.04), jammy (22.04), and noble (24.04) are supported."
exit 1
;;
esac
fi
print_info "Selected ROS distro option: $ROS_DISTRO_OPT"
print_info "Selected UBUNTU distro option: $UBUNTU"
print_info "Selected BRANCH option: $BRANCH_OPT"
# Set ROS-related variables
case "$ROS_DISTRO_OPT" in
noetic)
ROS_VERSION_NAME="ros"
ROS_DISTRO="$ROS_DISTRO_OPT"
LIST_FILE="/etc/apt/sources.list.d/ros-latest.list"
;;
foxy|humble)
ROS_VERSION_NAME="ros2"
ROS_DISTRO="$ROS_DISTRO_OPT"
LIST_FILE="/etc/apt/sources.list.d/ros2.list"
;;
one)
ROS_VERSION_NAME="ros"
ROS_DISTRO="$ROS_DISTRO_OPT"
LIST_FILE="/etc/apt/sources.list.d/ros1.list"
;;
*)
print_warn "Unsupported ROS distro! Only noetic, foxy, humble, and one are supported."
exit 1
;;
esac
# Install base components
if [[ "$INSTALL_OPT" == "base" || "$INSTALL_OPT" == "all" ]]; then
# Define variables
KEY_FILE="/usr/share/keyrings/ros-archive-keyring.gpg"
ROS_REPO="http://packages.ros.org/${ROS_VERSION_NAME}/ubuntu"
# Check if the repository is already added
if grep -q "${ROS_REPO}" /etc/apt/sources.list /etc/apt/sources.list.d/* 2>/dev/null; then
print_info "ROS repository is already present. Skipping repository setup."
else
print_info "Adding ROS repository..."
if [[ "$ROS_DISTRO" == "one" ]]; then
sudo mkdir -p /etc/apt/keyrings
sudo curl -sSL https://ros.packages.techfak.net/gpg.key -o /etc/apt/keyrings/ros-one-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/ros-one-keyring.gpg] https://ros.packages.techfak.net $(lsb_release -cs) main" | sudo tee "$LIST_FILE"
echo "# deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/ros-one-keyring.gpg] https://ros.packages.techfak.net $(lsb_release -cs) main-dbg" | sudo tee -a "$LIST_FILE"
else
sudo mkdir -p /usr/share/keyrings
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /tmp/ros.key
sudo gpg --no-tty --batch --yes --dearmor -o "$KEY_FILE" /tmp/ros.key
rm /tmp/ros.key
echo "deb [arch=$(dpkg --print-architecture) signed-by=${KEY_FILE}] ${ROS_REPO} $(lsb_release -cs) main" | \
sudo tee "$LIST_FILE" > /dev/null
fi
fi
sudo apt-get update
print_info "Installing system libraries..."
grep -v '#' "$SCRIPTPATH/config/${ROS_DISTRO}/sys_deps_list.txt" | xargs sudo apt-get install -y
print_info "Installing Python libraries..."
grep -v '#' "$SCRIPTPATH/config/${ROS_DISTRO}/python_deps_list.txt" | xargs printf -- "${PYTHON_NAME}-%s\n" | xargs sudo apt-get install -y
PIP_DEPS_FILE="$SCRIPTPATH/config/${ROS_DISTRO}/pip_deps_list.txt"
if [[ -f "$PIP_DEPS_FILE" ]]; then
mapfile -t PIP_DEPS < <(grep -vE '^\s*#|^\s*$' "$PIP_DEPS_FILE")
if [[ ${#PIP_DEPS[@]} -gt 0 ]]; then
print_info "Installing pip libraries..."
sudo apt-get install -y python3-pip
PIP_ARGS=(install --no-cache-dir)
if ${PYTHON_NAME} -m pip install --help 2>/dev/null | grep -q -- '--break-system-packages'; then
PIP_ARGS+=(--break-system-packages)
fi
sudo ${PYTHON_NAME} -m pip "${PIP_ARGS[@]}" "${PIP_DEPS[@]}"
fi
fi
print_info "Installing ROS packages..."
grep -v '#' "$SCRIPTPATH/config/${ROS_DISTRO}/ros_deps_list.txt" | xargs printf -- "ros-${ROS_DISTRO}-%s\n" | xargs sudo apt-get install -y
if ${PYTHON_NAME} -c "import casadi" >/dev/null 2>&1; then
print_info "Configuring CasADi CMake/loader paths..."
CASADI_DIR="$(${PYTHON_NAME} -c 'import casadi; from pathlib import Path; print(Path(casadi.__file__).resolve().parent)')"
sudo ln -sfn "$CASADI_DIR" /usr/local/casadi
echo "/usr/local/casadi" | sudo tee /etc/ld.so.conf.d/casadi.conf > /dev/null
fi
sudo ldconfig
sudo rosdep init || true
rosdep update
if [[ "$ROS_DISTRO" == "one" ]]; then
echo "yaml https://ros.packages.techfak.net/ros-one.yaml one" | sudo tee /etc/ros/rosdep/sources.list.d/1-ros-one.list
rosdep update
fi
fi
# Install application components
if [[ "$INSTALL_OPT" == "app" || "$INSTALL_OPT" == "all" ]]; then
/bin/bash "$SCRIPTPATH/support/get_debians.sh"
print_info "Installing WoLF debian packages..."
sudo dpkg -i --force-overwrite "$SCRIPTPATH/debs/$BRANCH_OPT/$UBUNTU/"*.deb || true
sudo apt-get install -f -y
fi
# Update Bashrc
for LINE in "source /opt/ros/${ROS_DISTRO}/setup.bash" "source /opt/ocs2/setup.sh"; do
if ! grep -Fwq "$LINE" ~/.bashrc; then
print_info "Adding $LINE to .bashrc"
echo "$LINE" >> ~/.bashrc
else
print_info "$LINE is already in .bashrc"
fi
done