github.com/opencontainers/umoci@v0.4.8-0.20240508124516-656e4836fb0d/contrib/pkg/suse/make_spec.sh (about)

     1  #!/bin/bash
     2  # umoci: Umoci Modifies Open Containers' Images
     3  # Copyright (C) 2016-2020 SUSE LLC
     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  set -Eeuo pipefail
    18  
    19  if [ -z "$1" ]; then
    20    cat <<EOF
    21  usage:
    22    ./make_spec.sh PACKAGE [BRANCH]
    23  EOF
    24    exit 1
    25  fi
    26  
    27  cd $(dirname $0)
    28  
    29  YEAR=$(date +%Y)
    30  VERSION=$(cat ../../../VERSION)
    31  COMMIT_UNIX_TIME=$(git show -s --format=%ct)
    32  VERSION="${VERSION%+*}+$(date -d @$COMMIT_UNIX_TIME +%Y%m%d).$(git rev-parse --short HEAD)"
    33  NAME=$1
    34  BRANCH=${2:-master}
    35  SAFE_BRANCH=${BRANCH//\//-}
    36  
    37  cat <<EOF > ${NAME}.spec
    38  #
    39  # spec file for package $NAME
    40  #
    41  # Copyright (C) $YEAR SUSE LLC
    42  #
    43  # All modifications and additions to the file contributed by third parties
    44  # remain the property of their copyright owners, unless otherwise agreed
    45  # upon. The license for this file, and modifications and additions to the
    46  # file, is the same license as for the pristine package itself (unless the
    47  # license for the pristine package is not an Open Source License, in which
    48  # case the license is the MIT License). An "Open Source License" is a
    49  # license that conforms to the Open Source Definition (Version 1.9)
    50  # published by the Open Source Initiative.
    51  
    52  # Please submit bugfixes or comments via http://bugs.opensuse.org/
    53  #
    54  # nodebuginfo
    55  
    56  # Handle all Go arches.
    57  %{!?go_arches: %global go_arches %ix86 x86_64 aarch64 ppc64le}
    58  
    59  # Remove stripping of Go binaries.
    60  %define __arch_install_post export NO_BRP_STRIP_DEBUG=true
    61  
    62  # Project name when using go tooling.
    63  %define project github.com/opencontainers/umoci
    64  
    65  Name:           $NAME
    66  Version:        $VERSION
    67  Release:        0
    68  Summary:        Open Container Image manipulation tool
    69  License:        Apache-2.0
    70  Group:          System/Management
    71  Url:            https://github.com/opencontainers/umoci
    72  Source:         ${SAFE_BRANCH}.tar.gz
    73  %ifarch %{go_arches}
    74  BuildRequires:  go >= 1.6
    75  BuildRequires:  go-go-md2man
    76  %else
    77  BuildRequires:  gcc6-go >= 6.1
    78  %endif
    79  BuildRequires:  fdupes
    80  BuildRoot:      %{_tmppath}/%{name}-%{raw_version}-build
    81  %if 0%{?is_opensuse}
    82  ExcludeArch:    s390x
    83  %endif
    84  
    85  %description
    86  umoci modifies Open Container images.
    87  
    88  umoci is a manipulation tool for OCI images. In particular, it is an
    89  alternative to oci-image-tools provided by the OCI.
    90  
    91  %prep
    92  %setup -q -n $NAME-${SAFE_BRANCH}
    93  
    94  %build
    95  
    96  # We can't use symlinks here because go-list gets confused by symlinks, so we
    97  # have to copy the source to \$HOME/go and then use that as the GOPATH.
    98  export GOPATH=\$HOME/go
    99  mkdir -pv \$HOME/go/src/%{project}
   100  rm -rf \$HOME/go/src/%{project}/*
   101  cp -avr * \$HOME/go/src/%{project}
   102  
   103  export VERSION="\$(cat ./VERSION)"
   104  if [ "\$VERSION" != "%{version}" ]; then
   105    VERSION="%{version}_suse"
   106  fi
   107  
   108  # Build the binary.
   109  make VERSION="\$VERSION" umoci
   110  
   111  # Build the docs if we have go-md2man.
   112  %ifarch %{go_arches}
   113  make doc
   114  %endif
   115  
   116  %install
   117  # Install the binary.
   118  install -D -m 0755 %{name} "%{buildroot}/%{_bindir}/%{name}"
   119  
   120  # Install all of the docs.
   121  %ifarch %{go_arches}
   122  for file in doc/man/*.1; do
   123    install -D -m 0644 \$file "%{buildroot}/%{_mandir}/man1/\$(basename \$file)"
   124  done
   125  %endif
   126  
   127  %fdupes %{buildroot}/%{_prefix}
   128  
   129  %check
   130  export GOPATH=\$HOME/go
   131  hack/test-unit.sh
   132  
   133  %files
   134  %defattr(-,root,root)
   135  %doc COPYING README.md doc/*
   136  %{_bindir}/%{name}
   137  %ifarch %{go_arches}
   138  %{_mandir}/man1/umoci*
   139  %endif
   140  
   141  %changelog
   142  EOF