Last active
October 16, 2018 08:00
-
-
Save djnugent/371ae1cd038ba726c48244c25380f265 to your computer and use it in GitHub Desktop.
Install ROS kinetic with one command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Install any version of ROS Kinetic with one command! | |
# Daniel Nugent 2018 | |
# Requirements: | |
# - Ubuntu 16 | |
# - python 2.7 | |
# - pip | |
# Import subprocess and sys | |
import subprocess | |
import sys | |
# execute bash commands with live printing stdout and stderr | |
def bash(cmd, print_cmd=True, print_stdout=True): | |
if print_cmd: | |
print("\033[92m\033[1m>> {}\033[0m".format(cmd)) # print cmd in bold green | |
popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) #, universal_newlines=True) | |
if print_stdout: | |
for stdout_line in iter(popen.stdout.readline, ""): | |
print(stdout_line) | |
popen.stdout.close() | |
return_code = popen.wait() | |
if return_code: | |
raise subprocess.CalledProcessError(return_code, cmd) | |
# Get the sudo password prompt out of the way (assuming you use a sudo timeout) | |
bash("sudo echo",print_cmd=False) | |
# Attempt to import inquirer | |
try: | |
import inquirer | |
# Attempt to fix import error | |
except ImportError: | |
valid_input = False | |
# Prompt user about fix | |
while not valid_input: | |
raw = raw_input("Inquirer was not found and is required to run this script, would you like to install it? (y/n): ").lower() | |
# Fix it | |
if raw == "y" or raw == "yes": | |
valid_input = True | |
bash("sudo pip install inquirer") | |
import inquirer | |
# Dont fix it | |
elif raw == "n" or raw == "no": | |
print("Exitting") | |
sys.exit(-1) | |
# Prompt user to pick install type | |
install_candidates = [ | |
inquirer.List('candidate', | |
message="What type of installation would you like?", | |
choices=['ros-kinetic-desktop-full', 'ros-kinetic-desktop', 'ros-kinetic-ros-base'], | |
), | |
] | |
answer = inquirer.prompt(install_candidates) | |
candidate = answer["candidate"] | |
# Track all repositories | |
bash("sudo add-apt-repository main") | |
bash("sudo add-apt-repository universe") | |
bash("sudo add-apt-repository restricted") | |
bash("sudo add-apt-repository multiverse") | |
# Add ROS repositories | |
bash("sudo sh -c 'echo \"deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main\" > /etc/apt/sources.list.d/ros-latest.list'") | |
bash("sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116") | |
bash("sudo apt-get update") | |
# Install ROS | |
bash("sudo apt-get install {} -y".format(candidate)) | |
# Initialize rosdep | |
bash("sudo rm -rf /etc/ros/rosdep/sources.list.d/20-default.list") # Remove the file if it already exists | |
bash("sudo rosdep init") | |
bash("rosdep update") | |
# Add kinetic to your bashrc | |
bash('echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc') | |
# Install build tools | |
bash("sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential -y") | |
# Done | |
print("\033[92m\033[1mComplete! Please reload your bashrc or start a new session\033[0m") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment