github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/packaging/pack-source (about)

     1  #!/bin/bash
     2  
     3  set -e
     4  
     5  show_help() {
     6      echo "usage: $(basename "$0") [-v <version>] [-o <output-dir>] [-g] [-h]"
     7      echo "       -v <version>       set version"
     8      echo "       -o <output-dir>    write source packages to this directory"
     9      echo "       -g                 use 'git describe' output as version string"
    10      echo "       -s                 use single source archive instead of no-vendor and"
    11      echo "                          only-vendor packages"
    12      echo "       -h                 show help"
    13      exit 1
    14  }
    15  
    16  if [ ! -e "packaging/$(basename "$0")" ]; then
    17      echo "must be executed at the top of srcdir"
    18      exit 1
    19  fi
    20  
    21  outdir=.
    22  single=0
    23  
    24  while getopts "v:o:gsh" arg; do
    25      case "$arg" in
    26          o)
    27              outdir="$OPTARG"
    28              ;;
    29          v)
    30              version="$OPTARG"
    31              ;;
    32          g)
    33              version="$(git describe | tr '-' '.')"
    34              ;;
    35          s)
    36              single=1
    37              ;;
    38          h|*)
    39              show_help
    40              ;;
    41      esac
    42  done
    43  
    44  if [ -z "$version" ]; then
    45      echo "error: version is unset"
    46      exit 1
    47  fi
    48  
    49  set -x
    50  
    51  tmpdir=$(mktemp -d)
    52  trap 'rm -rf "$tmpdir"' EXIT
    53  
    54  if [[ "$single" == 0 ]]; then
    55      tar -cJf "$tmpdir"/snapd_"$version".no-vendor.tar.xz --exclude='vendor/*' --exclude='.git/*' --transform "s#^#snapd-$version/#" .
    56      tar -cJf "$tmpdir"/snapd_"$version".only-vendor.tar.xz --exclude='.git/*' --transform "s#^#snapd-$version/#" vendor
    57  
    58      mv "$tmpdir"/snapd_"$version".no-vendor.tar.xz "$outdir"/
    59      mv "$tmpdir"/snapd_"$version".only-vendor.tar.xz "$outdir"/
    60  else
    61      tar -cJf "$tmpdir"/snapd_"$version".vendor.tar.xz --exclude='.git/*' --transform "s#^#snapd-$version/#" .
    62      mv "$tmpdir"/snapd_"$version".vendor.tar.xz "$outdir"/
    63  fi