-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathros_setup.sh
127 lines (101 loc) · 4.36 KB
/
ros_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
#!/bin/bash
# Software License Agreement (BSD License)
#
# Authors : Brighten Lee <[email protected]>
#
# Copyright (c) 2020, ROAS Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
# THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
helpFunction() {
echo "Usage: ./ros_setup.sh -r <ros distro>"
echo ""
echo -e " -r <ros distro>\tmelodic, noetic"
echo ""
exit 1
}
ROS_DISTRO=""
while getopts "r:h" opt; do
case "$opt" in
r) ROS_DISTRO="$OPTARG" ;;
h) helpFunction ;;
?) helpFunction ;;
esac
done
if [ "$ROS_DISTRO" != "melodic" ] && [ "$ROS_DISTRO" != "noetic" ]; then
echo -e "\033[1;31mInvalid ROS version.\033[0m"
exit 1
fi
# Update repository and install dependencies
echo -e "\033[1;31mUpdate repository and install dependencies.\033[0m"
sudo apt update
sudo apt upgrade -y
sudo apt install -y ssh net-tools terminator ntpdate curl vim git
sudo ntpdate ntp.ubuntu.com
# Install ROS
echo -e "\033[1;31mInstall ROS $ROS_DISTRO.\033[0m"
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
sudo apt update
sudo apt install -y ros-$ROS_DISTRO-desktop-full
source /opt/ros/$ROS_DISTRO/setup.bash
if [ "$ROS_DISTRO" == "melodic" ]; then
sudo apt install -y python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential ros-$ROS_DISTRO-rqt* ros-$ROS_DISTRO-ros-control ros-$ROS_DISTRO-ros-controllers ros-$ROS_DISTRO-navigation ros-$ROS_DISTRO-serial
fi
if [ "$ROS_DISTRO" == "noetic" ]; then
sudo apt install -y python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool python3-vcstool build-essential ros-$ROS_DISTRO-rqt* ros-$ROS_DISTRO-ros-control ros-$ROS_DISTRO-ros-controllers ros-$ROS_DISTRO-navigation ros-$ROS_DISTRO-serial
fi
sudo rosdep init
rosdep update
# Create the ROS workspace
echo -e "\033[1;31mCreate the ROS workspace.\033[0m"
if [ ! -d "$HOME/catkin_ws" ]; then
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
cd ~/catkin_ws
catkin_make
fi
# Create the ROS enviornmnet file
echo -e "\033[1;31mCreate the ROS enviornmnet file.\033[0m"
if [ ! -f "$HOME/env.sh" ] && [ ! -f "/etc/ros/env.sh" ]; then
echo -e "\nsource /etc/ros/env.sh" >>~/.bashrc
fi
if [ -f "$HOME/env.sh" ]; then
sudo rm $HOME/env.sh
fi
if [ -f "/etc/ros/env.sh" ]; then
sudo rm /etc/ros/env.sh
fi
echo -e "#!/bin/bash
# Please write the ROS environment variables here
source /opt/ros/$ROS_DISTRO/setup.bash
source ~/catkin_ws/devel/setup.bash
export ROS_MASTER_URI=http://localhost:11311" >>$HOME/env.sh
sudo mv $HOME/env.sh /etc/ros/
# Install the RealSense SDK
echo -e "\033[1;31mInstall the RealSense SDK.\033[0m"
sudo apt install -y apt-transport-https
sudo mkdir -p /etc/apt/keyrings
curl -sSf https://librealsense.intel.com/Debian/librealsense.pgp | sudo tee /etc/apt/keyrings/librealsense.pgp >/dev/null
echo "deb [signed-by=/etc/apt/keyrings/librealsense.pgp] https://librealsense.intel.com/Debian/apt-repo $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/librealsense.list
sudo apt update
sudo apt install -y librealsense2-dkms librealsense2-utils