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
27 _level
="${1:?Missing argument to function}"
30 if [ "${#}" -le 0 ]; then
31 echo "${_level}: No content for this message ..."
35 echo "${_level}: ${*}"
56 echo 'Helper script to bump the target kernel version, whilst keeping history.'
57 echo " -p Optional Platform name (e.g. 'ath79' [PLATFORM_NAME]"
58 echo " -s Source version of kernel (e.g. 'v6.1' [SOURCE_VERSION])"
59 echo " -t Target version of kernel (e.g. 'v6.6' [TARGET_VERSION]')"
61 echo 'All options can also be passed in environment variables (listed between [BRACKETS]).'
62 echo 'Example: scripts/kernel_bump.sh -p realtek -s v6.1 -t v6.6'
67 trap - EXIT HUP INT QUIT ABRT ALRM TERM
69 if [ -n "${initial_branch:-}" ] && \
70 [ "$(git rev-parse --abbrev-ref HEAD)" != "${initial_branch:-}" ]; then
71 git switch
"${initial_branch}"
77 initial_branch
="$(git rev-parse --abbrev-ref HEAD)"
78 initial_commitish
="$(git rev-parse HEAD)"
80 source_version
="${source_version#v}"
81 target_version
="${target_version#v}"
83 trap cleanup EXIT HUP INT QUIT ABRT ALRM TERM
88 platform_name
="${platform_name##*'/'}"
90 if [ -z "${platform_name:-}" ]; then
91 platform_name
="${PWD##*'/'}"
94 if [ "${PWD##*'/'}" = "${platform_name}" ]; then
97 _target_dir
="target/linux/${platform_name}"
100 if [ ! -d "${_target_dir}/image" ]; then
101 e_err
'Cannot find target linux directory.'
105 git switch
--force-create '__openwrt_kernel_files_mover'
107 for _path
in "${_target_dir}/"*; do
108 if [ ! -s "${_path}" ] || \
109 [ "${_path}" = "${_path%%"-${source_version}"}" ]; then
113 _target_path
="${_path%%"-${source_version}"}-${target_version}"
114 if [ -s "${_target_path}" ]; then
115 e_err
"Target '${_target_path}' already exists!"
124 find "${_target_dir}" -iname "config-${source_version}" |
while read -r _config
; do
125 _path
="${_config%%"/config-${source_version}"}"
126 git
mv "${_config}" "${_path}/config-${target_version}"
131 --message "kernel/${platform_name}: Create kernel files for v${target_version} (from v${source_version})" \
132 --message 'This is an automatically generated commit.' \
133 --message 'When doing `git bisect`, consider `git bisect --skip`.'
135 git checkout
'HEAD~' "${_target_dir}"
138 --message "kernel/${platform_name}: Restore kernel files for v${source_version}" \
139 --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.
")"
140 git switch
"${initial_branch:?Unable to switch back to original branch. Quitting.}"
141 GIT_EDITOR
=true git merge
--no-ff '__openwrt_kernel_files_mover'
142 git branch
--delete '__openwrt_kernel_files_mover'
144 echo "Original commitish was '${initial_commitish}'."
145 echo 'Kernel bump complete. Remember to use `git log --follow`.'
150 for _cmd
in ${REQUIRED_COMMANDS}; do
151 if ! _test_result
="$(command -V "${_cmd}")"; then
152 _test_result_fail
="${_test_result_fail:-}${_test_result}\n"
154 _test_result_pass
="${_test_result_pass:-}${_test_result}\n"
158 echo 'Available commands:'
159 # As the results contain \n, we expect these to be interpreted.
160 # shellcheck disable=SC2059
161 printf "${_test_result_pass:-none\n}"
163 echo 'Missing commands:'
164 # shellcheck disable=SC2059
165 printf "${_test_result_fail:-none\n}"
168 if [ -n "${_test_result_fail:-}" ]; then
169 echo 'Command test failed, missing programs.'
176 while getopts 'hp:s:t:' _options
; do
177 case "${_options}" in
183 platform_name
="${OPTARG}"
186 source_version
="${OPTARG}"
189 target_version
="${OPTARG}"
192 e_err
"Option -${OPTARG} requires an argument."
196 e_err
"Invalid option: -${OPTARG}"
201 shift "$((OPTIND - 1))"
203 platform_name
="${platform_name:-${PLATFORM_NAME:-}}"
204 source_version
="${source_version:-${SOURCE_VERSION:-}}"
205 target_version
="${target_version:-${TARGET_VERSION:-}}"
207 if [ -z "${source_version:-}" ] ||
[ -z "${target_version:-}" ]; then
208 e_err
"Source (${source_version:-missing source version}) and target (${target_version:-missing target version}) versions need to be defined."