2018-10-07 03:58:27 +02:00
|
|
|
#!/usr/bin/env bash
|
2017-07-23 05:31:56 +02:00
|
|
|
#
|
util/: Replace GPLv2 boiler plate with SPDX header
Used commands:
perl -i -p0e 's|\/\*[\s*]*.*is free software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and\/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-2.0-only */|' $(cat filelist)
perl -i -p0e 's|This[\s*]*program[\s*]*is[\s*]*free[\s*]*software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*either[\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License,[\s*]*or[\s*]*.at[\s*]*your[\s*]*option.*[\s*]*any[\s*]*later[\s*]*version.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-2.0-or-later */|' $(cat filelist)
perl -i -p0e 's|\/\*[\s*]*.*This[\s*#]*program[\s*#]*is[\s*#]*free[\s*#]*software[;:,][\s*#]*you[\s*#]*can[\s*#]*redistribute[\s*#]*it[\s*#]*and/or[\s*#]*modify[\s*#]*it[\s*#]*under[\s*#]*the[\s*#]*terms[\s*#]*of[\s*#]*the[\s*#]*GNU[\s*#]*General[\s*#]*Public[\s*#]*License[\s*#]*as[\s*#]*published[\s*#]*by[\s*#]*the[\s*#]*Free[\s*#]*Software[\s*#]*Foundation[;:,][\s*#]*either[\s*#]*version[\s*#]*3[\s*#]*of[\s*#]*the[\s*#]*License[;:,][\s*#]*or[\s*#]*.at[\s*#]*your[\s*#]*option.*[\s*#]*any[\s*#]*later[\s*#]*version.[\s*#]*This[\s*#]*program[\s*#]*is[\s*#]*distributed[\s*#]*in[\s*#]*the[\s*#]*hope[\s*#]*that[\s*#]*it[\s*#]*will[\s*#]*be[\s*#]*useful[;:,][\s*#]*but[\s*#]*WITHOUT[\s*#]*ANY[\s*#]*WARRANTY[;:,][\s*#]*without[\s*#]*even[\s*#]*the[\s*#]*implied[\s*#]*warranty[\s*#]*of[\s*#]*MERCHANTABILITY[\s*#]*or[\s*#]*FITNESS[\s*#]*FOR[\s*#]*A[\s*#]*PARTICULAR[\s*#]*PURPOSE.[\s*#]*See[\s*#]*the[\s*#]*GNU[\s*#]*General[\s*#]*Public[\s*#]*License[\s*#]*for[\s*#]*more[\s*#]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-3.0-or-later */|' $(cat filelist)
perl -i -p0e 's|(\#\#*)[\w]*.*is free software[:;][\#\s]*you[\#\s]*can[\#\s]*redistribute[\#\s]*it[\#\s]*and\/or[\#\s]*modify[\#\s]*it[\s\#]*under[\s \#]*the[\s\#]*terms[\s\#]*of[\s\#]*the[\s\#]*GNU[\s\#]*General[\s\#]*Public[\s\#]*License[\s\#]*as[\s\#]*published[\s\#]*by[\s\#]*the[\s\#]*Free[\s\#]*Software[\s\#]*Foundation[;,][\s\#]*version[\s\#]*2[\s\#]*of[\s\#]*the[\s\#]*License.*[\s\#]*This[\s\#]*program[\s\#]*is[\s\#]*distributed[\s\#]*in[\s\#]*the[\s\#]*hope[\s\#]*that[\s\#]*it[\s\#]*will[\#\s]*be[\#\s]*useful,[\#\s]*but[\#\s]*WITHOUT[\#\s]*ANY[\#\s]*WARRANTY;[\#\s]*without[\#\s]*even[\#\s]*the[\#\s]*implied[\#\s]*warranty[\#\s]*of[\#\s]*MERCHANTABILITY[\#\s]*or[\#\s]*FITNESS[\#\s]*FOR[\#\s]*A[\#\s]*PARTICULAR[\#\s]*PURPOSE.[\#\s]*See[\#\s]*the[\#\s]*GNU[\#\s]*General[\#\s]*Public[\#\s]*License[\#\s]*for[\#\s]*more[\#\s]*details.\s(#* *\n)*|\1 SPDX-License-Identifier: GPL-2.0-only\n\n|' $(cat filelist)
perl -i -p0e 's|(\#\#*)[\w*]*.*is free software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and\/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.\s(#* *\n)*|\1 SPDX-License-Identifier: GPL-2.0-only\n\n|' $(cat filelist)
Change-Id: I1008a63b804f355a916221ac994701d7584f60ff
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/41177
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2020-05-08 20:48:04 +02:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-only
|
2017-07-23 05:31:56 +02:00
|
|
|
|
|
|
|
# Description:
|
|
|
|
# Check all submodules for updates. If there are more than a minimum
|
|
|
|
# number of changes, create a commit to update the submodule to the
|
|
|
|
# new version.
|
|
|
|
|
2022-01-06 06:54:30 +01:00
|
|
|
set -eu -o pipefail
|
|
|
|
|
|
|
|
VERSION="1.01"
|
|
|
|
PROGRAM=$0
|
|
|
|
PROGNAME="$(basename "${PROGRAM}")"
|
|
|
|
|
2017-07-23 05:31:56 +02:00
|
|
|
export LANG=C
|
|
|
|
export LC_ALL=C
|
2017-09-27 15:06:57 +02:00
|
|
|
export TZ=UTC0
|
2017-07-23 05:31:56 +02:00
|
|
|
|
|
|
|
min_commits=10
|
|
|
|
TOP=${PWD}
|
|
|
|
SUBMODULES_WITH_UPDATES=0
|
2022-01-06 06:54:30 +01:00
|
|
|
submodule_dirs=()
|
|
|
|
skip_sync=""
|
|
|
|
max_commits_to_list=65
|
|
|
|
|
|
|
|
show_version() {
|
|
|
|
echo "${PROGNAME} version ${VERSION}"
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
echo "Usage: ${PROGNAME} [options]"
|
|
|
|
echo
|
|
|
|
echo "Options:"
|
|
|
|
echo " -c | --changes <#> Specify the minimum number of changes to update a repo"
|
|
|
|
echo " -h | --help Print usage and exit"
|
|
|
|
echo " -R | --repo <dir> Specify a single repo directory to update"
|
|
|
|
echo " -s | --skipsync Assume that repos are already synced"
|
|
|
|
echo " -V | --version Print the version and exit"
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
get_args() {
|
|
|
|
args=$(getopt -l changes:,help,repo:,skipsync,version -o c:hR:sV -- "$@")
|
|
|
|
getopt_ret=$?
|
|
|
|
eval set -- "${args}"
|
|
|
|
|
|
|
|
if [ ${getopt_ret} != 0 ]; then
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
local opt
|
|
|
|
opt="$1"
|
|
|
|
shift
|
|
|
|
case "${opt}" in
|
|
|
|
-c | --changes)
|
|
|
|
min_commits="${1}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-h | --help)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-R | --repo)
|
|
|
|
submodule_dirs=("$(readlink -f "${1}")")
|
|
|
|
shift
|
|
|
|
if [[ ! -d "${submodule_dirs[0]}" ]]; then
|
|
|
|
echo "Error: ${submodule_dirs[0]} is not valid."
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
-s | --skipsync)
|
|
|
|
skip_sync=1
|
|
|
|
;;
|
|
|
|
-V | --version)
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
main() {
|
|
|
|
show_version
|
|
|
|
get_args "$@"
|
|
|
|
|
|
|
|
if (( ${#submodule_dirs[@]} == 0 )); then
|
|
|
|
readarray -t submodule_dirs < <(git submodule foreach pwd | grep -v "Entering")
|
2017-07-23 05:31:56 +02:00
|
|
|
fi
|
2022-01-06 06:54:30 +01:00
|
|
|
|
|
|
|
for submodule in "${submodule_dirs[@]}"; do
|
|
|
|
echo "Checking submodule ${submodule}"
|
|
|
|
if ! cd "$submodule"; then
|
|
|
|
echo "Error: could not cd to $submodule"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
initial_commit_id="$(git log --pretty='%h' -n 1)"
|
|
|
|
initial_commit_description="$(git log --pretty='%ci - (%s)' -n 1)"
|
|
|
|
if [[ ${skip_sync} != "1" ]]; then
|
|
|
|
git fetch 2>/dev/null
|
|
|
|
fi
|
|
|
|
|
2023-08-08 11:54:05 +02:00
|
|
|
declare -a branches=("origin/main" "origin/master" "origin/trunk")
|
|
|
|
for branch in "${branches[@]}"; do
|
|
|
|
if git branch -a | grep "${branch}" > /dev/null; then
|
|
|
|
branch_name="${branch}"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2022-01-06 06:54:30 +01:00
|
|
|
|
|
|
|
updated_commit_id="$(git log --pretty='%h' -n 1 "${branch_name}" -- )"
|
|
|
|
updated_commit_description="$(git log --pretty='%ci - (%s)' -n 1 "${updated_commit_id}")"
|
|
|
|
if [ "${initial_commit_id}" = "${updated_commit_id}" ]; then
|
|
|
|
echo "No updates for ${submodule}"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
SUBMODULES_WITH_UPDATES+=1
|
|
|
|
update_log="$(git log --oneline "${initial_commit_id}..${updated_commit_id}")"
|
|
|
|
update_count="$(echo "${update_log}" | wc -l)"
|
|
|
|
if [[ "${update_count}" -gt "${max_commits_to_list}" ]]; then
|
|
|
|
update_log=""
|
|
|
|
new_commit_terminator="."
|
|
|
|
else
|
|
|
|
new_commit_terminator=":"
|
|
|
|
fi
|
|
|
|
echo "${update_count} new commits for ${submodule}"
|
|
|
|
if [ "${update_count}" -ge "${min_commits}" ]; then
|
|
|
|
echo "Creating commit to update ${submodule##*/} submodule"
|
|
|
|
git checkout "${updated_commit_id}" > /dev/null 2>&1
|
|
|
|
cd "${TOP}" || exit 1
|
|
|
|
git add "${submodule}" > /dev/null 2>&1 || exit 1
|
|
|
|
git commit -s -F- > /dev/null 2>&1 <<-EOF
|
2023-08-08 11:54:05 +02:00
|
|
|
Update ${submodule##*/} submodule to upstream ${branch##*/}
|
2022-01-06 06:54:30 +01:00
|
|
|
|
|
|
|
Updating from commit id ${initial_commit_id}:
|
|
|
|
$initial_commit_description
|
|
|
|
|
|
|
|
to commit id ${updated_commit_id}:
|
|
|
|
${updated_commit_description}
|
|
|
|
|
|
|
|
This brings in ${update_count} new commits${new_commit_terminator}
|
|
|
|
${update_log}
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "${SUBMODULES_WITH_UPDATES}" = "0" ]; then
|
|
|
|
echo "No submodules with any updates."
|
2017-07-23 05:31:56 +02:00
|
|
|
fi
|
2022-01-06 06:54:30 +01:00
|
|
|
}
|
2017-07-23 05:31:56 +02:00
|
|
|
|
2022-01-06 06:54:30 +01:00
|
|
|
main "$@"
|