Skip to content

Instantly share code, notes, and snippets.

@NathanaelGandhi
Last active July 30, 2025 02:57
Show Gist options
  • Save NathanaelGandhi/7efdc366bacd7164513edf0b70b8c683 to your computer and use it in GitHub Desktop.
Save NathanaelGandhi/7efdc366bacd7164513edf0b70b8c683 to your computer and use it in GitHub Desktop.
Setup Scripts - Ubuntu 24.04
#!/bin/bash
## Author: Nathanael Gandhi
################################################################################
FILES=("setup_ubuntu_2404.bash" "setup_ohmybash.sh" "setup_ros_rolling.bash" "setup_ros_rolling_aliases.sh")
for file in "${FILES[@]}"; do
FILE_PATH="$(dirname "${BASH_SOURCE[0]}")/${file}"
if [[ -f "$FILE_PATH" ]]; then
"$FILE_PATH"
else
echo "${file} is missing from the script's directory."
fi
done
#!/bin/bash -eu
## Author: Nathanael Gandhi
################################################################################
if [ -d ~/.oh-my-bash ]
then
echo "Directory ~/.oh-my-bash already exists. Not installing"
else
echo "Downloading oh-my-bash"
bash -c "$(curl -fsSL https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh)" --unattended
fi
wait
## Uncomment one custom theme you would like configured
## Note: this will only change from the default 'font' theme
# sed -i 's/OSH_THEME="font"/OSH_THEME="agnoster"/g' ~/.bashrc
sed -i 's/OSH_THEME="font"/OSH_THEME="roderik"/g' ~/.bashrc
# sed -i 's/OSH_THEME="font"/OSH_THEME="vscode"/g' ~/.bashrc
if [ $? -eq 0 ]
then
echo "You may need to source your config or restart your shell:"
echo " source ~/.bashrc"
else
echo "Theme not modified"
fi
#!/bin/bash
## Author: Nathanael Gandhi
## Notes.: Only tested with Ubuntu 24.04
################################################################################
# Func runs given command with sudo if not already root, allows for running without
# sudo in a root context (ie. in docker containers). Falls back to sudo on error
# shellcheck disable=SC2015
function runSudo(){ [[ "${USER:-root}" == "root" ]] && "$@" || sudo "$@"; }
# Set locale
runSudo apt update && runSudo apt install -y locales
runSudo locale-gen en_US en_US.UTF-8
runSudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8
# Enable required repositories
runSudo apt install -y software-properties-common
runSudo add-apt-repository universe
runSudo apt update && runSudo apt install curl -y
export ROS_APT_SOURCE_VERSION=$(curl -s https://api.github.com/repos/ros-infrastructure/ros-apt-source/releases/latest | grep -F "tag_name" | awk -F\" '{print $4}')
curl -L -o /tmp/ros2-apt-source.deb "https://github.com/ros-infrastructure/ros-apt-source/releases/download/${ROS_APT_SOURCE_VERSION}/ros2-apt-source_${ROS_APT_SOURCE_VERSION}.$(. /etc/os-release && echo $VERSION_CODENAME)_all.deb" # If using Ubuntu derivates use $UBUNTU_CODENAME
runSudo dpkg -i /tmp/ros2-apt-source.deb
runSudo apt update
# Install prerequisites
runSudo apt install -y tar bzip2 wget
# Install development tools
runSudo apt install -y ros-dev-tools
# Install ROS 2
runSudo apt install -y ros-rolling-ros-base
#!/bin/sh
## Author: Nathanael Gandhi
################################################################################
# Define the shell rc (ie. ~/.bashrc or ~/.zshrc)
SHELL_RC="${HOME}/.$(basename ${SHELL})rc"
# Check if SHELL_RC exists, if not, use .profile
if [ ! -f "${SHELL_RC}" ]; then
echo "${SHELL_RC} not found"
SHELL_RC="$HOME/.profile"
fi
# Add sr alias to the selected shell rc file
if ! grep -q 'alias sr=' "${SHELL_RC}"; then
echo 'alias sr="[ -f \"/opt/ros/rolling/setup.$(basename $SHELL)\" ] && source \"/opt/ros/rolling/setup.$(basename $SHELL)\" || echo \"/opt/ros/rolling/setup.$(basename $SHELL) does not exist.\""' >> "${SHELL_RC}"
echo "alias sr has been added to ${SHELL_RC}"
else
echo "alias sr already exists in ${SHELL_RC}"
fi
# Add sc alias to the selected shell rc file
if ! grep -q 'alias sc=' "${SHELL_RC}"; then
echo 'alias sc="[ -f \"install/setup.$(basename $SHELL)\" ] && source \"install/setup.$(basename $SHELL)\" || echo \"install/setup.$(basename $SHELL) does not exist.\""' >> "${SHELL_RC}"
echo "alias sc has been added to ${SHELL_RC}"
else
echo "alias sc already exists in ${SHELL_RC}"
fi
# Add slc alias to the selected shell rc file
if ! grep -q 'alias slc=' "${SHELL_RC}"; then
echo 'alias slc="[ -f \"install/local_setup.$(basename $SHELL)\" ] && source \"install/local_setup.$(basename $SHELL)\" || echo \"install/local_setup.$(basename $SHELL) does not exist.\""' >> "${SHELL_RC}"
echo "alias slc has been added to ${SHELL_RC}"
else
echo "alias slc already exists in ${SHELL_RC}"
fi
#!/bin/bash
## Author: Nathanael Gandhi
################################################################################
# Func runs given command with sudo if not already root, allows for running without
# sudo in a root context (ie. in docker containers). Falls back to sudo on error
# shellcheck disable=SC2015
function runSudo(){ [[ "${USER:-root}" == "root" ]] && "$@" || sudo "$@"; }
# Install APT packages
## Note: libfuse2 is for AppImages
## Note: python3-gpg is for dropbox
runSudo apt update \
&& runSudo apt upgrade -y \
curl \
file \
git \
git-lfs \
gitg \
gnome-tweaks \
htop \
libfuse2
nano \
pre-commit \
python3-gpg \
tmux \
tree
# Install snap packages
## Note: you can't directly specify --classic for individual snaps in the same command line
runSudo snap install code --classic
# Install flatpak packages
runSudo apt install -y flatpak \
&& flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo \
&& flatpak install flathub \
com.mattjakeman.ExtensionManager \
it.mijorus.gearlever \
flathub org.kde.kolourpaint
# Install Docker
curl -fsSL https://get.docker.com -o /tmp/get-docker.sh
runSudo sh /tmp/get-docker.sh
runSudo groupadd docker || true
runSudo usermod -aG docker $USER || true
# Install GH Cli
(type -p wget >/dev/null || (runSudo apt update && runSudo apt install wget -y)) \
&& runSudo mkdir -p -m 755 /etc/apt/keyrings \
&& out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg \
&& cat $out | runSudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \
&& runSudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
&& runSudo mkdir -p -m 755 /etc/apt/sources.list.d \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | runSudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& runSudo apt update \
&& runSudo apt install gh -y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment