99set -e -o pipefail
1010
1111# Parse arguments
12- if [ $# -ne 1 ]; then
13- echo " Usage: $0 <path-to-linux-dir>"
12+ if [ $# -lt 1 ] || [ $# -gt 2 ]; then
13+ echo " Usage: $0 <path-to-linux-dir> [branch-name] "
1414 exit 1
1515fi
1616
1717LINUX_DIR=" $1 "
18+ INFIX_BRANCH=" ${2:- kernel-upgrade} "
1819
1920# Configuration
2021INFIX_DIR=" $( dirname " $( dirname " $( readlink -f " $0 " ) " ) " ) "
21- INFIX_BRANCH=" kernel-upgrade"
2222LINUX_BRANCH=" kkit-linux-6.12.y"
2323UPSTREAM_REMOTE=" upstream"
2424UPSTREAM_URL=" https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git"
2525KKIT_REMOTE=" origin"
26- KKIT_URL=
" [email protected] :kernelkit/linux.git" 26+
27+ # Detect if running in CI (GitHub Actions sets CI=true)
28+ if [ " ${CI:- false} " = " true" ]; then
29+ KKIT_URL=" https://github.com/kernelkit/linux.git"
30+ else
31+ KKIT_URL=
" [email protected] :kernelkit/linux.git" 32+ fi
33+
2734KERNEL_VERSION_PATTERN=" 6.12"
2835
2936# Colors for output
@@ -50,8 +57,18 @@ check_directories() {
5057
5158 if [ ! -d " $LINUX_DIR " ]; then
5259 log_info " Linux directory '$LINUX_DIR ' not found, cloning..."
53- if git clone " $KKIT_URL " " $LINUX_DIR " ; then
60+ # Clone to parent directory if LINUX_DIR is a relative path without slashes
61+ if [[ " $LINUX_DIR " != * /* ]]; then
62+ CLONE_TARGET=" ../$LINUX_DIR "
63+ log_info " Cloning to $CLONE_TARGET (parent directory)"
64+ else
65+ CLONE_TARGET=" $LINUX_DIR "
66+ fi
67+
68+ if git clone " $KKIT_URL " " $CLONE_TARGET " ; then
5469 log_info " Successfully cloned linux repository"
70+ # Update LINUX_DIR to the actual path
71+ LINUX_DIR=" $CLONE_TARGET "
5572 else
5673 log_error " Failed to clone linux repository"
5774 exit 1
@@ -204,24 +221,8 @@ update_infix() {
204221 exit 1
205222 fi
206223
207- # Update ChangeLog.md with new kernel version
208- log_info " Updating ChangeLog.md..."
209- if [ -f " doc/ChangeLog.md" ]; then
210- # Check if there's already a kernel upgrade entry in the latest release
211- if grep -q " ^- Upgrade Linux kernel to" doc/ChangeLog.md | head -20; then
212- # Find and update the existing kernel upgrade line
213- sed -i " 0,/^- Upgrade Linux kernel to.*/{s/^- Upgrade Linux kernel to.*/- Upgrade Linux kernel to $NEW_VERSION (LTS)/}" doc/ChangeLog.md
214- log_info " Updated existing kernel version entry to $NEW_VERSION "
215- else
216- # Add new kernel upgrade entry after the first "### Changes" section
217- sed -i " 0,/^### Changes/a\\
218- \\
219- - Upgrade Linux kernel to $NEW_VERSION (LTS)" doc/ChangeLog.md
220- log_info " Added new kernel version entry: $NEW_VERSION "
221- fi
222- else
223- log_warn " doc/ChangeLog.md not found, skipping changelog update"
224- fi
224+ # Update changelog
225+ update_changelog " $NEW_VERSION "
225226
226227 # Commit all changes
227228 log_info " Committing changes to infix..."
@@ -234,6 +235,50 @@ update_infix() {
234235 fi
235236}
236237
238+ # Update ChangeLog.md with new kernel version
239+ update_changelog () {
240+ local NEW_VERSION=" $1 "
241+
242+ log_info " Updating ChangeLog.md..."
243+ if [ ! -f " doc/ChangeLog.md" ]; then
244+ log_warn " doc/ChangeLog.md not found, skipping changelog update"
245+ return 0
246+ fi
247+
248+ # Check if the latest release is UNRELEASED (first release header in file)
249+ FIRST_RELEASE=$( grep -m1 " ^\[v" doc/ChangeLog.md)
250+ if ! echo " $FIRST_RELEASE " | grep -q " \[UNRELEASED\]" ; then
251+ log_error " First release section in ChangeLog.md is not UNRELEASED"
252+ log_error " Please create an UNRELEASED section first before running this script"
253+ exit 1
254+ fi
255+
256+ # Extract just the UNRELEASED section (from start until next version header)
257+ UNRELEASED_SECTION=$( sed -n ' 1,/^\[v[0-9]/p' doc/ChangeLog.md | head -n -1)
258+
259+ # Check if there's already a kernel upgrade entry in the UNRELEASED section
260+ if echo " $UNRELEASED_SECTION " | grep -q " ^- Upgrade Linux kernel to" ; then
261+ # Update existing kernel upgrade line (only first occurrence)
262+ sed -i " 0,/^- Upgrade Linux kernel to.*/{s|^- Upgrade Linux kernel to.*|- Upgrade Linux kernel to $NEW_VERSION (LTS)|}" doc/ChangeLog.md
263+ log_info " Updated existing kernel version entry to $NEW_VERSION "
264+ else
265+ # Add new kernel upgrade entry after first "### Changes"
266+ # Use awk to insert at the right place
267+ awk -v new_line=" - Upgrade Linux kernel to $NEW_VERSION (LTS)" '
268+ /^### Changes/ && !done {
269+ print
270+ getline
271+ if (NF == 0) print
272+ print new_line
273+ done=1
274+ next
275+ }
276+ {print}
277+ ' doc/ChangeLog.md > doc/ChangeLog.md.tmp && mv doc/ChangeLog.md.tmp doc/ChangeLog.md
278+ log_info " Added new kernel version entry: $NEW_VERSION "
279+ fi
280+ }
281+
237282# Check for uncommitted changes
238283check_clean_working_tree () {
239284 log_info " Checking for uncommitted changes..."
@@ -255,20 +300,18 @@ check_clean_working_tree() {
255300 log_info " Working tree is clean"
256301}
257302
258- # Push changes to remotes
303+ # Push changes to both repositories
259304push_changes () {
260- log_info " Pushing changes to remotes..."
261-
262- # Push rebased linux branch to kkit remote
263- log_info " Pushing rebased linux branch to $KKIT_REMOTE ..."
305+ # Push rebased linux branch
306+ log_info " Pushing linux branch to $KKIT_REMOTE ..."
264307 if git -C " $LINUX_DIR " push " $KKIT_REMOTE " " $LINUX_BRANCH " --force-with-lease; then
265308 log_info " Successfully pushed linux branch to $KKIT_REMOTE "
266309 else
267310 log_error " Push to linux remote failed"
268311 exit 1
269312 fi
270313
271- # Push infix branch to origin
314+ # Push infix changes
272315 log_info " Pushing infix branch to origin..."
273316 if git -C " $INFIX_DIR " push origin " $INFIX_BRANCH " ; then
274317 log_info " Successfully pushed infix branch to origin"
0 commit comments