# ---
# ## used by gem2rpm
# :summary: this is a custom summary
# ## used by gem2rpm
# :description: |-
#   this is a custom description
#
#   it can be multiline
# ## used by gem2rpm
# :license: MIT or Ruby
# ## used by gem2rpm and gem_packages
# :version_suffix: -x_y
# ## used by gem2rpm and gem_packages
# :disable_docs: true
# ## used by gem2rpm
# :disable_automatic_rdoc_dep: true
# ## used by gem2rpm
# :preamble: |-
#   BuildRequires: foobar
#   Requires: foobar
# ## used by gem2rpm
# :patches:
#   foo.patch: -p1
#   bar.patch:
# ## used by gem2rpm
# :sources:
# - foo.desktop
# - bar.desktop
# :gem_install_args: '....'
# ## used by gem2rpm
# :pre_install: |-
#   %if 0%{?use_system_libev}
#   export USE_VENDORED_LIBEV="no"
#   %endif
# ## used by gem2rpm
# :post_install: |-
#   # delete custom files here or do other fancy stuff
#   install -D -m 0644 %{S:1} %{buildroot}%{_bindir}/gem2rpm-opensuse
# ## used by gem2rpm
# :testsuite_command: |-
#   (pushd %{buildroot}%{gem_base}/gems/%{mod_full_name} && rake test)
# ## used by gem2rpm
# :filelist: |-
#   /usr/bin/gem2rpm-opensuse
# ## used by gem2rpm
# :scripts:
#   :post: |-
#     /bin/echo foo
# ## used by gem_packages
# :main:
#   :preamble: |-
#     Requires: util-linux
#     Recommends: pwgen
#   :filelist: |-
#     /usr/bin/gem2rpm-opensuse
# ## used by gem_packages
# :custom:
#   apache:
#     :preamble: |-
#       Requires: .....
#     :filelist: |-
#       /etc/apache2/conf.d/passenger.conf
#     :summary: Custom summary is optional
#     :description: |-
#       Custom description is optional
#
#       bar
#     :post: |-
#       /bin/echo foo
#
:name: SUSEConnect
:sources:
  - 'suse-connect-%{version}.gem'
  - '%{name}.5.gz'
  - '%{name}.8.gz'
  - '%{name}.example'

:license: LGPL-2.1
:disable_docs: true
:preamble: |-
  %define rb_build_versions %{rb_default_ruby}
  Requires: rubygem(%{rb_default_ruby_abi}:%{mod_name})
  Requires: coreutils, util-linux, net-tools, hwinfo, zypper, ca-certificates-mozilla
  Conflicts: suseRegister
  %ifarch x86_64
  PreReq: dmidecode
  %endif
:patches:
    url-implies-writeconfig.diff: -p1
:post_install: |-
  install -D -m 644 %_sourcedir/SUSEConnect.5.gz %{buildroot}%_mandir/man5/SUSEConnect.5.gz
  install -D -m 644 %_sourcedir/SUSEConnect.8.gz %{buildroot}%_mandir/man8/SUSEConnect.8.gz
  install -D -m 644 %_sourcedir/SUSEConnect.example %{buildroot}%_sysconfdir/SUSEConnect.example

  ln -s SUSEConnect.8.gz %{buildroot}%_mandir/man8/SUSEConnect-%{version}.8.gz
  mkdir %{buildroot}%{_sbindir}
  ln -s %{_bindir}/SUSEConnect %{buildroot}%{_sbindir}/SUSEConnect
:scripts: |-
  %post
  if [ -s /etc/zypp/credentials.d/NCCcredentials ] && [ ! -e /etc/zypp/credentials.d/SCCcredentials ]; then
      echo "Imported NCC system credentials to /etc/zypp/credentials.d/SCCcredentials"
      cp /etc/zypp/credentials.d/NCCcredentials /etc/zypp/credentials.d/SCCcredentials
  fi

  if [ -s /etc/suseRegister.conf ]; then
      reg_server=$(sed -n "s/^[[:space:]]*url[[:space:]]*=[[:space:]]*\(https\?:\/\/[^\/]*\).*/\1/p" /etc/suseRegister.conf)
      # if we have a custom regserver and no SCC config yet, write it
      if [ -n "$reg_server" ] && [ "$reg_server" != "https://secure-www.novell.com" ] && [ ! -e /etc/SUSEConnect ]; then
          echo "Imported /etc/suseRegister.conf registration server url to /etc/SUSEConnect"
          echo "url: $reg_server" > /etc/SUSEConnect
      fi
  fi
:filelist: |-
  %_mandir/man5/SUSEConnect*
  %_mandir/man8/SUSEConnect*
  %{_sbindir}/SUSEConnect
  %_sysconfdir/SUSEConnect.example

