github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/tools/make_release.sh (about)

     1  #!/bin/bash
     2  
     3  # Copyright 2018 The gVisor Authors.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #   http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  if [[ "$#" -le 2 ]]; then
    18    echo "usage: $0 <private-key> <root> <binaries & packages...>"
    19    echo "The environment variable NIGHTLY may be set to control"
    20    echo "whether the nightly packages are produced or not."
    21    exit 1
    22  fi
    23  
    24  set -xeo pipefail
    25  declare -r private_key="$1"
    26  shift
    27  declare -r root="$1"
    28  shift
    29  declare -a binaries
    30  declare -a pkgs
    31  
    32  # Collect binaries & packages.
    33  for arg in "$@"; do
    34    if [[ "${arg}" == *.deb ]] || [[ "${arg}" == *.changes ]]; then
    35      pkgs+=("${arg}")
    36    else
    37      binaries+=("${arg}")
    38    fi
    39  done
    40  
    41  # install_raw installs raw artifacts.
    42  install_raw() {
    43    for binary in "${binaries[@]}"; do
    44      # Copy the raw file & generate a sha512sum, sorted by architecture.
    45      arch=$(file "${binary}" | cut -d',' -f2 | awk '{print $NF}' | tr '-' '_')
    46      name=$(basename "${binary}")
    47      mkdir -p "${root}/$1/${arch}"
    48      cp -f "${binary}" "${root}/$1/${arch}"
    49      (cd "${root}/$1/${arch}" && sha512sum "${name}" >"${name}.sha512")
    50    done
    51  }
    52  
    53  # install_apt installs an apt repository.
    54  install_apt() {
    55    tools/make_apt.sh "${private_key}" "$1" "${root}" "${pkgs[@]}"
    56  }
    57  
    58  # If nightly, install only nightly artifacts.
    59  if [[ "${NIGHTLY:-false}" == "true" ]]; then
    60    # Install the nightly release.
    61    # https://gvisor.dev/docs/user_guide/install/#nightly
    62    stamp="$(date -Idate)"
    63    install_raw "nightly/latest"
    64    install_raw "nightly/${stamp}"
    65    install_apt "nightly"
    66  else
    67    # Is it a tagged release? Build that.
    68    tags="$(git tag --points-at HEAD 2>/dev/null || true)"
    69    if ! [[ -z "${tags}" ]]; then
    70      # Note that a given commit can match any number of tags. We have to iterate
    71      # through all possible tags and produce associated artifacts.
    72      for tag in ${tags}; do
    73        name=$(echo "${tag}" | cut -d'-' -f2)
    74        base=$(echo "${name}" | cut -d'.' -f1)
    75        # Install the "specific" release. This is the latest release with the
    76        # given date.
    77        # https://gvisor.dev/docs/user_guide/install/#specific-release
    78        install_raw "release/${base}"
    79        # Install the "point release".
    80        # https://gvisor.dev/docs/user_guide/install/#point-release
    81        install_raw "release/${name}"
    82        # Install the latest release.
    83        # https://gvisor.dev/docs/user_guide/install/#latest-release
    84        install_raw "release/latest"
    85  
    86        install_apt "release"
    87        install_apt "${base}"
    88      done
    89    else
    90      # Otherwise, assume it is a raw master commit.
    91      # https://gvisor.dev/docs/user_guide/install/#head
    92      install_raw "master/latest"
    93      install_apt "master"
    94    fi
    95  fi