Setup¶
The following bash script can be used to completely setup the environment for the software project on a Linux-based system. All required software is fetched from the internet and installed by the script.
Just copy the code below to a file (i.e. setup.sh
) and make it executable (chmod u+x setup.sh
). Then, run the script like
>$ ./setup.sh
.
#!/bin/bash ############# # FUNCTIONS # ############# # print an error function printError { echo "$(tput setaf 1)>>> ERROR: $1$(tput sgr 0)" } # print a warning function printWarning { echo "$(tput setaf 3)>>> WARNING: $1$(tput sgr 0)" } # print an information text function printInfo { echo "$(tput setaf 4)>>> INFO: $1$(tput sgr 0)" } ############ ### MAIN ### ############ ### make sure the user can switch to root permissions printInfo "Some commands in this skript require root permissions." printInfo "This is now tested for once by executing 'sudo echo \${PWD}'..." sudo echo ${PWD} if [ $? != 0 ]; then printError "Insufficient permissions." exit 1 fi ### Ask whether this a temporary directory? printInfo "You should run this script in a temporary directory." printInfo "The current directory is '${PWD}'." read -p "Continue? [Y/n] " user_input # abort if the answer was neither empty nor 'yes' if ! [ "${user_input}" = "" ] && ! [ "${user_input}" = "Y" ] && ! [ "${user_input}" = "y" ] && ! [ "${user_input}" = "Yes" ] && ! [ "${user_input}" = "yes" ]; then printWarning "aborted" exit 1 fi ### set some variables before we start printInfo "setting temporary variables..." # the directory where this script is executed EXEC_DIR=${PWD} # installation directory which is in the PATH variable INSTALL_DIR="/usr/local/bin" # directory where the big binaries go PROG_DIR="/opt" ### Install required packages printInfo "installing cmake, git, and required 32bit libraries..." sudo dpkg --add-architecture i386 sudo apt-get update sudo apt-get -y install cmake git libc6:i386 libstdc++6:i386 libncurses5:i386 gcc g++ ### configure GIT if [[ -z $(git config --global user.name) ]] || [[ -z $(git config --global user.email) ]]; then printInfo "GIT configuration incomplete..." user_input="" while [[ -z $user_input ]]; do read -p "full name: " user_input done git config --global user.name "$user_input" user_input="" while [[ -z $user_input ]]; do read -p "email: " user_input done git config --global user.email "$user_input" fi ### Install and configure gtkterm printInfo "installing gtkterm..." sudo apt-get -y install gtkterm printInfo "starting gtkterm..." printInfo "Please ignore all warnings (if any) and close the application again." read gtkterm if [ -f ${HOME}/.gtktermrc ]; then printf "\n" >> ${HOME}/.gtktermrc printf "[AMiRo]\n" >> ${HOME}/.gtktermrc printf "port = /dev/ttyUSB0\n" >> ${HOME}/.gtktermrc printf "speed = 115200\n" >> ${HOME}/.gtktermrc printf "bits = 8\n" >> ${HOME}/.gtktermrc printf "stopbits = 1\n" >> ${HOME}/.gtktermrc printf "parity = none\n" >> ${HOME}/.gtktermrc printf "flow = none\n" >> ${HOME}/.gtktermrc printf "wait_delay = 0\n" >> ${HOME}/.gtktermrc printf "wait_char = -1\n" >> ${HOME}/.gtktermrc printf "rs485_rts_time_before_tx = 30\n" >> ${HOME}/.gtktermrc printf "rs485_rts_time_after_tx = 30\n" >> ${HOME}/.gtktermrc printf "echo = False\n" >> ${HOME}/.gtktermrc printf "crlfauto = True\n" >> ${HOME}/.gtktermrc printf "font = \"Nimbus Mono L, 11\"\n" >> ${HOME}/.gtktermrc printf "term_transparency = False\n" >> ${HOME}/.gtktermrc printf "term_show_cursor = True\n" >> ${HOME}/.gtktermrc printf "term_rows = 80\n" >> ${HOME}/.gtktermrc printf "term_columns = 25\n" >> ${HOME}/.gtktermrc printf "term_scrollback = 10000\n" >> ${HOME}/.gtktermrc printf "term_visual_bell = True\n" >> ${HOME}/.gtktermrc printf "term_foreground_red = 43253\n" >> ${HOME}/.gtktermrc printf "term_foreground_blue = 43253\n" >> ${HOME}/.gtktermrc printf "term_foreground_green = 43253\n" >> ${HOME}/.gtktermrc printf "term_background_red = 0\n" >> ${HOME}/.gtktermrc printf "term_background_blue = 0\n" >> ${HOME}/.gtktermrc printf "term_background_green = 0\n" >> ${HOME}/.gtktermrc printf "term_background_saturation = 0,500000\n" >> ${HOME}/.gtktermrc else printWarning "Configuration file ${HOME}/.gtktermrc does not exit.\n" printWarning "Create the file with the following content:" printf "[AMiRo]\n" printf "port = /dev/ttyUSB0\n" printf "speed = 115200\n" printf "bits = 8\n" printf "stopbits = 1\n" printf "parity = none\n" printf "flow = none\n" printf "wait_delay = 0\n" printf "wait_char = -1\n" printf "rs485_rts_time_before_tx = 30\n" printf "rs485_rts_time_after_tx = 30\n" printf "echo = False\n" printf "crlfauto = True\n" printf "font = \"Nimbus Mono L, 11\"\n" printf "term_transparency = False\n" printf "term_show_cursor = True\n" printf "term_rows = 80\n" printf "term_columns = 25\n" printf "term_scrollback = 10000\n" printf "term_visual_bell = True\n" printf "term_foreground_red = 43253\n" printf "term_foreground_blue = 43253\n" printf "term_foreground_green = 43253\n" printf "term_background_red = 0\n" printf "term_background_blue = 0\n" printf "term_background_green = 0\n" printf "term_background_saturation = 0,500000\n" read fi printInfo "Use gtkterm like this: >$ gtkterm -c AMiRo" read -p "Do you want an alias ('amiroterm') for that? [y/N] " user_input # create alias only if the answer was explicitly 'yes' if [ "${user_input}" = "Y" ] || [ "${user_input}" = "y" ] || [ "${user_input}" = "Yes" ] || [ "${user_input}" = "yes" ]; then echo "" >> ${HOME}/.bashrc echo "# shortcut for gtkterm call for AMiRo communication (press F8 to toggle the RTS pin)" >> ${HOME}/.bashrc echo "alias amiroterm='gtkterm -c AMiRo'" >> ${HOME}/.bashrc printInfo "alias 'amiroterm' created." fi ### Install hterm read -p "Do you want to install the optional hterm tool? [y/N] " user_input # install only if the answer was explicitly 'yes' if [ "${user_input}" = "Y" ] || [ "${user_input}" = "y" ] || [ "${user_input}" = "Yes" ] || [ "${user_input}" = "yes" ]; then printInfo "installing hterm..." HTERM_LOCATION="http://www.der-hammer.info/terminal/hterm.tar.gz" wget ${HTERM_LOCATION} tar -xzf `basename ${HTERM_LOCATION}` cp ./hterm ${INSTALL_DIR} unset HTERM_LOCATION fi #### OPTIONAL: Install BeBot/AMiRo cross compiler for CognitionBoard #printInfo "installing poky..." #INSTALL_DIR="/opt/poky/1.5+snapshot-20140203" #${SRC_FOLDER}/poky-eglibc-x86_64-meta-toolchain-openrobotix-cortexa8hf-vfp-neon-toolchain-openrobotix-1.5+snapshot-20140203.sh -d "${INSTALL_DIR}" -y printWarning "This script does not install the Poky cross compiler yet. [TODO]" ### STM32FLASH printInfo "installing stm32flash..." STM32FLASH_DIR="stm32flash" git clone git://git.code.sf.net/p/stm32flash/code ${STM32FLASH_DIR} cd ${STM32FLASH_DIR} git checkout fb52b4d80613b19b28ab82ba9fa415378d00fb9a make cp ./stm32flash ${INSTALL_DIR} cd ${EXEC_DIR} unset STM32FLASH_DIR ### arm-gnu-none-eabi printInfo "installing arm-gnu-none-eabi..." ARM_GCC_LOCATION="https://launchpad.net/gcc-arm-embedded/4.8/4.8-2014-q1-update/+download/gcc-arm-none-eabi-4_8-2014q1-20140314-linux.tar.bz2" wget ${ARM_GCC_LOCATION} ARM_GCC_TARBALL=`basename ${ARM_GCC_LOCATION}` tar -jxf ${ARM_GCC_TARBALL} COMPILER_DIR=`tar --bzip2 -tf ${ARM_GCC_TARBALL} | sed -e 's@/.*@@' | uniq` sudo cp -fR "${EXEC_DIR}/${COMPILER_DIR}" ${PROG_DIR} # Link the programs to the ${INSTALL_DIR} directory sudo sh -c 'ls ${PROG_DIR}/${COMPILER_DIR}/bin/ | xargs -i ln -sf ${PROG_DIR}/${COMPILER_DIR}/bin/{} ${INSTALL_DIR}/{}' unset ARM_GCC_LOCATION unset ARM_GCC_TARBALL unset COMPILER_DIR ### Create a UDEV rule, that everyone can access the /dev/ttyUSB* devices printInfo "setting USB permissions..." sudo echo 'KERNEL=="ttyUSB[0-9]*",NAME="tts/USB%n",SYMLINK+="%k",MODE="0666"' > /etc/udev/rules.d/50-ttyusb.rules ### Installation path printInfo "The required repositories with all source code will be cloned now." printInfo "Please specify installation path." user_input="" while [ -z $user_input ]; do read -p "installation path: " -e user_input if [ -z $user_input ]; then printError "invalid input" fi done CLONE_PATH=${user_input} if [ ${CLONE_PATH:0:1} == "~" ]; then CLONE_PATH=${CLONE_PATH:1} CLONE_PATH=${HOME}/$CLONE_PATH fi mkdir -p $(realpath -m ${CLONE_PATH}) ### AMiRo-BLT printInfo "cloning AMiRo-BLT repository to ${CLONE_PATH}/amiro-blt..." cd ${CLONE_PATH} git clone http://openresearch.cit-ec.de/git/amiro-os.amiro-blt.git -b 1.0_stable amiro-blt cd ${EXEC_DIR} ### AMiRo-OS printInfo "cloning AMiRo-OS repository to ${CLONE_PATH}/amiro-os..." cd ${CLONE_PATH} git clone http://openresearch.cit-ec.de/git/amiro-os.amiro-os.git -b 1.0_stable amiro-os cd ${EXEC_DIR} ### ChibiOS printInfo "cloning ChibiOS repository to ${CLONE_PATH}/ChibiOS..." cd ${CLONE_PATH} git clone https://github.com/ChibiOS/ChibiOS.git ChibiOS cd ChibiOS git checkout 2e6dfc7364e7551483922ea6afbaea8f3501ab0e cd ${EXEC_DIR} ### ChibiOS patches printInfo "applying custom patches to ChibiOS..." cd ${CLONE_PATH}/ChibiOS cp ../amiro-os/patches/* ./ for i in `ls | grep patch`; do git am --ignore-space-change --ignore-whitespace < ${i}; done cd ${EXEC_DIR} ### SerailBoot printInfo "installing SerialBoot..." cd ${CLONE_PATH}/amiro-blt/Host/Source/SerialBoot mkdir build cd build cmake .. make cd ${EXEC_DIR} ### clean up printInfo "done" read -p "Do you want this directory to be deleted? [y/N] " user_input # delete only if the answer was explicitly 'yes' if [ "${user_input}" = "Y" ] || [ "${user_input}" = "y" ] || [ "${user_input}" = "Yes" ] || [ "${user_input}" = "yes" ]; then printInfo "deleting ${EXEC_DIR}..." cd .. rm -rf `basename ${EXEC_DIR}` else printInfo "Please cleanup this directory manually." fi ### unset all remaining variables printInfo "clearing temporary variables..." unset CLONE_PATH unset INSTALL_DIR unset EXEC_DIR unset PROG_DIR unset user_input ### done printInfo "setup done." printWarning "Several new environment variables have been set.\nStart a new shell so these changes will be applied." read -p "I got it!"