Skip to content

Instantly share code, notes, and snippets.

@dpfrakes
Last active August 16, 2024 21:23
Show Gist options
  • Save dpfrakes/d7c3f5d160752beac9567f6f9e579f4f to your computer and use it in GitHub Desktop.
Save dpfrakes/d7c3f5d160752beac9567f6f9e579f4f to your computer and use it in GitHub Desktop.
Simple public shell script to run directly from terminal to check OS
#!/bin/bash
# Get the Ubuntu version number
os_version=$(lsb_release -sr)
# Function to install ROS 2 Humble (for Ubuntu 22.04)
install_ros_humble() {
echo "Installing ROS 2 Humble..."
sudo apt update && sudo apt install -y curl gnupg2 lsb-release
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key | sudo apt-key add -
echo "deb http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/ros2-latest.list
sudo apt update
sudo apt upgrade -y
sudo apt install -y ros-humble-desktop-full
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
source ~/.bashrc
echo "ROS 2 Humble installed."
}
# Function to install ROS 2 Iron (for Ubuntu 24.04)
install_ros_iron() {
echo "Installing ROS 2 Iron..."
sudo apt update && sudo apt install -y curl gnupg2 lsb-release
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key | sudo apt-key add -
echo "deb http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/ros2-latest.list
sudo apt update
sudo apt upgrade -y
sudo apt install -y ros-iron-desktop-full
echo "source /opt/ros/iron/setup.bash" >> ~/.bashrc
source ~/.bashrc
echo "ROS 2 Iron installed."
}
# Check if ROS 2 Humble is installed
check_ros_humble() {
if ! dpkg-query -W ros-humble-desktop > /dev/null 2>&1; then
install_ros_humble
else
echo "ROS 2 Humble is already installed."
fi
}
# Check if ROS 2 Iron is installed
check_ros_iron() {
if ! dpkg-query -W ros-iron-desktop > /dev/null 2>&1; then
install_ros_iron
else
echo "ROS 2 Iron is already installed."
fi
}
# Main script logic based on OS version
if [[ "$os_version" == "22.04" ]]; then
echo "Ubuntu 22.04 detected."
check_ros_humble
elif [[ "$os_version" == "24.04" ]]; then
echo "Ubuntu 24.04 detected."
check_ros_iron
else
echo "OS not supported."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment