yocto-img-build/src-rev.sh

191 lines
6.1 KiB
Bash
Executable File

#!/bin/bash
SCRIPT_PARAMS="$*"
SCRIPT_PATHNAME=$(realpath ${0})
SCRIPT_NAME=$(basename ${SCRIPT_PATHNAME})
SCRIPT_PATH=$(dirname ${SCRIPT_PATHNAME})
YOCTO_DIR="${YOCTO_DIR:-$SCRIPT_PATH}"
LOGFILE=/dev/null
IS_REPLACE_SRCREV=false
IS_VERBOSE=false
IS_DISPLAY=false
LIST=""
#**********************************************************************************************
# local helper functions
#**********************************************************************************************
#----------------------------------------------------------------------------------------------
function printUsage()
{
echo -e "\nUsage: ${SCRIPT_NAME} [OPTIONS]\n"
echo -e "find the source revision of the packages within the netmodule meta layers and"
echo -e "display/replace them with the latest hashes."
echo -e "NOTE: there is a list containing packages set to AUTOREV. Use option -a to handle"
echo -e "only revisions of this list. Otherwise we might get incompatible versions of 3rd"
echo -e "party packages.\n"
echo -e ""
echo -e " OPTIONS:"
echo -e " -r|--replace replace SRCREVs"
echo -e " -d|--display display found SRVREVs"
echo -e " -a|--autorev-list=LIST handle only revisions of LIST (e.g. autorev-packages.inc)"
echo -e " -l|--log=LOGFILE write command output to LOGFILE (default = $LOGFILE)"
echo -e " -h|--help show this help"
echo -e " -v|--verbose set script to verbose"
}
#----------------------------------------------------------------------------------------------
function logMessage()
{
local msg="${1}"
echo "${msg}" >> $LOGFILE
}
#----------------------------------------------------------------------------------------------
function printMessage()
{
local msg="${1}"
logMessage "${msg}"
if [[ "${IS_VERBOSE}" == "false" ]]; then
return
fi
echo "${msg}"
}
#----------------------------------------------------------------------------------------------
function checkingEnvironment()
{
printMessage "> checking environment for devtool..."
isEnvLoaded=$(which devtool | wc -l)
logMessage "> isEnvLoaded=${isEnvLoaded}"
if [[ "${isEnvLoaded}" == "0" ]]; then
logMessage "Yocto environment not loaded (devtool not found) --> exiting"
echo "Yocto environment not loaded (devtool not found) --> exiting"
exit 1
fi
}
#----------------------------------------------------------------------------------------------
function getBBFiles()
{
if [[ "${LIST}" == "" ]]; then
files=$(find ${YOCTO_DIR}/meta-netmodule* -name "*.bb" | xargs -i sh -c "grep -q SRCREV {} && echo {}")
else
files=$(cat $LIST | grep "#" | cut -d'#' -f2)
fi
echo "${files}"
}
#----------------------------------------------------------------------------------------------
function displayItem()
{
local bbfile="${1}"
local recipeName="${2}"
local revision="${3}"
printMessage "Recipe: $recipeName"
printMessage "New Revision: $revision"
printMessage "BB File: $bbfile"
if [[ "${IS_DISPLAY}" == "true" && "${IS_VERBOSE}" == "false" ]]; then
echo "Recipe: $recipeName"
echo "New Revision: $revision"
echo "BB File: $bbfile"
fi
}
#**********************************************************************************************
# main
#**********************************************************************************************
O=$(getopt -o hl:a:vrd --long help,log:,autorev-list:,verbose,replace,display -- "$@")
if [ $? != 0 ]; then
echo "ERROR: Could not parse command line options"
exit 1
fi
eval set -- "$O"
while true; do
case "${1}" in
-v|--verbose)
export IS_VERBOSE=true
shift
;;
-d|--display)
export IS_DISPLAY=true
shift
;;
-r|--replace)
export IS_REPLACE_SRCREV=true
shift
;;
-a|--autorev-list)
export LIST="${2}"
export LIST=$(realpath "${LIST}")
shift 2
;;
-l|--log)
export LOGFILE="${2}"
export LOGFILE=$(realpath "${LOGFILE}")
shift 2
;;
-h|--help)
export IS_VERBOSE=false
printUsage
exit 0
;;
--)
shift
break
;;
*)
printUsage; exit 0 ;;
esac
done
echo "${SCRIPT_NAME} called with ${SCRIPT_PARAMS}" > $LOGFILE
checkingEnvironment
printMessage "> get bbfiles (LIST='${LIST}')..."
bbfiles=$(getBBFiles)
logMessage "${bbfiles}"
printMessage "> getting recipes residing in bbfiles..."
recipes=$(echo "$bbfiles" | xargs -i basename {} | sed 's/_.*//' | sed 's/\.bb//')
logMessage "${recipes}"
printMessage "> getting check-upgrade-status..."
newcommits=$(devtool check-upgrade-status $recipes 2>&1 | grep "new commits")
logMessage "${newcommits}"
IFS=$'\n'
for newcommit in $newcommits; do
# We need to restore IFS for sed
IFS=$' \t\n'
# Get recipe name
recipe_name=$(echo $newcommit | cut -d " " -f 2)
# Get the last string in line
newrev=$(echo $newcommit | sed 's/.* //')
logMessage "> newCommit=${newcommit}; recipeName=${recipe_name}; newRev=${newrev}"
# i acts as bbfile index like bbfile[i]
i=1
found=0
for recipe in $recipes; do
if [ "$recipe" == "$recipe_name" ]; then
bbfile=$(echo $bbfiles | cut -d " " -f$i)
displayItem "${bbfile}" "${recipe}" "${newrev}"
found=1
if [ "${IS_REPLACE_SRCREV}" == "true" ]; then
printMessage " --> updating ${recipe} in ${bbfile} to ${newrev}"
sed -i "s/SRCREV.*/SRCREV ?= \"$newrev\"/g" $bbfile
fi
break
fi
i=$((i+1))
done
if [ "$found" == "0" ]; then
logMessage "Recipe ${recipe_name} not found --> exiting"
echo "Recipe ${recipe_name} not found"
exit 1
fi
logMessage "--------------------"
done
logMessage "> all recipes handled"
exit 0