Skip to content

Instantly share code, notes, and snippets.

@CSpyridakis
Last active September 5, 2021 02:34
Show Gist options
  • Select an option

  • Save CSpyridakis/26572803699147f5c646b68584bac649 to your computer and use it in GitHub Desktop.

Select an option

Save CSpyridakis/26572803699147f5c646b68584bac649 to your computer and use it in GitHub Desktop.
TUC-ECE-Thesis-scripts
#!/bin/bash
# --------------------------------------------------------------------------------------
#
# This project is part of thesis submitted in fulfillment of the requirements
# for the diploma of Electrical and Computer Engineer
#
# Engineer: Spyridakis Christos
# University: Technical University of Crete (TUC) - GR
# Create Date: 14/8/2021
# Last Update Date: 5/9/2021
#
# Description:
# Install all needed apps and settings in ubuntu for raspberry pi drone swarm MoCap system
#
# Dependencies:
# https://raw.githubusercontent.com/CSpyridakis/SCTT/master/shellScripts/Debian/install-ros-ubuntu-x86.sh
#
# Steps:
# 1. Download ubuntu from https://ubuntu.com/download/raspberry-pi
# 2. Create bootable sd
# 3. Plug Raspberry to Ethernet
# 4. Log in ubuntu for the first time with ssh, change password, then re-login
# 5. Run this command (CHANGE WIFI_SSID with your access point's name and WIFI_PASS with your access point's password)
#
#
# wget -O - https://gist.githubusercontent.com/CSpyridakis/26572803699147f5c646b68584bac649/raw/6ae14cbb3b7842e0a3fae49459265ffff1d7f0ff/raspberry-pi-4-ubuntu-env-mocap-setup.sh | bash /dev/stdin -s WIFI_SSID -p WIFI_PASS
#
#
#
# Ubuntu version tested:
# Ubuntu Server 20.04.03 LTS
#
# Extra:
# Default OS username: ubuntu | password: ubuntu
#
# KNOWN BUGS:
# YOU NEED TO HAVE RX DISCONNECTED DURING BOOT!
# --------------------------------------------------------------------------------------
# TODO: edit them
WIFI_SSID=""
WIFI_PASS=""
WIFI_HIDDEN="0"
LOG_FILENAME="${HOME}/raspberry-pi-4-ubuntu-env-mocap-setup-log.txt"
# --------------------------------------------------------------------------------------
while :
do
case "$1" in
-s | --wifi-ssid) shift ; WIFI_SSID="$1"; shift ;;
-p | --wifi-pass) shift ; WIFI_PASS="$2"; shift ;;
-h | --wifi-hidden) WIFI_HIDDEN="1"; shift ;;
--*)
echo "Unknown option: $1" >&2
helpMenu
exit 1
;;
-*)
echo "Unknown option: $1" >&2
helpMenu
exit 1
;;
*)
break
esac
done
# --------------------------------------------------------------------------------------
# __ __ _
# | \/ (_)___ ___
# | |\/| | / __|/ __|
# | | | | \__ \ (__
# |_| |_|_|___/\___|
#
# --------------------------------------------------------------------------------------
red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
reset=`tput sgr0`
procNumber=$(nproc --all)
echoe(){
echo "${red}[ERRO]${reset} $@" | tee -a "${LOG_FILENAME}"
}
echoi(){
echo "${yellow}[INFO]${reset} $@" | tee -a "${LOG_FILENAME}"
}
__INST(){
for app in "$@"
do
sudo apt-get -y install ${app}
done
}
echoi "Update System..."
sudo apt-get -y update && sudo apt-get -y upgrade
# --------------------------------------------------------------------------------------
# ____ _ _
# | __ ) __ _ ___(_) ___ / \ _ __ _ __ ___
# | _ \ / _` / __| |/ __| / _ \ | '_ \| '_ \/ __|
# | |_) | (_| \__ \ | (__ / ___ \| |_) | |_) \__ \
# |____/ \__,_|___/_|\___| /_/ \_\ .__/| .__/|___/
# |_| |_|
#
# --------------------------------------------------------------------------------------
echoi "Install basic applications..."
__INST htop
__INST python3-pip
__INST wget
__INST psensor
# ZSH
__INST zsh
__INST fonts-powerline
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
chsh -s $(which zsh)
# Tmux
__INST tmux
__INST xclip
# --------------------------------------------------------------------------------------
# ____ _
# / ___| _ _ ___| |_ ___ _ __ ___
# \___ \| | | / __| __/ _ \ '_ ` _ \
# ___) | |_| \__ \ || __/ | | | | |
# |____/ \__, |___/\__\___|_| |_| |_|
# |___/
#
# --------------------------------------------------------------------------------------
# Connect to WiFi
if [ ! -z "${WIFI_SSID}" ] && [ ! -z "${WIFI_PASS}" ] ; then
echoi "Connect to wifi SSID: [${WIFI_SSID}] PASS: [${WIFI_PASS}] Hidden: [`([ "${WIFI_HIDDEN}" == "0" ] && echo "NOT") || ([ "${WIFI_HIDDEN}" == "1" ] && echo "YES")`]..."
[ "${WIFI_HIDDEN}" == "0" ] && nmcli device wifi connect ${WIFI_SSID} password ${WIFI_PASS}
[ "${WIFI_HIDDEN}" == "1" ] && nmcli device wifi connect ${WIFI_SSID} password ${WIFI_PASS} hidden yes
fi
# Disable GUI on boot
echoi "Disable GUI on boot..."
sudo systemctl set-default multi-user
gnome-session-quit
# Disable suspend
echoi "Disable auto-suspend..."
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
# Install I2C library
echoi "Disable I2C library..."
sudo apt get install libi2c-dev
# Install ROS
echoi "Download ROS installation script and install ROS..."
wget -O - https://raw.githubusercontent.com/CSpyridakis/SCTT/master/shellScripts/Debian/install-ros-ubuntu-x86.sh | bash /dev/stdin -b -n # If Ubuntu 20.04 then -n, elif 18.04 -m, else check ROS doc
# --------------------------------------------------------------------------------------
#
# ____ ___ ____ ____ _
# | _ \ / _ \/ ___| | _ \ __ _ ___| | ____ _ __ _ ___ ___
# | |_) | | | \___ \ | |_) / _` |/ __| |/ / _` |/ _` |/ _ \/ __|
# | _ <| |_| |___) | | __/ (_| | (__| < (_| | (_| | __/\__ \
# |_| \_\\___/|____/ |_| \__,_|\___|_|\_\__,_|\__, |\___||___/
# |___/
#
# --------------------------------------------------------------------------------------
echoi "Install ROS packages..."
__INST ros-${ROS_DISTRO}-nmea-navsat-driver # For UART GPS
__INST ros-${ROS_DISTRO}-robot-localization # For tf and EKF
__INST ros-${ROS_DISTRO}-usb-cam # For USB camera
__INST ros-${ROS_DISTRO}-opencv # For image processing
__INST ros-${ROS_DISTRO}-cv-bridge # ROS < -- > OpenCV transports (need to include image_transport/image_transport.h & cv_bridge/cv_bridge.h)
__INST ros-${ROS_DISTRO}-rviz-imu-plugin #
# --------------------------------------------------------------------------------------
# ____ _ _ _____ _
# / ___| ___ _ __(_) __ _| | | ___(_)_ __
# \___ \ / _ \ '__| |/ _` | | | |_ | \ \/ /
# ___) | __/ | | | (_| | | | _| | |> <
# |____/ \___|_| |_|\__,_|_| |_| |_/_/\_\
#
# --------------------------------------------------------------------------------------
#
# Notes:
# Raspberry Pi's Serial port is: /dev/ttyS0
# Raspberry Pi's Bluetooth port is: /dev/ttyAMA0
#
echoi "Fix Serial accessibility..."
# 1. add enable_uart=1 to /boot/config.txt
if [ -f /boot/config.txt ]; then
if [ -z `grep "enable_uart=" "/boot/config.txt"` ]; then
sudo cp -n /boot/config.txt /boot/config.txt.bu
sudo bash -c 'echo "enable_uart=1" >> /boot/config.txt' # String does not exist, so just append it
echoi " 1. Appended to /boot/config.txt content [enable_uart=1]"
else
echoe ' 1. Please change manualy on /boot/config.txt content [enable_uart=1]' >&2
fi
else
sudo bash -c 'echo "enable_uart=1" > /boot/config.txt'
echoi " 1. Created file /boot/config.txt with content [enable_uart=1]"
fi
# 2. remove console=serial0,115200 from /boot/firmware/cmdline.txt
if [ -f /boot/firmware/cmdline.txt ] ; then
if [ -z `grep "console=serial0,115200" "/boot/firmware/cmdline.txt"` ]; then
echoi " 2. There is not content [console=serial0,115200] to remove from /boot/firmware/cmdline.txt"
else
sudo cp -n /boot/firmware/cmdline.txt /boot/firmware/cmdline.txt.bu
sudo sed -e "s/console=serial0,115200//g" -i /boot/firmware/cmdline.txt
echoi " 2. Removed from /boot/firmware/cmdline.txt content [console=serial0,115200]"
fi
else
echoi " 2. /boot/firmware/cmdline.txt does not exists"
fi
# 3. disable the serial console:
sudo systemctl stop serial-getty@ttyS0.service && sudo systemctl disable serial-getty@ttyS0.service
echoi " 3. Serial console disabled"
sudo adduser $USER tty
sudo adduser $USER dialout
echoi " 4. Added user to tty and dialout groups"
sudo chmod g+r /dev/ttyS0
sudo chmod g+r /dev/ttyAMA0
echoi " 5. Chmod add read permittion for groups of [/dev/ttyS0] and [/dev/ttyS0]"
# --------------------------------------------------------------------------------------
# ____ _ _
# | _ \ ___| |__ ___ ___ | |_
# | |_) / _ \ '_ \ / _ \ / _ \| __|
# | _ < __/ |_) | (_) | (_) | |_
# |_| \_\___|_.__/ \___/ \___/ \__|
#
# --------------------------------------------------------------------------------------
echoi "Reboot NOW..."
sudo shutdown 0 -r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment