本文主要说一下怎么使用shell脚本建立ros_install.sh来完成ros-kinetic的安装,只是给大家提供一个思路,每次重新安装ubuntu之后,都得把所有的软件一步步的在控制台安装,还得重新去找网页教程。关于ubuntu16.04系统如何使用控制台安装ros-kinetic版本可以百度关键字“ros kinetic installation”,不管是访问CSDN的中文详解还是roswiki的,都可以轻松的学会。
在任意的位置,比如在Desktop上新建一个ros_install.sh,程序语句尽量的精简,方便第一次接触的读者慢慢的了解。
主要有4个函数,一个是install_ros_kinetic(),一个是remove_ros_kinetic(),一个是create_catkin_ws(),还有一个是main(),其实也别忘记了就是main后边还有一段话。
使用下面的命令进行安装,接下来会看到效果和控制台安装的效果一样。
helloros@ubuntu:~/Desktop$ bash ros_install.sh
#/bin/bash
password="123456"
#
install_ros_kinetic()
{
clear
echo "$FUNCNAME start."
source $/.bashrc
which roscore >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "ROS already installed."
return
fi
echo "the system is going to install ROS kinetic..."
echo $ | sudo -S su >/dev/null 2>&1
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
sudo apt-get update
sudo apt-get install ros-kinetic-desktop-full
echo $ | sudo -S su >/dev/null 2>&1
sudo rosdep init
rosdep update
grep "source /opt/ros/kinetic/setup.bash" $/.bashrc >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "source /opt/ros/kinetic/setup.bash" >> $/.bashrc
echo "ROS has sourced."
source $/.bashrc
fi
if [ $? -eq 0 ]; then
echo "Install ROS kinetic successfully."
return 0
fi
sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential
return 0
}
#
remove_ros_kinetic(){
clear
echo "$FUNCNAME remove ..."
which roscore >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "the system is going to remove ROS kinetic."
echo $ | sudo -S su >/dev/null 2>&1
sudo apt-get remove ros-kinetic-*
if [ $? -eq 0 ]; then
echo "Remove ROS kinetic successfully."
return 0
fi
fi
}
#
create_catkin_ws() {
if [ -d "$/catkin_ws" ]; then
echo "$/catkin_ws already exist. "
return
fi
mkdir -p $/catkin_ws
return 0
}
#
main(){
install_ros_kinetic
}
#
main $@ 2>&1
exit $?
领取专属 10元无门槛券
私享最新 技术干货