From de99603f2007951a658780862f5abefb9a8f5132 Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Tue, 2 Jan 2024 10:56:34 +0100 Subject: [PATCH] UBUNTU: [Packaging] remove helper scripts BugLink: https://bugs.launchpad.net/bugs/1786013 Signed-off-by: Andrea Righi --- debian/scripts/helpers/close | 195 ---------------------------- debian/scripts/helpers/open | 234 ---------------------------------- debian/scripts/helpers/rebase | 159 ----------------------- 3 files changed, 588 deletions(-) delete mode 100755 debian/scripts/helpers/close delete mode 100755 debian/scripts/helpers/open delete mode 100755 debian/scripts/helpers/rebase diff --git a/debian/scripts/helpers/close b/debian/scripts/helpers/close deleted file mode 100755 index f699cec41022..000000000000 --- a/debian/scripts/helpers/close +++ /dev/null @@ -1,195 +0,0 @@ -#!/bin/bash -eu -export LC_ALL=C.UTF-8 - -usage() { - cat << EOF -Usage: ${P:-$(basename "$0")} [-h|--help] [-d|--dry-run] [-c|--include-config] [-s|--skip-master] [-b BASE_VERSION] - -Prepare the closing release commit. Include all the changelog entries -in the current release, including the changes from the base -kernel. Also close the changelog entry and check for config changes. - -Optional arguments: - -d, --dry-run Perform a trial run with no changes made - printing the commands instead. - -c, --include-config Include config changes in the closing commit. - -s, --skip-master Skip master kernel changelog entries (used when - bootstraping new kernels). - -b BASE_VERSION For derivatives and backports, force the changelog - entries to have the base version as provided (used - when changing the base derivative version of a - backport). - -h, --help Show this help message and exit. - -Examples: - Simply close a release: - \$ cranky close - - Also include any config changes to the closing commit: - \$ cranky close -c - -EOF -} - -dry_run=0 -commit_configs=0 -skip_master_entries=0 -base_version= -while [ "$#" -gt 0 ]; do - case "$1" in - -h|--help) - usage - exit 0 - ;; - -d|--dry-run) - dry_run=1 - ;; - -c|--include-config) - commit_configs=1 - ;; - -s|--skip-master) - skip_master_entries=1 - ;; - -b) - shift - base_version="$1" - ;; - *) - usage - exit 1 - ;; - esac - shift -done - -hl() { echo -e "\e[1m$*\e[0m"; } - -run() { - # Quote args for echo or eval - local quoted=() - for token; do - quoted+=( "$(printf '%q' "$token")" ) - done - # Run - if [ "$dry_run" -eq 1 ]; then - hl "DRY RUN: ${quoted[*]}" - else - hl "${quoted[*]}" - "$@" - echo - fi -} - -# Trick shellcheck so it doesn't complain every time it's necessary to -# use `run $CHROOT`. Use `chroot_run` instead. -shopt -s expand_aliases -alias chroot_run='run ${CHROOT:-}' - -DEBIAN= -# shellcheck disable=SC1091 -. debian/debian.env - -# Check if the "$DEBIAN" directory exists. -if [ ! -d "$DEBIAN" ]; then - echo "You must run this script from the top directory of this repository." - exit 1 -fi - -CONF="$DEBIAN/etc/update.conf" -if [ -f "$CONF" ]; then - # shellcheck disable=SC1090 - . "$CONF" -fi - -# Check if changelog is open -series=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SDistribution) -if [ "$series" != 'UNRELEASED' ]; then - echo "The last entry of the changelog is already released." - exit 1 -fi - -# Update configs -if [ -d "$DEBIAN/config" ]; then - chroot_run fakeroot debian/rules clean updateconfigs - changes=$(git diff HEAD -- "./$DEBIAN/config/") - if [ "$commit_configs" -eq 0 ] && [ -n "$changes" ]; then - echo "Config has changed! please, review it and commit." - exit 1 - fi -fi - -# For normal trees the fact that the update.conf file exists means that they are rebase -# kernels. There are some special trees which started with uc20-efi, which have that -# file because they logically depend on another source but do not have the directory -# which DEBIAN_MASTER points to. -# Skip inserting parent source entries if this is not a rebase tree. -if [ ! -f "$DEBIAN/etc/update.conf" ]; then - skip_master_entries=1 -elif [ "$DEBIAN_MASTER" != "" -a ! -d "$DEBIAN_MASTER" ]; then - skip_master_entries=1 -fi -if [ $skip_master_entries == 0 ]; then - if [ "$DEBIAN_MASTER" = "" ]; then - echo "DEBIAN_MASTER should be defined either in $DEBIAN/etc/update.conf or the environment" - exit 1 - fi - - if [ -z "${base_version}" ]; then - offset=0 - # If not provided as an option, loop through each entry of the current changelog, - # searching for an entry that refers to the master version used as base - # (ie a line containing "[ Ubuntu: 4.15.0-39.42 ]"): - while true; do - changes=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SChanges -c1 -o"$offset") - if ! [ "$changes" ]; then - echo "Failed to retrieve base master version from changelog file: $DEBIAN/changelog" - exit 1 - fi - base_version=$(echo "$changes" | sed -n -r -e '/^\s.*\[ Ubuntu: ([~0-9.-]*) \]$/{s//\1/p;q}') - [ "$base_version" ] && break - offset=$(( offset + 1 )) - done - fi - - master_version=$(dpkg-parsechangelog -l${DEBIAN_MASTER}/changelog -SVersion) - if ! [ "$master_version" ]; then - echo "Failed to retrieve current master version from changelog: $DEBIAN/changelog" - exit 1 - fi - run ./debian/scripts/misc/insert-ubuntu-changes "$DEBIAN/changelog" "$base_version" "$master_version" \ - "$DEBIAN_MASTER/changelog" -fi - -# Insert local changes -run fakeroot debian/rules insertchanges - -# This should be the last step. If there were no changes to the -# changelog, there is nothing to release, so nothing to commit. -changes=$(git diff HEAD) -if [ -z "$changes" ] && [ "$dry_run" -eq 0 ]; then - hl "No changes to commit." - exit 1 -fi - -# Find the current series from previous changelog entries: -series='' -offset=0 -while true; do - series=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SDistribution -c1 -o"$offset") - if [ "$series" ] && [ "$series" != 'UNRELEASED' ]; then - break - fi - offset=$(( offset + 1 )) -done -if ! [ "$series" ]; then - echo "Failed to retrieve the package series from changelog: $DEBIAN/changelog" - exit 1 -fi -# Close the changelog -run dch --nomultimaint -c "$DEBIAN/changelog" -r -D "$series" '' - -# Commit changes -package=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SSource) -prefix="Ubuntu$(echo "$package" | sed -r -e 's/linux(-?)/\1/')-" -version=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SVersion) -run git commit -sam "UBUNTU: $prefix$version" diff --git a/debian/scripts/helpers/open b/debian/scripts/helpers/open deleted file mode 100755 index 797d778d29d1..000000000000 --- a/debian/scripts/helpers/open +++ /dev/null @@ -1,234 +0,0 @@ -#!/bin/bash -eu -export LC_ALL=C.UTF-8 - -out() -{ - local rc=${?} - - trap - EXIT INT TERM HUP - [ "${rc}" -eq 0 ] || echo "Error: Script failed" >&2 - - exit "${rc}" -} - -hl() { - echo -e "\e[1m$*\e[0m" -} - -run() { - # Quote args for echo or eval - local quoted=() - for token; do - quoted+=("$(printf '%q' "$token")") - done - # Run - if [ "$dry_run" -eq 1 ]; then - hl "DRY RUN: ${quoted[*]}" - else - hl "${quoted[*]}" - "$@" - echo - fi -} - -usage() { - cat << EOF -Usage: ${P:-$(basename "$0")} [-h|--help] [-d|--dry-run] [-r|--reuse-abi] - -Create a "start new release" commit. The new commit will contain ABI -changes and any customization required by backport kernels. - -Optional arguments: - -d, --dry-run Perform a trial run with no changes made - printing the commands instead. - -r, --reuse-abi Do not download the previous release ABI files - for the new release and just rename the - current ABI directory. This might cause the - build to fail if the module list or the - retpoline information has changed. - -h, --help Show this help message and exit. - -Environment variable: - CRANKY_MAILENFORCE Regular expression used to validate \$DEBEMAIL. If not - set, it defaults to "@canonical.com$". - -Examples: - Simply start a new release (that will fetch the ABI files from the - archieve repositories): - \$ cranky open - - Start a new release re-using the ABI files already present in the - tree: - \$ cranky open --reuse-abi - -EOF -} - -dry_run=0 -reuse_abi=0 -while [ "$#" -gt 0 ]; do - case "$1" in - -h|--help) - usage - exit 0 - ;; - -d|--dry-run) - dry_run=1 - ;; - -r|--reuse-abi) - reuse_abi=1 - ;; - *) - usage - exit 1 - ;; - esac - shift -done - -trap out EXIT INT TERM HUP - -# Trick shellcheck so it doesn't complain every time it's necessary to -# use `run $CHROOT`. Use `chroot_run` instead. -shopt -s expand_aliases -alias chroot_run='run ${CHROOT:-}' - -# Check DEBEMAIL (used to create the new changelog stanza): -DEBEMAIL="${DEBEMAIL:-}" -CRANKY_MAILENFORCE="${CRANKY_MAILENFORCE:-@canonical.com\$}" -if [ -z "$DEBEMAIL" ] || ! echo "$DEBEMAIL" | grep -qE "$CRANKY_MAILENFORCE"; then - echo "DEBEMAIL is unset, or does not contain \"$CRANKY_MAILENFORCE\": $DEBEMAIL" >&2 - exit 1 -fi - -# Requires a git repo -if [ ! -e .git ]; then - echo "Not a git repository!" >&2 - exit 1 -fi - -# Check the debian directory -if [ ! -e debian/debian.env ]; then - echo "Cannot find debian/debian.env!" >&2 - exit 1 -fi -DEBIAN= -# shellcheck disable=SC1091 -. debian/debian.env -if [ -z "$DEBIAN" ] || [ ! -d "$DEBIAN" ]; then - echo "Invalid DEBIAN directory: $DEBIAN" >&2 - exit 1 -fi - -# Abort if changes or untracked files are found in the debian -# directory (ie, in "debian.master/"). cranky open is expected to -# change and commit files in this directory. -if ! git diff-index --quiet HEAD -- "$DEBIAN/" || \ - [ -n "$(git ls-files --others -- "$DEBIAN/")" ]; then - echo "\"$DEBIAN/\" is not clean!" >&2 - exit 1 -fi - -# Check changelog -series=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SDistribution) -if [ "$series" == 'UNRELEASED' ]; then - echo "$DEBIAN/changelog is not closed!" >&2 - exit 1 -fi - -# Load the info about derivative -BACKPORT_SUFFIX= -BACKPORT_NO_SUFFIX= -derivative_conf="$DEBIAN/etc/update.conf" -if [ -f "$derivative_conf" ]; then - # shellcheck disable=SC1090 - . "$derivative_conf" -fi - -# Run the update script used for backport kernels -if [ -n "$BACKPORT_SUFFIX" ] || [ -n "$BACKPORT_NO_SUFFIX" ]; then - update_from_master_script="$DEBIAN/scripts/helpers/copy-files" - if [ ! -x "$update_from_master_script" ]; then - echo "Backport kernel is missing the"\ - "\"$update_from_master_script\" script!"; - exit 1 - fi - # The tree should be clean at this point, since that is enforced at - # the beginning of the script. Because of that, it's safe to git add - # "$DEBIAN/". - run env CHROOT="$CHROOT" "$update_from_master_script" - run git add "$DEBIAN" - # Update configs after the necessary files were copied from - # the base kernel. It's not expected that `fdr updateconfigs` - # will fail at this point, because the base kernel's - # configuration and annotations file are expected to be in a - # correct state. `fdr updateconfigs` should only change a few - # configuration options that depend on the userspace tooling - # version, such as gcc. - if ! chroot_run fakeroot debian/rules clean updateconfigs; then - echo "Failed to update configs. Please review the previous" \ - "rebase operation and \"$update_from_master_script\""; - exit 1 - fi - run git add "$DEBIAN/config" -fi - -# fdr clean should be called after copy-files, that way we can git add -# any changes in "debian./" (`fdr clean` in trusty will -# usually generate changes in "debian./). Also, fdr clean -# removes an ABI that matches the current version in the -# changelog. Since `fdr startnewrelease` requires `fdr clean`, we need -# to call it before getabis. -chroot_run fakeroot debian/rules clean - -# Update ABI -if [ -d "$DEBIAN/abi" ]; then - # The new ABI directory should use the current version in the - # changelog since `fdr startnewrelease` was't called at this - # point yet: - new=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SVersion) - - if [ "$reuse_abi" -ne 0 ]; then - if [ -f "$DEBIAN/abi/version" ]; then - # This is an unversioned ABI directory, so simply update the - # version file - echo "$new" | run tee "$DEBIAN/abi/version" >/dev/null - run git add "$DEBIAN/abi/version" - else - # Get the old ABI directory: - old=$(find "$DEBIAN/abi/" -mindepth 1 -maxdepth 1 -type d | \ - grep -P '/abi/[0-9]+\.[0-9]+\.[0-9]+-[0-9]+\.[0-9]+') - if [ -z "${old}" ] ; then - echo "Failed to find the previous ABI directory." \ - "Please check \"$DEBIAN/abi/\"!" >&2 - exit 1 - elif [ "$(echo "$old" | wc -l)" -gt 1 ]; then - echo "Failed to rename the current ABI directory." \ - "Multiple directories found. Please check \"$DEBIAN/abi/\"!" >&2 - exit 1 - fi - new="$DEBIAN/abi/$new" - # Rename the ABI directory - run git mv "$old" "$new" - fi - else - # Call in-tree getabis: - # Use the single argument form since getabis is now - # updated by cranky fix. - run debian/scripts/misc/getabis "${new}" - # getabis already handles the necessary git add/rm calls. - fi -fi - -# Create the new changelog entry: -run fakeroot debian/rules startnewrelease -run git add "$DEBIAN/changelog" - -# Create the commit -run git commit -s -F debian/commit-templates/newrelease - -# Mimic maint-startnewrelease -[ "$dry_run" -eq 0 ] && \ - hl "\n***** Now please inspect the commit before pushing *****" - -exit 0 diff --git a/debian/scripts/helpers/rebase b/debian/scripts/helpers/rebase deleted file mode 100755 index 925f163f57ac..000000000000 --- a/debian/scripts/helpers/rebase +++ /dev/null @@ -1,159 +0,0 @@ -#!/bin/bash -e -# -# This script is intended as a helper when rebasing from its master branch. -# - -LOCAL_BRANCH= -RELEASE_REPO= -SOURCE_RELEASE_BRANCH= -OWN= - -function out() -{ - local rc="${?}" - trap - EXIT INT TERM HUP - [ "${rc}" -eq 0 ] || echo "Error: Script failed" - exit "${rc}" -} - -trap out EXIT INT TERM HUP - -if [ -f debian/debian.env ]; then - # shellcheck disable=SC1091 - . debian/debian.env -fi - -if [ ! -d "${DEBIAN}" ]; then - echo You must run this script from the top directory of this repository. - exit 1 -fi - -CONF="${DEBIAN}"/etc/update.conf -if [ -f "${CONF}" ]; then - # shellcheck disable=SC1090 - . "${CONF}" -fi - -usage="$0 [-r RELEASE_REPO] [ -b REMOTE_BRANCH ] [-l LOCAL_BRANCH] [-d]"$'\n\n' -usage+="-r RELEASE_REPO Git repository to fetch the reference branch from."$'\n' -usage+="-b REMOTE_BRANCH Remote branch to fetch from."$'\n' -usage+="-l LOCAL_BRANCH Use LOCAL_BRANCH as the reference branch."$'\n' -usage+="-o Rebase against own kernel."$'\n' -usage+="-d,--dry-run Dry run (do not rebase)." - -# Convert long options to short options -for arg in "$@" -do - shift - case "$arg" in - '--dry-run') set -- "$@" '-d' ;; - '--'*) echo "usage: ${usage}"; exit ;; - *) set -- "$@" "$arg" ;; - esac -done - -# -# command line options: -# [-r RELEASE_REPO] - override default git repository. -# [-b REMOTE_BRANCH] - override default remote branch. -# [-l LOCAL_BRANCH] - do not fetch from remote repo, use a local branch. - -while getopts "r:b:l:od" opt; do - case $opt in - r ) RELEASE_REPO="$OPTARG" ;; - b ) SOURCE_RELEASE_BRANCH="$OPTARG" ;; - l ) LOCAL_BRANCH="$OPTARG" ;; - d ) DRY_RUN=1 ;; - o ) OWN=1 ;; - \? ) echo "usage: ${usage}"; exit ;; - esac -done -shift $((OPTIND - 1)) - -# For normal trees the fact that the update.conf file exists means that they are rebase -# kernels. There are some special trees which started with uc20-efi, which have that -# file because they logically depend on another source but do not have the directory -# which DEBIAN_MASTER points to. -IS_REBASE_KERNEL=true -if [ ! -f "$DEBIAN/etc/update.conf" ]; then - IS_REBASE_KERNEL=false -elif [ "$DEBIAN_MASTER" != "" -a ! -d "$DEBIAN_MASTER" ]; then - IS_REBASE_KERNEL=false -fi -if ! $IS_REBASE_KERNEL && [ -z "$OWN" ]; then - echo "This is not a rebase kernel, no rebase should be needed, please report if otherwise" - exit 0 -fi - -if [ "${OWN}" ] ; then - DEBIAN_MASTER="${DEBIAN}" -fi - -if [ "$DEBIAN_MASTER" = "" ]; then - echo "DEBIAN_MASTER should be defined either in ${DEBIAN}/etc/update.conf or the environment" - exit 1 -fi - -if [ -z "${LOCAL_BRANCH}" ]; then - if [ -z "${RELEASE_REPO}" ] || [ -z "${SOURCE_RELEASE_BRANCH}" ]; then - echo Missing update.conf or missing parameters for remote repo and branch. - exit 1 - fi - # - # Fetch the upstream branch. - # - git fetch "${RELEASE_REPO}" - git fetch "${RELEASE_REPO}" "${SOURCE_RELEASE_BRANCH}" - LOCAL_BRANCH=FETCH_HEAD -fi - -# -# Find the most recent tag on given upstream branch, then -# rebase against it. This avoids the case where there have been some -# commits since the last official tag. -# -MASTER_COMMIT=$(git log --pretty=one "${LOCAL_BRANCH}" "${DEBIAN_MASTER}" | \ - awk ' - /Ubuntu-/ { - if (match($0, /UBUNTU: Ubuntu-/)) { - print $1 - exit - } - } - ' -) -# -# Find the current merge point where current branch was based. -# -BASE_COMMIT=$(git log --pretty=one "${DEBIAN_MASTER}" | \ - awk ' - /Ubuntu-/ { - if (match($0, /UBUNTU: Ubuntu-/)) { - print $1 - exit - } - } - ' -) -if [ "${MASTER_COMMIT}" = "${BASE_COMMIT}" ]; then - echo Already up to date. - exit 0 -fi - -if [ -z "${MASTER_COMMIT}" ] || [ -z "${BASE_COMMIT}" ]; then - echo "Could not find either master or base commit." - echo "master commit: ${MASTER_COMMIT}" - echo "base commit: ${BASE_COMMIT}" - exit 1 -fi - -MASTER_VERSION=$(git show --format=%s -s "$MASTER_COMMIT" | sed 's/^UBUNTU: //') -BASE_VERSION=$(git show --format=%s -s "$BASE_COMMIT" | sed 's/^UBUNTU: //') -echo "Rebase still needed between $BASE_VERSION and $MASTER_VERSION." - -if [ "${DRY_RUN}" ]; then - echo "DRY RUN: git rebase --onto ${MASTER_COMMIT} ${BASE_COMMIT}" - exit 0 -fi - -git rebase --onto "${MASTER_COMMIT}" "${BASE_COMMIT}"