1- #! /bin/bash
1+ #! /usr/ bin/env bash
22#
33# Copyright 2018, 2020 Delphix
44#
@@ -234,20 +234,24 @@ function kernel_update_upstream() {
234234 # version and the ABI num that we got above.
235235 #
236236 # Note that "generic" (used mainly ESX) is a special
237- # case as we are currently using the HWE kernel image.
237+ # case on bionic where we are using the HWE kernel image.
238238 #
239239 local tag_prefix_flavour
240- if [[ " ${platform} " == generic ]] &&
241- [[ " $UBUNTU_DISTRIBUTION " == bionic ]]; then
242- tag_prefix_flavour=" Ubuntu-hwe"
243- elif [[ " ${platform} " == aws ]] ||
244- [[ " ${platform} " == azure ]] ||
245- [[ " ${platform} " == gcp ]] ||
246- [[ " ${platform} " == oracle ]]; then
240+ case " ${platform} " in
241+ generic)
242+ if [[ " $UBUNTU_DISTRIBUTION " == bionic ]]; then
243+ tag_prefix_flavour=" Ubuntu-hwe"
244+ else
245+ tag_prefix_flavour=" Ubuntu"
246+ fi
247+ ;;
248+ aws | azure | gcp | oracle)
247249 tag_prefix_flavour=" Ubuntu-${platform} "
248- else
250+ ;;
251+ * )
249252 die " assertion: unexpected platform: ${platform} "
250- fi
253+ ;;
254+ esac
251255
252256 local tag_prefix kvers_major kvers_minor short_kvers
253257 kvers_major=$( echo " ${kernel_version} " | cut -d ' .' -f 1)
@@ -282,6 +286,26 @@ function kernel_update_upstream() {
282286 #
283287 local upstream_tag_info
284288 upstream_tag_info=$( git ls-remote --tags --ref upstream | grep " ${tag_prefix} " | tail -n 1)
289+
290+ if [[ -z " ${upstream_tag_info} " ]]; then
291+ echo " tag with prefix ${tag_prefix} not found."
292+ tag_prefix=" ${tag_prefix_flavour} -${kernel_version} -${abinum} "
293+ #
294+ # Canonical has 2 ways of naming their tags:
295+ # - Ubuntu-gcp-5.4.0-1046.49
296+ # - Ubuntu-gcp-5.4-5.4.0-1046.49_18.04.1
297+ #
298+ # For a given kernel version and a given distribution, only one
299+ # naming scheme is being used. When two distributions (such
300+ # as 20.04 and 18.04) use the same major kernel version,
301+ # Canonical first applies the patches to one distribution and
302+ # then creates a base tag. It then backports those changes to
303+ # the older distribution, and then creates a longer tag name.
304+ #
305+ echo " trying tag prefix: ${tag_prefix} ."
306+ upstream_tag_info=$( git ls-remote --tags --ref upstream | grep " ${tag_prefix} " | tail -n 1)
307+ fi
308+
285309 [[ -z " ${upstream_tag_info} " ]] && die " could not find upstream tag for tag prefix: ${tag_prefix} "
286310
287311 local upstream_tag
@@ -347,17 +371,12 @@ function kernel_merge_with_upstream() {
347371
348372 check_git_ref " $upstream_ref " " $repo_ref "
349373
350- if git merge-base --is-ancestor " $upstream_ref " " $repo_ref " ; then
351- echo " NOTE: $PACKAGE is already up-to-date with upstream."
352- return 0
353- fi
354-
355374 #
356375 # Ensure that there is a commit marking the start of
357376 # the Delphix set of patches. Then get the hash of
358377 # the commit right before it.
359378 #
360- local dlpx_patch_end dlpx_patch_start current_ubuntu_commit
379+ local dlpx_patch_end dlpx_patch_start current_ubuntu_commit upstream_head_commit
361380 dlpx_patch_start=$( git log --pretty=oneline repo-HEAD | grep @@DELPHIX_PATCHSET_START@@ | awk ' { print $1 }' )
362381 [[ -z " ${dlpx_patch_start} " ]] && die " could not find DELPHIX_PATCHSET_START"
363382 [[ $( wc -l <<< " ${dlpx_patch_start}" ) != 1 ]] && die " multiple DELPHIX_PATCHSET_START commits - ${dlpx_patch_start} "
@@ -366,6 +385,13 @@ function kernel_merge_with_upstream() {
366385 dlpx_patch_end=$( git rev-parse repo-HEAD)
367386 [[ -z " ${dlpx_patch_end} " ]] && die " could not find repo-HEAD's head commit"
368387
388+ upstream_head_commit=" $( git rev-parse " $upstream_ref " ) "
389+
390+ if [[ " $current_ubuntu_commit " == " $upstream_head_commit " ]]; then
391+ echo " NOTE: $PACKAGE is already up-to-date with upstream."
392+ return 0
393+ fi
394+
369395 #
370396 # We rebase all the Delphix commits on top of the new upstream-HEAD
371397 # by using git cherry-pick. Note that we also save the previous
0 commit comments