]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
UBUNTU: [Packaging] update helper scripts
authorAndrea Righi <andrea.righi@canonical.com>
Mon, 14 Jun 2021 07:35:08 +0000 (09:35 +0200)
committerAndrea Righi <andrea.righi@canonical.com>
Tue, 7 Dec 2021 06:32:05 +0000 (07:32 +0100)
BugLink: https://bugs.launchpad.net/bugs/1786013
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
debian/scripts/helpers/open

index b62784259bb920ea2f4e900edf8f68c2aaa289d4..a457377a76b7577febdcac65ff4baafb939e31bc 100755 (executable)
@@ -1,6 +1,36 @@
 #!/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]
@@ -56,23 +86,7 @@ while [ "$#" -gt 0 ]; do
        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
-}
+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.
@@ -174,14 +188,28 @@ if [ -d "$DEBIAN/abi" ]; then
        new=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SVersion)
 
        if [ "$reuse_abi" -ne 0 ]; then
-               # Re-use ABI => simply update ABI version
-               abi_version="$DEBIAN/abi/version"
-               if ! [ -f "$abi_version" ]; then
-                       echo "$abi_version ABI version file missing"
-                       exit 1
+               if [ -f "$DEBIAN/abi/version" ]; then
+                       # This is an unversioned ABI directory, so simply update the
+                       # version file
+                       echo "$new" > "$DEBIAN/abi/version"
+                       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
-               echo $new > $abi_version
-               git add $abi_version
        else
                # Call in-tree getabis:
                # Use the single argument form since getabis is now