110 lines
2.9 KiB
Bash
Executable File
110 lines
2.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# This script will look for git recipes in our own layers and
|
|
# automatically check if there are new upstream commit in order
|
|
# to update the SRCREV entry in the recipe.
|
|
#
|
|
# For it to work properly, UPSTREAM_CHECK_COMMITS = "1" must be set
|
|
# in your local.conf (see our template)
|
|
#
|
|
# This script does not commit anything, please review the changes
|
|
# before committing and pushing.
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
ABSOLUTE_PATH="$(readlink -f "$0")"
|
|
SCRIPTS_DIR=$(dirname "${ABSOLUTE_PATH}")
|
|
YOCTO_DIR=$(readlink -f "${SCRIPTS_DIR}/../")
|
|
|
|
|
|
updatable_recipes=()
|
|
updatable_packages=()
|
|
|
|
get_updatable_recipes()
|
|
{
|
|
all_recipes=$(find "${YOCTO_DIR}"/layers -name "*.bb")
|
|
for recipe in ${all_recipes}; do
|
|
if grep -q SRCREV "${recipe}"; then
|
|
updatable_recipes+=("${recipe}")
|
|
fi
|
|
done
|
|
}
|
|
|
|
convert_recipes_to_package_names()
|
|
{
|
|
for file in "${updatable_recipes[@]}"; do
|
|
filename=$(basename "${file}")
|
|
package_name=${filename/_git\.bb/}
|
|
updatable_packages+=("${package_name}")
|
|
done
|
|
}
|
|
|
|
get_new_commit_lines()
|
|
{
|
|
# Load build environment (disable flags to avoid problems while sourcing
|
|
set +eu
|
|
export BB_ENV_PASSTHROUGH_ADDITIONS="UPSTREAM_CHECK_COMMITS"
|
|
export MACHINE=netmodule-hw20
|
|
export UPSTREAM_CHECK_COMMITS="1"
|
|
# shellcheck source=/dev/null
|
|
source "${YOCTO_DIR}"/nwl-init-build-env >/dev/null
|
|
set -eu
|
|
|
|
# the relevant output is on stderr
|
|
if ! upgrade_status=$(devtool check-upgrade-status "${updatable_packages[@]}" 2>&1 >/dev/null);
|
|
then
|
|
echo "devtool failed"
|
|
echo "${upgrade_status}"
|
|
exit 1
|
|
fi
|
|
|
|
if ! new_commit_lines=$(grep "new commits" <<< "${upgrade_status}")
|
|
then
|
|
echo "Nothing to update"
|
|
exit 0
|
|
fi
|
|
}
|
|
|
|
get_bbfile_from_package()
|
|
{
|
|
package="${1}"
|
|
for file in "${updatable_recipes[@]}"; do
|
|
# The grepped output will be used by caller
|
|
if grep "${package}" <<< "${file}"; then
|
|
return
|
|
fi
|
|
done
|
|
}
|
|
|
|
|
|
get_updatable_recipes
|
|
#echo -e "Found bbfiles: \n" "${updatable_recipes[@]}\n"
|
|
|
|
convert_recipes_to_package_names
|
|
echo -e "Looking for updates for these packages: \n" "${updatable_packages[@]}" "\n"
|
|
|
|
get_new_commit_lines
|
|
echo -e "New commits: \n${new_commit_lines}\n"
|
|
|
|
echo "Starting to update files"
|
|
IFS=$'\n' # Read line by line instead of word by word
|
|
for line in ${new_commit_lines}; do
|
|
# Get package name (2nd word of the line)
|
|
package_name=$(cut -d " " -f 2 <<< "${line}")
|
|
# Convert to recipe filename
|
|
bbfile=$(get_bbfile_from_package "${package_name}")
|
|
relative_bbfile_path=$(realpath --relative-to="${YOCTO_DIR}" "${bbfile}")
|
|
|
|
# The commit is the last word of the line
|
|
newrev=$(grep --only-matching --extended-regexp '[^ ]+\s?$' <<< "${line}")
|
|
newrev=$(tr -d " " <<< "${newrev}")
|
|
|
|
echo "Updating ${relative_bbfile_path}"
|
|
echo "To ${newrev}"
|
|
echo
|
|
sed -i "s/^SRCREV.*/SRCREV = \"${newrev}\"/g" "${bbfile}"
|
|
done
|
|
|
|
exit 0
|