Skip to content
Snippets Groups Projects

Command Execution Test setup script

The snippet can be accessed without any authentication.
Authored by Jonathan Miller

Setup

This script is used to set up all of the software interfaces for the Command Execution test. Run

curl -# https://git.mst.edu/snippets/46/raw?inline=false > setup.sh && chmod +x setup.sh

to download it and to run it just run ./setup.sh. It will ask you for you GitLab username and password.

Edited
setup.sh 2.48 KiB
#!/bin/bash

# This script clones the git repositories stored in the $repos list in the
# current directory. Afterwards it looks to see if there's a CMakeLists.txt file
# in the top level project directory and if so it creates build/ and attempts to
# build the project automatically. If it successfully builds then it links the
# executable in the directory the script is located in. After everything is
# complete then it prints out info such as how many repos there are and how many
# built.

# ADD INTERFACE REPOS HERE
repos=( NS-8_CDH_Sunsensor \
        NS-8_CDH_Comm \
        NS-8_CDH_Adac \
        NS-8_CDH_Gib \
        NS-8_CDH_Prop \
        NS-8_CDH_IMU \
        NS-8_CDH_Thermal )

##########
# Colors #
#########
NC='\033[0m'   # No color (default)
LG='\033[1;32m' # Light green

TAG="[${LG}setup${NC}]"

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

built=0
build_err=0
no_build=0

clone_repo() {
    echo -e "$TAG Cloning $1 ..."
    git clone https://$git_username:$git_password@git.mst.edu/MSAT/$1 > /dev/null 2>&1
    if [ $? -ne 0 ]; then
        echo -e "$TAG Error cloning $1 repo."
        exit
    fi
    echo -e "$TAG $1 repo cloned."
}


echo -n -e "$TAG GitLab username: "
read git_username

echo -n -e "$TAG GitLab password: "
read -s git_password
echo

echo

echo -e "$TAG Cloning projects ... "
echo

for r in "${repos[@]}"; do
    clone_repo $r &
done

wait $(jobs -p)
echo
echo -e "$TAG Projects cloned. Now building projects ... ${NC}"

cd $DIR

for d in $(ls -d */); do
    echo
    echo -e "$TAG Going into $(pwd)/$d"
    cd $d

    if [ -f CMakeLists.txt ]; then
        echo -e "$TAG CMakeLists.txt file found. Building project ..."
        mkdir build
        cd build
        cmake ..

        if [ $? -eq 0 ]; then
            make -j4
            if [ $? -eq 0 ]; then
                ((built++))
                bin=$(ls bin)
                echo -e "$TAG Creating shortcut to $bin in $DIR."
                ln -s $(pwd)/bin/$bin $DIR/$bin
            else
                echo -e "$TAG Compilation failed. Ignoring ..."
                ((build_err++))
            fi
        fi

    else
        echo -e "$TAG CMakeLists.txt file not found. Skipping project."
        ((no_build++))
    fi
    cd $DIR
done

echo
echo -e "$TAG $built projects built successfully."
echo -e "$TAG $build_err ran into an error during compilation."
echo -e "$TAG $no_build did not have a CMakeLists.txt."
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment