epm-create_fake 3.69 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#!/bin/sh
#
# Copyright (C) 2017-2018, 2020  Etersoft
# Copyright (C) 2017-2018, 2020  Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

load_helper epm-assure
load_helper epm-repack-rpm


__create_spec() {

echo "%{!?fake_name: %global fake_name $NAME}" >> "$1"
echo "%{!?fake_version: %global fake_version $VERSION}" >> "$1"
echo "%{!?fake_release: %global fake_release $RELEASE}" >> "$1"
if [ -n "$REQUIRES" ]; then
  echo "%{!?fake_requires: %global fake_requires $REQUIRES}" >> "$1"
fi
if [ -n "$PROVIDES" ]; then
  echo "%{!?fake_provides: %global fake_provides $PROVIDES}" >> "$1"
fi

  cat <<EOF >> "$1"
%define _rpmdir $PWD

Name: fake-%{fake_name}

Version: %{fake_version}
Release: %{fake_release}
License: CC0
Group: Other

Summary: Faked provides package

%if "%{?fake_provides}" != ""
Provides: %{fake_provides}
%endif
Provides: %{fake_name}
%if "%{?fake_requires}" != ""
Requires: %{fake_requires}
%endif
BuildArch: noarch

%description
This package is empty. It has been created to put fake entry in rpmdb.

%files
#intentionaly empty

%changelog
#intentionaly empty
EOF
}


Vitaly Lipatov's avatar
Vitaly Lipatov committed
69
__epm_create_fake_help()
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
{
message '

epm create-fake - create package with fake provides and requires. Use follow params:
    --install                - auto install fake package
    --version=*              - set package version (by default version is 0)
    --release=*              - set package release (by default release is 0)
    --requires=*             - set package requires
    --provides=*             - set package provides (by default package provide only it self)

Examples:
    # epm create-fake --install python-somepackage
    # epm create-fake --install --provides="python3dist(somepackage)" python-somepackage
    # epm create-fake --install --requires=python3 --requires=python3-module python-somepackage

'
    return
}

Vitaly Lipatov's avatar
Vitaly Lipatov committed
89
epm_create_fake()
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
{

  VERSION=0
  RELEASE=0
  REQUIRES=""

  for i in "$@"; do
    case $i in
      --version=*)
      VERSION="${i#*=}"
      shift # past argument
      ;;
      --release=*)
      RELEASE="${i#*=}"
      shift # past argument
      ;;
      --requires=*)
      REQUIRES+=" ${i#*=}"
      shift # past argument
      ;;
      --provides=*)
      PROVIDES+=" ${i#*=}"
      shift # past argument
      ;;
      --help|-h)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
115
      __epm_create_fake_help
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
      return
      ;;
      *)
            # unknown option
      ;;
    esac
  done

  NAME=$1

  if [ -z "$NAME" ]; then
    fatal "Error: You have to specify PACKAGE_NAME"
  fi

    # will set RPMBUILD
  __assure_exists_rpmbuild

  HOME="$(mktemp -d --tmpdir=$BIGTMPDIR)" || fatal
  remove_on_exit $HOME
  export HOME
  __create_rpmmacros

  tmpbuilddir=$HOME/$(basename $NAME).tmpdir
  mkdir $tmpbuilddir

  cd $tmpbuilddir/ || fatal

  SPECFILE=${PWD}/${NAME}.spec
  __create_spec "$SPECFILE"

  showcmd $RPMBUILD -bb $SPECFILE
  if [ -n "$verbose" ] ; then
      a='' $RPMBUILD  -bb $SPECFILE || fatal
  else
      a='' $RPMBUILD -bb $SPECFILE >/dev/null || fatal
  fi

   repacked_rpm="$(realpath "$tmpbuilddir/noarch/*.rpm")"
   remove_on_exit "$repacked_rpm"

  if [ -n "$install" ] ; then
    epm install "$repacked_rpm"
  fi
}