#!/usr/bin/env bash
function cli_patch_kernel_pre_run() {
declare -g ARMBIAN_COMMAND_REQUIRE_BASIC_DEPS="yes"
declare -g DOCKER_PASS_SSH_AGENT="yes"
declare -g DOCKER_PASS_GIT="yes"
function add_host_dependencies__ssh_client_for_patch_pushing_over_ssh() {
EXTRA_BUILD_DEPS+=("openssh-client")
}
cli_standard_relaunch_docker_or_sudo
}
function common_config_for_automated_patching() {
declare -g SYNC_CLOCK=no
declare -g PATCHES_TO_GIT=yes
declare -g PATCH_ONLY=yes
declare -g GIT_ARCHEOLOGY=yes
declare -g FAST_ARCHEOLOGY=yes
declare -g KERNEL_CONFIGURE=no
declare -g RELEASE="${RELEASE:-"jammy"}"
declare -g BUILD_DESKTOP="no"
prep_conf_main_build_single
}
function cli_patch_kernel_run() {
display_alert "Patching kernel" "$BRANCH - rewrite: ${REWRITE_PATCHES:-"no"} " "info"
common_config_for_automated_patching
declare -A GIT_INFO_KERNEL=([GIT_SOURCE]="${KERNELSOURCE}" [GIT_REF]="${KERNELBRANCH}")
obtain_kernel_git_info_and_makefile
declare target_repo_url target_branch do_push="no" used_github_shorthand="no"
declare -a push_command=()
determine_git_push_details "${LINUXFAMILY}-${KERNEL_MAJOR_MINOR}"
prepare_host
compile_kernel
display_alert "Done patching kernel" "${BRANCH} - ${LINUXFAMILY} - ${KERNEL_MAJOR_MINOR}" "cachehit"
if [[ "${do_push}" == "yes" ]]; then
display_alert "Pushing kernel to Git branch ${target_branch}" "$(git_redact_credentials "${target_repo_url}")" "info"
git_ensure_safe_directory "${SRC}/cache/git-bare/kernel"
push_command=(git -C "${SRC}/cache/git-bare/kernel" push "--force" "--verbose" "${target_repo_url}" "kernel-${LINUXFAMILY}-${KERNEL_MAJOR_MINOR}:${target_branch}")
display_alert "Git push command: " "$(git_redact_credentials "${push_command[*]}")" "info"
execute_git_push
fi
return 0
}
function cli_patch_uboot_pre_run() {
cli_patch_kernel_pre_run
}
function cli_patch_uboot_run() {
display_alert "Patching u-boot" "$BRANCH - rewrite: ${REWRITE_PATCHES:-"no"} " "info"
common_config_for_automated_patching
declare -A GIT_INFO_UBOOT=([GIT_SOURCE]="${BOOTSOURCE}" [GIT_REF]="${BOOTBRANCH}")
run_memoized GIT_INFO_UBOOT "git2info" memoized_git_ref_to_info "include_makefile_body"
[[ "${GIT_INFO_UBOOT[SHA1]}" =~ ^[0-9a-f]{40}$ ]] || exit_with_error "SHA1 is not sane: '${GIT_INFO_UBOOT[SHA1]}'"
declare target_repo_url target_branch do_push="no" used_github_shorthand="no"
declare -a push_command=()
determine_git_push_details "${BOARD}-${BRANCH}"
prepare_host
declare uboot_git_revision="not_determined_yet"
LOG_SECTION="uboot_prepare_git" do_with_logging_unless_user_terminal uboot_prepare_git
local ubootdir="${SRC}/cache/sources/${BOOTSOURCEDIR}"
cd "${ubootdir}" || exit_with_error "Could not cd to ${ubootdir}"
LOG_SECTION="patch_uboot_target" do_with_logging patch_uboot_target
display_alert "Done patching u-boot" "${BRANCH} - ${LINUXFAMILY} - ${BOOTSOURCE}#${BOOTBRANCH}" "cachehit"
if [[ "${do_push}" == "yes" ]]; then
display_alert "Pushing u-boot to Git branch ${target_branch}" "$(git_redact_credentials "${target_repo_url}")" "info"
git_ensure_safe_directory "${SRC}/cache/git-bare/u-boot"
push_command=(git -C "${SRC}/cache/git-bare/u-boot" push "--force" "--verbose" "${target_repo_url}" "u-boot-${BRANCH}-${BOARD}:${target_branch}")
display_alert "Git push command: " "$(git_redact_credentials "${push_command[*]}")" "info"
execute_git_push
fi
}
function git_redact_credentials() {
sed -E 's|(://)[^/@[:space:]]*@|\1***@|g' <<< "${1}"
}
function determine_git_push_details() {
if [[ -n "${PUSH_TO_GITHUB}" && -z "${PUSH_TO_REPO}" ]]; then
PUSH_TO_REPO="git@github.com:${PUSH_TO_GITHUB}.git"
used_github_shorthand="yes"
display_alert "Will push to GitHub" "${PUSH_TO_GITHUB}" "info"
fi
if [[ -n "${PUSH_TO_REPO}" ]]; then
do_push="yes"
declare ymd vendor_lc
ymd="$(date +%Y%m%d)"
vendor_lc="$(tr '[:upper:]' '[:lower:]' <<< "${VENDOR}" | tr ' ' '_')"
target_branch="${vendor_lc}-${1}-${ymd}${PUSH_BRANCH_POSTFIX:-""}"
target_repo_url="${PUSH_TO_REPO}"
display_alert "Will push to Git" "$(git_redact_credentials "${target_repo_url}") branch ${target_branch}" "info"
else
display_alert "Will NOT push to Git" "use PUSH_TO_GITHUB=org/repo or PUSH_TO_REPO=<url> to push" "info"
fi
}
function execute_git_push() {
display_alert "Pushing to ${target_branch}" "$(git_redact_credentials "${target_repo_url}")" "info"
GIT_SSH_COMMAND="ssh -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" "${push_command[@]}"
display_alert "Done pushing to ${target_branch}" "$(git_redact_credentials "${target_repo_url}")" "info"
if [[ "${used_github_shorthand:-no}" == "yes" ]]; then
display_alert "GitHub tree URL" "https://github.com/${PUSH_TO_GITHUB}/tree/${target_branch}" "info"
display_alert "GitHub commits URL" "https://github.com/${PUSH_TO_GITHUB}/commits/${target_branch}" "info"
fi
}