ubuntu系统下自动化安装ROS的脚本
0x00 脚本简介
虽然在ROS的wiki官网上已经有现成完善的安装步骤,官网地址奉上:ROS官网安装步骤,虽然网站上都是英文,但是英文都是很简单的。但是经常还是有小伙伴偶尔问如何安装ROS,经常指导一番,由于对方不熟悉linux下的操作导致不能很好的辅导小伙伴安装好ROS,所以就想出来这个办法,写个自动化安装脚本,只要想安装ROS执行一下脚本就能自动帮忙配置好,那不是就容易多了嘛,同时该脚本也方便在多台电脑上安装ros,如果没有该脚本的话,要安装5台电脑可是够折腾半小时了,自从用了自动化安装脚本,那就是分分钟搞定,腰不酸了,腿不疼了,一口气装5台!
0x01 脚本下载
目前我在小课堂的gerrit上创建了该项目,大家可以通过如下命令直接将该脚本项目下载到本地(当然前提是要先安装好git,否则无法使用git clone命令):
git clone http://corvin.cn:8081/gerrit/autoInstallROS
具体操作如下图所示:
0x02 执行脚本
如果要为当前的ubuntu系统安装ROS系统,接下来就可以在直接运行该脚本,如下图所示:
现在的自动化安装脚本只提供安装ROS的稳定版本,包括ubuntu14.04上的indigo和16.04上的kinetic版本,随着不断的维护将来会增加安装更多的ROS版本。根据提示输入1安装indigo版本,2是安装kinetic版本,我这里演示的是安装kinetic版本,当安装完成后会有提示需要重启,只有当输入y或者Y或yes后等待3秒钟会自动重启,因为有些配置只有在重启后才能生效,因此大家可以根据需要来选择是否需要立即重启。
0x03 脚本代码分析
当前脚本版本是1.1版本代码如下,随着脚本的不断完善代码会不断更新的:
#!/bin/bash ################################################################### # Author: www.corvin.cn ################################################################### # Description: 该脚本主要为了简化安装ROS流程,只要在终端执行该脚本就 # 就可以自动的安装好指定的ROS版本,目前支持安装ROS的indigo和kinetic # 版本,随着不断维护后面会提供安装ROS其他版本的功能。 # ################################################################### # History: # 20171225 - 初始化该脚本,增加自动安装kinetic功能; # 20171226 - 增加自动安装indigo功能,完善提示信息,同时增加当安 # 装软件包错误时,延时10秒后继续尝试安装的功能; # 20180107 - 增加在安装ubuntu16.04的ROS kinetic版本时,先更新 # 软件源列表的功能,这样在安装软件时速度更快; # 20180122 - 增加安装carebot运行时的必须软件包,这样就可以通过 # 执行该脚本基本上完成大部分的配置; ################################################################### ##### USER UPDATE AREA START ##### TOOL_VER="V1.1" ##### USER UPDATE AREA END ##### green="\e[32;1m" red="\e[31m" blue="\e[34m" normal="\e[0m" SELECT_OK="false" INDIGO_VER="ubuntu14.04_x64_indigo" KINETIC_VER="ubuntu16.04_x64_kinetic" echo -e "${green}***************************************************************** ${normal}\n" echo -e "${green}********** Welcome To Use Auto Install ROS Tool (${TOOL_VER}) ********** ${normal}\n" echo -e "${green}********** www.corvin.cn ********** ${normal}\n" echo -e "${green}***************************************************************** ${normal}\n" echo -e "${green}\n0x00: Install prerequired softwares${normal}" sudo apt-get install -y vim git while [ $? -ne 0 ] do echo -e "${red}Can't install git pkg, wait 10 seconds will retry...${normal}" sleep 10 sudo apt-get install -y vim git done echo -e "${green}\n0x01: The ROS stable version list below:${normal}" echo -e "${green}1: ${INDIGO_VER}${normal}" echo -e "${green}2: ${KINETIC_VER}${normal}" function updateUbuntu1604SourceList() { SOURCE_FILE=/etc/apt/sources.list BACKUP_FILE=/etc/apt/sources.list.backup echo -e "${green} Now backup sources list file:${SOURCE_FILE}->${BACKUP_FILE}${normal}" sudo cp ${SOURCE_FILE} ${BACKUP_FILE} sudo rm -f ${SOURCE_FILE} sudo sh -c "echo #deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted > ${SOURCE_FILE}" sudo sh -c "echo deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties >> ${SOURCE_FILE}" sudo sh -c "echo deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted >> ${SOURCE_FILE}" sudo sh -c "echo deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties >> ${SOURCE_FILE}" sudo sh -c "echo deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted >> ${SOURCE_FILE}" sudo sh -c "echo deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties >> ${SOURCE_FILE}" sudo sh -c "echo deb http://mirrors.aliyun.com/ubuntu/ xenial universe >> ${SOURCE_FILE}" sudo sh -c "echo deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe >> ${SOURCE_FILE}" sudo sh -c "echo deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse >> ${SOURCE_FILE}" sudo sh -c "echo deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse >> ${SOURCE_FILE}" sudo sh -c "echo deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse >> ${SOURCE_FILE}" sudo sh -c "echo deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties >>${SOURCE_FILE}" sudo sh -c "echo deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted >> ${SOURCE_FILE}" sudo sh -c "echo deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties >> ${SOURCE_FILE}" sudo sh -c "echo deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe >>${SOURCE_FILE}" sudo sh -c "echo deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse >> ${SOURCE_FILE}" } function installKinetic() { echo -e "${green} Now will auto install ${KINETIC_VER} ...${normal}" updateUbuntu1604SourceList 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 -y ros-kinetic-desktop-full while [ $? -ne 0 ] do echo -e "${red}Install ros-kinetic-desktop-full occured unkonwn error, wait 10 secondes will retry...${normal}" sleep 10 sudo apt-get install -y ros-kinetic-desktop-full done sudo rosdep init rosdep update while [ $? -ne 0 ] do echo -e "${red}rosdep update occured unkonwn error, wait 10 seconds will retry ...${normal}" sleep 10 rosdep update done echo "#config ros system env" >> ~/.bashrc echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc source ~/.bashrc sudo apt-get install -y python-rosinstall python-rosinstall-generator python-wstool build-essential sudo apt-get autoremove -y #config device serial dialout group sudo usermod -aG dialout $USER #for carebot install neccessary pkgs sudo apt-get install -y ros-kinetic-robot-pose-ekf ros-kinetic-move-base ros-kinetic-slam-gmapping sudo apt-get install -y ros-kinetic-dwa-local-planner ros-kinetic-imu-tools ros-kinetic-map-server sudo apt-get install -y ros-kinetic-amcl echo -e "${green}Congratulation ! Auto install ${KINETIC_VER} has completed successfully !${normal}" return 0; } function installIndigo() { echo -e "${green} Now will install ${INDIGO_VER} ...${normal}" 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 -y ros-indigo-desktop-full while [ $? -ne 0 ] do echo -e "${red}Install ros-indigo-desktop-full occured unkonwn error, wait 10 secondes will retry...${normal}" sleep 10 sudo apt-get install -y ros-indigo-desktop-full done sudo rosdep init rosdep update while [ $? -ne 0 ] do echo -e "${red}rosdep update occured unkonwn error, wait 10 seconds will retry ...${normal}" sleep 10 rosdep update done echo "#config ros system env" >> ~/.bashrc echo "source /opt/ros/indigo/setup.bash" >> ~/.bashrc source ~/.bashrc sudo apt-get install -y python-rosinstall python-rosinstall-generator python-wstool build-essential sudo apt-get autoremove -y #config device serial dialout group sudo usermod -aG dialout $USER #for carebot install neccessary pkgs sudo apt-get install -y ros-indigo-robot-pose-ekf ros-indigo-move-base ros-indigo-slam-gmapping sudo apt-get install -y ros-indigo-dwa-local-planner ros-indigo-imu-tools ros-indigo-map-server sudo apt-get install -y ros-indigo-amcl echo -e "${green}Congratulation ! Auto install ${INDIGO_VER} has completed successfully !${normal}" return 0; } while [ $SELECT_OK == "false" ] do read -p "Please select want to install ros version: " index case $index in 1)installIndigo SELECT_OK="true";; 2)installKinetic SELECT_OK="true";; *) echo -e "${red}Selected index error! ${normal}";; esac done echo -e "${green}>>>>> Now Will Reboot To Make ROS Environment Enable... <<<${normal}" read -p "Input (y/Y/yes) to reboot :" flag case $flag in y);& Y);& yes) sleep 3 #wait 3 seconds sudo reboot ;; esac exit 0
0x04 问题反馈
大家在使用该脚本安装过程中有任何问题,可以关注ROS小课堂的官方微信公众号,在公众号中给我发消息反馈问题即可,我基本上每天都会处理公众号中的留言!当然,如果你要是顺便给ROS小课堂打个赏,我也会感激不尽的!