github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/release-tools/repack-debian-tarball.sh (about)

     1  #!/bin/sh
     2  #doc# This script is used to re-pack the "orig" tarball from the Debian package
     3  #doc# into a suitable upstream release. There are two changes applied: The Debian
     4  #doc# tarball contains the directory snapd.upstream/ which needs to become
     5  #doc# snapd-$VERSION. The Debian tarball contains the vendor/ directory which must
     6  #doc# be removed from one of those.
     7  #doc#
     8  #doc# Example usage, using tarball from the archive or from the image ppa:
     9  #doc#
    10  #doc# $ wget https://launchpad.net/ubuntu/+archive/primary/+files/snapd_2.31.2.tar.xz
    11  #doc# $ wget https://launchpad.net/~snappy-dev/+archive/ubuntu/image/+files/snapd_2.32.1.tar.xz
    12  #doc#
    13  #doc# $ repack-debian-tarball.sh snapd_2.31.2.tar.xz
    14  #doc#
    15  #doc# This will produce three files that need to be added to the github release page:
    16  #doc#
    17  #doc# - snapd_2.31.2.no-vendor.tar.xz
    18  #doc# - snapd_2.31.2.vendor.tar.xz
    19  #doc# - snapd_2.31.2.only-vendor.xz
    20  
    21  set -ue
    22  
    23  # Get the filename from argv[1]
    24  debian_tarball="${1:-}"
    25  if [ "$debian_tarball" = "" ]; then
    26  	echo "Usage: repack-debian-tarball.sh <snapd-debian-tarball>"
    27  	echo
    28  	grep -e '^#doc#' "$0" | cut -b 7-
    29  	exit 1
    30  fi
    31  
    32  if [ ! -f "$debian_tarball" ]; then
    33  	echo "cannot operate on $debian_tarball, no such file"
    34  	exit 1
    35  fi
    36  
    37  # Extract the upstream version from the filename.
    38  # For example: snapd_2.31.2.tar.xz => 2.32.2
    39  # NOTE: There is no dash (-) in the version because snapd is a native Debian package.
    40  upstream_version="$(echo "$debian_tarball" | cut -d _ -f 2 | sed -e 's/\.tar\..*//')"
    41  
    42  # Scratch directory is where the original tarball is unpacked.
    43  scratch_dir="$(mktemp -d)"
    44  cleanup() {
    45  	rm -rf "$scratch_dir"
    46  }
    47  trap cleanup EXIT
    48  
    49  # Unpack the original with fakeroot (to preserve ownership of files). 
    50  fakeroot tar \
    51  	--auto-compress \
    52  	--extract \
    53  	--file="$debian_tarball" \
    54  	--directory="$scratch_dir/"
    55  
    56  # Top-level directory may be either snappy.upstream or snapd.upstream, because
    57  # of small differences between the release manager's laptop and desktop machines.
    58  if [ -d "$scratch_dir/snapd.upstream" ]; then
    59  	top_dir=snapd.upstream
    60  elif [ -d "$scratch_dir/snappy.upstream" ]; then
    61  	top_dir=snappy.upstream
    62  elif [ -d "$scratch_dir/snapd-${upstream_version}" ]; then
    63  	top_dir=snapd-${upstream_version}
    64  else
    65  	echo "Unexpected contents of given tarball, expected snap{py,d}.upstream/"
    66  	exit 1
    67  fi
    68  
    69  # Pack a fully copy with vendor tree
    70  fakeroot tar \
    71  	--create \
    72  	--transform="s/$top_dir/snapd-$upstream_version/" \
    73  	--file=snapd_"$upstream_version".vendor.tar.xz \
    74  	--auto-compress \
    75  	--directory="$scratch_dir/" "$top_dir"
    76  
    77  # Pack a copy without vendor tree
    78  fakeroot tar \
    79  	--create \
    80  	--transform="s/$top_dir/snapd-$upstream_version/" \
    81  	--exclude='snapd*/vendor/*' \
    82  	--file=snapd_"$upstream_version".no-vendor.tar.xz \
    83  	--auto-compress \
    84  	--directory="$scratch_dir/" "$top_dir"
    85  
    86  # Pack a copy of the vendor tree
    87  fakeroot tar \
    88  	--create \
    89  	--transform="s/$top_dir/snapd-$upstream_version/" \
    90  	--file=snapd_"$upstream_version".only-vendor.tar.xz \
    91  	--auto-compress \
    92  	--directory="$scratch_dir/" "$top_dir"/vendor/