1
0

autoInstallROS.sh 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #!/bin/bash
  2. #####################################################################
  3. # Author: www.corvin.cn
  4. #####################################################################
  5. # Copyright: 该脚本可以任意下载分发和传播,但是在使用过程中由于不可
  6. # 预测等原因造成软件无法正常安装或运行,ROS小课堂不负责赔偿。欢迎
  7. # 反馈在使用中遇到的各种问题,以便于ROS小课堂来持续维护更新该脚本,
  8. # 这样就可以增加该程序稳定性。
  9. #
  10. # copyright(c) 2016-2019 ROS小课堂. All Right Reserved.
  11. #
  12. #####################################################################
  13. # Description: 该脚本主要为了简化安装ROS流程,只要在终端执行该脚本就
  14. # 就可以自动的安装好指定的ROS版本,目前支持安装ROS的indigo和kinetic
  15. # 版本,随着不断维护后面会提供安装ROS其他版本的功能。
  16. # 该脚步还具备将当前用户增加到dialout组的功能,这样在使用串口时不要
  17. # 担心权限的问题了,不过该功能需要重启后才能生效。
  18. #
  19. #####################################################################
  20. # History:
  21. # 20171225 - 初始化该脚本,增加自动安装kinetic功能;
  22. # 20171226 - 增加自动安装indigo功能,完善提示信息,同时增加当安
  23. # 装软件包错误时,延时10秒后继续尝试安装的功能;
  24. # 20180107 - 增加在安装ubuntu16.04的ROS kinetic版本时,先更新
  25. # 软件源列表的功能,这样在安装软件时速度更快;
  26. # 20180122 - 增加安装carebot运行时的必须软件包,这样就可以通过
  27. # 执行该脚本基本上完成大部分的配置;
  28. # 20180226 - 安装ROS时各版本下载的ROS key步骤相同,因此增加函数
  29. # downloadROSKey各版本统一调用,减少代码量;
  30. #
  31. #####################################################################
  32. ##### USER UPDATE AREA START #####
  33. TOOL_VER="V1.1"
  34. ##### USER UPDATE AREA END #####
  35. green="\e[32;1m"
  36. red="\e[31m"
  37. blue="\e[34m"
  38. normal="\e[0m"
  39. SELECT_OK="false"
  40. INDIGO_VER="ubuntu14.04_x64_indigo"
  41. KINETIC_VER="ubuntu16.04_x64_kinetic"
  42. echo -e "${green}***************************************************************** ${normal}\n"
  43. echo -e "${green}********** Welcome To Use Auto Install ROS Tool (${TOOL_VER}) ********** ${normal}\n"
  44. echo -e "${green}********** www.corvin.cn ********** ${normal}\n"
  45. echo -e "${green}***************************************************************** ${normal}\n"
  46. echo -e "${green}\n0x00: Install prerequired softwares${normal}"
  47. sudo apt-get install -y vim git
  48. while [ $? -ne 0 ]
  49. do
  50. echo -e "${red}Can't install git pkg, wait 10 seconds will retry...${normal}"
  51. sleep 10
  52. sudo apt-get install -y vim git build-essential
  53. done
  54. echo -e "${green}\n0x01: The ROS stable version list below:${normal}"
  55. echo -e "${green}1: ${INDIGO_VER}${normal}"
  56. echo -e "${green}2: ${KINETIC_VER}${normal}"
  57. function setNetworkTimeProtocol()
  58. {
  59. sudo apt-get install -y chrony ntpdate
  60. sudo ntpdate -q cn.ntp.org.cn
  61. }
  62. function updateUbuntu1604SourceList()
  63. {
  64. SOURCE_FILE=/etc/apt/sources.list
  65. BACKUP_FILE=/etc/apt/sources.list.backup
  66. echo -e "${green} Now backup sources list file:${SOURCE_FILE}->${BACKUP_FILE}${normal}"
  67. sudo cp ${SOURCE_FILE} ${BACKUP_FILE}
  68. sudo rm -f ${SOURCE_FILE}
  69. sudo sh -c "echo #deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted > ${SOURCE_FILE}"
  70. sudo sh -c "echo deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties >> ${SOURCE_FILE}"
  71. sudo sh -c "echo deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted >> ${SOURCE_FILE}"
  72. sudo sh -c "echo deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties >> ${SOURCE_FILE}"
  73. sudo sh -c "echo deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted >> ${SOURCE_FILE}"
  74. sudo sh -c "echo deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties >> ${SOURCE_FILE}"
  75. sudo sh -c "echo deb http://mirrors.aliyun.com/ubuntu/ xenial universe >> ${SOURCE_FILE}"
  76. sudo sh -c "echo deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe >> ${SOURCE_FILE}"
  77. sudo sh -c "echo deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse >> ${SOURCE_FILE}"
  78. sudo sh -c "echo deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse >> ${SOURCE_FILE}"
  79. sudo sh -c "echo deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse >> ${SOURCE_FILE}"
  80. sudo sh -c "echo deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties >>${SOURCE_FILE}"
  81. sudo sh -c "echo deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted >> ${SOURCE_FILE}"
  82. sudo sh -c "echo deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties >> ${SOURCE_FILE}"
  83. sudo sh -c "echo deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe >>${SOURCE_FILE}"
  84. sudo sh -c "echo deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse >> ${SOURCE_FILE}"
  85. }
  86. function downloadROSKey()
  87. {
  88. echo -e "${green}[Download the ROS keys and update ros source list]${normal}"
  89. sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
  90. roskey=`apt-key list | grep "ROS Builder"`
  91. if [ -z "$roskey" ]; then
  92. sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
  93. fi
  94. while [ $? -ne 0 ]
  95. do
  96. echo -e "${red}Download ROS keys occured error, wait 10 seconds retry...${normal}"
  97. sleep 10
  98. sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
  99. done
  100. sudo apt-get update
  101. }
  102. function installKinetic()
  103. {
  104. echo -e "${green} Now will auto install ${KINETIC_VER} ...${normal}"
  105. setNetworkTimeProtocol
  106. updateUbuntu1604SourceList
  107. downloadROSKey
  108. sudo apt-get install -y ros-kinetic-desktop-full
  109. while [ $? -ne 0 ]
  110. do
  111. echo -e "${red}Install ros-kinetic-desktop-full occured unkonwn error, wait 10 seconds will retry...${normal}"
  112. sleep 10
  113. sudo apt-get install -y ros-kinetic-desktop-full
  114. done
  115. sudo rosdep init
  116. while [ $? -ne 0 ]
  117. do
  118. echo -e "${red}<sudo rosde init> command can't invoke successfully, wait 10 secondes will retry ...${normal}"
  119. sleep 10
  120. sudo rosdep init
  121. done
  122. rosdep update
  123. while [ $? -ne 0 ]
  124. do
  125. echo -e "${red}rosdep update occured unkonwn error, wait 10 seconds will retry ...${normal}"
  126. sleep 10
  127. rosdep update
  128. done
  129. echo "#config ros system env" >> ~/.bashrc
  130. echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
  131. source ~/.bashrc
  132. sudo apt-get install -y python-rosinstall python-rosinstall-generator python-wstool
  133. sudo apt-get autoremove -y
  134. #config device serial dialout group
  135. sudo usermod -aG dialout $USER
  136. #for carebot install neccessary pkgs
  137. sudo apt-get install -y ros-kinetic-robot-pose-ekf ros-kinetic-move-base ros-kinetic-slam-gmapping
  138. sudo apt-get install -y ros-kinetic-dwa-local-planner ros-kinetic-imu-tools ros-kinetic-map-server
  139. sudo apt-get install -y ros-kinetic-amcl ros-kinetic-rqt* ros-kinetic-rgbd-launch
  140. echo -e "${green}Congratulation ! Auto install ${KINETIC_VER} has completed successfully !${normal}"
  141. return 0;
  142. }
  143. function installIndigo()
  144. {
  145. echo -e "${green} Now will install ${INDIGO_VER} ...${normal}"
  146. setNetworkTimeProtocol
  147. downloadROSKey
  148. sudo apt-get install -y ros-indigo-desktop-full
  149. while [ $? -ne 0 ]
  150. do
  151. echo -e "${red}Install ros-indigo-desktop-full occured unkonwn error, wait 10 secondes will retry...${normal}"
  152. sleep 10
  153. sudo apt-get install -y ros-indigo-desktop-full
  154. done
  155. sudo rosdep init
  156. while [ $? -ne 0 ]
  157. do
  158. echo -e "${red}<sudo rosde init> command can't invoke successfully, wait 10 secondes will retry ...${normal}"
  159. sleep 10
  160. sudo rosdep init
  161. done
  162. rosdep update
  163. while [ $? -ne 0 ]
  164. do
  165. echo -e "${red}rosdep update occured unkonwn error, wait 10 seconds will retry ...${normal}"
  166. sleep 10
  167. rosdep update
  168. done
  169. echo "#config ros system env" >> ~/.bashrc
  170. echo "source /opt/ros/indigo/setup.bash" >> ~/.bashrc
  171. source ~/.bashrc
  172. sudo apt-get install -y python-rosinstall python-rosinstall-generator python-wstool
  173. sudo apt-get autoremove -y
  174. #config device serial dialout group
  175. sudo usermod -aG dialout $USER
  176. #for carebot install neccessary pkgs
  177. sudo apt-get install -y ros-indigo-robot-pose-ekf ros-indigo-move-base ros-indigo-slam-gmapping
  178. sudo apt-get install -y ros-indigo-dwa-local-planner ros-indigo-imu-tools ros-indigo-map-server
  179. sudo apt-get install -y ros-indigo-amcl ros-indigo-rqt*
  180. echo -e "${green}Congratulation ! Auto install ${INDIGO_VER} has completed successfully !${normal}"
  181. return 0;
  182. }
  183. while [ $SELECT_OK == "false" ]
  184. do
  185. read -p "Please select want to install ros version: " index
  186. case $index in
  187. 1)installIndigo
  188. SELECT_OK="true";;
  189. 2)installKinetic
  190. SELECT_OK="true";;
  191. *) echo -e "${red}Selected index error! ${normal}";;
  192. esac
  193. done
  194. echo -e "${green}>>>>> Now Will Reboot To Make ROS Environment Enable... <<<${normal}"
  195. read -p "Input (y/Y/yes) to reboot :" flag
  196. case $flag in
  197. y);&
  198. Y);&
  199. yes)
  200. sleep 3 #wait 3 seconds
  201. sudo reboot
  202. ;;
  203. esac
  204. exit 0