#!/bin/bash #---------------------------------------------- # Make sure script has been sourced # if [ "$0" = "$BASH_SOURCE" ]; then echo "###################################" echo "ERROR: YOU MUST SOURCE the script" echo "###################################" exit 1 fi BUILD_DIR=$1 # Init env var SCLE_ROOT_DIR=`realpath $PWD` SCLE_DIR="meta-cyber-scle" if [ "a${SCLE_DL_DIR}" = "a" ]; then SCLE_DL_DIR="$SCLE_ROOT_DIR/oe-downloads" fi if [ "a${SCLE_SSTATE_DIR}" = "a" ]; then SCLE_SSTATE_DIR="${SCLE_ROOT_DIR}/sstate-cache" fi # Use utf-8 encoding if ! echo $LANG | grep -q "en_US.UTF-8" then export LANG="en_US.UTF-8" fi if [ "a${DISTRO}" = "a" ]; then DISTRO="rpi-distro" fi if [ "a${MACHINE}" = "a" ]; then MACHINE="raspberrypi" fi if [ "a${VERS}" = "a" ]; then VERS="none" fi if [ "a${REV}" = "a" ]; then REV="0" fi _TEMPLATECONF="$SCLE_ROOT_DIR/${SCLE_DIR}/conf/template/" #---------------------------------------------- # Standard Openembedded init # echo -e "[source $SCLE_ROOT_DIR/poky/oe-init-build-env]" TEMPLATECONF=${_TEMPLATECONF} source $SCLE_ROOT_DIR/poky/oe-init-build-env ${BUILD_DIR} > /dev/null 2> /dev/null _FORMAT_PATTERN='::-::' ###################################################### # Make selection for requested from provided using shell or ui choice # _choice_shell() { #format list to have display aligned on column with '-' separation between name and description local options=$(echo "$2" | column -t -s "::") if [ "z$ZSH_NAME" != "z" ] then # zsh don't split string as expected (see http://zsh.sourceforge.net/FAQ/zshfaq03.html) eval "options=($options)" fi #change separator from 'space' to 'end of line' for 'select' command old_IFS=$IFS IFS=$'\n' local i=1 unset LAUNCH_MENU_CHOICES for opt in $options; do printf "%3.3s. %s\n" $i $opt LAUNCH_MENU_CHOICES=(${LAUNCH_MENU_CHOICES[@]} $opt) i=$(($i+1)) done IFS=$old_IFS # Item selection from list local selection="" while [ -z "$selection" ]; do echo -n "Please enter your choice of $1 (1-$(echo "$options" | wc -l)): " read answer if [[ $answer =~ ^[0-9]+$ ]]; then if [ $answer -gt 0 ] && [ $answer -le ${#LAUNCH_MENU_CHOICES[@]} ]; then if [ "z$ZSH_NAME" != "z" ] then selection=${LAUNCH_MENU_CHOICES[$(($answer))]} else selection=${LAUNCH_MENU_CHOICES[$(($answer-1))]} fi break fi fi echo "Invalid choice: $answer" done eval $1=$(echo $selection | cut -d' ' -f1) } _choice_ui() { local target="" #change separator from 'space' to 'end of line' to get full line old_IFS=$IFS IFS=$'\n' for ITEM in $2; do local target_name=$(echo $ITEM | awk -F''"${_FORMAT_PATTERN}"'' '{print $1}') local target_desc=$(echo $ITEM | awk -F''"${_FORMAT_PATTERN}"'' '{print $NF}') TARGETTABLE+=($target_name "$target_desc" OFF) done IFS=$old_IFS while [[ -z $target ]] do target=$(${UI_CMD} --title "Available $1" --radiolist "Please choose a $1" 0 0 0 "${TARGETTABLE[@]}" 3>&1 1>&2 2>&3) test -z $target || break #display dialog box to provide some help to user ${UI_CMD} --title "How to select $1" --msgbox "Keyboard usage:\n\n'ENTER' to validate\n'SPACE' to select\n 'TAB' to navigate" 0 0 done unset TARGETTABLE unset ITEM eval $1=$target } choice() { local __TARGET=$1 local choices="$2" echo "[$__TARGET configuration]" if [ $(echo "$choices" | wc -l) -eq 1 ]; then eval $__TARGET=$(echo $choices | awk -F''"${_FORMAT_PATTERN}"'' '{print $1}') else if ! [[ -z $DISPLAY ]] && ! [[ -z ${UI_CMD} ]]; then _choice_ui $__TARGET "$choices" else _choice_shell $__TARGET "$choices" fi fi echo "Selected $__TARGET: $(eval echo \$$__TARGET)" echo "" } ###################################################### # Choose target machine # conf_machine() { local choices=$(find ${SCLE_ROOT_DIR}/${SCLE_DIR}/conf/machine/ -name "*.conf" 2>/dev/null | sort | uniq) for ITEM in $choices do if [[ -z $(grep "#@DESCRIPTION" $ITEM) ]]; then echo "" echo "ERROR: No '#@DESCRIPTION' field available in $__CONGIG file:" echo "$ITEM" echo "" return 1 fi done unset ITEM if [ $(echo $choices | wc -l) -eq 1 ]; then # return only file name (distro or machine) echo "$(echo $choices | sed 's|^.*/\(.*\)\.conf|\1|')" else echo "$(echo $choices | xargs grep "#@DESCRIPTION" | sed 's|^.*/\(.*\)\.conf:#@DESCRIPTION:[ \t]*\(.*$\)|\1'"${_FORMAT_PATTERN}"'\2|')" fi } ###################################################### # Apply configuration to site.conf file # conf_siteconf() { _NCPU=$(grep '^processor' /proc/cpuinfo 2>/dev/null | wc -l) # Sanity check that we have a valid number, if not then fallback to a safe default [ "$_NCPU" -ge 1 ] 2>/dev/null || _NCPU=2 cat > conf/site.conf < !!!! [WARNING] site.conf already exists. Nothing done... !!!!" else conf_siteconf fi update_layerconf ${SCLE_ROOT_DIR}/${SCLE_DIR} list_images ${SCLE_DIR}