2 # SPDX-License-Identifier: GPL-2.0-or-later
4 # Copyright (C) 2024 Olliver Schinagl <oliver@schinagl.nl>
7 if [ -n "${DEBUG_TRACE_SH:-}" ] && \
8 [ "${DEBUG_TRACE_SH:-}" != "${DEBUG_TRACE_SH#*"$(basename "${0}")"*}" ] || \
9 [ "${DEBUG_TRACE_SH:-}" = 'all' ]; then
29 _level
="${1:?Missing argument to function}"
32 if [ "${#}" -le 0 ]; then
33 echo "${_level}: No content for this message ..."
37 echo "${_level}: ${*}"
58 echo 'Helper script to bump the target kernel version, whilst keeping history.'
59 echo ' -c Migrate config files (e.g. subtargets) only.'
60 echo " -p Optional Platform name (e.g. 'ath79' [PLATFORM_NAME]"
61 echo " -s Source version of kernel (e.g. 'v6.1' [SOURCE_VERSION])"
62 echo " -t Target version of kernel (e.g. 'v6.6' [TARGET_VERSION]')"
64 echo 'All options can also be passed in environment variables (listed between [BRACKETS]).'
65 echo 'Note that this script must be run from within the OpenWrt git repository.'
66 echo 'Example: scripts/kernel_bump.sh -p realtek -s v6.1 -t v6.6'
71 trap - EXIT HUP INT QUIT ABRT ALRM TERM
73 if [ -n "${initial_branch:-}" ] && \
74 [ "$(git rev-parse --abbrev-ref HEAD)" != "${initial_branch:-}" ]; then
75 git switch
"${initial_branch}"
81 src_file
="$(readlink -f "${0}")"
82 src_dir
="${src_file%%"${src_file##*'/'}"}"
83 initial_branch
="$(git rev-parse --abbrev-ref HEAD)"
84 initial_commitish
="$(git rev-parse HEAD)"
86 if [ -n "$(git status --porcelain | grep -v '^?? .*')" ]; then
87 echo 'Git respository not in a clean state, will not continue.'
91 if [ -n "${src_dir##*'/scripts/'}" ]; then
92 echo "This script '${src_file}' is not in the scripts subdirectory, this is unexpected, cannot continue."
96 source_version
="${source_version#v}"
97 target_version
="${target_version#v}"
99 trap cleanup EXIT HUP INT QUIT ABRT ALRM TERM
104 if [ -z "${platform_name}" ] || \
105 [ -d "${PWD}/image" ]; then
106 platform_name
="${PWD}"
108 platform_name
="${platform_name##*'/'}"
110 _target_dir
="${src_dir}/../target/linux/${platform_name}"
112 if [ ! -d "${_target_dir}/image" ]; then
113 e_err
"Cannot find target linux directory '${_target_dir:-not defined}'. Not in a platform directory, or -p not set."
117 git switch
--force-create '__openwrt_kernel_files_mover'
119 if [ "${config_only:-false}" != 'true' ]; then
120 for _path
in $
(git ls-tree
-d -r --name-only '__openwrt_kernel_files_mover' "${_target_dir}" |
121 sed -n "s|^\(.*-${source_version}\).*|\1|p" |
123 if [ ! -e "${_path}" ] || \
124 [ "${_path}" = "${_path%%"-${source_version}"}" ]; then
128 _target_path
="${_path%%"-${source_version}"}-${target_version}"
129 if [ -e "${_target_path}" ]; then
130 e_err
"Target '${_target_path}' already exists!"
140 for _config
in $
(git ls-files
"${_target_dir}" |
141 sed -n "s|^\(.*config-${source_version}\).*|\1|p" |
143 if [ ! -e "${_config}" ]; then
147 _subtarget
="${_config%%"/config-${source_version}"}"
148 git
mv "${_config}" "${_subtarget}/config-${target_version}"
153 --message "kernel/${platform_name}: Create kernel files for v${target_version} (from v${source_version})" \
154 --message 'This is an automatically generated commit.' \
155 --message 'When doing `git bisect`, consider `git bisect --skip`.'
157 git checkout
'HEAD~' "${_target_dir}"
160 --message "kernel/${platform_name}: Restore kernel files for v${source_version}" \
161 --message "$(printf "This is an automatically generated commit
which aids following Kernel
patch history,\nas git will see the move and copy as a rename thus defeating the purpose.
\n\nSee
: https
://lists.openwrt.org
/pipermail
/openwrt-devel
/2023-October/041673.html
\nfor the original discussion.
")"
162 git switch
"${initial_branch:?Unable to switch back to original branch. Quitting.}"
163 GIT_EDITOR
=true git merge
--no-ff '__openwrt_kernel_files_mover'
164 git branch
--delete '__openwrt_kernel_files_mover'
166 echo "Original commitish was '${initial_commitish}'."
167 echo 'Kernel bump complete. Remember to use `git log --follow`.'
172 for _cmd
in ${REQUIRED_COMMANDS}; do
173 if ! _test_result
="$(command -V "${_cmd}")"; then
174 _test_result_fail
="${_test_result_fail:-}${_test_result}\n"
176 _test_result_pass
="${_test_result_pass:-}${_test_result}\n"
180 echo 'Available commands:'
181 # As the results contain \n, we expect these to be interpreted.
182 # shellcheck disable=SC2059
183 printf "${_test_result_pass:-none\n}"
185 echo 'Missing commands:'
186 # shellcheck disable=SC2059
187 printf "${_test_result_fail:-none\n}"
190 if [ -n "${_test_result_fail:-}" ]; then
191 echo 'Command test failed, missing programs.'
198 while getopts 'chp:s:t:' _options
; do
199 case "${_options}" in
208 platform_name
="${OPTARG}"
211 source_version
="${OPTARG}"
214 target_version
="${OPTARG}"
217 e_err
"Option -${OPTARG} requires an argument."
221 e_err
"Invalid option: -${OPTARG}"
226 shift "$((OPTIND - 1))"
228 platform_name
="${platform_name:-${PLATFORM_NAME:-}}"
229 source_version
="${source_version:-${SOURCE_VERSION:-}}"
230 target_version
="${target_version:-${TARGET_VERSION:-}}"
232 if [ -z "${source_version:-}" ] ||
[ -z "${target_version:-}" ]; then
233 e_err
"Source (${source_version:-missing source version}) and target (${target_version:-missing target version}) versions need to be defined."